Project

General

Profile

Download (56.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
  if (is_array($descriptionElements)) {
779
    // --- normal description element arrays
780
    foreach ($descriptionElements as $descriptionElement) {
781

    
782
      // --- IMAGE_SOURCES --- //
783
      if ($descriptionElement->feature->uuid == UUID_IMAGE_SOURCES) {
784
        $image_sources[] = $descriptionElement;
785
      }
786
      // --- USE TEXTDATA --- //
787
      elseif ($descriptionElement->feature->uuid == UUID_USE) {
788
        // Do nothing to avoid rendering.
789
      } else {
790
        /* decide based on the description element class
791
         *
792
         * TODO provide api_hook as extension point for this
793
         */
794
        switch ($descriptionElement->class) {
795
          case 'TextData':
796
            $asListElement = TRUE;
797
            $outArray[] = theme('cdm_descriptionElementTextData', array(
798
              'element' => $descriptionElement,
799
              'asListElement' => $asListElement,
800
              'feature_uuid' => $descriptionElement->feature->uuid,
801
            ));
802
            break;
803
          case 'CommonTaxonName':
804
            $outArray[] = theme('cdm_descriptionElement_CommonTaxonName', array('element' => $descriptionElement));
805
          break;
806
          case 'CategoricalData':
807
            $outArray[] = theme('cdm_descriptionElement_CategoricalData', array('element' => $descriptionElement));
808
            break;
809
          case 'QuantitativeData':
810
            $outArray[] = theme('cdm_descriptionElement_QuantitativeData', array('element' => $descriptionElement));
811
            break;
812
          case 'IndividualsAssociation':
813
            $outArray[] = theme('cdm_descriptionElement_IndividualsAssociation', array('element' => $descriptionElement));
814
            break;
815
          case 'TaxonInteraction':
816
            $outArray[] = theme('cdm_descriptionElement_TaxonInteraction', array('element' => $descriptionElement));
817
            break;
818
          case 'Uses':
819
          /* IGNORE Uses classes, these are handled completely in theme_cdm_UseDescription */
820
          break;
821
        default:
822
        $outArray[] = '<li>No method for rendering unknown description class: ' . $descriptionElement->class . '</li>';
823
      }
824
    }
825
    } // --- END loop over normal description element arrays
826

    
827
    // If feature = NAME USAGE sort the list of sources.
828
    // This is ONLY for FLORA MALESIANA and FLORE d'AFRIQUE CENTRALE.
829
    if ($descriptionElement->feature->uuid == UUID_NAME_USAGE) {
830
      sort($outArray);
831
    }
832

    
833
    if (isset($image_sources)) {
834
      $outArray[] = theme('cdm_description_element_image_source', array('image_sources' => $image_sources, 'asListElement' => TRUE));
835
    }
836
  } // END normal description element arrays
837

    
838

    
839
  $out = theme('cdm_descriptionElementArray', array(
840
    'elementArray' => $outArray,
841
    'feature' => $feature,
842
    'glue' => $glue,
843
    'sortArray' => $sortOutArray,
844
    'enclosingHtml' => $enclosingTag,
845
  ));
846

    
847
  RenderHints::popFromRenderStack();
848
  return $out;
849
}
850

    
851
/**
852
 * @todo Please document this function.
853
 * @see http://drupal.org/node/1354
854
 */
855
function compare_image_sources($a, $b) {
856
  if ($a->multilanguageText_L10n->text == $b->multilanguageText_L10n->text) {
857
    return 0;
858
  }
859
  return ($a->multilanguageText_L10n->text < $b->multilanguageText_L10n->text) ? -1 : 1;
860
}
861

    
862
/**
863
 * @todo Please document this function.
864
 * @see http://drupal.org/node/1354
865
 */
866
function theme_cdm_description_element_image_source($variables) {
867
  $image_sources = $variables['image_sources'];
868
  $asListElement = $variables['asListElement'];
869
  $out = '';
870
  $separator = ',';
871
  RenderHints::pushToRenderStack('descriptionElementImageSource');
872
  RenderHints::setFootnoteListKey(UUID_IMAGE_SOURCES);
873

    
874
  // Sorting the image sources.
875
  usort($image_sources, "compare_image_sources");
876
  // Generate the footnotes.
877
  foreach ($image_sources as $image_source) {
878
    $footNoteKeys = cdm_annotations_as_footnotekeys($image_source);
879
    foreach ($image_source->sources as $source) {
880
      if (_is_original_source_type($source)) {
881
        $fn_key = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), theme('cdm_OriginalSource', array(
882
          'source' => $source,
883
          'doLink' => FALSE,
884
        )));
885
        // Ensure uniqueness of the footnote keys.
886
        cdm_add_footnote_to_array($footNoteKeys, $fn_key);
887
      }
888
    }
889
    // Sort and render footnote keys.
890
    $footnote_key_list_str = '';
891
    asort($footNoteKeys);
892
    foreach ($footNoteKeys as $footNoteKey) {
893
      $footnote_key_list_str .= theme('cdm_footnote_key', array('footnoteKey' => $footNoteKey, 'separator' => ($footnote_key_list_str ? $separator : '')));
894
    }
895
    // Return value!
896
    $out .= '<span class="descriptionElement descriptionElement-' . $image_source->uuid . '">' . $image_source->multilanguageText_L10n->text . $footnote_key_list_str . '; </span>';
897
  }
898

    
899
  RenderHints::popFromRenderStack();
900
  return $out;
901
}
902

    
903
/**
904
 * @todo Please document this function.
905
 * @see http://drupal.org/node/1354
906
 */
907
function theme_cdm_descriptionElement_Distribution($variables) {
908
  $descriptionElements = $variables['descriptionElements'];
909
  $enclosingTag = $variables['enclosingTag'];
910
  if (!$enclosingTag) {
911
    $enclosingTag = "span";
912
  }
913

    
914
  $out = '';
915
  RenderHints::pushToRenderStack('descriptionElementDistribution');
916
  RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
917

    
918
  foreach ($descriptionElements as $descriptionElement) {
919

    
920
    $footnote_key_list_str = cdm_create_description_element_footnotes($descriptionElement);
921

    
922
    $out .= '<' . $enclosingTag . ' class="descriptionElement descriptionElement-' . $descriptionElement->uuid . '">'
923
        . $descriptionElement->area->representation_L10n . $footnote_key_list_str
924
        . ' </' . $enclosingTag . '>';
925
  }
926

    
927
  RenderHints::popFromRenderStack();
928
  return $out;
929
}
930

    
931

    
932
/**
933
 * Compare two different footnotes objects.
934
 *
935
 * The comparison is based on the footnote key. The one which is
936
 * displayed as footnote number.
937
 *
938
 * @param mixed $a
939
 *   Footnote object $a.
940
 * @param mixed $b
941
 *   Footnote object $b.
942
 */
943
function footnotes_key_compare($a, $b) {
944
  $res = 0;
945
  if (empty($a) || empty($b)) {
946
    return $res;
947
  }
948
  if ($a->keyStr < $b->keyStr) {
949
    $res = -1;
950
  }
951
  elseif ($a->keyStr > $b->keyStr) {
952
    $res = 1;
953
  }
954
  return $res;
955
}
956

    
957
/**
958
 * @todo Please document this function.
959
 * @see http://drupal.org/node/1354
960
 */
961
function theme_cdm_description_ordered_distributions($variables) {
962

    
963
  $distribution_tree = $variables['distribution_tree'];
964

    
965
  // Returning NULL if there are no description elements.
966
  if ($distribution_tree == null) {
967
    return NULL;
968
  }
969

    
970
  // Initialization of some variables.
971
  $out = '';
972
  $separator = ',';
973
  RenderHints::pushToRenderStack('descriptionElementDistribution');
974
  RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
975

    
976
  $ordered_areas = $distribution_tree;
977
  if (isset($ordered_areas->rootElement->children)) {
978
    $ordered_areas = $ordered_areas->rootElement->children;
979
  }
980

    
981
  // Printing the distributions.
982
  if (is_array($ordered_areas) && count($ordered_areas) > 0) {
983
    foreach ($ordered_areas as $element_level1) {
984
      // Level1.
985
      $out .= '<dt>' . $element_level1->nodeId->representation_L10n . ':</dt> ';
986
      $out .= '<dd>';
987

    
988
      // Level3.
989
      foreach ($element_level1->children as $element_level3) {
990
        $text_l3 = $element_level3->nodeId->representation_L10n;
991
        $fnKeysLevel3Str = '';
992
        $fnKeysLevel3 = cdm_annotations_as_footnotekeys($element_level3->data);
993
        if (isset($element_level3->data[0])) {
994
          foreach ($element_level3->data as $description_level3){
995
            foreach ($description_level3->sources as $source) {
996
              if (_is_original_source_type($source)) {
997
                $fn_key3 = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), theme('cdm_OriginalSource', array('source' => $source, 'doLink' => FALSE)));
998
                cdm_add_footnote_to_array($fnKeysLevel3, $fn_key3);
999
              }
1000
            }
1001
          }
1002
        }
1003
        // Level4.
1004
        $l4_regions = array();
1005
        foreach ($element_level3->children as $element_level4) {
1006
          if (isset($element_level4->data[0])) {
1007
            $text_l4 = $element_level4->nodeId->representation_L10n;
1008
            $l4_regions[$element_level3->nodeId->representation_L10n] = array();
1009
            $fnKeysLevel4Str = '';
1010
            foreach($element_level4->data as $description_level4) {
1011
              $fnKeysLevel4 = cdm_annotations_as_footnotekeys($description_level4);
1012
              foreach ($description_level4->sources as $source) {
1013
                if (_is_original_source_type($source)) {
1014
                  $fn_key4 = FootnoteManager::addNewFootnote(
1015
                      RenderHints::getFootnoteListKey(),
1016
                      theme('cdm_OriginalSource', array('source' => $source, 'doLink' => FALSE)));
1017
                  cdm_add_footnote_to_array($fnKeysLevel4, $fn_key4);
1018
                }
1019
              }
1020
              usort($fnKeysLevel4, "footnotes_key_compare");
1021
              if(!isset( $l4_regions[$text_l4])){
1022
                $l4_regions[$text_l4] = $fnKeysLevel4;
1023
              } else {
1024
                $l4_regions[$text_l4] = array_merge($l4_regions[$text_l4], $fnKeysLevel4);
1025
              }
1026
            }
1027
          }
1028
        }// Level4.
1029
        // Managing level3 and level4 for generating the right output.
1030
        usort($fnKeysLevel3, "footnotes_key_compare");
1031
        foreach ($fnKeysLevel3 as $key3) {
1032
          foreach ($l4_regions as $key4 => $value4) {
1033
            cdm_add_footnote_to_array($l4_regions[$key4], $key3);
1034
          }
1035
        }
1036
        if ($element_level3->numberOfChildren == 1 && $text_l3 == $element_level3->children[0]->nodeId->representation_L10n) {
1037
          // var_dump($element_level3->children[0]->data->area->representation_L10n);
1038
          $fnStr = '';
1039
          $region = array_pop($l4_regions);
1040
          foreach ($region as $key) {
1041
            $fnStr .= theme('cdm_footnote_key', array('footnoteKey' => $key, 'separator' => ($fnStr ? $separator : '')));
1042
          }
1043
          $out .= "$text_l3 $fnStr; ";
1044
          // Removing whitespaces when &fnStr is empty.
1045
          if (substr($out, -3) == ' ; ') {
1046
            $out = substr($out, 0, -3) . '; ';
1047
          }
1048
        } else {
1049
          $fnKeysLevel3Str = '';
1050
          foreach ($fnKeysLevel3 as $key) {
1051
            $fnKeysLevel3Str .= theme('cdm_footnote_key', array('footnoteKey' => $key, 'separator' => ($fnKeysLevel3Str ? $separator : '')));
1052
          }
1053
          $text_l4_aux = '';
1054
          foreach ($l4_regions as $key => $value) {
1055
            $fnKeysLevel4Str = '';
1056
            if (is_array($l4_regions[$key])) {
1057
              foreach ($l4_regions[$key] as $fnkey) {
1058
                $fnKeysLevel4Str .= theme('cdm_footnote_key', array('footnoteKey' => $fnkey, 'separator' => ($fnKeysLevel4Str ? $separator : '')));
1059
              }
1060
            }
1061
            // if ($key != $text_l3 || sizeof($l4_regions > 1)){
1062
            if ($key != $text_l3) {
1063
              $text_l4_aux .= "$key $fnKeysLevel4Str, ";
1064
            }
1065
          }
1066
          $text_l4_aux = substr($text_l4_aux, 0, -2);
1067

    
1068
          if (strlen($text_l4_aux) > 0) {
1069
            $out .= "$text_l3 $fnKeysLevel3Str ($text_l4_aux); ";
1070
          }
1071
          else {
1072
            $out .= "$text_l3 $fnKeysLevel3Str; ";
1073
          }
1074
        }
1075
      }// Level3.
1076
      $out = substr($out, 0, -2);
1077
      $out .= '.</dd>';
1078
    }// Level1.
1079
  }
1080
  RenderHints::popFromRenderStack();
1081
  return $out;
1082
}
1083

    
1084

    
1085
/*
1086
function theme_cdm_descriptionElement_Distribution($descriptionElements){ $out
1087
  = ''; $separator = ',';
1088
  RenderHints::pushToRenderStack('descriptionElementDistribution');
1089
  RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
1090
  foreach($descriptionElements as $descriptionElement){ // annotations as
1091
  footnotes $annotationFootnoteKeys = theme('cdm_annotations_as_footnotekeys',
1092
  $descriptionElement); // source references as footnotes
1093
  $sourcesFootnoteKeyList = ''; foreach($descriptionElement->sources as
1094
  $source){ if(_is_original_source_type($source)){ $_fkey =
1095
  FootnoteManager::addNewFootnote(UUID_DISTRIBUTION,
1096
  theme('cdm_OriginalSource', $source, FALSE));
1097
  $sourcesFootnoteKeyList .= theme('cdm_footnote_key', $_fkey,
1098
  UUID_DISTRIBUTION, ($sourcesFootnoteKeyList ? $separator : '')); } }
1099
  if($annotationFootnoteKeys && $sourcesFootnoteKeyList){
1100
  $annotationFootnoteKeys .= $separator; } $out .=
1101
  $descriptionElement->area->representation_L10n . $annotationFootnoteKeys .
1102
  $sourcesFootnoteKeyList . ' '; } $out = substr($out, 0,
1103
  strlen($out)-strlen($separator) ); RenderHints::popFromRenderStack(); return
1104
  $out; }
1105
*/
1106

    
1107
/**
1108
 * Returns a list of a specific type of IdentificationKeys.
1109
 *
1110
 * The list can be restricteded by a taxon.
1111
 *
1112
 * @param string $type
1113
 *   The simple name of the cdm class implementing the interface
1114
 *   IdentificationKey, valid values are:
1115
 *   PolytomousKey, MediaKey, MultiAccessKey.
1116
 * @param string $taxonUuid
1117
 *   If given this parameter restrict the listed keys to those which have
1118
 *   the taxon identified be this uuid in scope.
1119
 *
1120
 * @return array
1121
 *   List with identification keys.
1122
 */
1123
function _list_IdentificationKeys($type, $taxonUuid = NULL, $pageSize = NULL, $pageNumber = NULL) {
1124
  if (!$type) {
1125
    drupal_set_message(t('Type parameter is missing'), 'error');
1126
    return;
1127
  }
1128
  $cdm_ws_pasepath = NULL;
1129
  switch ($type) {
1130
    case "PolytomousKey":
1131
      $cdm_ws_pasepath = CDM_WS_POLYTOMOUSKEY;
1132
      break;
1133

    
1134
    case "MediaKey":
1135
      $cdm_ws_pasepath = CDM_WS_MEDIAKEY;
1136
      break;
1137

    
1138
    case "MultiAccessKey":
1139
      $cdm_ws_pasepath = CDM_WS_MULTIACCESSKEY;
1140
      break;
1141

    
1142
  }
1143

    
1144
  if (!$cdm_ws_pasepath) {
1145
    drupal_set_message(t('Type parameter is not valid: ') . $type, 'error');
1146
  }
1147

    
1148
  $queryParameters = '';
1149
  if (is_numeric($pageSize)) {
1150
    $queryParameters = "pageSize=" . $pageSize;
1151
  }
1152
  else {
1153
    $queryParameters = "pageSize=0";
1154
  }
1155

    
1156
  if (is_numeric($pageNumber)) {
1157
    $queryParameters = "pageNumber=" . $pageNumber;
1158
  }
1159
  else {
1160
    $queryParameters = "pageNumber=0";
1161
  }
1162
  $queryParameters = NULL;
1163
  if ($taxonUuid) {
1164
    $queryParameters = "findByTaxonomicScope=$taxonUuid";
1165
  }
1166
  $pager = cdm_ws_get($cdm_ws_pasepath, NULL, $queryParameters);
1167

    
1168
  if (!$pager || $pager->count == 0) {
1169
    return array();
1170
  }
1171
  return $pager->records;
1172
}
1173

    
1174
/**
1175
 * @todo Please document this function.
1176
 * @see http://drupal.org/node/1354
1177
 */
1178
function theme_cdm_IdentificationKey($variables) {
1179
  $out = '';
1180
  $identificationKey = $variables['identificationKey'];
1181
  $doLinkToKeyPage = $variables['doLinkToKeyPage'];
1182
  $showIdentificationKeyTitle = $variables['showIdentificationKeyTitle'];
1183
  $parentRenderPath = RenderHints::getRenderPath();
1184
  RenderHints::pushToRenderStack("IdentificationKey");
1185

    
1186
  if ($showIdentificationKeyTitle) {
1187
    if ($doLinkToKeyPage) {
1188
      $out = l($identificationKey->titleCache, path_to_key($identificationKey->class, $identificationKey->uuid));
1189
    }
1190
    else {
1191
      $out = $identificationKey->titleCache;
1192
    }
1193
  }
1194
  if (isset($identificationKey->sources) && is_array($identificationKey->sources)) {
1195
    // order and display sources.
1196
    $sources = oder_sources($identificationKey->sources, TRUE);
1197
    $out .= '<div class="sources">';
1198
    $out .=  implode('', $sources);
1199
    $out .= '</div>';
1200
  }
1201
  // Display annotations.
1202
  $out .= theme('cdm_annotations', array('annotations' => cdm_ws_getAnnotationsFor($identificationKey), 'enclosingTag' => 'div'));
1203
  RenderHints::popFromRenderStack();
1204
  return $out;
1205
}
1206

    
1207
/**
1208
 * @todo Please document this function.
1209
 * @see http://drupal.org/node/1354
1210
 */
1211
function theme_cdm_polytomousKey($variables) {
1212
  $polytomousKey = $variables['polytomousKey'];
1213

    
1214
  // TODO settings needed.
1215
  // @see http://en.wikipedia.org/wiki/Single_access_key#Presentation_styles
1216
  // @see http://dev.e-taxonomy.eu/trac/ticket/2152
1217
  $keyStyle = "linkedStyle";
1218

    
1219
  RenderHints::pushToRenderStack("polytomousKey");
1220
  // Key nodes in linked style.
1221
  $out = '<table class="polytomousKey polytomousKey_' . $keyStyle . '">';
1222
  $out .= theme('cdm_polytomousKey_' . $keyStyle . '_subgraph', array('polytomousKeyNode' => $polytomousKey->root));
1223
  $out .= '</table>';
1224
  RenderHints::popFromRenderStack();
1225
  return $out;
1226
}
1227

    
1228
/**
1229
 * @todo Please document this function.
1230
 * @see http://drupal.org/node/1354
1231
 */
1232
function theme_cdm_polytomousKey_linkedStyle_subgraph($variables) {
1233
  $polytomousKeyNode = $variables['polytomousKeyNode'];
1234
  static $statementCountCharacter = '\'';
1235
  $out = "";
1236

    
1237
  if (is_array($polytomousKeyNode->children)) {
1238
    $childIndex = 0;
1239

    
1240
    // Render edges of the current node.
1241
    foreach ($polytomousKeyNode->children as &$child) {
1242

    
1243
      if (!isset($child->statement) && isset($child->taxon->uuid)) {
1244
        // Skip node with empty statements (see below for explanation: "Special
1245
        // case").
1246
        // this skipping here happens always in the next deeper level of iteration
1247
        // the check below is node on the level above
1248
        continue;
1249
      }
1250

    
1251
      /*
1252
       * Special case: Child nodes with empty statements but taxa as leaf are to
1253
       * treated as if all those taxa where direct children of the source node.
1254
       */
1255
      $islinkToManyTaxa = !isset($child->children[0]->statement) && isset($child->children[0]->taxon->uuid);
1256
      $islinkToTaxon = isset($child->taxon->uuid);
1257
      $islinkToSubKey = isset($child->subkey->uuid);
1258
      $islinkToOtherNode = isset($child->otherNode);
1259
      // Either NULL or 0.
1260
      $islinkToNode = $child->nodeNumber && !$islinkToManyTaxa && !$islinkToOtherNode;
1261
      $hasQuestion = !empty($polytomousKeyNode->question->label_l10n);
1262
      $hasFeature = isset($polytomousKeyNode->feature);
1263

    
1264
      // $indentEdge = $hasQuestion && $childIndex > 0;
1265
      // Question.
1266
      if ($hasQuestion && $childIndex == 0) {
1267
        // Place question, as extra table row.
1268
        $out .= '<tr class="question new_section">';
1269
        $out .= '<td class="nodeNumber">' . uuid_anchor($polytomousKeyNode->uuid, $polytomousKeyNode->nodeNumber) . "</td>";
1270
        $out .= '<td class="question">' . $polytomousKeyNode->question->label_l10n . '</td>';
1271
        $out .= '</tr>';
1272
      }
1273

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

    
1276
      if ($hasQuestion) {
1277
        $out .= '<td class="nodeNumber"></td>';
1278
      }
1279
      else {
1280
        $out .= '<td class="nodeNumber">' . uuid_anchor($polytomousKeyNode->uuid, $polytomousKeyNode->nodeNumber . str_pad("", $childIndex, $statementCountCharacter)) . "</td>";
1281
      }
1282

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

    
1285
      // Feature.
1286
      if ($hasFeature) {
1287
        $out .= $polytomousKeyNode->feature->representation_L10n . ": ";
1288
      }
1289

    
1290
      // Statement.
1291
      $out .= $child->statement->label_l10n;
1292

    
1293
      // --- Links to nodes taxa and subkeys.
1294
      $out .= '<div class="nodeLink">';
1295

    
1296
      // Link to a PolytomousKeyNode.
1297
      if ($islinkToNode) {
1298
        $out .= '<div class="nodeLinkToNode">';
1299
        if (isset($child->modifyingText)) {
1300
          $out .= theme('cdm_poytomousKeyNode_modifyingText', array('modifyingText' => $child->modifyingText));
1301
        }
1302
        $out .= l($child->nodeNumber, request_path(), array(
1303
          'attributes' => NULL,
1304
          'query' => NULL,
1305
          'fragment' => $child->uuid,
1306
        )) . '</div>';
1307
      }
1308

    
1309
      // Link to a PolytomousKeyNode.
1310
      if ($islinkToOtherNode) {
1311
        $out .= '<div class="nodeLinkToOtherNode">';
1312
        if (isset($child->modifyingText)) {
1313
          $out .= theme('cdm_poytomousKeyNode_modifyingText', array('modifyingText' => $child->modifyingText));
1314
        }
1315
        $out .= l($child->otherNode->nodeNumber, $_REQUEST["q"], array(
1316
          'attributes' => NULL,
1317
          'query' => NULL,
1318
          'fragment' => $child->otherNode->uuid,
1319
        )) . '</div>';
1320
      }
1321

    
1322
      // Link to one or many taxa.
1323
      if ($islinkToTaxon || $islinkToManyTaxa) {
1324

    
1325
        if ($islinkToManyTaxa) {
1326
          $taxonChildren = $child->children;
1327
        }
1328
        else {
1329
          $taxonChildren = array(
1330
            $child,
1331
          );
1332
        }
1333

    
1334
        foreach ($taxonChildren as $taxonChild) {
1335
          // TODO many taxa $child->children->taxon.
1336
          $out .= '<div class="nodeLinkToTaxon">';
1337
          if (isset($taxonChild->modifyingText)) {
1338
            $out .= theme('cdm_poytomousKeyNode_modifyingText', array('modifyingText' => $taxonChild->modifyingText));
1339
          }
1340
          $out .= theme("cdm_taxonName", array('taxonName' => $taxonChild->taxon->name, 'nameLink' => url(path_to_taxon($taxonChild->taxon->uuid))));
1341
          $out .= '</div>';
1342
        }
1343

    
1344
        // Link to a subkey.
1345
        if ($islinkToSubKey) {
1346
          $out .= '<div class="nodeLinkToSubkey">' . theme('cdm_IdentificationKey', array('identificationKey' => $child->subkey)) . '</div>';
1347
        }
1348
      }
1349

    
1350
      $out .= '</div>'; // End node link.
1351
      $out .= '</td>'; // End edge.
1352
      $out .= '</tr>';
1353

    
1354
      $childIndex++;
1355
    }
1356

    
1357
    // Recurse into child nodes.
1358
    foreach ($polytomousKeyNode->children as &$child) {
1359
      $out .= theme('cdm_polytomousKey_linkedStyle_subgraph', array('polytomousKeyNode' => $child));
1360
    }
1361
  }
1362

    
1363
  return $out;
1364
}
1365

    
1366
/**
1367
 * @todo Please document this function.
1368
 * @see http://drupal.org/node/1354
1369
 */
1370
function theme_cdm_poytomousKeyNode_modifyingText($variables) {
1371
  $out = '';
1372
  $modifyingText = $variables['modifyingText'];
1373
  if (is_object($modifyingText)) {
1374
    $i = 0;
1375
    foreach (get_object_vars($modifyingText) as $lang => $languageString) {
1376
      $out .= ($i++ > 0 ? ', ' : '') . '<span class="modifyingText">' . $languageString->text . '</span> ';
1377
    }
1378
  }
1379
  return $out;
1380
}
1381

    
1382
/**
1383
 * Returns HTML for a list of a specific type of IdentificationKeys.
1384
 *
1385
 * The list can be restricteded by a taxon.
1386
 *
1387
 * @param array $variables
1388
 *   An associative array containing:
1389
 *   - type: The simple name of the cdm class implementing the interface
1390
 *     IdentificationKey, valid values are:
1391
 *     PolytomousKey, MediaKey, MultiAccessKey
1392
 *   - taxonUuid: If given, this parameter restrict the listed keys to those
1393
 *     which have the taxon identified be this uuid in scope.
1394
 *
1395
 * @ingroup themeable
1396
 */
1397
function theme_cdm_list_IdentificationKeys($variables) {
1398
  $type = $variables['type'];
1399
  $taxonUuid = $variables['taxonUuid'];
1400
  $keyList = _list_IdentificationKeys($type, $taxonUuid);
1401
  if (!$keyList || count($keyList) == 0) {
1402
    return;
1403
  }
1404

    
1405
  RenderHints::pushToRenderStack('list_IdentificationKeys');
1406
  $out = '<ul>';
1407
  foreach ($keyList as $key) {
1408
    $out .= '<li>';
1409
    $out .= theme('cdm_IdentificationKey', array('identificationKey' => $key));
1410
    $out .= '</li>';
1411
  }
1412
  $out .= '</ul>';
1413
  $out .= theme("cdm_annotation_footnotes", array('footnoteListKey' => RenderHints::getRenderPath()));
1414
  RenderHints::popFromRenderStack();
1415

    
1416
  return $out;
1417
}
1418

    
1419
/**
1420
 * @todo Please document this function.
1421
 * @see http://drupal.org/node/1354
1422
 */
1423
function theme_cdm_block_IdentificationKeys($variables) {
1424
  $taxonUuid = $variables['taxonUuid'];
1425
  static $types = array(
1426
    "PolytomousKey" => "Polytomous",
1427
    "MediaKey" => "Media",
1428
    "MultiAccessKey" => "Multiaccess",
1429
  );
1430
  RenderHints::pushToRenderStack('block_IdentificationKeys');
1431
  $out = '';
1432
  foreach ($types as $type => $label) {
1433
    $keylist = theme('cdm_list_IdentificationKeys', array('type' => $type, 'taxonUuid' => $taxonUuid));
1434
    if (!$keylist) {
1435
      continue;
1436
    }
1437
    $out .= '<div class="' . $type . '">';
1438
    $out .= '<h3>' . t($label) . "</h3>";
1439
    $out .= $keylist;
1440
    $out .= '</div>';
1441
  }
1442
  RenderHints::popFromRenderStack();
1443
  return $out;
1444
}
1445

    
1446
/**
1447
 * This theming function formats the use description and use record list for
1448
 * these descriptions.
1449
 *
1450
 * @see http://drupal.org/node/1354
1451
 */
1452
function theme_cdm_UseDescription($variables) {
1453
  $descriptions = $variables['description'];
1454
  $taxonUuid = $variables['taxonUuid'];
1455
  $out = '<div id="content"><ul id="Description" class ="description">';
1456
  if ($descriptions == NULL) {
1457
    return;
1458
  }
1459
  $descriptionSynonyms = '';
1460
  $descriptionOut = '';
1461
  $synonymOut = '';
1462
  $currentTaxon = cdm_ws_get(CDM_WS_PORTAL_TAXON, $taxonUuid);
1463

    
1464
  foreach ($descriptions as $description) {
1465
    $useSummary = '';
1466
    foreach ($description->elements as $element) {
1467

    
1468
      if ($element->feature->uuid == UUID_USE && !(strlen($useSummary) > 0) && isset($element->multilanguageText_L10n)) {
1469
        $useSummary = $element->multilanguageText_L10n->text;
1470
      }
1471
    }
1472
    // uses will be ordered by source
1473
    foreach ($description->sources as $source) {
1474
      $is_about_current_taxon = FALSE;
1475
      $originalTaxonUsedInSource = NULL;
1476
      $originalTaxonPager = NULL;
1477
      if ($source->originalNameString) {
1478
        $request_params = array();
1479
        $request_params['query'] = $source->originalNameString;
1480
        $request_params['matchMode'] = "EXACT";
1481
        $originalTaxonPager = cdm_ws_get(CDM_WS_PORTAL_NAME_FINDBYNAME, NULL, queryString($request_params));
1482
        if ($originalTaxonPager->count > 0) {
1483
          $originalTaxonUsedInSource = $originalTaxonPager->records[0];
1484
        }
1485
        else {
1486
          $originalTaxonUsedInSource = $currentTaxon->name;
1487
        }
1488
      }
1489
      else {
1490
        $originalTaxonUsedInSource = $currentTaxon->name;
1491
      }
1492

    
1493
      $is_about_current_taxon = $currentTaxon->name->uuid == $originalTaxonUsedInSource->uuid;
1494

    
1495
      if (!$is_about_current_taxon) {
1496
        $descriptionOut .= '<li class="descriptionText DescriptionElement">';
1497
        $name_used_in_source_link_to_show_use = l($source->originalNameString, path_to_name($originalTaxonUsedInSource->uuid), array(
1498
          'absolute' => TRUE,
1499
          'html' => TRUE,
1500
        ));
1501
        $descriptionOut .= $name_used_in_source_link_to_show_use . ': ';
1502
        $descriptionOut .= $useSummary;
1503
        foreach ($description->sources as $source) {
1504
          $descriptionOut .= " (" . theme('cdm_OriginalSource', array('source' => $source, 'doLink' => TRUE)) . ")";
1505
        }
1506
        $hasUseRecords = FALSE;
1507
        $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>';
1508
        foreach ($description->elements as $descriptionElement) {
1509
          if ($descriptionElement->feature->uuid == UUID_USE_RECORD) {
1510
            $hasUseRecords = TRUE;
1511
            // FIXME localization hardcoded to English
1512
            $useRecordTags = explode(';', $descriptionElement->modifyingText_l10n);
1513
            $descriptionUseRecordOut .= '<tr>';
1514
            $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>';
1515
            $descriptionUseRecordOut .= '</tr>';
1516
          }
1517
        }
1518
        $descriptionUseRecordOut .= '</table></div>';
1519
        if ($hasUseRecords) {
1520
          $descriptionOut .= $descriptionUseRecordOut . '</li>';
1521
        }
1522
      }
1523
      else {
1524
        // TODO +/- duplicate of above, unify this code
1525
        $synonymOut .= '<li class="descriptionText DescriptionElement">';
1526
        $name_used_in_source_link_to_show_use = l($source->originalNameString, path_to_name($originalTaxonUsedInSource->uuid), array(
1527
          'absolute' => TRUE,
1528
          'html' => TRUE,
1529
        ));
1530

    
1531
        $synonymOut .= $name_used_in_source_link_to_show_use . ': ';
1532
        $synonymOut .= $useSummary;
1533
        foreach ($description->sources as $source) {
1534
          $synonymOut .= " (" . theme('cdm_OriginalSource', array('source' => $source, 'doLink' => TRUE)) . ")";
1535
        }
1536

    
1537
        $hasUseRecords = FALSE;
1538
        $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>';
1539
        foreach ($description->elements as $descriptionElement) {
1540
          if ($descriptionElement->feature->uuid == UUID_USE_RECORD) {
1541
            $hasUseRecords = TRUE;
1542
            $useRecordTags = explode(';', $descriptionElement->modifyingText_l10n);
1543
            $useRecordTableOut .= '<tr>';
1544
            $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>';
1545
            $useRecordTableOut .= '</tr>';
1546
          }
1547
        }
1548
        $useRecordTableOut .= '</table></div>';
1549
        if ($hasUseRecords) {
1550
          $synonymOut .= $useRecordTableOut . '</li>';
1551
        }
1552
      }
1553

    
1554
      // }
1555
    }
1556
  }
1557
  $out .= $descriptionOut . $synonymOut;
1558
  $out .= "</ul></div>";
1559
  return $out;
1560
}
1561

    
1562

    
1563
/**
1564
 * The theming function for a block of Uses Descriptions for a given taxon.
1565
 *
1566
 * The Uses block has been removed from the code but the according theme function
1567
 * is kept for compatibility reasons with existing code regarding palmweb.
1568
 *
1569
 */
1570
function theme_cdm_block_Uses($variables) {
1571
  $taxonUuid = $variables['taxonUuid'];
1572
  RenderHints::pushToRenderStack('block_Uses');
1573

    
1574
  if ($taxonUuid == NULL) {
1575
    return;
1576
  }
1577
  $out = '';
1578
  $markerTypes = array();
1579
  $markerTypes['markerTypes'] = UUID_MARKERTYPE_USE;
1580
  $useDescriptions = cdm_ws_get(CDM_WS_PORTAL_TAXON_DESCRIPTIONS, $taxonUuid, queryString($markerTypes));
1581
  if (!empty($useDescriptions)) {
1582
    // FIXME use theme_block instaed of hardcoding the block html here !!!!
1583
    $out .= '<div id="block-cdm_dataportal-feature-description" class="clear-block block block-cdm_dataportal-feature"><H2><a name="userecords"> </a> Uses </H2>';
1584
    $formatUseDescriptions = theme('cdm_UseDescription', array('description' => $useDescriptions, 'taxonUuid' => $taxonUuid));
1585

    
1586
    $out .= $formatUseDescriptions;
1587
    $out .= "</div>";
1588
  }
1589

    
1590
  return $out;
1591
}
(3-3/10)