Project

General

Profile

Download (60.1 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
/**
18
 * Theme function to alter the feature representation.
19
 *
20
 * It is highly qeutionalbe if this function should be completely removed.
21
 * If a feature needs a different representation this should be edited directly
22
 * in the cdm data but it shoud not be tweeked like this in the portal.
23
 *
24
 * Used in:
25
 *  - theme_cdm_feature_nodesTOC()
26
 *  - theme_cdm_feature_nodes()
27
 *  - theme_cdm_media_mime_application()
28
 *  - theme_cdm_media_mime_text()
29
 *
30
 * TODO delete this function? (a.kohlbecker feb 2013)
31
 *
32
 */
33
function theme_cdm_feature_name($variables) {
34
  $feature_name = $variables['feature_name'];
35
  // TODO replace by using translations ?
36
  return t($feature_name);
37
}
38

    
39
/**
40
 * Returns HTML for a taxon profile from the $mergedFeatureNodes of a given $taxon.
41
 *
42
 * The taxon profile consists of description elements which are ordered by the
43
 * structure defined by specific FeatureTree. The chosen FeatureTree is merged
44
 * with the list of desctiprion elements prior to using this method.
45
 *
46
 * The merged nodes can be obtained by making use of the
47
 * function cdm_ws_descriptions_by_featuretree().
48
 *
49
 * @see cdm_ws_descriptions_by_featuretree()
50
 *
51
 * @param array $variables
52
 *   An associative array containing:
53
 *   - mergedFeatureNodes
54
 *   -taxon
55
 *
56
 * @ingroup themeable
57
 */
58
function theme_cdm_feature_nodes($variables) {
59

    
60
  $mergedFeatureNodes = $variables['mergedFeatureNodes'];
61
  $taxon = $variables['taxon'];
62
  $out = '';
63

    
64
  RenderHints::pushToRenderStack('feature_nodes');
65

    
66
  $gallery_settings = getGallerySettings(CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME);
67

    
68
  // Creating an array to place the description elements in.
69
  foreach ($mergedFeatureNodes as $node) {
70

    
71
    if (isset($node->descriptionElements['#type']) || hasFeatureNodeDescriptionElements($node)) {
72

    
73
      $featureRepresentation = isset($node->feature->representation_L10n) ? $node->feature->representation_L10n : 'Feature';
74
      $block = new stdclass(); // Empty object.
75
      $block->module = 'cdm_dataportal';
76
      $media_list = array();
77

    
78
      if (true || $node->feature->uuid != UUID_IMAGE) {
79

    
80
        $block->delta = generalizeString($featureRepresentation);
81
        $block->subject = '<span class="' . html_class_atttibute_ref($node->feature) . '">' . theme('cdm_feature_name', array('feature_name' => $featureRepresentation)) . '</span>';
82
        $block->module = "cdm_dataportal-feature";
83
        $block->content = '';
84

    
85
        /*
86
         * Content/DISTRIBUTION.
87
         */
88
        if ($node->feature->uuid == UUID_DISTRIBUTION) {
89

    
90
          $distributionElements = null;
91
          $distribution_info_dto = null;
92
          $text_data_out_array = array();
93

    
94
          $distribution_sortOutArray = FALSE;
95
          if (variable_get('distribution_sort', 'NO_SORT') != 'NO_SORT') {
96
            $distribution_glue = '';
97
            $distribution_enclosingTag = 'dl';
98
          }
99
          else {
100
            $distribution_glue = '';
101
            $distribution_enclosingTag = 'ul';
102
          }
103

    
104
          if(!isset($node->descriptionElements['#type']) || !$node->descriptionElements['#type']=='DTO') {
105
            // skip the DISTRIBUTION section if there is no DTO type element
106
            continue;
107
          }
108

    
109
          if(isset($node->descriptionElements['TextData'])){
110
            // --- TextData
111
            foreach ($node->descriptionElements['TextData'] as $text_data_element){
112
              $asListElement = FALSE;
113
              $repr = theme('cdm_descriptionElementTextData', array(
114
                  'element' => $text_data_element,
115
                  'asListElement' => $asListElement,
116
                  'feature_uuid' => $text_data_element->feature->uuid,
117
              ));
118

    
119
              if (!array_search($repr, $text_data_out_array)) {
120
                $text_data_out_array[] = $repr;
121
                // TODO HINT: sorting in theme_cdm_descriptionElementArray will
122
                // not work since this array contains html attributes with uuids
123
                // !!!!
124
                $text_data_sortOutArray = TRUE;
125
                $text_data_glue = '<br/> ';
126
                $text_data_enclosingTag = 'p';
127
              }
128
            }
129
          }
130

    
131

    
132
          if ($text_data_out_array && variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0)) {
133
            $block->content .= theme('cdm_descriptionElementArray', array(
134
              'elementArray' => $text_data_out_array,
135
              'feature' => $node->feature,
136
              'glue' => $text_data_glue,
137
              'sortArray' => $text_data_sortOutArray,
138
              'enclosingHtml' => $text_data_enclosingTag,
139
            ));
140
          }
141

    
142
          // --- Distribution map
143
          $distribution_map_query_parameters = null;
144
          if(isset($node->descriptionElements['DistributionInfoDTO'])) {
145
            $distribution_map_query_parameters = $node->descriptionElements['DistributionInfoDTO']->mapUriParams;
146
          }
147
          $map_render_element = compose_distribution_map($taxon, $distribution_map_query_parameters);
148
          $block->content .= $map_render_element['#markup'];
149

    
150
            // --- tree or list
151
              $dto_out_array = array();
152
          if(isset($node->descriptionElements['DistributionInfoDTO'])) {
153
            $distribution_info_dto = $node->descriptionElements['DistributionInfoDTO'];
154

    
155
            // --- tree
156
            if (is_object($distribution_info_dto->tree)) {
157
              $dto_out_array[] = theme('cdm_description_ordered_distributions', array('distribution_tree' => $distribution_info_dto->tree));
158
            }
159

    
160
            // --- sorted element list
161
            if( is_array($distribution_info_dto->elements) && count($distribution_info_dto->elements) > 0 ) {
162
              foreach ($distribution_info_dto->elements as $descriptionElement){
163
                if (is_object($descriptionElement->area)) {
164
                  $sortKey = $descriptionElement->area->representation_L10n;
165
                  $distributionElements[$sortKey] = $descriptionElement;
166
                }
167
              }
168
              ksort($distributionElements);
169
              $dto_out_array[] = theme('cdm_descriptionElement_Distribution', array(
170
                  'descriptionElements' => $distributionElements,
171
              ));
172

    
173
            }
174
            //
175
            $block->content .= theme('cdm_descriptionElementArray', array(
176
                'elementArray' => $dto_out_array,
177
                'feature' => $node->feature,
178
                'glue' => $distribution_glue,
179
                'sortArray' => $distribution_sortOutArray,
180
                'enclosingHtml' => $distribution_enclosingTag,
181
            ));
182
          }
183

    
184
          // --- TextData at the bottom
185
          if ($text_data_out_array && !variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0)) {
186
            $block->content .= theme('cdm_descriptionElementArray', array(
187
                'elementArray' => $text_data_out_array,
188
                'feature' => $node->feature,
189
                'glue' => $text_data_glue,
190
                'sortArray' => $text_data_sortOutArray,
191
                'enclosingHtml' => $text_data_enclosingTag,
192
            ));
193
          }
194

    
195
        }
196

    
197
        /*
198
         * Content/COMMON_NAME.
199
         */
200
        elseif ($node->feature->uuid == UUID_COMMON_NAME) {
201
          // TODO why is theme_cdm_descriptionElement_CommonTaxonName not
202
          // beeing used???
203
         $block->content .= theme('cdm_common_names', array('elements' => $node->descriptionElements));
204
          /*
205
          }else if($node->feature->uuid == UUID_IMAGE_SOURCES) {
206
          $block->content .= theme('cdm_image_sources',
207
          $node->descriptionElements);
208
          */
209
        }
210

    
211
        /*
212
         * Content/ALL OTHER FEATURES.
213
         */
214
        else {
215
          if (isset($node->descriptionElements)) {
216
            $taxon_uuid = NULL;
217
            if(isset($taxon) ) {
218
              $taxon_uuid = $taxon->uuid;
219
            }
220
            $block->content .= theme('cdm_descriptionElements', array(
221
              'descriptionElements' => $node->descriptionElements,
222
              'feature' => $node->feature,
223
              'taxon_uuid' => $taxon_uuid,
224
            ));
225
          }
226

    
227
//           Content/ALL OTHER FEATURES/Subordinate Features
228
//           subordinate features are printed inline in one floating text,
229
//           it is expected hat supordinate features can "contain" TextData,
230
//           Qualitative- and Qualitative- DescriptioneElements
231
          if (isset($node->childNodes[0])) {
232

    
233
            // TODO support more than one level of children.
234
            // can this be solved by resursively calling this very function?
235
            // @see http://dev.e-taxonomy.eu/trac/ticket/2393
236
            $text = '';
237
            foreach ($node->childNodes as $child) {
238

    
239
              if (isset($child->descriptionElements) && is_array($child->descriptionElements)) {
240
                foreach ($child->descriptionElements as $element) {
241

    
242
                  if (is_array($element->media)) {
243
                    // Append media of supordinate elements to list of main
244
                    // feature.
245
                    $media_list = array_merge($media_list, $element->media);
246
                  }
247

    
248
                  switch ($element->class) {
249
                    case 'TextData':
250
                      // TODO use theme_cdm_descriptionElementTextData()
251
                      $out_child_elements = str_replace("\n", "<br/>", $element->multilanguageText_L10n->text);
252
                      $out_child_elements = str_replace($child->feature->titleCache, '<em>' . $child->feature->representation_L10n . '</em>', $out_child_elements);
253
                      break;
254
                    case 'CategoricalData':
255
                      $out_child_elements  = '<em>' . $child->feature->representation_L10n . '</em> '
256
                        . theme('cdm_descriptionElement_CategoricalData', array('element' => $element));
257
                      break;
258
                    case 'QuantitativeData':
259
                      $out_child_elements = '<em>' . $child->feature->representation_L10n . '</em> '
260
                        . theme('cdm_descriptionElement_QuantitativeData', array('element' => $element));
261

    
262
                  }
263

    
264
                }
265
                $text .= " " . $out_child_elements;
266
                $out_child_elements = '';
267
              }
268
            }
269
            $block->content .= $text;
270
          }
271
        }
272

    
273
        /*
274
         * Media/ALL FEATURES.
275
         */
276
        if (isset($node->descriptionElements)) {
277
          $media_list = array_merge($media_list, cdm_dataportal_media_from_descriptionElements($node->descriptionElements));
278
        }
279
        $captionElements = array('title', 'rights');
280
        $gallery = '';
281
        if (isset($gallery_settings['cdm_dataportal_media_maxextend']) && isset($gallery_settings['cdm_dataportal_media_cols'])) {
282
          $gallery = theme('cdm_media_gallerie', array(
283
            'mediaList' => $media_list,
284
            'galleryName' => CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME . '_' . $node->feature->uuid,
285
            'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
286
            'cols' => $gallery_settings['cdm_dataportal_media_cols'],
287
            'captionElements' => $captionElements,
288
          ));
289
        }
290
        $block->content .= $gallery;
291
        $block->content .= theme('cdm_footnotes', array('footnoteListKey' => $node->feature->uuid));
292
        $block->content .= theme('cdm_annotation_footnotes', array('footnoteListKey' => $node->feature->uuid));
293

    
294
        // Add anchor to subject.
295
        $block->subject = '<a name="' . $block->delta . '"></a>' . $block->subject;
296

    
297
        // In D6: $out .= theme('block', $block);
298
        // Comment @WA @TODO check if need to set a region, and which one.
299
        $block->region = FALSE;
300
        $out .= theme('block', array('elements' => array(
301
          '#block' => $block,
302
          '#children' => $block->content,
303
        )));
304
      }
305
    }
306
  }
307
  RenderHints::popFromRenderStack();
308
  return $out;
309
}
310

    
311
/**
312
 * @todo Please document this function.
313
 * @see http://drupal.org/node/1354
314
 */
315
function theme_FeatureTree_hierarchy($variables) {
316

    
317
  $FeatureTreeUuid = $variables['FeatureTreeUuid'];
318
  if (!is_uuid($FeatureTreeUuid)) {
319
    return;
320
  }
321

    
322
  $out = '';
323
  $featureTree = cdm_ws_get(CDM_WS_FEATURETREE, array(
324
    $FeatureTreeUuid,
325
  ));
326

    
327
  if (isset($featureTree) && isset($featureTree->root)) {
328
    $out = '<ul class="' . $featureTree->class . '">';
329
    $out .= theme('FeatureTree_hierarchy_children', array('node' => $featureTree->root));
330
    $out .= '</ul>';
331
  }
332
  return $out;
333
}
334

    
335
/**
336
 * @todo Please document this function.
337
 * @see http://drupal.org/node/1354
338
 */
339
function theme_FeatureTree_hierarchy_children($variables) {
340

    
341
  $node = $variables['node'];
342
  $out = '';
343
  if (isset($node->childNodes)) {
344

    
345
    foreach ($node->childNodes as $childNode) {
346
      $out .= '<li>' . check_plain($childNode->feature->representation_L10n);
347
      if (isset($childNode->childNodes) && count($childNode->childNodes) > 0) {
348
        $out .= '<ul>' . theme('FeatureTree_hierarchy_children', array('node' => $childNode)) . '</ul>';
349
      }
350
      $out .= '</li>';
351
    }
352
  }
353
  return $out;
354
}
355

    
356
/**
357
 * Returns HTML for the texts in a description $elementArray.
358
 *
359
 * Joins the texts in $elementArray and encloses with a HTML tag.
360
 *
361
 * @param array $variables
362
 *   An associative array containing:
363
 *   - elementArray
364
 *   - feature: The feature to which the elements given in $elementArray are
365
 *     belonging to.
366
 *   - glue: Defaults to empty string.
367
 *   - sortArray: Whether to sort the $elementArray alphabetically.
368
 *   - enclosingHtml
369
 *
370
 * @ingroup themeable
371
 */
372
function theme_cdm_descriptionElementArray($variables) {
373
  $elementArray = $variables['elementArray'];
374

    
375
  $feature = $variables['feature'];
376
  $glue = $variables['glue'];
377
  $sortArray = $variables['sortArray'];
378
  $enclosingHtml = $variables['enclosingHtml'];
379
  $out = '<' . $enclosingHtml . ' class="description" id="' . $feature->representation_L10n . '">';
380

    
381
  if ($sortArray) {
382
    sort($elementArray);
383
  }
384

    
385
  $out .= join($elementArray, $glue);
386

    
387
  $out .= '</' . $enclosingHtml . '>';
388
  return $out;
389
}
390

    
391
/**
392
 * @todo Please document this function.
393
 * @see http://drupal.org/node/1354
394
 */
395
function theme_cdm_descriptionElement_CommonTaxonName($variables) {
396
  $element = $variables['element'];
397
  $out = '<span class="' . html_class_atttibute_ref($element) . '">' . $element->language->representation_L10n . ' (' . $element->area->titleCache . '): ' . $element->name . '</span>';
398
  return $out;
399
}
400

    
401
/**
402
 * @todo Please document this function.
403
 * @see http://drupal.org/node/1354
404
 */
405
function theme_cdm_descriptionElement_CategoricalData($variables) {
406
  $element = $variables['element'];
407

    
408
  $state_data_strings = array();
409
  if (isset($element->states)) {
410
    foreach ($element->states as $stateData) {
411

    
412
      $state  = NULL;
413

    
414
      if(isset($stateData->state)){
415
        $state = cdm_term_representation($stateData->state);
416
      }
417

    
418
      if (isset($stateData->modifyingText_L10n)) {
419
        $state = ' ' . $stateData->modifyingText_L10n;
420
      }
421

    
422
      $modifiers_strings = cdm_modifers_representations($stateData);
423

    
424
      $state_data_strings[] = $state . ($modifiers_strings ? ' ' . $modifiers_strings : '');
425

    
426
      // FIXME render sources and annotations
427

    
428
    }
429
  }
430
  $out = '<span class="' . html_class_atttibute_ref($element) . '">' . implode(', ', $state_data_strings) . '</span>';
431
  return $out;
432
}
433

    
434
function theme_cdm_descriptionElement_QuantitativeData($variables) {
435
  /*
436
   * - statisticalValues
437
   *   - value
438
   *   - modifiers
439
   *   - type
440
   * - unit->representation_L10n
441
   * - modifyingText
442
   * - modifiers
443
   * - sources
444
   */
445
  $element = $variables['element'];
446

    
447
  $out = '';
448

    
449
  $type_representation = NULL;
450
  $modifiers_strings = array();
451

    
452

    
453
  if (isset($element->statisticalValues)) {
454
    $value_array = array();
455
    foreach ($element->statisticalValues as $val) {
456
      if (isset($val->value)) {
457
        $value_array[] = $val->value;
458
      }
459
    }
460

    
461
    $out .= implode($value_array, ', ');
462
  }
463

    
464
  if (isset($element->unit)) {
465
    $out .= ' '. cdm_term_representation($element->unit);
466
  }
467

    
468
  if (isset($element->statisticalValues->modifyingText_L10n)) {
469
    $out .=  ' ' . $element->statisticalValues->modifyingText_L10n;
470
  }
471
  $modifers_string = cdm_modifers_representations($element->statisticalValues);
472
  $out .= ($modifers_string ? ' ' . cdm_modifers_representations($element->statisticalValues) : '');
473

    
474
  $footnote_key_list_str = cdm_create_description_element_footnotes($element);
475

    
476
  return $out . $footnote_key_list_str;
477

    
478
}
479

    
480
/**
481
 * Theme function to render CDM DescriptionElements of the type IndividualsAssociations.
482
 *
483
 */
484
function theme_cdm_descriptionElement_IndividualsAssociation($variables) {
485

    
486
  $element = $variables['element'];
487

    
488
  $out = '';
489

    
490
  $render_array = compose_cdm_specimenOrObservation($element->associatedSpecimenOrObservation);
491

    
492
  if (isset($element->description_L10n)) {
493
    $out .=  ' ' . $element->description_L10n;
494
  }
495

    
496
  $out .= drupal_render($render_array);
497

    
498
  $footnote_key_list_str = cdm_create_description_element_footnotes($element);
499

    
500
  return $out . $footnote_key_list_str;
501

    
502

    
503
}
504

    
505
/**
506
 * Theme function to render CDM DescriptionElements of the type TaxonInteraction.
507
 *
508
 */
509
function theme_cdm_descriptionElement_TaxonInteraction($variables) {
510

    
511
  $element = $variables['element'];
512

    
513
  $out = '';
514

    
515
  if (isset($element->description_L10n)) {
516
    $out .=  ' ' . $element->description_L10n;
517
  }
518

    
519
  if(isset($element->taxon2)){
520
    $out = theme('cdm_taxonName',
521
        array(
522
            'taxonName' => $element->taxon2->name,
523
            'nameLink' => url(path_to_taxon($element->taxon2->uuid))
524
        )
525
      );
526
  }
527

    
528
  $footnote_key_list_str = cdm_create_description_element_footnotes($element);
529

    
530
  return $out . $footnote_key_list_str;
531

    
532

    
533
}
534

    
535
/**
536
 * Returns HTML for citations textdata elements.
537
 *
538
 * TODO: assign a new name to the function? Because it is used for the citations
539
 * textdata elements and not for all text data description elements.
540
 *
541
 * @param array $variables
542
 *   An associative array containing:
543
 *   - element: The description element which contains the text information.
544
 *   - asListElement: A boolean which determines whether the citations should
545
 *     be rendered as a list or not.
546
 *   - feature_uuid
547
 *
548
 * @ingroup themeable
549
 */
550
function theme_cdm_descriptionElementTextData($variables) {
551

    
552
  $element = $variables['element'];
553
  $asListElement = $variables['asListElement'];
554
  $feature_uuid = $variables['feature_uuid'];
555

    
556
  $description = '';
557
  if (isset($element->multilanguageText_L10n->text)) {
558
    $description = str_replace("\n", "<br/>", $element->multilanguageText_L10n->text);
559
  }
560
  $sourceRefs = '';
561
  $result = array();
562
  $out = '';
563
  $res_author = '';
564
  $res_date = '';
565
  if (isset($element->sources) && is_array($element->sources) && count($element->sources) > 0) {
566
    foreach ($element->sources as $source) {
567
      $referenceCitation = theme('cdm_OriginalSource', array('source' => $source));
568
      if ($description && strlen($description) > 0 && $referenceCitation) {
569
        $sourceRefs .= ' (' . $referenceCitation . ')';
570
      }
571
      elseif ($referenceCitation) {
572
        $sourceRefs = $referenceCitation;
573
      }
574

    
575
      if (strlen($sourceRefs) > 0) {
576
        $sourceRefs = '<span class="sources">' . $sourceRefs . '</span>';
577
      }
578
      $name_used_in_source_link_to_show = '';
579
      // Do a link to name page.
580
      if (isset($source->nameUsedInSource->uuid) && isset($source->nameUsedInSource->titleCache)) {
581
        $name_used_in_source_link_to_show = l($source->nameUsedInSource->titleCache, path_to_name($source->nameUsedInSource->uuid), array(
582
          'attributes' => array(),
583
          'absolute' => TRUE,
584
          'html' => TRUE,
585
        ));
586
      }
587
      // Show a text without link.
588
      elseif (isset($source->nameUsedInSource->originalNameString) && strlen($source->nameUsedInSource->originalNameString) > 0) {
589
        $name_used_in_source_link_to_show = $source->nameUsedInSource->originalNameString;
590
      }
591

    
592
      if ($asListElement) {
593

    
594
       $out = '<li class="descriptionText DescriptionElement">';
595
        // Adding ":" if necessary.
596
        if (!empty($name_used_in_source_link_to_show)) {
597
          if ( (!empty($description)|| !empty($sourceRefs)) && $feature_uuid != UUID_CHROMOSOMES_NUMBERS) {
598
            $out .= $name_used_in_source_link_to_show . ': ';
599
          } else {
600
            $out .= $name_used_in_source_link_to_show . ' ';
601
          }
602
        }
603
        $out .= $description . $sourceRefs . theme('cdm_annotations_as_footnotekeys', array('cdmBase_list' => $element, 'footnote_list_key' => $feature_uuid)) . '</li>';
604
      }
605
      else {
606
        if ($name_used_in_source_link_to_show) {
607
          $name_used_in_source_link_to_show = ' (name in source: ' . $name_used_in_source_link_to_show . ')';
608
        }
609

    
610
        $out = '<span class="DescriptionElement DescriptionElement-' . $element->class . '">' . $description . $sourceRefs . $name_used_in_source_link_to_show . '</span>';
611
      }
612
    }
613
  }
614
  else {
615
    // If no sources, print the description.
616
    $out = $description;
617
  }
618

    
619
  // FIXME This will create footnotes for annotatios and source, sources are already rendered though
620
  // FIXME the footnoes are not shown in the page
621
  // FIXME RenderHints::getFootnoteListKey() ate not set here
622
  // to many problems, so the below line is diabled for now
623
  //$footnote_key_list_str = cdm_create_description_element_footnotes($element);
624
  // $out .= $footnote_key_list_str;
625

    
626
  return $out;
627
}
628

    
629
/**
630
 * @todo Please document this function.
631
 * @see http://drupal.org/node/1354
632
 */
633
function theme_cdm_common_names($variables) {
634
  $elements = $variables['elements'];
635
  $text_data_out = '';
636
  $common_name_out = '';
637
  $separator = ',';
638
  $textData_commonNames = array();
639

    
640
  if (is_array($elements)) {
641
    foreach ($elements as $element) {
642
      if ($element->class == 'CommonTaxonName') {
643

    
644
        // common name without a language or area, should not happen but is possible
645
        $language_area_key = '';
646
        if (isset($element->language->representation_L10n)) {
647
          $language_area_key .= '<b>' . $element->language->representation_L10n . '</b>';
648
        }
649
        if(isset($element->area->titleCache) && strlen($element->area->titleCache) > 0){
650
          $language_area_key .= ($language_area_key ? ' '  : '') . '(' . $element->area->titleCache . ')';
651
        }
652

    
653
        if(isset($common_names[$language_area_key][$element->name])) {
654
          // same name already exists for language and areae combination, se we merge the description elements
655
          cdm_merge_description_elements($common_names[$language_area_key][$element->name], $element);
656
        } else{
657
          // otherwise add as new entry
658
          $common_names[$language_area_key][$element->name] = $element;
659
        }
660

    
661
      }
662
      elseif ($element->class == 'TextData') {
663
        $textData_commonNames[] = $element;
664
      }
665
    }
666
  }
667
  // Handling common names.
668
  if (isset($common_names) && count($common_names) > 0) {
669
    // Sorting the array based on the key (language, + area if set).
670
    // Comment @WA there are common names without a language, so this sorting
671
    // can give strange results.
672
    ksort($common_names);
673

    
674
    // Creating the output to be render by Drupal.
675
    foreach ($common_names as $key => $elements) {
676
      ksort($elements); // sort names alphabetically
677
      $rendered_element_list = '';
678
      foreach ($elements as $element) {
679
        $sourcesFootnoteKeyList = '';
680
        // Adding footnotes sources.
681
        foreach ($element->sources as $source) {
682
          if (_is_original_source_type($source)) {
683
            $_fkey = FootnoteManager::addNewFootnote(UUID_COMMON_NAME, theme('cdm_OriginalSource', array('source' => $source, 'doLink' => FALSE)));
684
            $sourcesFootnoteKeyList .= theme('cdm_footnote_key', array('footnoteKey' => $_fkey, 'separator' => ($sourcesFootnoteKeyList ? $separator : '')));
685
          }
686
        }
687
        if ($element->name) {
688
          $rendered_element_list .= '<span class="' . html_class_atttibute_ref($element) . '">' . (strlen($rendered_element_list) > 0 ? ', ' : '') . $element->name . $sourcesFootnoteKeyList . '</span>';
689
        }
690
      }
691
      if ($key) {
692
        $common_name_out .= (strlen($common_name_out) > 0 ? '; ' : '') . $key . ': ' . $rendered_element_list;
693
      }
694
      else {
695
        $common_name_out .= (strlen($common_name_out) > 0 ? '; ' : '') . $rendered_element_list;
696
      }
697
    }
698
  }
699
  // Handling commons names as text data.
700
  foreach ($textData_commonNames as $text_data_element) {
701
    $text_data_out .= theme('cdm_descriptionElementTextData', array(
702
      'element' => $text_data_element,
703
      'asListElement' => TRUE,
704
      'feature_uuid' => $text_data_element->feature->uuid,
705
    ));
706
  }
707

    
708
  $common_name_out = "<div class=common_names_as_common_names> $common_name_out </div>";
709
  $out_array[] = $text_data_out;
710
  $common_name_out_text_data = '<div class=common_names_as_text_data>' . theme('cdm_descriptionElementArray', array('elementArray' => $out_array, 'feature' => $element->feature)) . '</div>';
711

    
712
  return $common_name_out . $common_name_out_text_data;
713
  /*
714
  return $common_name_out . theme('cdm_descriptionElementArray', $out_array,
715
  $element->feature);
716
  return "<div class=common_names> $common_name_out
717
  $common_name_out_text_data";
718
  */
719
}
720

    
721
/**
722
 * Return HTML for a list of description elements.
723
 *
724
 * Usually these are of a specific feature type.
725
 *
726
 * @param array $variables
727
 *   An associative array containing:
728
 *   - array of descriptionElements which belong to the same feature.
729
 *     These descriptions elements of a Description must be ordered by the chosen feature tree by
730
 *     calling the function _mergeFeatureTreeDescriptions().
731
 *     @see _mergeFeatureTreeDescriptions()
732
 *   - featureUuid: currently unused, accoding code disabled
733
 *   - taxon_uuid: only used for ordered dditributions (will be removed!)
734
 *
735
 * @ingroup themeable
736
 */
737
function theme_cdm_descriptionElements($variables) {
738

    
739
  $descriptionElements = $variables['descriptionElements'];
740
  $feature = $variables['feature'];
741
  $taxon_uuid = $variables['taxon_uuid'];
742
  $outArray = array();
743

    
744
  /*
745
  $userDefined = mixed_variable_get(LAYOUT_SETTING_PREFIX . $feature_uuid, FEATURE_TREE_LAYOUT_DEFAULTS);
746
  if(variable_get('distribution_sort',
747
      'NO_SORT') != 'NO_SORT'){
748
      $glue = '';
749
      $enclosingTag = 'dl';
750
      $entryEnclosingTag = NULL;
751
  } else if($userDefined &&
752
      $userDefined['enabled']){
753
    $glue = $userDefined['glue'];
754
    $enclosingTag =  $userDefined['enclosingTag'];
755
    $entryEnclosingTag = $userDefined['entryEnclosingTag'];
756
  } else { // TODO remove once  LAYOUT_SETTING_PREFIX-{uuid} setting are configured to work for all portals(selenium test still missing!!!)
757
    $glue = ''; $enclosingTag = 'ul';
758
    $entryEnclosingTag = NULL ;
759
  }
760
  */
761

    
762

    
763
  if (variable_get('distribution_sort', 'NO_SORT') != 'NO_SORT') {
764
    $glue = '';
765
    $enclosingTag = 'dl';
766
  }
767
  else {
768
    $glue = '';
769
    $enclosingTag = 'ul';
770
  }
771

    
772
  $sortOutArray = FALSE;
773
  $distributionElements = array();
774
  $distribution_tree = null;
775

    
776
  RenderHints::pushToRenderStack('cdm_descriptionElements');
777

    
778
  // --- Handle DTO
779
  // fully disabled !!!!!!!!!!!!!
780
  if(false
781
    && $feature->uuid == UUID_DISTRIBUTION && $descriptionElements['#type'] == 'DTO'){
782
    // new faster DTO web services have been used
783

    
784
    if(isset($descriptionElements['TextData'])){
785
      // --- TextData
786
      foreach ($descriptionElements['TextData'] as $descriptionElement){
787
        $asListElement = FALSE;
788
        $repr = theme('cdm_descriptionElementTextData', array(
789
            'element' => $descriptionElement,
790
            'asListElement' => $asListElement,
791
            'feature_uuid' => $descriptionElement->feature->uuid,
792
        ));
793

    
794
        if (!array_search($repr, $outArray)) {
795
          $outArray[] = $repr;
796
          // TODO HINT: sorting in theme_cdm_descriptionElementArray will
797
          // not work since this array contains html attributes with uuids
798
          // !!!!
799
          $sortOutArray = TRUE;
800
          $glue = '<br/> ';
801
          $enclosingTag = 'p';
802
        }
803
      }
804
    }
805

    
806
    // ---
807
    if(isset($descriptionElements['DistributionInfoDTO'])){
808
      if(isset($descriptionElements['DistributionInfoDTO']->elements)){
809
        foreach ($descriptionElements['DistributionInfoDTO']->elements as $descriptionElement){
810
          if (is_object($descriptionElement->area)) {
811
            $sortKey = $descriptionElement->area->representation_L10n;
812
            $distributionElements[$sortKey] = $descriptionElement;
813
          }
814
        }
815
      }
816
      if(isset($descriptionElements['DistributionInfoDTO']->tree)){
817
        $distribution_tree = $descriptionElements['DistributionInfoDTO']->tree;
818
      }
819
    }
820

    
821
  } else if (is_array($descriptionElements)) {
822
    // --- normal description element arrays
823
    foreach ($descriptionElements as $descriptionElement) {
824

    
825
      // --- DISTRIBUTION ---- //
826
      /* no longer in use, has been replaced
827
       *
828
      if ($descriptionElement->feature->uuid == UUID_DISTRIBUTION) {
829
        if ($descriptionElement->class == 'Distribution' && is_object($descriptionElement->area)) {
830
          $sortKey = $descriptionElement->area->representation_L10n;
831
          $distributionElements[$sortKey] = $descriptionElement;
832
        }
833
        else if ($descriptionElement->class == 'TextData') {
834
          $asListElement = FALSE;
835
          $repr = theme('cdm_descriptionElementTextData', array(
836
            'element' => $descriptionElement,
837
            'asListElement' => $asListElement,
838
            'feature_uuid' => $descriptionElement->feature->uuid,
839
          ));
840

    
841
          if (!array_search($repr, $outArray)) {
842
            $outArray[] = $repr;
843
            // TODO HINT: sorting in theme_cdm_descriptionElementArray will
844
            // not work since this array contains html attributes with uuids
845
            // !!!!
846
            $sortOutArray = TRUE;
847
            $glue = '<br/> ';
848
            $enclosingTag = 'p';
849
          }
850
        }
851
      }
852
      else
853
*/
854
      // --- IMAGE_SOURCES --- //
855
      if ($descriptionElement->feature->uuid == UUID_IMAGE_SOURCES) {
856
        $image_sources[] = $descriptionElement;
857
      }
858
      // --- USE TEXTDATA --- //
859
      elseif ($descriptionElement->feature->uuid == UUID_USE) {
860
        // Do nothing to avoid rendering.
861
      } else {
862
        /* decide based on the description element class
863
         *
864
         * TODO provide api_hook as extension point for this
865
         */
866
        switch ($descriptionElement->class) {
867
          case 'TextData':
868
            $asListElement = TRUE;
869
            $outArray[] = theme('cdm_descriptionElementTextData', array(
870
              'element' => $descriptionElement,
871
              'asListElement' => $asListElement,
872
              'feature_uuid' => $descriptionElement->feature->uuid,
873
            ));
874
            break;
875
          case 'CommonTaxonName':
876
            $outArray[] = theme('cdm_descriptionElement_CommonTaxonName', array('element' => $descriptionElement));
877
          break;
878
          case 'CategoricalData':
879
            $outArray[] = theme('cdm_descriptionElement_CategoricalData', array('element' => $descriptionElement));
880
            break;
881
          case 'QuantitativeData':
882
            $outArray[] = theme('cdm_descriptionElement_QuantitativeData', array('element' => $descriptionElement));
883
            break;
884
          case 'IndividualsAssociation':
885
            $outArray[] = theme('cdm_descriptionElement_IndividualsAssociation', array('element' => $descriptionElement));
886
            break;
887
          case 'TaxonInteraction':
888
            $outArray[] = theme('cdm_descriptionElement_TaxonInteraction', array('element' => $descriptionElement));
889
            break;
890
          case 'Uses':
891
          /* IGNORE Uses classes, these are handled completely in theme_cdm_UseDescription */
892
          break;
893
        default:
894
        $outArray[] = '<li>No method for rendering unknown description class: ' . $descriptionElement->class . '</li>';
895
      }
896
    }
897
    } // --- END loop over normal description element arrays
898

    
899
    // If feature = NAME USAGE sort the list of sources.
900
    // This is ONLY for FLORA MALESIANA and FLORE d'AFRIQUE CENTRALE.
901
    if ($descriptionElement->feature->uuid == UUID_NAME_USAGE) {
902
      sort($outArray);
903
    }
904

    
905
    if (isset($image_sources)) {
906
      $outArray[] = theme('cdm_description_element_image_source', array('image_sources' => $image_sources, 'asListElement' => TRUE));
907
    }
908
  } // END normal description element arrays
909

    
910

    
911
//   if ($distribution_tree) {
912
//     $outArray[] = theme('cdm_description_ordered_distributions', array('taxon_uuid' => $taxon_uuid, 'distribution_tree' => $distribution_tree));
913
//   }
914
//   else {
915
//     ksort($distributionElements);
916
//     // TODO , $entryEnclosingTag);
917
//     $outArray[] = theme('cdm_descriptionElement_Distribution', array(
918
//       'descriptionElements' => $distributionElements,
919
//     ));
920
//   }
921

    
922
  $out = theme('cdm_descriptionElementArray', array(
923
    'elementArray' => $outArray,
924
    'feature' => $feature,
925
    'glue' => $glue,
926
    'sortArray' => $sortOutArray,
927
    'enclosingHtml' => $enclosingTag,
928
  ));
929

    
930
  RenderHints::popFromRenderStack();
931
  return $out;
932
}
933

    
934
/**
935
 * @todo Please document this function.
936
 * @see http://drupal.org/node/1354
937
 */
938
function compare_image_sources($a, $b) {
939
  if ($a->multilanguageText_L10n->text == $b->multilanguageText_L10n->text) {
940
    return 0;
941
  }
942
  return ($a->multilanguageText_L10n->text < $b->multilanguageText_L10n->text) ? -1 : 1;
943
}
944

    
945
/**
946
 * @todo Please document this function.
947
 * @see http://drupal.org/node/1354
948
 */
949
function theme_cdm_description_element_image_source($variables) {
950
  $image_sources = $variables['image_sources'];
951
  $asListElement = $variables['asListElement'];
952
  $out = '';
953
  $separator = ',';
954
  RenderHints::pushToRenderStack('descriptionElementImageSource');
955
  RenderHints::setFootnoteListKey(UUID_IMAGE_SOURCES);
956

    
957
  // Sorting the image sources.
958
  usort($image_sources, "compare_image_sources");
959
  // Generate the footnotes.
960
  foreach ($image_sources as $image_source) {
961
    $footNoteKeys = cdm_annotations_as_footnotekeys($image_source);
962
    foreach ($image_source->sources as $source) {
963
      if (_is_original_source_type($source)) {
964
        $fn_key = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), theme('cdm_OriginalSource', array(
965
          'source' => $source,
966
          'doLink' => FALSE,
967
        )));
968
        // Ensure uniqueness of the footnote keys.
969
        cdm_add_footnote_to_array($footNoteKeys, $fn_key);
970
      }
971
    }
972
    // Sort and render footnote keys.
973
    $footnote_key_list_str = '';
974
    asort($footNoteKeys);
975
    foreach ($footNoteKeys as $footNoteKey) {
976
      $footnote_key_list_str .= theme('cdm_footnote_key', array('footnoteKey' => $footNoteKey, 'separator' => ($footnote_key_list_str ? $separator : '')));
977
    }
978
    // Return value!
979
    $out .= '<span class="descriptionElement descriptionElement-' . $image_source->uuid . '">' . $image_source->multilanguageText_L10n->text . $footnote_key_list_str . '; </span>';
980
  }
981

    
982
  RenderHints::popFromRenderStack();
983
  return $out;
984
}
985

    
986
/**
987
 * @todo Please document this function.
988
 * @see http://drupal.org/node/1354
989
 */
990
function theme_cdm_descriptionElement_Distribution($variables) {
991
  $descriptionElements = $variables['descriptionElements'];
992
  $enclosingTag = $variables['enclosingTag'];
993
  if (!$enclosingTag) {
994
    $enclosingTag = "span";
995
  }
996

    
997
  $out = '';
998
  RenderHints::pushToRenderStack('descriptionElementDistribution');
999
  RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
1000

    
1001
  foreach ($descriptionElements as $descriptionElement) {
1002

    
1003
    $footnote_key_list_str = cdm_create_description_element_footnotes($descriptionElement);
1004

    
1005
    $out .= '<' . $enclosingTag . ' class="descriptionElement descriptionElement-' . $descriptionElement->uuid . '">'
1006
        . $descriptionElement->area->representation_L10n . $footnote_key_list_str
1007
        . ' </' . $enclosingTag . '>';
1008
  }
1009

    
1010
  RenderHints::popFromRenderStack();
1011
  return $out;
1012
}
1013

    
1014

    
1015
/**
1016
 * Compare two different footnotes objects.
1017
 *
1018
 * The comparison is based on the footnote key. The one which is
1019
 * displayed as footnote number.
1020
 *
1021
 * @param mixed $a
1022
 *   Footnote object $a.
1023
 * @param mixed $b
1024
 *   Footnote object $b.
1025
 */
1026
function footnotes_key_compare($a, $b) {
1027
  $res = 0;
1028
  if (empty($a) || empty($b)) {
1029
    return $res;
1030
  }
1031
  if ($a->keyStr < $b->keyStr) {
1032
    $res = -1;
1033
  }
1034
  elseif ($a->keyStr > $b->keyStr) {
1035
    $res = 1;
1036
  }
1037
  return $res;
1038
}
1039

    
1040
/**
1041
 * @todo Please document this function.
1042
 * @see http://drupal.org/node/1354
1043
 */
1044
function theme_cdm_description_ordered_distributions($variables) {
1045

    
1046
//  TODO REMOVE $taxon_uuid = $variables['taxon_uuid'];
1047
// TODO REMOVE
1048
  $distribution_tree = $variables['distribution_tree'];
1049

    
1050
  // Returning NULL if there are no description elements.
1051
  if ($distribution_tree == null) {
1052
    return NULL;
1053
  }
1054

    
1055
  // Initialization of some variables.
1056
  $out = '';
1057
  $separator = ',';
1058
  RenderHints::pushToRenderStack('descriptionElementDistribution');
1059
  RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
1060

    
1061

    
1062
  /* TODO REMOVE
1063
  // Getting all the taxon description for a given taxon.
1064
  $markerTypesEmpty = array();
1065
  // $markerTypesEmpty['markerTypes'] = 'af9860ff-08f5-4b4d-863c-49ae96985115';
1066
  $markerTypesEmpty['markerTypes'] = '';
1067
  $queryString = $markerTypesEmpty['markerTypes'] ? queryString($markerTypesEmpty) : '';
1068

    
1069
  // Getting the sortered distributions (omitting level ??).
1070
  $taxonDescriptions = cdm_ws_get(CDM_WS_TAXON . "/$0/descriptions", $taxon_uuid, $queryString);
1071
  foreach ($taxonDescriptions->records as $description) {
1072
    $descriptions_uuids[] = $description->uuid;
1073
  }
1074
  $request_params = cdm_distribution_filter_query();
1075
  $request_params['omitLevels'] = UUID_NAMEDAREALEVEL_TDWGLEVEL_2;
1076
  $ordered_areas = cdm_ws_get(CDM_WS_PORTAL_DESCRIPTION_DISTRIBUTION_TREE, join(',', $descriptions_uuids), queryString($request_params));
1077
  */
1078

    
1079
  $ordered_areas = $distribution_tree;
1080
  if (isset($ordered_areas->rootElement->children)) {
1081
    $ordered_areas = $ordered_areas->rootElement->children;
1082
  }
1083

    
1084
  // Printing the distributions.
1085
  if (is_array($ordered_areas) && count($ordered_areas) > 0) {
1086
    foreach ($ordered_areas as $element_level1) {
1087
      // Level1.
1088
      $out .= '<dt>' . $element_level1->nodeId->representation_L10n . ':</dt> ';
1089
      $out .= '<dd>';
1090

    
1091
      // Level3.
1092
      foreach ($element_level1->children as $element_level3) {
1093
        $text_l3 = $element_level3->nodeId->representation_L10n;
1094
        $fnKeysLevel3Str = '';
1095
        $fnKeysLevel3 = cdm_annotations_as_footnotekeys($element_level3->data);
1096
        if (isset($element_level3->data[0])) {
1097
          foreach ($element_level3->data as $description_level3){
1098
            foreach ($description_level3->sources as $source) {
1099
              if (_is_original_source_type($source)) {
1100
                $fn_key3 = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), theme('cdm_OriginalSource', array('source' => $source, 'doLink' => FALSE)));
1101
                cdm_add_footnote_to_array($fnKeysLevel3, $fn_key3);
1102
              }
1103
            }
1104
          }
1105
        }
1106
        // Level4.
1107
        $l4_regions = array();
1108
        foreach ($element_level3->children as $element_level4) {
1109
          if (isset($element_level4->data[0])) {
1110
            $text_l4 = $element_level4->nodeId->representation_L10n;
1111
            $l4_regions[$element_level3->nodeId->representation_L10n] = array();
1112
            $fnKeysLevel4Str = '';
1113
            foreach($element_level4->data as $description_level4) {
1114
              $fnKeysLevel4 = cdm_annotations_as_footnotekeys($description_level4);
1115
              foreach ($description_level4->sources as $source) {
1116
                if (_is_original_source_type($source)) {
1117
                  $fn_key4 = FootnoteManager::addNewFootnote(
1118
                      RenderHints::getFootnoteListKey(),
1119
                      theme('cdm_OriginalSource', array('source' => $source, 'doLink' => FALSE)));
1120
                  cdm_add_footnote_to_array($fnKeysLevel4, $fn_key4);
1121
                }
1122
              }
1123
              usort($fnKeysLevel4, "footnotes_key_compare");
1124
              if(!isset( $l4_regions[$text_l4])){
1125
                $l4_regions[$text_l4] = $fnKeysLevel4;
1126
              } else {
1127
                $l4_regions[$text_l4] = array_merge($l4_regions[$text_l4], $fnKeysLevel4);
1128
              }
1129
            }
1130
          }
1131
        }// Level4.
1132
        // Managing level3 and level4 for generating the right output.
1133
        usort($fnKeysLevel3, "footnotes_key_compare");
1134
        foreach ($fnKeysLevel3 as $key3) {
1135
          foreach ($l4_regions as $key4 => $value4) {
1136
            cdm_add_footnote_to_array($l4_regions[$key4], $key3);
1137
          }
1138
        }
1139
        if ($element_level3->numberOfChildren == 1 && $text_l3 == $element_level3->children[0]->nodeId->representation_L10n) {
1140
          // var_dump($element_level3->children[0]->data->area->representation_L10n);
1141
          $fnStr = '';
1142
          $region = array_pop($l4_regions);
1143
          foreach ($region as $key) {
1144
            $fnStr .= theme('cdm_footnote_key', array('footnoteKey' => $key, 'separator' => ($fnStr ? $separator : '')));
1145
          }
1146
          $out .= "$text_l3 $fnStr; ";
1147
          // Removing whitespaces when &fnStr is empty.
1148
          if (substr($out, -3) == ' ; ') {
1149
            $out = substr($out, 0, -3) . '; ';
1150
          }
1151
        } else {
1152
          $fnKeysLevel3Str = '';
1153
          foreach ($fnKeysLevel3 as $key) {
1154
            $fnKeysLevel3Str .= theme('cdm_footnote_key', array('footnoteKey' => $key, 'separator' => ($fnKeysLevel3Str ? $separator : '')));
1155
          }
1156
          $text_l4_aux = '';
1157
          foreach ($l4_regions as $key => $value) {
1158
            $fnKeysLevel4Str = '';
1159
            if (is_array($l4_regions[$key])) {
1160
              foreach ($l4_regions[$key] as $fnkey) {
1161
                $fnKeysLevel4Str .= theme('cdm_footnote_key', array('footnoteKey' => $fnkey, 'separator' => ($fnKeysLevel4Str ? $separator : '')));
1162
              }
1163
            }
1164
            // if ($key != $text_l3 || sizeof($l4_regions > 1)){
1165
            if ($key != $text_l3) {
1166
              $text_l4_aux .= "$key $fnKeysLevel4Str, ";
1167
            }
1168
          }
1169
          $text_l4_aux = substr($text_l4_aux, 0, -2);
1170

    
1171
          if (strlen($text_l4_aux) > 0) {
1172
            $out .= "$text_l3 $fnKeysLevel3Str ($text_l4_aux); ";
1173
          }
1174
          else {
1175
            $out .= "$text_l3 $fnKeysLevel3Str; ";
1176
          }
1177
        }
1178
      }// Level3.
1179
      $out = substr($out, 0, -2);
1180
      $out .= '.</dd>';
1181
    }// Level1.
1182
  }
1183
  RenderHints::popFromRenderStack();
1184
  return $out;
1185
}
1186

    
1187

    
1188
/*
1189
function theme_cdm_descriptionElement_Distribution($descriptionElements){ $out
1190
  = ''; $separator = ',';
1191
  RenderHints::pushToRenderStack('descriptionElementDistribution');
1192
  RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
1193
  foreach($descriptionElements as $descriptionElement){ // annotations as
1194
  footnotes $annotationFootnoteKeys = theme('cdm_annotations_as_footnotekeys',
1195
  $descriptionElement); // source references as footnotes
1196
  $sourcesFootnoteKeyList = ''; foreach($descriptionElement->sources as
1197
  $source){ if(_is_original_source_type($source)){ $_fkey =
1198
  FootnoteManager::addNewFootnote(UUID_DISTRIBUTION,
1199
  theme('cdm_OriginalSource', $source, FALSE));
1200
  $sourcesFootnoteKeyList .= theme('cdm_footnote_key', $_fkey,
1201
  UUID_DISTRIBUTION, ($sourcesFootnoteKeyList ? $separator : '')); } }
1202
  if($annotationFootnoteKeys && $sourcesFootnoteKeyList){
1203
  $annotationFootnoteKeys .= $separator; } $out .=
1204
  $descriptionElement->area->representation_L10n . $annotationFootnoteKeys .
1205
  $sourcesFootnoteKeyList . ' '; } $out = substr($out, 0,
1206
  strlen($out)-strlen($separator) ); RenderHints::popFromRenderStack(); return
1207
  $out; }
1208
*/
1209

    
1210
/**
1211
 * Returns a list of a specific type of IdentificationKeys.
1212
 *
1213
 * The list can be restricteded by a taxon.
1214
 *
1215
 * @param string $type
1216
 *   The simple name of the cdm class implementing the interface
1217
 *   IdentificationKey, valid values are:
1218
 *   PolytomousKey, MediaKey, MultiAccessKey.
1219
 * @param string $taxonUuid
1220
 *   If given this parameter restrict the listed keys to those which have
1221
 *   the taxon identified be this uuid in scope.
1222
 *
1223
 * @return array
1224
 *   List with identification keys.
1225
 */
1226
function _list_IdentificationKeys($type, $taxonUuid = NULL, $pageSize = NULL, $pageNumber = NULL) {
1227
  if (!$type) {
1228
    drupal_set_message(t('Type parameter is missing'), 'error');
1229
    return;
1230
  }
1231
  $cdm_ws_pasepath = NULL;
1232
  switch ($type) {
1233
    case "PolytomousKey":
1234
      $cdm_ws_pasepath = CDM_WS_POLYTOMOUSKEY;
1235
      break;
1236

    
1237
    case "MediaKey":
1238
      $cdm_ws_pasepath = CDM_WS_MEDIAKEY;
1239
      break;
1240

    
1241
    case "MultiAccessKey":
1242
      $cdm_ws_pasepath = CDM_WS_MULTIACCESSKEY;
1243
      break;
1244

    
1245
  }
1246

    
1247
  if (!$cdm_ws_pasepath) {
1248
    drupal_set_message(t('Type parameter is not valid: ') . $type, 'error');
1249
  }
1250

    
1251
  $queryParameters = '';
1252
  if (is_numeric($pageSize)) {
1253
    $queryParameters = "pageSize=" . $pageSize;
1254
  }
1255
  else {
1256
    $queryParameters = "pageSize=0";
1257
  }
1258

    
1259
  if (is_numeric($pageNumber)) {
1260
    $queryParameters = "pageNumber=" . $pageNumber;
1261
  }
1262
  else {
1263
    $queryParameters = "pageNumber=0";
1264
  }
1265
  $queryParameters = NULL;
1266
  if ($taxonUuid) {
1267
    $queryParameters = "findByTaxonomicScope=$taxonUuid";
1268
  }
1269
  $pager = cdm_ws_get($cdm_ws_pasepath, NULL, $queryParameters);
1270

    
1271
  if (!$pager || $pager->count == 0) {
1272
    return array();
1273
  }
1274
  return $pager->records;
1275
}
1276

    
1277
/**
1278
 * @todo Please document this function.
1279
 * @see http://drupal.org/node/1354
1280
 */
1281
function theme_cdm_IdentificationKey($variables) {
1282
  $out = '';
1283
  $identificationKey = $variables['identificationKey'];
1284
  $doLinkToKeyPage = $variables['doLinkToKeyPage'];
1285
  $showIdentificationKeyTitle = $variables['showIdentificationKeyTitle'];
1286
  $parentRenderPath = RenderHints::getRenderPath();
1287
  RenderHints::pushToRenderStack("IdentificationKey");
1288

    
1289
  if ($showIdentificationKeyTitle) {
1290
    if ($doLinkToKeyPage) {
1291
      $out = l($identificationKey->titleCache, path_to_key($identificationKey->class, $identificationKey->uuid));
1292
    }
1293
    else {
1294
      $out = $identificationKey->titleCache;
1295
    }
1296
  }
1297
  if (isset($identificationKey->sources) && is_array($identificationKey->sources)) {
1298
    // order and display sources.
1299
    $sources = oder_sources($identificationKey->sources, TRUE);
1300
    $out .= '<div class="sources">';
1301
    $out .=  implode('', $sources);
1302
    $out .= '</div>';
1303
  }
1304
  // Display annotations.
1305
  $out .= theme('cdm_annotations', array('annotations' => cdm_ws_getAnnotationsFor($identificationKey), 'enclosingTag' => 'div'));
1306
  RenderHints::popFromRenderStack();
1307
  return $out;
1308
}
1309

    
1310
/**
1311
 * @todo Please document this function.
1312
 * @see http://drupal.org/node/1354
1313
 */
1314
function theme_cdm_polytomousKey($variables) {
1315
  $polytomousKey = $variables['polytomousKey'];
1316

    
1317
  // TODO settings needed.
1318
  // @see http://en.wikipedia.org/wiki/Single_access_key#Presentation_styles
1319
  // @see http://dev.e-taxonomy.eu/trac/ticket/2152
1320
  $keyStyle = "linkedStyle";
1321

    
1322
  RenderHints::pushToRenderStack("polytomousKey");
1323
  // Key nodes in linked style.
1324
  $out = '<table class="polytomousKey polytomousKey_' . $keyStyle . '">';
1325
  $out .= theme('cdm_polytomousKey_' . $keyStyle . '_subgraph', array('polytomousKeyNode' => $polytomousKey->root));
1326
  $out .= '</table>';
1327
  RenderHints::popFromRenderStack();
1328
  return $out;
1329
}
1330

    
1331
/**
1332
 * @todo Please document this function.
1333
 * @see http://drupal.org/node/1354
1334
 */
1335
function theme_cdm_polytomousKey_linkedStyle_subgraph($variables) {
1336
  $polytomousKeyNode = $variables['polytomousKeyNode'];
1337
  static $statementCountCharacter = '\'';
1338
  $out = "";
1339

    
1340
  if (is_array($polytomousKeyNode->children)) {
1341
    $childIndex = 0;
1342

    
1343
    // Render edges of the current node.
1344
    foreach ($polytomousKeyNode->children as &$child) {
1345

    
1346
      if (!isset($child->statement) && isset($child->taxon->uuid)) {
1347
        // Skip node with empty statements (see below for explanation: "Special
1348
        // case").
1349
        // this skipping here happens always in the next deeper level of iteration
1350
        // the check below is node on the level above
1351
        continue;
1352
      }
1353

    
1354
      /*
1355
       * Special case: Child nodes with empty statements but taxa as leaf are to
1356
       * treated as if all those taxa where direct children of the source node.
1357
       */
1358
      $islinkToManyTaxa = !isset($child->children[0]->statement) && isset($child->children[0]->taxon->uuid);
1359
      $islinkToTaxon = isset($child->taxon->uuid);
1360
      $islinkToSubKey = isset($child->subkey->uuid);
1361
      $islinkToOtherNode = isset($child->otherNode);
1362
      // Either NULL or 0.
1363
      $islinkToNode = $child->nodeNumber && !$islinkToManyTaxa && !$islinkToOtherNode;
1364
      $hasQuestion = !empty($polytomousKeyNode->question->label_l10n);
1365
      $hasFeature = isset($polytomousKeyNode->feature);
1366

    
1367
      // $indentEdge = $hasQuestion && $childIndex > 0;
1368
      // Question.
1369
      if ($hasQuestion && $childIndex == 0) {
1370
        // Place question, as extra table row.
1371
        $out .= '<tr class="question new_section">';
1372
        $out .= '<td class="nodeNumber">' . uuid_anchor($polytomousKeyNode->uuid, $polytomousKeyNode->nodeNumber) . "</td>";
1373
        $out .= '<td class="question">' . $polytomousKeyNode->question->label_l10n . '</td>';
1374
        $out .= '</tr>';
1375
      }
1376

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

    
1379
      if ($hasQuestion) {
1380
        $out .= '<td class="nodeNumber"></td>';
1381
      }
1382
      else {
1383
        $out .= '<td class="nodeNumber">' . uuid_anchor($polytomousKeyNode->uuid, $polytomousKeyNode->nodeNumber . str_pad("", $childIndex, $statementCountCharacter)) . "</td>";
1384
      }
1385

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

    
1388
      // Feature.
1389
      if ($hasFeature) {
1390
        $out .= $polytomousKeyNode->feature->representation_L10n . ": ";
1391
      }
1392

    
1393
      // Statement.
1394
      $out .= $child->statement->label_l10n;
1395

    
1396
      // --- Links to nodes taxa and subkeys.
1397
      $out .= '<div class="nodeLink">';
1398

    
1399
      // Link to a PolytomousKeyNode.
1400
      if ($islinkToNode) {
1401
        $out .= '<div class="nodeLinkToNode">';
1402
        if (isset($child->modifyingText)) {
1403
          $out .= theme('cdm_poytomousKeyNode_modifyingText', array('modifyingText' => $child->modifyingText));
1404
        }
1405
        $out .= l($child->nodeNumber, request_path(), array(
1406
          'attributes' => NULL,
1407
          'query' => NULL,
1408
          'fragment' => $child->uuid,
1409
        )) . '</div>';
1410
      }
1411

    
1412
      // Link to a PolytomousKeyNode.
1413
      if ($islinkToOtherNode) {
1414
        $out .= '<div class="nodeLinkToOtherNode">';
1415
        if (isset($child->modifyingText)) {
1416
          $out .= theme('cdm_poytomousKeyNode_modifyingText', array('modifyingText' => $child->modifyingText));
1417
        }
1418
        $out .= l($child->otherNode->nodeNumber, $_REQUEST["q"], array(
1419
          'attributes' => NULL,
1420
          'query' => NULL,
1421
          'fragment' => $child->otherNode->uuid,
1422
        )) . '</div>';
1423
      }
1424

    
1425
      // Link to one or many taxa.
1426
      if ($islinkToTaxon || $islinkToManyTaxa) {
1427

    
1428
        if ($islinkToManyTaxa) {
1429
          $taxonChildren = $child->children;
1430
        }
1431
        else {
1432
          $taxonChildren = array(
1433
            $child,
1434
          );
1435
        }
1436

    
1437
        foreach ($taxonChildren as $taxonChild) {
1438
          // TODO many taxa $child->children->taxon.
1439
          $out .= '<div class="nodeLinkToTaxon">';
1440
          if (isset($taxonChild->modifyingText)) {
1441
            $out .= theme('cdm_poytomousKeyNode_modifyingText', array('modifyingText' => $taxonChild->modifyingText));
1442
          }
1443
          $out .= theme("cdm_taxonName", array('taxonName' => $taxonChild->taxon->name, 'nameLink' => url(path_to_taxon($taxonChild->taxon->uuid))));
1444
          $out .= '</div>';
1445
        }
1446

    
1447
        // Link to a subkey.
1448
        if ($islinkToSubKey) {
1449
          $out .= '<div class="nodeLinkToSubkey">' . theme('cdm_IdentificationKey', array('identificationKey' => $child->subkey)) . '</div>';
1450
        }
1451
      }
1452

    
1453
      $out .= '</div>'; // End node link.
1454
      $out .= '</td>'; // End edge.
1455
      $out .= '</tr>';
1456

    
1457
      $childIndex++;
1458
    }
1459

    
1460
    // Recurse into child nodes.
1461
    foreach ($polytomousKeyNode->children as &$child) {
1462
      $out .= theme('cdm_polytomousKey_linkedStyle_subgraph', array('polytomousKeyNode' => $child));
1463
    }
1464
  }
1465

    
1466
  return $out;
1467
}
1468

    
1469
/**
1470
 * @todo Please document this function.
1471
 * @see http://drupal.org/node/1354
1472
 */
1473
function theme_cdm_poytomousKeyNode_modifyingText($variables) {
1474
  $out = '';
1475
  $modifyingText = $variables['modifyingText'];
1476
  if (is_object($modifyingText)) {
1477
    $i = 0;
1478
    foreach (get_object_vars($modifyingText) as $lang => $languageString) {
1479
      $out .= ($i++ > 0 ? ', ' : '') . '<span class="modifyingText">' . $languageString->text . '</span> ';
1480
    }
1481
  }
1482
  return $out;
1483
}
1484

    
1485
/**
1486
 * Returns HTML for a list of a specific type of IdentificationKeys.
1487
 *
1488
 * The list can be restricteded by a taxon.
1489
 *
1490
 * @param array $variables
1491
 *   An associative array containing:
1492
 *   - type: The simple name of the cdm class implementing the interface
1493
 *     IdentificationKey, valid values are:
1494
 *     PolytomousKey, MediaKey, MultiAccessKey
1495
 *   - taxonUuid: If given, this parameter restrict the listed keys to those
1496
 *     which have the taxon identified be this uuid in scope.
1497
 *
1498
 * @ingroup themeable
1499
 */
1500
function theme_cdm_list_IdentificationKeys($variables) {
1501
  $type = $variables['type'];
1502
  $taxonUuid = $variables['taxonUuid'];
1503
  $keyList = _list_IdentificationKeys($type, $taxonUuid);
1504
  if (!$keyList || count($keyList) == 0) {
1505
    return;
1506
  }
1507

    
1508
  RenderHints::pushToRenderStack('list_IdentificationKeys');
1509
  $out = '<ul>';
1510
  foreach ($keyList as $key) {
1511
    $out .= '<li>';
1512
    $out .= theme('cdm_IdentificationKey', array('identificationKey' => $key));
1513
    $out .= '</li>';
1514
  }
1515
  $out .= '</ul>';
1516
  $out .= theme("cdm_annotation_footnotes", array('footnoteListKey' => RenderHints::getRenderPath()));
1517
  RenderHints::popFromRenderStack();
1518

    
1519
  return $out;
1520
}
1521

    
1522
/**
1523
 * @todo Please document this function.
1524
 * @see http://drupal.org/node/1354
1525
 */
1526
function theme_cdm_block_IdentificationKeys($variables) {
1527
  $taxonUuid = $variables['taxonUuid'];
1528
  static $types = array(
1529
    "PolytomousKey" => "Polytomous",
1530
    "MediaKey" => "Media",
1531
    "MultiAccessKey" => "Multiaccess",
1532
  );
1533
  RenderHints::pushToRenderStack('block_IdentificationKeys');
1534
  $out = '';
1535
  foreach ($types as $type => $label) {
1536
    $keylist = theme('cdm_list_IdentificationKeys', array('type' => $type, 'taxonUuid' => $taxonUuid));
1537
    if (!$keylist) {
1538
      continue;
1539
    }
1540
    $out .= '<div class="' . $type . '">';
1541
    $out .= '<h3>' . t($label) . "</h3>";
1542
    $out .= $keylist;
1543
    $out .= '</div>';
1544
  }
1545
  RenderHints::popFromRenderStack();
1546
  return $out;
1547
}
1548

    
1549
/**
1550
 * This theming function formats the use description and use record list for
1551
 * these descriptions.
1552
 *
1553
 * @see http://drupal.org/node/1354
1554
 */
1555
function theme_cdm_UseDescription($variables) {
1556
  $descriptions = $variables['description'];
1557
  $taxonUuid = $variables['taxonUuid'];
1558
  $out = '<div id="content"><ul id="Description" class ="description">';
1559
  if ($descriptions == NULL) {
1560
    return;
1561
  }
1562
  $descriptionSynonyms = '';
1563
  $descriptionOut = '';
1564
  $synonymOut = '';
1565
  $currentTaxon = cdm_ws_get(CDM_WS_PORTAL_TAXON, $taxonUuid);
1566

    
1567
  foreach ($descriptions as $description) {
1568
    $useSummary = '';
1569
    foreach ($description->elements as $element) {
1570

    
1571
      if ($element->feature->uuid == UUID_USE && !(strlen($useSummary) > 0) && isset($element->multilanguageText_L10n)) {
1572
        $useSummary = $element->multilanguageText_L10n->text;
1573
      }
1574
    }
1575
    // uses will be ordered by source
1576
    foreach ($description->sources as $source) {
1577
      $is_about_current_taxon = FALSE;
1578
      $originalTaxonUsedInSource = NULL;
1579
      $originalTaxonPager = NULL;
1580
      if ($source->originalNameString) {
1581
        $request_params = array();
1582
        $request_params['query'] = $source->originalNameString;
1583
        $request_params['matchMode'] = "EXACT";
1584
        $originalTaxonPager = cdm_ws_get(CDM_WS_PORTAL_NAME_FINDBYNAME, NULL, queryString($request_params));
1585
        if ($originalTaxonPager->count > 0) {
1586
          $originalTaxonUsedInSource = $originalTaxonPager->records[0];
1587
        }
1588
        else {
1589
          $originalTaxonUsedInSource = $currentTaxon->name;
1590
        }
1591
      }
1592
      else {
1593
        $originalTaxonUsedInSource = $currentTaxon->name;
1594
      }
1595

    
1596
      $is_about_current_taxon = $currentTaxon->name->uuid == $originalTaxonUsedInSource->uuid;
1597

    
1598
      if (!$is_about_current_taxon) {
1599
        $descriptionOut .= '<li class="descriptionText DescriptionElement">';
1600
        $name_used_in_source_link_to_show_use = l($source->originalNameString, path_to_name($originalTaxonUsedInSource->uuid), array(
1601
          'absolute' => TRUE,
1602
          'html' => TRUE,
1603
        ));
1604
        $descriptionOut .= $name_used_in_source_link_to_show_use . ': ';
1605
        $descriptionOut .= $useSummary;
1606
        foreach ($description->sources as $source) {
1607
          $descriptionOut .= " (" . theme('cdm_OriginalSource', array('source' => $source, 'doLink' => TRUE)) . ")";
1608
        }
1609
        $hasUseRecords = FALSE;
1610
        $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>';
1611
        foreach ($description->elements as $descriptionElement) {
1612
          if ($descriptionElement->feature->uuid == UUID_USE_RECORD) {
1613
            $hasUseRecords = TRUE;
1614
            // FIXME localization hardcoded to English
1615
            $useRecordTags = explode(';', $descriptionElement->modifyingText_l10n);
1616
            $descriptionUseRecordOut .= '<tr>';
1617
            $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>';
1618
            $descriptionUseRecordOut .= '</tr>';
1619
          }
1620
        }
1621
        $descriptionUseRecordOut .= '</table></div>';
1622
        if ($hasUseRecords) {
1623
          $descriptionOut .= $descriptionUseRecordOut . '</li>';
1624
        }
1625
      }
1626
      else {
1627
        // TODO +/- duplicate of above, unify this code
1628
        $synonymOut .= '<li class="descriptionText DescriptionElement">';
1629
        $name_used_in_source_link_to_show_use = l($source->originalNameString, path_to_name($originalTaxonUsedInSource->uuid), array(
1630
          'absolute' => TRUE,
1631
          'html' => TRUE,
1632
        ));
1633

    
1634
        $synonymOut .= $name_used_in_source_link_to_show_use . ': ';
1635
        $synonymOut .= $useSummary;
1636
        foreach ($description->sources as $source) {
1637
          $synonymOut .= " (" . theme('cdm_OriginalSource', array('source' => $source, 'doLink' => TRUE)) . ")";
1638
        }
1639

    
1640
        $hasUseRecords = FALSE;
1641
        $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>';
1642
        foreach ($description->elements as $descriptionElement) {
1643
          if ($descriptionElement->feature->uuid == UUID_USE_RECORD) {
1644
            $hasUseRecords = TRUE;
1645
            $useRecordTags = explode(';', $descriptionElement->modifyingText_l10n);
1646
            $useRecordTableOut .= '<tr>';
1647
            $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>';
1648
            $useRecordTableOut .= '</tr>';
1649
          }
1650
        }
1651
        $useRecordTableOut .= '</table></div>';
1652
        if ($hasUseRecords) {
1653
          $synonymOut .= $useRecordTableOut . '</li>';
1654
        }
1655
      }
1656

    
1657
      // }
1658
    }
1659
  }
1660
  $out .= $descriptionOut . $synonymOut;
1661
  $out .= "</ul></div>";
1662
  return $out;
1663
}
1664

    
1665

    
1666
/**
1667
 * The theming function for a block of Uses Descriptions for a given taxon.
1668
 *
1669
 * The Uses block has been removed from the code but the according theme function
1670
 * is kept for compatibility reasons with existing code regarding palmweb.
1671
 *
1672
 */
1673
function theme_cdm_block_Uses($variables) {
1674
  $taxonUuid = $variables['taxonUuid'];
1675
  RenderHints::pushToRenderStack('block_Uses');
1676

    
1677
  if ($taxonUuid == NULL) {
1678
    return;
1679
  }
1680
  $out = '';
1681
  $markerTypes = array();
1682
  $markerTypes['markerTypes'] = UUID_MARKERTYPE_USE;
1683
  $useDescriptions = cdm_ws_get(CDM_WS_PORTAL_TAXON_DESCRIPTIONS, $taxonUuid, queryString($markerTypes));
1684
  if (!empty($useDescriptions)) {
1685
    // FIXME use theme_block instaed of hardcoding the block html here !!!!
1686
    $out .= '<div id="block-cdm_dataportal-feature-description" class="clear-block block block-cdm_dataportal-feature"><H2><a name="userecords"> </a> Uses </H2>';
1687
    $formatUseDescriptions = theme('cdm_UseDescription', array('description' => $useDescriptions, 'taxonUuid' => $taxonUuid));
1688

    
1689
    $out .= $formatUseDescriptions;
1690
    $out .= "</div>";
1691
  }
1692

    
1693
  return $out;
1694
}
(3-3/10)