Project

General

Profile

Download (59.9 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/**
3
 * @file
4
 * Description theming functions.
5
 *
6
 * @copyright
7
 *   (C) 2007-2012 EDIT
8
 *   European Distributed Institute of Taxonomy
9
 *   http://www.e-taxonomy.eu
10
 *
11
 *   The contents of this module are subject to the Mozilla
12
 *   Public License Version 1.1.
13
 * @see http://www.mozilla.org/MPL/MPL-1.1.html
14
 */
15

    
16
/**
17
 * @todo Please document this function.
18
 * @see http://drupal.org/node/1354
19
 */
20
function theme_cdm_feature_nodesTOC($variables) {
21
  $featureNodes = $variables['featureNodes'];
22
  $out = '';
23
  $out .= '<ul>';
24

    
25
  foreach ($featureNodes as $node) {
26

    
27
    if (hasFeatureNodeDescriptionElements($node)) {
28

    
29
      $featureRepresentation = isset($node->feature->representation_L10n) ? $node->feature->representation_L10n : 'Feature';
30
      // HACK to implement images for taxa, should be removed.
31
      if ($node->feature->uuid != UUID_IMAGE) {
32
        $out .= '<li>' . l(t(theme('cdm_feature_name', array('feature_name' => $featureRepresentation))), $_GET['q'], array(
33
         'attributes' => array('class' => array('toc')), 'fragment' => generalizeString($featureRepresentation))) . '</li>';
34
      }
35
    }
36
  }
37

    
38
  $out .= '</ul>';
39
  return $out;
40
}
41

    
42
/**
43
 * Theme function to alter the feature representation.
44
 *
45
 * It is highly qeutionalbe if this function should be completely removed.
46
 * If a feature needs a different representation this should be edited directly
47
 * in the cdm data but it shoud not be tweeked like this in the portal.
48
 *
49
 * Used in:
50
 *  - theme_cdm_feature_nodesTOC()
51
 *  - theme_cdm_feature_nodes()
52
 *  - theme_cdm_media_mime_application()
53
 *  - theme_cdm_media_mime_text()
54
 *
55
 * TODO delete this function? (a.kohlbecker feb 2013)
56
 *
57
 */
58
function theme_cdm_feature_name($variables) {
59
  $feature_name = $variables['feature_name'];
60
  // TODO replace by using translations ?
61
  return t($feature_name);
62
}
63

    
64
/**
65
 * Returns HTML for a taxon profile from the $mergedFeatureNodes of a given $taxon.
66
 *
67
 * The taxon profile consists of description elements which are ordered by the
68
 * structure defined by specific FeatureTree. The chosen FeatureTree is merged
69
 * with the list of desctiprion elements prior to using this method.
70
 *
71
 * The merged nodes can be obtained by making use of the
72
 * function cdm_ws_descriptions_by_featuretree().
73
 *
74
 * @see cdm_ws_descriptions_by_featuretree()
75
 *
76
 * @param array $variables
77
 *   An associative array containing:
78
 *   - mergedFeatureNodes
79
 *   -taxon
80
 *
81
 * @ingroup themeable
82
 */
83
function theme_cdm_feature_nodes($variables) {
84

    
85
  $mergedFeatureNodes = $variables['mergedFeatureNodes'];
86
  $taxon = $variables['taxon'];
87
  $out = '';
88

    
89
  RenderHints::pushToRenderStack('feature_nodes');
90

    
91
  $gallery_settings = getGallerySettings(CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME);
92

    
93
  // Creating an array to place the description elements in.
94
  foreach ($mergedFeatureNodes as $node) {
95

    
96
    if (hasFeatureNodeDescriptionElements($node)) {
97

    
98
      $featureRepresentation = isset($node->feature->representation_L10n) ? $node->feature->representation_L10n : 'Feature';
99
      $block = new stdclass(); // Empty object.
100
      $block->module = 'cdm_dataportal';
101
      $media_list = array();
102

    
103
      if (true || $node->feature->uuid != UUID_IMAGE) {
104

    
105
        $block->delta = generalizeString($featureRepresentation);
106
        $block->subject = '<span class="' . html_class_atttibute_ref($node->feature) . '">' . theme('cdm_feature_name', array('feature_name' => $featureRepresentation)) . '</span>';
107
        $block->module = "cdm_dataportal-feature";
108
        $block->content = '';
109

    
110
        /*
111
         * Content/DISTRIBUTION.
112
         */
113
        if ($node->feature->uuid == UUID_DISTRIBUTION) {
114

    
115
          $node->descriptionElements = cdm_description_elements_prefer_computed($node->descriptionElements);
116

    
117
          if (variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0)) {
118
            $distributionTextDataList = array();
119
            $distributionElementsList = array();
120

    
121
            foreach ($node->descriptionElements as $descriptionElement) {
122
              if ($descriptionElement->class == "TextData") {
123
                $distributionTextDataList[] = $descriptionElement;
124
              }
125
              else {
126
                $distributionElementsList[] = $descriptionElement;
127
              }
128
            }
129

    
130

    
131
            if (count($distributionTextDataList) > 0) {
132
              $node->descriptionElements = $distributionElementsList;
133
              $block->content .= theme('cdm_descriptionElements', array(
134
                'descriptionElements' => $distributionTextDataList,
135
                'featureUuid' => $node->feature->uuid,
136
                'taxon_uuid' => $taxon->uuid,
137
              ));
138
            }
139
          }
140

    
141
          // Display cdm distribution map TODO this is a HACK to a proper
142
          // generic implementation?
143
          $block->content .= theme('cdm_distribution_map', array('taxon' => $taxon));
144
          $block->content .= theme('cdm_descriptionElements', array(
145
            'descriptionElements' => $node->descriptionElements,
146
            'featureUuid' => $node->feature->uuid,
147
            'taxon_uuid' => $taxon->uuid,
148
          ));
149

    
150
        }
151

    
152
        /*
153
         * Content/COMMON_NAME.
154
         */
155
        elseif ($node->feature->uuid == UUID_COMMON_NAME) {
156
          // TODO why is theme_cdm_descriptionElement_CommonTaxonName not
157
          // beeing used???
158
         $block->content .= theme('cdm_common_names', array('elements' => $node->descriptionElements));
159
          /*
160
          }else if($node->feature->uuid == UUID_IMAGE_SOURCES) {
161
          $block->content .= theme('cdm_image_sources',
162
          $node->descriptionElements);
163
          */
164
        }
165

    
166
        /*
167
         * Content/ALL OTHER FEATURES.
168
         */
169
        else {
170
          if (isset($node->descriptionElements)) {
171
            $taxon_uuid = NULL;
172
            if(isset($taxon) ) {
173
              $taxon_uuid = $taxon->uuid;
174
            }
175
            $block->content .= theme('cdm_descriptionElements', array(
176
              'descriptionElements' => $node->descriptionElements,
177
              'featureUuid' => $node->feature->uuid,
178
              'taxon_uuid' => $taxon_uuid,
179
            ));
180
          }
181

    
182
//           Content/ALL OTHER FEATURES/Subordinate Features
183
//           subordinate features are printed inline in one floating text,
184
//           it is expected hat supordinate features can "contain" TextData,
185
//           Qualitative- and Qualitative- DescriptioneElements
186
          if (isset($node->children[0])) {
187

    
188
            // TODO support more than one level of children.
189
            // can this be solved by resursively calling this very function?
190
            // @see http://dev.e-taxonomy.eu/trac/ticket/2393
191
            $text = '';
192
            foreach ($node->children as $child) {
193

    
194
              if (isset($child->descriptionElements) && is_array($child->descriptionElements)) {
195
                foreach ($child->descriptionElements as $element) {
196

    
197
                  if (is_array($element->media)) {
198
                    // Append media of supordinate elements to list of main
199
                    // feature.
200
                    $media_list = array_merge($media_list, $element->media);
201
                  }
202

    
203
                  switch ($element->class) {
204
                    case 'TextData':
205
                      // TODO use theme_cdm_descriptionElementTextData()
206
                      $out_child_elements = str_replace("\n", "<br/>", $element->multilanguageText_L10n->text);
207
                      $out_child_elements = str_replace($child->feature->titleCache, '<em>' . $child->feature->representation_L10n . '</em>', $out_child_elements);
208
                      break;
209
                    case 'CategoricalData':
210
                      $out_child_elements  = '<em>' . $child->feature->representation_L10n . '</em> '
211
                        . theme('cdm_descriptionElement_CategoricalData', array('element' => $element));
212
                      break;
213
                    case 'QuantitativeData':
214
                      $out_child_elements = '<em>' . $child->feature->representation_L10n . '</em> '
215
                        . theme('cdm_descriptionElement_QuantitativeData', array('element' => $element));
216

    
217
                  }
218

    
219
                }
220
                $text .= " " . $out_child_elements;
221
                $out_child_elements = '';
222
              }
223
            }
224
            $block->content .= $text;
225
          }
226
        }
227

    
228
        /*
229
         * Media/ALL FEATURES.
230
         */
231
        if (isset($node->descriptionElements)) {
232
          $media_list = array_merge($media_list, cdm_dataportal_media_from_descriptionElements($node->descriptionElements));
233
        }
234
        $captionElements = array('title', 'rights');
235
        $gallery = '';
236
        if (isset($gallery_settings['cdm_dataportal_media_maxextend']) && isset($gallery_settings['cdm_dataportal_media_cols'])) {
237
          $gallery = theme('cdm_media_gallerie', array(
238
            'mediaList' => $media_list,
239
            'galleryName' => CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME . '_' . $node->feature->uuid,
240
            'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
241
            'cols' => $gallery_settings['cdm_dataportal_media_cols'],
242
            'captionElements' => $captionElements,
243
          ));
244
        }
245
        $block->content .= $gallery;
246
        $block->content .= theme('cdm_footnotes', array('footnoteListKey' => $node->feature->uuid));
247
        $block->content .= theme('cdm_annotation_footnotes', array('footnoteListKey' => $node->feature->uuid));
248

    
249
        // Add anchor to subject.
250
        $block->subject = '<a name="' . $block->delta . '"></a>' . $block->subject;
251

    
252
        // In D6: $out .= theme('block', $block);
253
        // Comment @WA @TODO check if need to set a region, and which one.
254
        $block->region = FALSE;
255
        $out .= theme('block', array('elements' => array(
256
          '#block' => $block,
257
          '#children' => $block->content,
258
        )));
259
      }
260
    }
261
  }
262
  RenderHints::popFromRenderStack();
263
  return $out;
264
}
265

    
266
/**
267
 * @todo Please document this function.
268
 * @see http://drupal.org/node/1354
269
 */
270
function theme_FeatureTree_hierarchy($variables) {
271

    
272
  $FeatureTreeUuid = $variables['FeatureTreeUuid'];
273
  if (!is_uuid($FeatureTreeUuid)) {
274
    return;
275
  }
276

    
277
  $out = '';
278
  $featureTree = cdm_ws_get(CDM_WS_FEATURETREE, array(
279
    $FeatureTreeUuid,
280
  ));
281

    
282
  if (isset($featureTree) && isset($featureTree->root)) {
283
    $out = '<ul class="' . $featureTree->class . '">';
284
    $out .= theme('FeatureTree_hierarchy_children', array('node' => $featureTree->root));
285
    $out .= '</ul>';
286
  }
287
  return $out;
288
}
289

    
290
/**
291
 * @todo Please document this function.
292
 * @see http://drupal.org/node/1354
293
 */
294
function theme_FeatureTree_hierarchy_children($variables) {
295

    
296
  $node = $variables['node'];
297
  $out = '';
298
  if (isset($node->children)) {
299

    
300
    foreach ($node->children as $childNode) {
301
      $out .= '<li>' . check_plain($childNode->feature->representation_L10n);
302
      if (isset($childNode->children) && count($childNode->children) > 0) {
303
        $out .= '<ul>' . theme('FeatureTree_hierarchy_children', array('node' => $childNode)) . '</ul>';
304
      }
305
      $out .= '</li>';
306
    }
307
  }
308
  return $out;
309
}
310

    
311
/**
312
 * Returns HTML for the texts in a description $elementArray.
313
 *
314
 * Joins the texts in $elementArray and encloses with a HTML tag.
315
 *
316
 * @param array $variables
317
 *   An associative array containing:
318
 *   - elementArray
319
 *   - feature: The feature to which the elements given in $elementArray are
320
 *     belonging to.
321
 *   - glue: Defaults to empty string.
322
 *   - sortArray: Whether to sort the $elementArray alphabetically.
323
 *   - enclosingHtml
324
 *
325
 * @ingroup themeable
326
 */
327
function theme_cdm_descriptionElementArray($variables) {
328
  $elementArray = $variables['elementArray'];
329

    
330
  $feature = $variables['feature'];
331
  $glue = $variables['glue'];
332
  $sortArray = $variables['sortArray'];
333
  $enclosingHtml = $variables['enclosingHtml'];
334
  $out = '<' . $enclosingHtml . ' class="description" id="' . $feature->representation_L10n . '">';
335

    
336
  if ($sortArray) {
337
    sort($elementArray);
338
  }
339

    
340
  $out .= join($elementArray, $glue);
341

    
342
  $out .= '</' . $enclosingHtml . '>';
343
  return $out;
344
}
345

    
346
/**
347
 * @todo Please document this function.
348
 * @see http://drupal.org/node/1354
349
 */
350
function theme_cdm_descriptionElement_CommonTaxonName($variables) {
351
  $element = $variables['element'];
352
  $out = '<span class="' . html_class_atttibute_ref($element) . '">' . $element->language->representation_L10n . ' (' . $element->area->titleCache . '): ' . $element->name . '</span>';
353
  return $out;
354
}
355

    
356
/**
357
* @todo Please document this function.
358
* @see http://drupal.org/node/1354
359
*/
360
function theme_cdm_descriptionElement_CategoricalData($variables) {
361
  $element = $variables['element'];
362

    
363
  $state_data_strings = array();
364
  if (isset($element->states)) {
365
    foreach ($element->states as $stateData) {
366

    
367
      $state  = NULL;
368

    
369
      if(isset($stateData->state)){
370
        $state = cdm_term_representation($stateData->state);
371
      }
372

    
373
      if (isset($stateData->modifyingText_L10n)) {
374
        $state = ' ' . $stateData->modifyingText_L10n;
375
      }
376

    
377
      $modifiers_strings = cdm_modifers_representations($stateData);
378

    
379
      $state_data_strings[] = $state . ($modifiers_strings ? ' ' . $modifiers_strings : '');
380

    
381
      // FIXME render sources
382

    
383
    }
384
  }
385
  $out = '<span class="' . html_class_atttibute_ref($element) . '">' . implode(', ', $state_data_strings) . '</span>';
386
  return $out;
387
}
388

    
389
function theme_cdm_descriptionElement_QuantitativeData($variables) {
390
  /*
391
   * - statisticalValues
392
   *   - value
393
   *   - modifiers
394
   *   - type
395
   * - unit->representation_L10n
396
   * - modifyingText
397
   * - modifiers
398
   * - sources
399
   */
400
  $element = $variables['element'];
401

    
402
  $out = '';
403

    
404
  $type_representation = NULL;
405
  $modifiers_strings = array();
406

    
407

    
408
  if (isset($element->statisticalValues)) {
409
    $value_array = array();
410
    foreach ($element->statisticalValues as $val) {
411
      if (isset($val->value)) {
412
        $value_array[] = $val->value;
413
      }
414
    }
415

    
416
    $out .= implode($value_array, ', ');
417
  }
418

    
419
  if (isset($element->unit)) {
420
    $out .= ' '. cdm_term_representation($element->unit);
421
  }
422

    
423
  if (isset($element->statisticalValues->modifyingText_L10n)) {
424
    $out .=  ' ' . $element->statisticalValues->modifyingText_L10n;
425
  }
426
  $modifers_string = cdm_modifers_representations($element->statisticalValues);
427
  $out .= ($modifers_string ? ' ' . cdm_modifers_representations($element->statisticalValues) : '');
428

    
429
  // FIXME render sources
430

    
431
  return $out;
432

    
433
}
434

    
435
/**
436
 * Returns HTML for citations textdata elements.
437
 *
438
 * TODO: assign a new name to the function? Because it is used for the citations
439
 * textdata elements and not for all text data description elements.
440
 *
441
 * @param array $variables
442
 *   An associative array containing:
443
 *   - element: The description element which contains the text information.
444
 *   - asListElement: A boolean which determines whether the citations should
445
 *     be rendered as a list or not.
446
 *   - feature_uuid
447
 *
448
 * @ingroup themeable
449
 */
450
function theme_cdm_descriptionElementTextData($variables) {
451

    
452
  $element = $variables['element'];
453
  $asListElement = $variables['asListElement'];
454
  $feature_uuid = $variables['feature_uuid'];
455

    
456
  $description = '';
457
  if (isset($element->multilanguageText_L10n->text)) {
458
    $description = str_replace("\n", "<br/>", $element->multilanguageText_L10n->text);
459
  }
460
  $sourceRefs = '';
461
  $result = array();
462
  $out = '';
463
  $res_author = '';
464
  $res_date = '';
465
  if (isset($element->sources) && is_array($element->sources) && count($element->sources) > 0) {
466
    foreach ($element->sources as $source) {
467
      $referenceCitation = theme('cdm_OriginalSource', array('source' => $source));
468
      if ($description && strlen($description) > 0 && $referenceCitation) {
469
        $sourceRefs .= ' (' . $referenceCitation . ')';
470
      }
471
      elseif ($referenceCitation) {
472
        $sourceRefs = $referenceCitation;
473
      }
474

    
475
      if (strlen($sourceRefs) > 0) {
476
        $sourceRefs = '<span class="sources">' . $sourceRefs . '</span>';
477
      }
478
      $name_used_in_source_link_to_show = '';
479
      // Do a link to name page.
480
      if (isset($source->nameUsedInSource->uuid) && isset($source->nameUsedInSource->titleCache)) {
481
        $name_used_in_source_link_to_show = l($source->nameUsedInSource->titleCache, path_to_name($source->nameUsedInSource->uuid), array(
482
          'attributes' => array(),
483
          'absolute' => TRUE,
484
          'html' => TRUE,
485
        ));
486
      }
487
      // Show a text without link.
488
      elseif (isset($source->nameUsedInSource->originalNameString) && strlen($source->nameUsedInSource->originalNameString) > 0) {
489
        $name_used_in_source_link_to_show = $source->nameUsedInSource->originalNameString;
490
      }
491

    
492
      if ($asListElement) {
493

    
494
       $out = '<li class="descriptionText DescriptionElement">';
495
        // Adding ":" if necessary.
496
        if (!empty($name_used_in_source_link_to_show)) {
497
          if ( (!empty($description)|| !empty($sourceRefs)) && $feature_uuid != UUID_CHROMOSOMES_NUMBERS) {
498
            $out .= $name_used_in_source_link_to_show . ': ';
499
          } else {
500
            $out .= $name_used_in_source_link_to_show . ' ';
501
          }
502
        }
503
        $out .= $description . $sourceRefs . theme('cdm_annotations_as_footnotekeys', array('cdmBase_list' => $element, 'footnote_list_key' => $feature_uuid)) . '</li>';
504
      }
505
      else {
506
        if ($name_used_in_source_link_to_show) {
507
          $name_used_in_source_link_to_show = ' (name in source: ' . $name_used_in_source_link_to_show . ')';
508
        }
509

    
510
        $out = '<span class="DescriptionElement DescriptionElement-' . $element->class . '">' . $description . $sourceRefs . $name_used_in_source_link_to_show . '</span>';
511
      }
512
    }
513
  }
514
  else {
515
    // If no sources, print the description.
516
    $out = $description;
517
  }
518
  return $out;
519
}
520

    
521
/**
522
 * @todo Please document this function.
523
 * @see http://drupal.org/node/1354
524
 */
525
function theme_cdm_common_names($variables) {
526
  $elements = $variables['elements'];
527
  $text_data_out = '';
528
  $common_name_out = '';
529
  $separator = ',';
530
  $textData_commonNames = array();
531

    
532
  if (is_array($elements)) {
533
    foreach ($elements as $element) {
534
      if ($element->class == 'CommonTaxonName') {
535

    
536
        // common name without a language or area, should not happen but is possible
537
        $language_area_key = '';
538
        if (isset($element->language->representation_L10n)) {
539
          $language_area_key .= '<b>' . $element->language->representation_L10n . '</b>';
540
        }
541
        if(isset($element->area->titleCache) && strlen($element->area->titleCache) > 0){
542
          $language_area_key .= ($language_area_key ? ' '  : '') . '(' . $element->area->titleCache . ')';
543
        }
544

    
545
        if(isset($common_names[$language_area_key][$element->name])) {
546
          // same name already exists for language and areae combination, se we merge the description elements
547
          cdm_merge_description_elements($common_names[$language_area_key][$element->name], $element);
548
        } else{
549
          // otherwise add as new entry
550
          $common_names[$language_area_key][$element->name] = $element;
551
        }
552

    
553
      }
554
      elseif ($element->class == 'TextData') {
555
        $textData_commonNames[] = $element;
556
      }
557
    }
558
  }
559
  // Handling common names.
560
  if (isset($common_names) && count($common_names) > 0) {
561
    // Sorting the array based on the key (language, + area if set).
562
    // Comment @WA there are common names without a language, so this sorting
563
    // can give strange results.
564
    ksort($common_names);
565

    
566
    // Creating the output to be render by Drupal.
567
    foreach ($common_names as $key => $elements) {
568
      ksort($elements); // sort names alphabetically
569
      $rendered_element_list = '';
570
      foreach ($elements as $element) {
571
        $sourcesFootnoteKeyList = '';
572
        // Adding footnotes sources.
573
        foreach ($element->sources as $source) {
574
          if (_is_original_source_type($source)) {
575
            $_fkey = FootnoteManager::addNewFootnote(UUID_COMMON_NAME, theme('cdm_OriginalSource', array('source' => $source, 'doLink' => FALSE)));
576
            $sourcesFootnoteKeyList .= theme('cdm_footnote_key', array('footnoteKey' => $_fkey, 'separator' => ($sourcesFootnoteKeyList ? $separator : '')));
577
          }
578
        }
579
        if ($element->name) {
580
          $rendered_element_list .= '<span class="' . html_class_atttibute_ref($element) . '">' . (strlen($rendered_element_list) > 0 ? ', ' : '') . $element->name . $sourcesFootnoteKeyList . '</span>';
581
        }
582
      }
583
      if ($key) {
584
        $common_name_out .= (strlen($common_name_out) > 0 ? '; ' : '') . $key . ': ' . $rendered_element_list;
585
      }
586
      else {
587
        $common_name_out .= (strlen($common_name_out) > 0 ? '; ' : '') . $rendered_element_list;
588
      }
589
    }
590
  }
591
  // Handling commons names as text data.
592
  foreach ($textData_commonNames as $text_data_element) {
593
    $text_data_out .= theme('cdm_descriptionElementTextData', array(
594
      'element' => $text_data_element,
595
      'asListElement' => TRUE,
596
      'feature_uuid' => $text_data_element->feature->uuid,
597
    ));
598
  }
599

    
600
  $common_name_out = "<div class=common_names_as_common_names> $common_name_out </div>";
601
  $out_array[] = $text_data_out;
602
  $common_name_out_text_data = '<div class=common_names_as_text_data>' . theme('cdm_descriptionElementArray', array('elementArray' => $out_array, 'feature' => $element->feature)) . '</div>';
603

    
604
  return $common_name_out . $common_name_out_text_data;
605
  /*
606
  return $common_name_out . theme('cdm_descriptionElementArray', $out_array,
607
  $element->feature);
608
  return "<div class=common_names> $common_name_out
609
  $common_name_out_text_data";
610
  */
611
}
612

    
613
/**
614
 * Return HTML for a list of description elements.
615
 *
616
 * Usually these are of a specific feature type.
617
 *
618
 * @param array $variables
619
 *   An associative array containing:
620
 *   - array of descriptionElements which belong to the same feature.
621
 *     These descriptions elements of a Description must be ordered by the chosen feature tree by
622
 *     calling the function _mergeFeatureTreeDescriptions().
623
 *     @see _mergeFeatureTreeDescriptions()
624
 *   - featureUuid: currently unused, accoding code disabled
625
 *   - taxon_uuid: only used for ordered dditributions (will be removed!)
626
 *
627
 * @ingroup themeable
628
 */
629
function theme_cdm_descriptionElements($variables) {
630

    
631
  $descriptionElements = $variables['descriptionElements'];
632
  $featureUuid = $variables['featureUuid'];
633
  $taxon_uuid = $variables['taxon_uuid'];
634
  $outArray = array();
635

    
636
  /*
637
  $userDefined = mixed_variable_get(LAYOUT_SETTING_PREFIX . $featureUuid, FEATURE_TREE_LAYOUT_DEFAULTS);
638
  if(variable_get('distribution_sort',
639
      'NO_SORT') != 'NO_SORT'){
640
      $glue = '';
641
      $enclosingTag = 'dl';
642
      $entryEnclosingTag = NULL;
643
  } else if($userDefined &&
644
      $userDefined['enabled']){
645
    $glue = $userDefined['glue'];
646
    $enclosingTag =  $userDefined['enclosingTag'];
647
    $entryEnclosingTag = $userDefined['entryEnclosingTag'];
648
  } else { // TODO remove once  LAYOUT_SETTING_PREFIX-{uuid} setting are configured to work for all portals(selenium test still missing!!!)
649
    $glue = ''; $enclosingTag = 'ul';
650
    $entryEnclosingTag = NULL ;
651
  }
652
  */
653

    
654

    
655
  if (variable_get('distribution_sort', 'NO_SORT') != 'NO_SORT') {
656
    $glue = '';
657
    $enclosingTag = 'dl';
658
  }
659
  else {
660
    $glue = '';
661
    $enclosingTag = 'ul';
662
  }
663

    
664
  $sortOutArray = FALSE;
665
  $distributionElements = array();
666

    
667
  RenderHints::pushToRenderStack('cdm_descriptionElements');
668

    
669
  // Avoiding warning box in drupal for flora malesiana.
670
  if (is_array($descriptionElements)) {
671
    foreach ($descriptionElements as $descriptionElement) {
672

    
673
      // --- DISTRIBUTION ---- //
674
      if ($descriptionElement->feature->uuid == UUID_DISTRIBUTION) {
675
        if ($descriptionElement->class == 'Distribution' && is_object($descriptionElement->area)) {
676
          $sortKey = $descriptionElement->area->representation_L10n;
677
          $distributionElements[$sortKey] = $descriptionElement;
678
        }
679
        elseif ($descriptionElement->class == 'TextData') {
680
          $asListElement = FALSE;
681
          $repr = theme('cdm_descriptionElementTextData', array(
682
            'element' => $descriptionElement,
683
            'asListElement' => $asListElement,
684
            'feature_uuid' => $descriptionElement->feature->uuid,
685
          ));
686

    
687
          if (!array_search($repr, $outArray)) {
688
            $outArray[] = $repr;
689
            // TODO HINT: sorting in theme_cdm_descriptionElementArray will
690
            // not work since this array contains html attributes with uuids
691
            // !!!!
692
            $sortOutArray = TRUE;
693
            $glue = '<br/> ';
694
            $enclosingTag = 'p';
695
          }
696
        }
697
      }
698

    
699
      // --- IMAGE_SOURCES --- //
700
      elseif ($descriptionElement->feature->uuid == UUID_IMAGE_SOURCES) {
701
        $image_sources[] = $descriptionElement;
702
      }
703
      // --- USE TEXTDATA --- //
704
      elseif ($descriptionElement->feature->uuid == UUID_USE) {
705
        // Do nothing to avoid rendering.
706
      } else {
707
        /* decide based on the description element class
708
         *
709
         * TODO provide api_hook as extension point for this
710
         */
711
        switch ($descriptionElement->class) {
712
          case 'TextData':
713
            $asListElement = TRUE;
714
            $outArray[] = theme('cdm_descriptionElementTextData', array(
715
              'element' => $descriptionElement,
716
              'asListElement' => $asListElement,
717
              'feature_uuid' => $descriptionElement->feature->uuid,
718
            ));
719
            break;
720
          case 'CommonTaxonName':
721
            $outArray[] = theme('cdm_descriptionElement_CommonTaxonName', array('element' => $descriptionElement));
722
          break;
723
          case 'CategoricalData':
724
            $outArray[] = theme('cdm_descriptionElement_CategoricalData', array('element' => $descriptionElement));
725
            break;
726
          case 'QuantitativeData':
727
            $outArray[] = theme('cdm_descriptionElement_QuantitativeData', array('element' => $descriptionElement));
728
            break;
729
          case 'Uses':
730
          /* IGNORE Uses classes, these are handled completely in theme_cdm_UseDescription */
731
          break;
732
        default:
733
        $outArray[] = '<li>No method for rendering unknown description class: ' . $descriptionElement->class . '</li>';
734
      }
735
    }
736
    }
737
  }
738

    
739
  // If feature = NAME USAGE sort the list of sources.
740
  // This is ONLY for FLORA MALESIANA and FLORE d'AFRIQUE CENTRALE.
741
  if ($descriptionElement->feature->uuid == UUID_NAME_USAGE) {
742
    sort($outArray);
743
  }
744

    
745
  if (isset($image_sources)) {
746
    $outArray[] = theme('cdm_description_element_image_source', array('image_sources' => $image_sources, 'asListElement' => TRUE));
747
  }
748

    
749
  if (variable_get('distribution_sort', 'NO_SORT') != 'NO_SORT') {
750
    $outArray[] = theme('cdm_description_ordered_distributions', array('taxon_uuid' => $taxon_uuid, 'descriptionElements' => $distributionElements));
751
  }
752
  else {
753
    ksort($distributionElements);
754
    // TODO , $entryEnclosingTag);
755
    $outArray[] = theme('cdm_descriptionElementDistribution', array(
756
      'descriptionElements' => $distributionElements,
757
    ));
758
  }
759

    
760
  // Take the feature of the last $descriptionElement.
761
  $feature = $descriptionElement->feature;
762

    
763
  $out = theme('cdm_descriptionElementArray', array(
764
    'elementArray' => $outArray,
765
    'feature' => $feature,
766
    'glue' => $glue,
767
    'sortArray' => $sortOutArray,
768
    'enclosingHtml' => $enclosingTag,
769
  ));
770

    
771
  RenderHints::popFromRenderStack();
772
  return $out;
773
}
774

    
775
/**
776
 * @todo Please document this function.
777
 * @see http://drupal.org/node/1354
778
 */
779
function compare_image_sources($a, $b) {
780
  if ($a->multilanguageText_L10n->text == $b->multilanguageText_L10n->text) {
781
    return 0;
782
  }
783
  return ($a->multilanguageText_L10n->text < $b->multilanguageText_L10n->text) ? -1 : 1;
784
}
785

    
786
/**
787
 * @todo Please document this function.
788
 * @see http://drupal.org/node/1354
789
 */
790
function theme_cdm_description_element_image_source($variables) {
791
  $image_sources = $variables['image_sources'];
792
  $asListElement = $variables['asListElement'];
793
  $out = '';
794
  $separator = ',';
795
  RenderHints::pushToRenderStack('descriptionElementImageSource');
796
  RenderHints::setFootnoteListKey(UUID_IMAGE_SOURCES);
797

    
798
  // Sorting the image sources.
799
  usort($image_sources, "compare_image_sources");
800
  // Generate the footnotes.
801
  foreach ($image_sources as $image_source) {
802
    $footNoteKeys = cdm_annotations_as_footnotekeys($image_source);
803
    foreach ($image_source->sources as $source) {
804
      if (_is_original_source_type($source)) {
805
        $fn_key = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), theme('cdm_OriginalSource', array(
806
          'source' => $source,
807
          'doLink' => FALSE,
808
        )));
809
        // Ensure uniqueness of the footnote keys.
810
        cdm_add_footnote_to_array($footNoteKeys, $fn_key);
811
      }
812
    }
813
    // Sort and render footnote keys.
814
    $footnoteKeyListStr = '';
815
    asort($footNoteKeys);
816
    foreach ($footNoteKeys as $footNoteKey) {
817
      $footnoteKeyListStr .= theme('cdm_footnote_key', array('footnoteKey' => $footNoteKey, 'separator' => ($footnoteKeyListStr ? $separator : '')));
818
    }
819
    // Return value!
820
    $out .= '<span class="descriptionElement descriptionElement-' . $image_source->uuid . '">' . $image_source->multilanguageText_L10n->text . $footnoteKeyListStr . '; </span>';
821
  }
822

    
823
  RenderHints::popFromRenderStack();
824
  return $out;
825
}
826

    
827
/**
828
 * @todo Please document this function.
829
 * @see http://drupal.org/node/1354
830
 */
831
function theme_cdm_descriptionElementDistribution($variables) {
832
  $descriptionElements = $variables['descriptionElements'];
833
  $enclosingTag = $variables['enclosingTag'];
834
  if (!$enclosingTag) {
835
    $enclosingTag = "span";
836
  }
837

    
838
  $out = '';
839
  $separator = ',';
840
  RenderHints::pushToRenderStack('descriptionElementDistribution');
841
  RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
842

    
843
  foreach ($descriptionElements as $descriptionElement) {
844

    
845
    // Annotations as footnotes.
846
    $footNoteKeys = cdm_annotations_as_footnotekeys($descriptionElement);
847
    // Source references as footnotes.
848
    foreach ($descriptionElement->sources as $source) {
849
      if (_is_original_source_type($source)) {
850
        $fn_key = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), theme('cdm_OriginalSource', array(
851
          'source' => $source,
852
          'doLink' => FALSE,
853
        )));
854
        // Ensure uniqueness of the footnote keys.
855
        cdm_add_footnote_to_array($footNoteKeys, $fn_key);
856
      }
857
    }
858
    // Sort and render footnote keys.
859
    $footnoteKeyListStr = '';
860
    asort($footNoteKeys);
861
    foreach ($footNoteKeys as $footNoteKey) {
862
      $footnoteKeyListStr .= theme('cdm_footnote_key', array('footnoteKey' => $footNoteKey, 'separator' => ($footnoteKeyListStr ? $separator : '')));
863
    }
864

    
865
    $out .= '<' . $enclosingTag . ' class="descriptionElement descriptionElement-' . $descriptionElement->uuid . '">' . $descriptionElement->area->representation_L10n . $footnoteKeyListStr . ' </' . $enclosingTag . '>';
866
  }
867

    
868
  RenderHints::popFromRenderStack();
869
  return $out;
870
}
871

    
872
/**
873
 * Compare two different footnotes objects.
874
 *
875
 * The comparison is based on the footnote key. The one which is
876
 * displayed as footnote number.
877
 *
878
 * @param mixed $a
879
 *   Footnote object $a.
880
 * @param mixed $b
881
 *   Footnote object $b.
882
 */
883
function footnotes_key_compare($a, $b) {
884
  $res = 0;
885
  if (empty($a) || empty($b)) {
886
    return $res;
887
  }
888
  if ($a->keyStr < $b->keyStr) {
889
    $res = -1;
890
  }
891
  elseif ($a->keyStr > $b->keyStr) {
892
    $res = 1;
893
  }
894
  return $res;
895
}
896

    
897
/**
898
 * @todo Please document this function.
899
 * @see http://drupal.org/node/1354
900
 */
901
function theme_cdm_description_ordered_distributions($variables) {
902

    
903
  $taxon_uuid = $variables['taxon_uuid'];
904
  $descriptionElements = $variables['descriptionElements'];
905

    
906
  // Returning NULL if there are no description elements.
907
  if ($taxon_uuid == null || $descriptionElements == NULL) {
908
    return NULL;
909
  }
910

    
911
  // Initialization of some variables.
912
  $out = '';
913
  $separator = ',';
914
  RenderHints::pushToRenderStack('descriptionElementDistribution');
915
  RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
916

    
917
  // Getting all the taxon description for a given taxon.
918
  $markerTypesEmpty = array();
919
  // $markerTypesEmpty['markerTypes'] = 'af9860ff-08f5-4b4d-863c-49ae96985115';
920
  $markerTypesEmpty['markerTypes'] = '';
921
  $queryString = $markerTypesEmpty['markerTypes'] ? queryString($markerTypesEmpty) : '';
922

    
923
  $taxonDescriptions = cdm_ws_get(CDM_WS_PORTAL_TAXON_DESCRIPTIONS, $taxon_uuid, $queryString);
924
  foreach ($taxonDescriptions as $description) {
925
    $descriptions_uuids[] = $description->uuid;
926
  }
927

    
928
  // Getting the sortered distributions (omitting level ??).
929
  $request_params = array();
930
  $request_params['omitLevels'] = UUID_NAMEDAREALEVEL_TDWGLEVEL_2;
931
  $ordered_areas = cdm_ws_get(CDM_WS_PORTAL_DESCRIPTION_DISTRIBUTION_TREE, join(',', $descriptions_uuids), queryString($request_params));
932
  if (isset($ordered_areas->rootElement->children)) {
933
    $ordered_areas = $ordered_areas->rootElement->children;
934
  }
935

    
936
  // Printing the distributions.
937
  if (is_array($ordered_areas) && count($ordered_areas) > 0) {
938
    foreach ($ordered_areas as $element_level1) {
939
      // Level1.
940
      if ($element_level1->data) {
941
        $out .= '<dt>' . $element_level1->data->area->representation_L10n . ':</dt> ';
942
      }
943
      $out .= '<dd>';
944

    
945
      // Level3.
946
      foreach ($element_level1->children as $element_level3) {
947
        if ($element_level3->data) {
948
          $text_l3 = $element_level3->data->area->representation_L10n;
949
        }
950
        $fnKeysLevel3Str = '';
951
        $fnKeysLevel3 = cdm_annotations_as_footnotekeys($element_level3->data);
952
        foreach ($element_level3->data->sources as $source) {
953
          if (_is_original_source_type($source)) {
954
            $fn_key3 = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), theme('cdm_OriginalSource', array('source' => $source, 'doLink' => FALSE)));
955
            cdm_add_footnote_to_array($fnKeysLevel3, $fn_key3);
956
          }
957
        }
958
        // Level4.
959
        $l4_regions = array();
960
        foreach ($element_level3->children as $element_level4) {
961
          if ($element_level4->data) {
962
            $text_l4 = $element_level4->data->area->representation_L10n;
963
            $l4_regions[$element_level3->data->area->representation_L10n] = '';
964
            $fnKeysLevel4Str = '';
965
            $fnKeysLevel4 = cdm_annotations_as_footnotekeys($element_level4->data);
966
            foreach ($element_level4->data->sources as $source) {
967
              if (_is_original_source_type($source)) {
968
                $fn_key4 = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), theme('cdm_OriginalSource', array('source' => $source, 'doLink' => FALSE)));
969
                cdm_add_footnote_to_array($fnKeysLevel4, $fn_key4);
970
              }
971
            }
972
            usort($fnKeysLevel4, "footnotes_key_compare");
973
            $l4_regions[$text_l4] = $fnKeysLevel4;
974
          }
975
        }// Level4.
976
        // Managing level3 and level4 for generating the right output.
977
        usort($fnKeysLevel3, "footnotes_key_compare");
978
        foreach ($fnKeysLevel3 as $key3) {
979
          foreach ($l4_regions as $key4 => $value4) {
980
            cdm_add_footnote_to_array($l4_regions[$key4], $key3);
981
          }
982
        }
983
        if ($element_level3->numberOfChildren == 1 && $text_l3 == $element_level3->children[0]->data->area->representation_L10n) {
984
          // var_dump($element_level3->children[0]->data->area->representation_L10n);
985
          $fnStr = '';
986
          $region = array_pop($l4_regions);
987
          foreach ($region as $key) {
988
            $fnStr .= theme('cdm_footnote_key', array('footnoteKey' => $key, 'separator' => ($fnStr ? $separator : '')));
989
          }
990
          $out .= "$text_l3 $fnStr; ";
991
          // Removing whitespaces when &fnStr is empty.
992
          if (substr($out, -3) == ' ; ') {
993
            $out = substr($out, 0, -3) . '; ';
994
          }
995
        }
996
        else {
997
          $fnKeysLevel3Str = '';
998
          foreach ($fnKeysLevel3 as $key) {
999
            $fnKeysLevel3Str .= theme('cdm_footnote_key', array('footnoteKey' => $key, 'separator' => ($fnKeysLevel3Str ? $separator : '')));
1000
          }
1001
          $text_l4_aux = '';
1002
          foreach ($l4_regions as $key => $value) {
1003
            $fnKeysLevel4Str = '';
1004
            if (is_array($l4_regions[$key])) {
1005
              foreach ($l4_regions[$key] as $fnkey) {// Warning why?
1006
                $fnKeysLevel4Str .= theme('cdm_footnote_key', array('footnoteKey' => $fnkey, 'separator' => ($fnKeysLevel4Str ? $separator : '')));
1007
              }
1008
            }
1009
            // if ($key != $text_l3 || sizeof($l4_regions > 1)){
1010
            if ($key != $text_l3) {
1011
              $text_l4_aux .= "$key $fnKeysLevel4Str, ";
1012
            }
1013
          }
1014
          $text_l4_aux = substr($text_l4_aux, 0, -2);
1015

    
1016
          if (strlen($text_l4_aux) > 0) {
1017
            $out .= "$text_l3 $fnKeysLevel3Str ($text_l4_aux); ";
1018
          }
1019
          else {
1020
            $out .= "$text_l3 $fnKeysLevel3Str; ";
1021
          }
1022
        }
1023
      }// Level3.
1024
      $out = substr($out, 0, -2);
1025
      $out .= '.</dd>';
1026
    }// Level1.
1027
  }
1028
  RenderHints::popFromRenderStack();
1029
  return $out;
1030
}
1031

    
1032

    
1033
/*
1034
function theme_cdm_descriptionElementDistribution($descriptionElements){ $out
1035
  = ''; $separator = ',';
1036
  RenderHints::pushToRenderStack('descriptionElementDistribution');
1037
  RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
1038
  foreach($descriptionElements as $descriptionElement){ // annotations as
1039
  footnotes $annotationFootnoteKeys = theme('cdm_annotations_as_footnotekeys',
1040
  $descriptionElement); // source references as footnotes
1041
  $sourcesFootnoteKeyList = ''; foreach($descriptionElement->sources as
1042
  $source){ if(_is_original_source_type($source)){ $_fkey =
1043
  FootnoteManager::addNewFootnote(UUID_DISTRIBUTION,
1044
  theme('cdm_OriginalSource', $source, FALSE));
1045
  $sourcesFootnoteKeyList .= theme('cdm_footnote_key', $_fkey,
1046
  UUID_DISTRIBUTION, ($sourcesFootnoteKeyList ? $separator : '')); } }
1047
  if($annotationFootnoteKeys && $sourcesFootnoteKeyList){
1048
  $annotationFootnoteKeys .= $separator; } $out .=
1049
  $descriptionElement->area->representation_L10n . $annotationFootnoteKeys .
1050
  $sourcesFootnoteKeyList . ' '; } $out = substr($out, 0,
1051
  strlen($out)-strlen($separator) ); RenderHints::popFromRenderStack(); return
1052
  $out; }
1053
*/
1054

    
1055
/**
1056
 * TODO
1057
 * Quick-and-dirty solution to show distribution service to exemplar groups.
1058
 */
1059
function theme_cdm_distribution_map($variables) {
1060
  $taxon = $variables['taxon'];
1061
  $out = '';
1062
  $settings = get_edit_map_service_settings();
1063

    
1064
  $fontStyles = array(
1065
    0 => "plane",
1066
    1 => "italic",
1067
  );
1068

    
1069
  // Query cdm server for map service uri parameters.
1070
  $map_data_parameters = cdm_ws_get(CDM_WS_GEOSERVICE_DISTRIBUTIONMAP, $taxon->uuid);
1071
  $out .= "<!-- map_data_parameters:" . print_r($map_data_parameters, TRUE) . " -->";
1072
  $query_string = $map_data_parameters->String;
1073
  if (!$query_string) {
1074
    // The $query_string is empty if there are no distribution areas defined.
1075
    return;
1076
  }
1077

    
1078
  // Some cleaning of the URI paramters, TODO is this still needed?
1079
  $query_string = str_replace('%3A', ":", $query_string);
1080

    
1081
  /* ------ choose the display mode, either openlayers or static image ------ */
1082
  if (variable_get('cdm_dataportal_map_openlayers', 1)) {
1083

    
1084
    /* =========== display distributions using the openlayers map viewer =========== */
1085
    $legend_url_font_size = variable_get('cdm_dataportal_geoservice_legend_font_size', 10);
1086
    $legend_url_font_style = variable_get('cdm_dataportal_geoservice_legend_font_style', 1);
1087
    $legend_url_font_style = $fontStyles[$legend_url_font_style];
1088
    $legend_url_icon_width = variable_get('cdm_dataportal_geoservice_legend_icon_width', 35);
1089
    $legend_url_icon_height = variable_get('cdm_dataportal_geoservice_legend_icon_height', 15);
1090

    
1091
    $legendFormatQueryStr = "format=image" . urlencode('/') . "png&TRANSPARENT=TRUE";
1092
    $legendFormatQueryStr .= "&WIDTH=" . $legend_url_icon_width . "&HEIGHT=" . $legend_url_icon_height . "&";
1093
    // TODO why is the layer=topp:tdwg_level_4 parameter needed at all here??
1094
    $legendFormatQueryStr .= "layer=topp" . urlencode(':') . "tdwg_level_4&LEGEND_OPTIONS=forceLabels" . urlencode(':') . "on;fontStyle" . urlencode(':') . $legend_url_font_style . ";fontSize" . urlencode(':') . $legend_url_font_size . "&SLD=";
1095

    
1096
    $out .= get_openlayers_map(variable_get('cdm_dataportal_geoservice_display_width', 300), variable_get('cdm_dataportal_geoservice_bounding_box', FALSE), NULL, $query_string, $legendFormatQueryStr, variable_get('cdm_dataportal_geoservice_map_caption', ''));
1097
  }
1098
  else {
1099
    $legendFormatQueryStr = '';
1100
    return get_image_map(variable_get('cdm_dataportal_geoservice_display_width', 300), variable_get('cdm_dataportal_geoservice_bounding_box', FALSE), NULL, $query_string, $legendFormatQueryStr, variable_get('cdm_dataportal_geoservice_map_caption', ''));
1101

    
1102
    // Simple image.
1103
    $mapStaticCaption = '&mc_s=Georgia,15,blue&mc=' . variable_get('cdm_dataportal_geoservice_map_caption', '');
1104

    
1105
    $query_string .= '&img=true';
1106
    $query_string .= '&legend=1&mlp=3' . $mapStaticCaption . '&recalculate=FALSE';
1107

    
1108
    $map_service_script_name = "areas.php";
1109

    
1110
    // Apply Plain Image map settings.
1111
    if (get_edit_map_service_version_number() >= 1.1) {
1112
      /*
1113
       * example : title=a:Naturalized++non-invasive
1114
       * &ad=cyprusdivs:bdcode:a:5&as=a:ff9900,,0.1,&l=tdwg4
1115
       * &ms=500&bbox=32,34,35,36&img=true&legend=1&mlp=3
1116
       * &mc_s=Georgia,15,blue&mc=&recalculate=FALSE
1117
       * http://edit.br.fgov.be/edit_wp5/v1/rest_gen.php?
1118
       * l=background_gis:b,cyprusdivs&ad=cyprusdivs%3Abdcode%3Aa%3A8%2C4
1119
       * &as=a%3A339966%2C%2C0.1%2C|b:0000ff,,
1120
       * &bbox=32%2C34%2C35%2C36&img=true&legend=1&mc=&mc_s=Georgia%2C15%2Cblue
1121
       * &mlp=3&ms=500&recalculate=FALSE&title=a%3Aindigenous
1122
       */
1123

    
1124
      $map_service_script_name = "rest_gen.php";
1125

    
1126
      $bgcolor_areaStyleId = "y";
1127
      $baselayer_areaStyleId = "z";
1128
      $bgcolor_layer = '';
1129
      $additional_area_styles = array();
1130

    
1131
      // Background color.
1132
      if (variable_get('map_bg_color', '')) {
1133
        $bgcolor_layer = "background_gis:" . $bgcolor_areaStyleId;
1134
        $additional_area_styles[] = $bgcolor_areaStyleId . ":" . variable_get('map_bg_color', '') . ",,";
1135
      }
1136

    
1137
      // TODO HACK to replace the default base layer which currently is tdwg4
1138
      // !!!
1139
      if (strpos($query_string, "?l=") !== FALSE) {
1140
        $layer_param_token = "?l=";
1141
      }
1142
      else {
1143
        $layer_param_token = "&l=";
1144
      }
1145
      if (strpos($query_string, "?as=") !== FALSE) {
1146
        $areystyle_param_token = "?as=";
1147
      }
1148
      else {
1149
        $areystyle_param_token = "&as=";
1150
      }
1151

    
1152
      if (variable_get('map_base_layer', '')) {
1153
        $query_string = str_replace($layer_param_token . "tdwg4", "$layer_param_token" . variable_get('map_base_layer', '') . ":" . $baselayer_areaStyleId, $query_string);
1154
      }
1155
      else {
1156
        $query_string = str_replace($layer_param_token . "tdwg4", $layer_param_token . "tdwg4:" . $baselayer_areaStyleId . ",", $query_string);
1157
      }
1158

    
1159
      if ($bgcolor_layer) {
1160
        $query_string = str_replace($layer_param_token, $layer_param_token . $bgcolor_layer . ",", $query_string);
1161
      }
1162

    
1163
      if (variable_get('map_base_layer_style', '')) {
1164
        $additional_area_styles[] = $baselayer_areaStyleId . ":" . variable_get('map_base_layer_style', '');
1165
      }
1166

    
1167
      foreach ($additional_area_styles as $as) {
1168
        $query_string = str_replace($areystyle_param_token, $areystyle_param_token . $as . "|", $query_string);
1169
      }
1170
    }
1171

    
1172
    $mapUri = url(get_edit_map_service_full_uri() . '/' . $map_service_script_name . '? '. $query_string);
1173
    $out .= '<img class="distribution_map" src="' . urlencode($mapUri) . '" alt="Distribution Map" />';
1174
  }
1175
  return $out;
1176
}
1177

    
1178
/**
1179
 * Returns a list of a specific type of IdentificationKeys.
1180
 *
1181
 * The list can be restricteded by a taxon.
1182
 *
1183
 * @param string $type
1184
 *   The simple name of the cdm class implementing the interface
1185
 *   IdentificationKey, valid values are:
1186
 *   PolytomousKey, MediaKey, MultiAccessKey.
1187
 * @param string $taxonUuid
1188
 *   If given this parameter restrict the listed keys to those which have
1189
 *   the taxon identified be this uuid in scope.
1190
 *
1191
 * @return array
1192
 *   List with identification keys.
1193
 */
1194
function _list_IdentificationKeys($type, $taxonUuid = NULL, $pageSize = NULL, $pageNumber = NULL) {
1195
  if (!$type) {
1196
    drupal_set_message(t('Type parameter is missing'), 'error');
1197
    return;
1198
  }
1199
  $cdm_ws_pasepath = NULL;
1200
  switch ($type) {
1201
    case "PolytomousKey":
1202
      $cdm_ws_pasepath = CDM_WS_POLYTOMOUSKEY;
1203
      break;
1204

    
1205
    case "MediaKey":
1206
      $cdm_ws_pasepath = CDM_WS_MEDIAKEY;
1207
      break;
1208

    
1209
    case "MultiAccessKey":
1210
      $cdm_ws_pasepath = CDM_WS_MULTIACCESSKEY;
1211
      break;
1212

    
1213
  }
1214

    
1215
  if (!$cdm_ws_pasepath) {
1216
    drupal_set_message(t('Type parameter is not valid: ') . $type, 'error');
1217
  }
1218

    
1219
  $queryParameters = '';
1220
  if (is_numeric($pageSize)) {
1221
    $queryParameters = "pageSize=" . $pageSize;
1222
  }
1223
  else {
1224
    $queryParameters = "pageSize=0";
1225
  }
1226

    
1227
  if (is_numeric($pageNumber)) {
1228
    $queryParameters = "pageNumber=" . $pageNumber;
1229
  }
1230
  else {
1231
    $queryParameters = "pageNumber=0";
1232
  }
1233
  $queryParameters = NULL;
1234
  if ($taxonUuid) {
1235
    $queryParameters = "findByTaxonomicScope=$taxonUuid";
1236
  }
1237
  $pager = cdm_ws_get($cdm_ws_pasepath, NULL, $queryParameters);
1238

    
1239
  if (!$pager || $pager->count == 0) {
1240
    return array();
1241
  }
1242
  return $pager->records;
1243
}
1244

    
1245
/**
1246
 * @todo Please document this function.
1247
 * @see http://drupal.org/node/1354
1248
 */
1249
function theme_cdm_IdentificationKey($variables) {
1250
  $out = '';
1251
  $identificationKey = $variables['identificationKey'];
1252
  $doLinkToKeyPage = $variables['doLinkToKeyPage'];
1253
  $showIdentificationKeyTitle = $variables['showIdentificationKeyTitle'];
1254
  $parentRenderPath = RenderHints::getRenderPath();
1255
  RenderHints::pushToRenderStack("IdentificationKey");
1256

    
1257
  if ($showIdentificationKeyTitle) {
1258
    if ($doLinkToKeyPage) {
1259
      $out = l($identificationKey->titleCache, path_to_key($identificationKey->class, $identificationKey->uuid));
1260
    }
1261
    else {
1262
      $out = $identificationKey->titleCache;
1263
    }
1264
  }
1265
  if (isset($identificationKey->sources) && is_array($identificationKey->sources)) {
1266
    // order and display sources.
1267
    $sources = oder_sources($identificationKey->sources, TRUE);
1268
    $out .= '<div class="sources">';
1269
    $out .=  implode('', $sources);
1270
    $out .= '</div>';
1271
  }
1272
  // Display annotations.
1273
  $out .= theme('cdm_annotations', array('annotations' => cdm_ws_getAnnotationsFor($identificationKey), 'enclosingTag' => 'div'));
1274
  RenderHints::popFromRenderStack();
1275
  return $out;
1276
}
1277

    
1278
/**
1279
 * @todo Please document this function.
1280
 * @see http://drupal.org/node/1354
1281
 */
1282
function theme_cdm_polytomousKey($variables) {
1283
  $polytomousKey = $variables['polytomousKey'];
1284

    
1285
  // TODO settings needed.
1286
  // @see http://en.wikipedia.org/wiki/Single_access_key#Presentation_styles
1287
  // @see http://dev.e-taxonomy.eu/trac/ticket/2152
1288
  $keyStyle = "linkedStyle";
1289

    
1290
  RenderHints::pushToRenderStack("polytomousKey");
1291
  // Key nodes in linked style.
1292
  $out = '<table class="polytomousKey polytomousKey_' . $keyStyle . '">';
1293
  $out .= theme('cdm_polytomousKey_' . $keyStyle . '_subgraph', array('polytomousKeyNode' => $polytomousKey->root));
1294
  $out .= '</table>';
1295
  RenderHints::popFromRenderStack();
1296
  return $out;
1297
}
1298

    
1299
/**
1300
 * @todo Please document this function.
1301
 * @see http://drupal.org/node/1354
1302
 */
1303
function theme_cdm_polytomousKey_linkedStyle_subgraph($variables) {
1304
  $polytomousKeyNode = $variables['polytomousKeyNode'];
1305
  static $statementCountCharacter = '\'';
1306
  $out = "";
1307

    
1308
  if (is_array($polytomousKeyNode->children)) {
1309
    $childIndex = 0;
1310

    
1311
    // Render edges of the current node.
1312
    foreach ($polytomousKeyNode->children as &$child) {
1313

    
1314
      if (!isset($child->statement) && isset($child->taxon->uuid)) {
1315
        // Skip node with empty statements (see below for explanation: "Special
1316
        // case").
1317
        // this skipping here happens always in the next deeper level of iteration
1318
        // the check below is node on the level above
1319
        continue;
1320
      }
1321

    
1322
      /*
1323
       * Special case: Child nodes with empty statements but taxa as leaf are to
1324
       * treated as if all those taxa where direct children of the source node.
1325
       */
1326
      $islinkToManyTaxa = !isset($child->children[0]->statement) && isset($child->children[0]->taxon->uuid);
1327
      $islinkToTaxon = isset($child->taxon->uuid);
1328
      $islinkToSubKey = isset($child->subkey->uuid);
1329
      $islinkToOtherNode = isset($child->otherNode);
1330
      // Either NULL or 0.
1331
      $islinkToNode = $child->nodeNumber && !$islinkToManyTaxa && !$islinkToOtherNode;
1332
      $hasQuestion = !empty($polytomousKeyNode->question->label_l10n);
1333
      $hasFeature = isset($polytomousKeyNode->feature);
1334

    
1335
      // $indentEdge = $hasQuestion && $childIndex > 0;
1336
      // Question.
1337
      if ($hasQuestion && $childIndex == 0) {
1338
        // Place question, as extra table row.
1339
        $out .= '<tr class="question new_section">';
1340
        $out .= '<td class="nodeNumber">' . uuid_anchor($polytomousKeyNode->uuid, $polytomousKeyNode->nodeNumber) . "</td>";
1341
        $out .= '<td class="question">' . $polytomousKeyNode->question->label_l10n . '</td>';
1342
        $out .= '</tr>';
1343
      }
1344

    
1345
      $out .= '<tr class="childCount_' . $childIndex . (!$hasQuestion && $childIndex == 0 ? ' new_section' : '') . '">';
1346

    
1347
      if ($hasQuestion) {
1348
        $out .= '<td class="nodeNumber"></td>';
1349
      }
1350
      else {
1351
        $out .= '<td class="nodeNumber">' . uuid_anchor($polytomousKeyNode->uuid, $polytomousKeyNode->nodeNumber . str_pad("", $childIndex, $statementCountCharacter)) . "</td>";
1352
      }
1353

    
1354
      $out .= '<td ' . RenderHints::getHtmlElementID($child) . '  class="edge' . ($hasQuestion ? ' edge-indent' : '') . '">';
1355

    
1356
      // Feature.
1357
      if ($hasFeature) {
1358
        $out .= $polytomousKeyNode->feature->representation_L10n . ": ";
1359
      }
1360

    
1361
      // Statement.
1362
      $out .= $child->statement->label_l10n;
1363

    
1364
      // --- Links to nodes taxa and subkeys.
1365
      $out .= '<div class="nodeLink">';
1366

    
1367
      // Link to a PolytomousKeyNode.
1368
      if ($islinkToNode) {
1369
        $out .= '<div class="nodeLinkToNode">';
1370
        if (is_object($child->modifyingText)) {
1371
          $out .= theme('cdm_poytomousKeyNode_modifyingText', array('modifyingText' => $child->modifyingText));
1372
        }
1373
        $out .= l($child->nodeNumber, request_path(), array(
1374
          'attributes' => NULL,
1375
          'query' => NULL,
1376
          'fragment' => $child->uuid,
1377
        )) . '</div>';
1378
      }
1379

    
1380
      // Link to a PolytomousKeyNode.
1381
      if ($islinkToOtherNode) {
1382
        $out .= '<div class="nodeLinkToOtherNode">';
1383
        if (is_object($child->modifyingText)) {
1384
          $out .= theme('cdm_poytomousKeyNode_modifyingText', array('modifyingText' => $child->modifyingText));
1385
        }
1386
        $out .= l($child->otherNode->nodeNumber, $_REQUEST["q"], array(
1387
          'attributes' => NULL,
1388
          'query' => NULL,
1389
          'fragment' => $child->otherNode->uuid,
1390
        )) . '</div>';
1391
      }
1392

    
1393
      // Link to one or many taxa.
1394
      if ($islinkToTaxon || $islinkToManyTaxa) {
1395

    
1396
        if ($islinkToManyTaxa) {
1397
          $taxonChildren = $child->children;
1398
        }
1399
        else {
1400
          $taxonChildren = array(
1401
            $child,
1402
          );
1403
        }
1404

    
1405
        foreach ($taxonChildren as $taxonChild) {
1406
          // TODO many taxa $child->children->taxon.
1407
          $out .= '<div class="nodeLinkToTaxon">';
1408
          if (is_object($taxonChild->modifyingText)) {
1409
            $out .= theme('cdm_poytomousKeyNode_modifyingText', array('modifyingText' => $taxonChild->modifyingText));
1410
          }
1411
          $out .= theme("cdm_taxonName", array('taxonName' => $taxonChild->taxon->name, 'nameLink' => url(path_to_taxon($taxonChild->taxon->uuid))));
1412
          $out .= '</div>';
1413
        }
1414

    
1415
        // Link to a subkey.
1416
        if ($islinkToSubKey) {
1417
          $out .= '<div class="nodeLinkToSubkey">' . theme('cdm_IdentificationKey', array('identificationKey' => $child->subkey)) . '</div>';
1418
        }
1419
      }
1420

    
1421
      $out .= '</div>'; // End node link.
1422
      $out .= '</td>'; // End edge.
1423
      $out .= '</tr>';
1424

    
1425
      $childIndex++;
1426
    }
1427

    
1428
    // Recurse into child nodes.
1429
    foreach ($polytomousKeyNode->children as &$child) {
1430
      $out .= theme('cdm_polytomousKey_linkedStyle_subgraph', array('polytomousKeyNode' => $child));
1431
    }
1432
  }
1433

    
1434
  return $out;
1435
}
1436

    
1437
/**
1438
 * @todo Please document this function.
1439
 * @see http://drupal.org/node/1354
1440
 */
1441
function theme_cdm_poytomousKeyNode_modifyingText($variables) {
1442
  $out = '';
1443
  $modifyingText = $variables['modifyingText'];
1444
  if (is_object($modifyingText)) {
1445
    $i = 0;
1446
    foreach (get_object_vars($modifyingText) as $lang => $languageString) {
1447
      $out .= ($i++ > 0 ? ', ' : '') . '<span class="modifyingText">' . $languageString->text . '</span> ';
1448
    }
1449
  }
1450
  return $out;
1451
}
1452

    
1453
/**
1454
 * Returns HTML for a list of a specific type of IdentificationKeys.
1455
 *
1456
 * The list can be restricteded by a taxon.
1457
 *
1458
 * @param array $variables
1459
 *   An associative array containing:
1460
 *   - type: The simple name of the cdm class implementing the interface
1461
 *     IdentificationKey, valid values are:
1462
 *     PolytomousKey, MediaKey, MultiAccessKey
1463
 *   - taxonUuid: If given, this parameter restrict the listed keys to those
1464
 *     which have the taxon identified be this uuid in scope.
1465
 *
1466
 * @ingroup themeable
1467
 */
1468
function theme_cdm_list_IdentificationKeys($variables) {
1469
  $type = $variables['type'];
1470
  $taxonUuid = $variables['taxonUuid'];
1471
  $keyList = _list_IdentificationKeys($type, $taxonUuid);
1472
  if (!$keyList || count($keyList) == 0) {
1473
    return;
1474
  }
1475

    
1476
  RenderHints::pushToRenderStack('list_IdentificationKeys');
1477
  $out = '<ul>';
1478
  foreach ($keyList as $key) {
1479
    $out .= '<li>';
1480
    $out .= theme('cdm_IdentificationKey', array('identificationKey' => $key));
1481
    $out .= '</li>';
1482
  }
1483
  $out .= '</ul>';
1484
  $out .= theme("cdm_annotation_footnotes", array('footnoteListKey' => RenderHints::getRenderPath()));
1485
  RenderHints::popFromRenderStack();
1486

    
1487
  return $out;
1488
}
1489

    
1490
/**
1491
 * @todo Please document this function.
1492
 * @see http://drupal.org/node/1354
1493
 */
1494
function theme_cdm_block_IdentificationKeys($variables) {
1495
  $taxonUuid = $variables['taxonUuid'];
1496
  static $types = array(
1497
    "PolytomousKey" => "Polytomous",
1498
    "MediaKey" => "Media",
1499
    "MultiAccessKey" => "Multiaccess",
1500
  );
1501
  RenderHints::pushToRenderStack('block_IdentificationKeys');
1502
  $out = '';
1503
  foreach ($types as $type => $label) {
1504
    $keylist = theme('cdm_list_IdentificationKeys', array('type' => $type, 'taxonUuid' => $taxonUuid));
1505
    if (!$keylist) {
1506
      continue;
1507
    }
1508
    $out .= '<div class="' . $type . '">';
1509
    $out .= '<h3>' . t($label) . "</h3>";
1510
    $out .= $keylist;
1511
    $out .= '</div>';
1512
  }
1513
  RenderHints::popFromRenderStack();
1514
  return $out;
1515
}
1516

    
1517
/**
1518
 * This theming function formats the use description and use record list for
1519
 * these descriptions.
1520
 *
1521
 * @see http://drupal.org/node/1354
1522
 */
1523
function theme_cdm_UseDescription($variables) {
1524
  $descriptions = $variables['description'];
1525
  $taxonUuid = $variables['taxonUuid'];
1526
  $out = '<div id="content"><ul id="Description" class ="description">';
1527
  if ($descriptions == NULL) {
1528
    return;
1529
  }
1530
  $descriptionSynonyms = '';
1531
  $descriptionOut = '';
1532
  $synonymOut = '';
1533
  $currentTaxon = cdm_ws_get(CDM_WS_PORTAL_TAXON, $taxonUuid);
1534

    
1535
  foreach ($descriptions as $description) {
1536
    $useSummary = '';
1537
    foreach ($description->elements as $element) {
1538

    
1539
      if ($element->feature->uuid == UUID_USE && !(strlen($useSummary) > 0)) {
1540
        $useSummary = $element->multilanguageText_L10n->text;
1541
      }
1542
    }
1543
    // uses will be ordered by source
1544
    foreach ($description->sources as $source) {
1545
      $is_about_current_taxon = FALSE;
1546
      $originalTaxonUsedInSource = NULL;
1547
      $originalTaxonPager = NULL;
1548
      if ($source->originalNameString) {
1549
        $request_params = array();
1550
        $request_params['query'] = $source->originalNameString;
1551
        $request_params['matchMode'] = "EXACT";
1552
        $originalTaxonPager = cdm_ws_get(CDM_WS_PORTAL_NAME_FINDBYNAME, NULL, queryString($request_params));
1553
        if ($originalTaxonPager->count > 0) {
1554
          $originalTaxonUsedInSource = $originalTaxonPager->records[0];
1555
        }
1556
        else {
1557
          $originalTaxonUsedInSource = $currentTaxon->name;
1558
        }
1559
      }
1560
      else {
1561
        $originalTaxonUsedInSource = $currentTaxon->name;
1562
      }
1563

    
1564
      $is_about_current_taxon = $currentTaxon->name->uuid == $originalTaxonUsedInSource->uuid;
1565

    
1566
      if (!$is_about_current_taxon) {
1567
        $descriptionOut .= '<li class="descriptionText DescriptionElement">';
1568
        $name_used_in_source_link_to_show_use = l($source->originalNameString, path_to_name($originalTaxonUsedInSource->uuid), array(
1569
          'absolute' => TRUE,
1570
          'html' => TRUE,
1571
        ));
1572
        $descriptionOut .= $name_used_in_source_link_to_show_use . ': ';
1573
        $descriptionOut .= $useSummary;
1574
        foreach ($description->sources as $source) {
1575
          $descriptionOut .= " (" . theme('cdm_OriginalSource', array('source' => $source, 'doLink' => TRUE)) . ")";
1576
        }
1577
        $hasUseRecords = FALSE;
1578
        $descriptionUseRecordOut = '<div id=useRecords><table><th>Use Category</th><th>Use Sub Category</th><th>Plant Part</th><th>Human Group</th><th>Ethnic Group</th><th>Country</th>';
1579
        foreach ($description->elements as $descriptionElement) {
1580
          if ($descriptionElement->feature->uuid == UUID_USE_RECORD) {
1581
            $hasUseRecords = TRUE;
1582
            // FIXME localization hardcoded to English
1583
            $useRecordTags = explode(';', $descriptionElement->modifyingText->English->text);
1584
            $descriptionUseRecordOut .= '<tr>';
1585
            $descriptionUseRecordOut .= '<td>' . $useRecordTags[0] . '</td>' . '<td>' . $useRecordTags[1] . '</td>' . '<td>' . $useRecordTags[3] . '</td>' . '<td>' . $useRecordTags[4] . '</td>' . '<td>' . $useRecordTags[5] . '</td>' . '<td>' . $useRecordTags[2] . '</td>';
1586
            $descriptionUseRecordOut .= '</tr>';
1587
          }
1588
        }
1589
        $descriptionUseRecordOut .= '</table></div>';
1590
        if ($hasUseRecords) {
1591
          $descriptionOut .= $descriptionUseRecordOut . '</li>';
1592
        }
1593
      }
1594
      else {
1595
        // TODO +/- duplicate of above, unify this code
1596
        $synonymOut .= '<li class="descriptionText DescriptionElement">';
1597
        $name_used_in_source_link_to_show_use = l($source->originalNameString, path_to_name($originalTaxonUsedInSource->uuid), array(
1598
          'absolute' => TRUE,
1599
          'html' => TRUE,
1600
        ));
1601

    
1602
        $synonymOut .= $name_used_in_source_link_to_show_use . ': ';
1603
        $synonymOut .= $useSummary;
1604
        foreach ($description->sources as $source) {
1605
          $synonymOut .= " (" . theme('cdm_OriginalSource', array('source' => $source, 'doLink' => TRUE)) . ")";
1606
        }
1607

    
1608
        $hasUseRecords = FALSE;
1609
        $useRecordTableOut = '<div id=useRecords><table><th>Use Category</th><th>Use Sub Category</th><th>Plant Part</th><th>Human Group</th><th>Ethnic Group</th><th>Country</th>';
1610
        foreach ($description->elements as $descriptionElement) {
1611
          if ($descriptionElement->feature->uuid == UUID_USE_RECORD) {
1612
            $hasUseRecords = TRUE;
1613
            $useRecordTags = explode(';', $descriptionElement->modifyingText->English->text);
1614
            $useRecordTableOut .= '<tr>';
1615
            $useRecordTableOut .= '<td>' . $useRecordTags[0] . '</td>' . '<td>' . $useRecordTags[1] . '</td>' . '<td>' . $useRecordTags[3] . '</td>' . '<td>' . $useRecordTags[4] . '</td>' . '<td>' . $useRecordTags[5] . '</td>' . '<td>' . $useRecordTags[2] . '</td>';
1616
            $useRecordTableOut .= '</tr>';
1617
          }
1618
        }
1619
        $useRecordTableOut .= '</table></div>';
1620
        if ($hasUseRecords) {
1621
          $synonymOut .= $useRecordTableOut . '</li>';
1622
        }
1623
      }
1624

    
1625
      // }
1626
    }
1627
  }
1628
  $out .= $descriptionOut . $synonymOut;
1629
  $out .= "</ul></div>";
1630
  return $out;
1631
}
1632

    
1633
// The Uses theming function here will handle the display of the
1634
// Uses Descriptions.
1635
// Comment @WA: $pageSize is not used.
1636
// function theme_cdm_block_Uses ($taxonUuid = NULL, $pageSize = NULL {
1637
/**
1638
 * @todo Please document this function.
1639
 * @see http://drupal.org/node/1354
1640
 */
1641
function theme_cdm_block_Uses($variables) {
1642
  $taxonUuid = $variables['taxonUuid'];
1643
  RenderHints::pushToRenderStack('block_Uses');
1644

    
1645
  if ($taxonUuid == NULL) {
1646
    return;
1647
  }
1648
  $out = '';
1649
  $markerTypes = array();
1650
  $markerTypes['markerTypes'] = UUID_MARKERTYPE_USE;
1651
  $useDescriptions = cdm_ws_get(CDM_WS_PORTAL_TAXON_DESCRIPTIONS, $taxonUuid, queryString($markerTypes));
1652
  if (!empty($useDescriptions)) {
1653
    // FIXME use theme_block instaed of hardcoding the block html here !!!!
1654
    $out .= '<div id="block-cdm_dataportal-feature-description" class="clear-block block block-cdm_dataportal-feature"><H2><a name="userecords"> </a> Uses </H2>';
1655
    $formatUseDescriptions = theme('cdm_UseDescription', array('description' => $useDescriptions, 'taxonUuid' => $taxonUuid));
1656

    
1657
    $out .= $formatUseDescriptions;
1658
    $out .= "</div>";
1659
  }
1660

    
1661
  return $out;
1662
}
(3-3/10)