Project

General

Profile

Download (58.5 KB) Statistics
| Branch: | Tag: | Revision:
1 6657531f Andreas Kohlbecker
<?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 0c432a94 Andreas Kohlbecker
 * 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 6657531f Andreas Kohlbecker
 */
33
function theme_cdm_feature_name($variables) {
34
  $feature_name = $variables['feature_name'];
35
  // TODO replace by using translations ?
36 0c432a94 Andreas Kohlbecker
  return t($feature_name);
37 6657531f Andreas Kohlbecker
}
38
39
/**
40 28c5c87a Andreas Kohlbecker
 * Returns a set of feature blocks for a taxon profile from the $mergedFeatureNodes of a given $taxon.
41 6657531f Andreas Kohlbecker
 *
42 28c5c87a Andreas Kohlbecker
 * The taxon profile consists of drupal block elements, one for the description elements
43
 * of a specific feature. The structure is defined by specific FeatureTree.
44
 * The chosen FeatureTree is merged with the list of description elements prior to using this method.
45 6657531f Andreas Kohlbecker
 *
46
 * The merged nodes can be obtained by making use of the
47
 * function cdm_ws_descriptions_by_featuretree().
48
 *
49 37252893 Andreas Kohlbecker
 * @see cdm_ws_descriptions_by_featuretree()
50
 *
51 28c5c87a Andreas Kohlbecker
 * @param $mergedFeatureNodes
52 6657531f Andreas Kohlbecker
 *
53 28c5c87a Andreas Kohlbecker
 * @param $taxon
54
 *
55
 * @return array
56
 *  A Drupal render array
57
 *
58
 * @ingroup compose
59 6657531f Andreas Kohlbecker
 */
60 28c5c87a Andreas Kohlbecker
function compose_cdm_feature_nodes($mergedFeatureNodes, $taxon) {
61 6657531f Andreas Kohlbecker
62
  $out = '';
63
64
  RenderHints::pushToRenderStack('feature_nodes');
65 235fc94b Andreas Kohlbecker
66 6657531f Andreas Kohlbecker
  $gallery_settings = getGallerySettings(CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME);
67
68 28c5c87a Andreas Kohlbecker
  // Create a drupal block for each feature
69 6657531f Andreas Kohlbecker
  foreach ($mergedFeatureNodes as $node) {
70
71 28c5c87a Andreas Kohlbecker
    if ((isset($node->descriptionElements['#type']) ||
72
        has_feature_node_description_elements($node)) && $node->feature->uuid != UUID_IMAGE) { // skip empty or supressed features
73 6657531f Andreas Kohlbecker
74 28c5c87a Andreas Kohlbecker
      $feature_name = cdm_term_representation($node->feature, 'Unnamed Feature');
75 6657531f Andreas Kohlbecker
76 f19f47fa Andreas Kohlbecker
      $block = feature_block($feature_name, $node->feature);
77 6f5c7f2a Andreas Kohlbecker
      $block->content = array();
78
      $block_content_weight = 0;
79 6657531f Andreas Kohlbecker
80 f19f47fa Andreas Kohlbecker
      /*
81
       * Content/DISTRIBUTION.
82
       */
83 6657531f Andreas Kohlbecker
84 28c5c87a Andreas Kohlbecker
      if ($node->feature->uuid == UUID_DISTRIBUTION) {
85
        $block = compose_feature_block_distribution($taxon, $node->descriptionElements, $node->feature);
86 f19f47fa Andreas Kohlbecker
      }
87
      /*
88
       * Content/COMMON_NAME.
89
       */
90 6f5c7f2a Andreas Kohlbecker
      else if ($node->feature->uuid == UUID_COMMON_NAME) {
91 28c5c87a Andreas Kohlbecker
        $common_names_render_array = compose_cdm_common_names($node->descriptionElements, $node->feature);
92 6f5c7f2a Andreas Kohlbecker
        $block->content[] = $common_names_render_array;
93 f19f47fa Andreas Kohlbecker
      }
94
95
      /*
96
       * Content/ALL OTHER FEATURES.
97
       */
98
      else {
99 28c5c87a Andreas Kohlbecker
100
        $media_list = array();
101
        $out_child_elements = '';
102
103 f19f47fa Andreas Kohlbecker
        if (isset($node->descriptionElements)) {
104
          $taxon_uuid = NULL;
105
          if(isset($taxon) ) {
106
            $taxon_uuid = $taxon->uuid;
107 6657531f Andreas Kohlbecker
          }
108 6f5c7f2a Andreas Kohlbecker
          $block->content[] = compose_cdm_descriptionElements($node->descriptionElements, $node->feature, $taxon_uuid);
109 f19f47fa Andreas Kohlbecker
        }
110 0c432a94 Andreas Kohlbecker
111 28c5c87a Andreas Kohlbecker
          // Content/ALL OTHER FEATURES/Subordinate Features
112
          // subordinate features are printed inline in one floating text,
113 6f5c7f2a Andreas Kohlbecker
          // it is expected hat subordinate features can "contain" TextData,
114 28c5c87a Andreas Kohlbecker
          // Qualitative- and Qualitative- DescriptioneElements
115
          if (isset($node->childNodes[0])) {
116 f19f47fa Andreas Kohlbecker
117
          // TODO support more than one level of children.
118 6f5c7f2a Andreas Kohlbecker
          // can this be solved by recursively calling this function?
119 f19f47fa Andreas Kohlbecker
          // @see http://dev.e-taxonomy.eu/trac/ticket/2393
120
          $text = '';
121
          foreach ($node->childNodes as $child) {
122
123
            if (isset($child->descriptionElements) && is_array($child->descriptionElements)) {
124
              foreach ($child->descriptionElements as $element) {
125 8db340ef Andreas Kohlbecker
126 6f5c7f2a Andreas Kohlbecker
                //TODO it woud be better if we could use compose_cdm_descriptionElements() directly instead of the below stuff
127
128 f19f47fa Andreas Kohlbecker
                if (is_array($element->media)) {
129
                  // Append media of supordinate elements to list of main
130
                  // feature.
131
                  $media_list = array_merge($media_list, $element->media);
132 6657531f Andreas Kohlbecker
                }
133 f19f47fa Andreas Kohlbecker
134
                switch ($element->class) {
135
                  case 'TextData':
136 6f5c7f2a Andreas Kohlbecker
                    // FIXME use theme_cdm_descriptionElementTextData()
137 f19f47fa Andreas Kohlbecker
                    $out_child_elements = str_replace("\n", "<br/>", $element->multilanguageText_L10n->text);
138
                    $out_child_elements = str_replace($child->feature->titleCache, '<em>' . $child->feature->representation_L10n . '</em>', $out_child_elements);
139
                    break;
140
                  case 'CategoricalData':
141
                    $out_child_elements  = '<em>' . $child->feature->representation_L10n . '</em> '
142
                      . theme('cdm_descriptionElement_CategoricalData', array('element' => $element));
143
                    break;
144
                  case 'QuantitativeData':
145
                    $out_child_elements = '<em>' . $child->feature->representation_L10n . '</em> '
146
                      . theme('cdm_descriptionElement_QuantitativeData', array('element' => $element));
147
148
                }
149
150 6657531f Andreas Kohlbecker
              }
151 f19f47fa Andreas Kohlbecker
              $text .= " " . $out_child_elements;
152
              $out_child_elements = '';
153 6657531f Andreas Kohlbecker
            }
154
          }
155 6f5c7f2a Andreas Kohlbecker
          $block->content[] = markup_to_render_array($text);
156
          $block->content[] = compose_feature_media_gallery($node, $media_list, $gallery_settings);
157 28c5c87a Andreas Kohlbecker
158
159 6f5c7f2a Andreas Kohlbecker
          }
160
        /*
161
         * Footnotes for the feature block
162
         */
163
        $block->content[] = markup_to_render_array(theme('cdm_footnotes', array('footnoteListKey' => $node->feature->uuid)));
164
        $block->content[] = markup_to_render_array(theme('cdm_annotation_footnotes', array('footnoteListKey' => $node->feature->uuid)));
165 f19f47fa Andreas Kohlbecker
      }
166 6657531f Andreas Kohlbecker
167 f19f47fa Andreas Kohlbecker
168
      $out .= theme('block',
169
        array(
170
          'elements' => array(
171
            '#block' => $block,
172 6f5c7f2a Andreas Kohlbecker
            '#children' => drupal_render($block->content),
173 22f5e82d Andreas Kohlbecker
          ),
174 f19f47fa Andreas Kohlbecker
        )
175
      );
176 28c5c87a Andreas Kohlbecker
    } // END: skip empty or supressed features
177
  } // END: creating a block per feature
178 6657531f Andreas Kohlbecker
  RenderHints::popFromRenderStack();
179 28c5c87a Andreas Kohlbecker
180
  return markup_to_render_array($out);
181 6657531f Andreas Kohlbecker
}
182
183 28c5c87a Andreas Kohlbecker
  /**
184
   * @param $node
185
   * @param $media_list
186
   * @param $gallery_settings
187
   * @return array
188
   */
189
  function compose_feature_media_gallery($node, $media_list, $gallery_settings) {
190
    if (isset($node->descriptionElements)) {
191
      $media_list = array_merge($media_list, cdm_dataportal_media_from_descriptionElements($node->descriptionElements));
192
    }
193
    $captionElements = array('title', 'rights');
194
    $gallery = '';
195
    if (isset($gallery_settings['cdm_dataportal_media_maxextend']) && isset($gallery_settings['cdm_dataportal_media_cols'])) {
196
      $gallery = theme('cdm_media_gallerie', array(
197
        'mediaList' => $media_list,
198
        'galleryName' => CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME . '_' . $node->feature->uuid,
199
        'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
200
        'cols' => $gallery_settings['cdm_dataportal_media_cols'],
201
        'captionElements' => $captionElements,
202
      ));
203
      return array($media_list, $gallery);
204
    }
205
    return array($media_list, $gallery);
206
  }
207
208
  /**
209
   * @param $taxon
210
   * @param $descriptionElements
211
   *   an associative array with two elements:
212
   *   - '#type': must be 'DTO'
213
   *   - 'DistributionInfoDTO': a CDM DistributionInfoDTO object as returned by the DistributionInfo web service
214
   * @param $feature
215
   *
216
   * @ingroup compose
217
   */
218
  function compose_feature_block_distribution($taxon, $descriptionElements, $feature) {
219
    $text_data_glue = '';
220
    $text_data_sortOutArray = FALSE;
221
    $text_data_enclosingTag = 'ul';
222
    $text_data_out_array = array();
223
224
    $distributionElements = NULL;
225
    $distribution_info_dto = NULL;
226
    $distribution_sortOutArray = FALSE;
227
228
    if (variable_get('distribution_sort', 'NO_SORT') != 'NO_SORT') {
229
      $distribution_glue = '';
230
      $distribution_enclosingTag = 'dl';
231
    } else {
232
      $distribution_glue = '';
233
      $distribution_enclosingTag = 'ul';
234
    }
235
236
    if (!isset($descriptionElements['#type']) || !$descriptionElements['#type'] == 'DTO') {
237
      // skip the DISTRIBUTION section if there is no DTO type element
238
      return array(); // FIXME is it ok to return an empty array?
239
    }
240 f19f47fa Andreas Kohlbecker
241 28c5c87a Andreas Kohlbecker
    $block = feature_block(
242
      cdm_term_representation($feature, 'Unnamed Feature'),
243
      $feature
244
    );
245
246 22f5e82d Andreas Kohlbecker
    // $$descriptionElements['TextData'] is added to to the feature node in merged_taxon_feature_tree()
247 28c5c87a Andreas Kohlbecker
    if (isset($descriptionElements['TextData'])) {
248
      // --- TextData
249
      foreach ($descriptionElements['TextData'] as $text_data_element) {
250
        $asListElement = FALSE;
251
        $repr = theme('cdm_descriptionElementTextData', array(
252
          'element' => $text_data_element,
253
          'asListElement' => $asListElement,
254
          'feature_uuid' => $text_data_element->feature->uuid,
255
        ));
256 f19f47fa Andreas Kohlbecker
257 28c5c87a Andreas Kohlbecker
        if (!array_search($repr, $text_data_out_array)) {
258
          $text_data_out_array[] = $repr;
259 c367b0ab Andreas Kohlbecker
          // TODO HINT: sorting in compose_cdm_feature_block_elements will
260 28c5c87a Andreas Kohlbecker
          // not work since this array contains html attributes with uuids
261
          // !!!!
262
          $text_data_sortOutArray = TRUE;
263
          $text_data_glue = '<br/> ';
264
          $text_data_enclosingTag = 'p';
265
        }
266
      }
267
    }
268
269
270
    if ($text_data_out_array && variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0)) {
271 6f5c7f2a Andreas Kohlbecker
      $block->content[] = compose_cdm_feature_block_elements(
272 c367b0ab Andreas Kohlbecker
        $text_data_out_array,
273
        $feature,
274
        $text_data_glue,
275
        $text_data_sortOutArray,
276
        $text_data_enclosingTag
277
      );
278 28c5c87a Andreas Kohlbecker
    }
279
280
    // --- Distribution map
281
    $distribution_map_query_parameters = NULL;
282
    if (isset($descriptionElements['DistributionInfoDTO'])) {
283
      $distribution_map_query_parameters = $descriptionElements['DistributionInfoDTO']->mapUriParams;
284
    }
285
    $map_render_element = compose_distribution_map($taxon, $distribution_map_query_parameters);
286 6f5c7f2a Andreas Kohlbecker
    $block->content[] = $map_render_element;
287 28c5c87a Andreas Kohlbecker
288
    // --- tree or list
289
    $dto_out_array = array();
290
    if (isset($descriptionElements['DistributionInfoDTO'])) {
291
      $distribution_info_dto = $descriptionElements['DistributionInfoDTO'];
292
293
      // --- tree
294
      if (is_object($distribution_info_dto->tree)) {
295
        $dto_out_array[] = theme('cdm_description_ordered_distributions', array('distribution_tree' => $distribution_info_dto->tree));
296
      }
297
298
      // --- sorted element list
299
      if (is_array($distribution_info_dto->elements) && count($distribution_info_dto->elements) > 0) {
300
        foreach ($distribution_info_dto->elements as $descriptionElement) {
301
          if (is_object($descriptionElement->area)) {
302
            $sortKey = $descriptionElement->area->representation_L10n;
303
            $distributionElements[$sortKey] = $descriptionElement;
304
          }
305
        }
306
        ksort($distributionElements);
307
        $dto_out_array[] = theme('cdm_descriptionElement_Distribution', array(
308
          'descriptionElements' => $distributionElements,
309
        ));
310
311
      }
312
      //
313 6f5c7f2a Andreas Kohlbecker
      $block->content[] = compose_cdm_feature_block_elements(
314 c367b0ab Andreas Kohlbecker
        $dto_out_array,
315
        $feature,
316
        $distribution_glue,
317
        $distribution_sortOutArray,
318
        $distribution_enclosingTag
319
      );
320 28c5c87a Andreas Kohlbecker
    }
321
322
    // --- TextData at the bottom
323
    if ($text_data_out_array && !variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0)) {
324 6f5c7f2a Andreas Kohlbecker
      $block->content[] = compose_cdm_feature_block_elements(
325 c367b0ab Andreas Kohlbecker
        $text_data_out_array,
326
        $feature,
327
        $text_data_glue,
328
        $text_data_sortOutArray,
329
        $text_data_enclosingTag
330
      );
331 28c5c87a Andreas Kohlbecker
    }
332
333 6f5c7f2a Andreas Kohlbecker
    $block->content[] = markup_to_render_array(theme('cdm_footnotes', array('footnoteListKey' => UUID_DISTRIBUTION)));
334
    $block->content[] = markup_to_render_array(theme('cdm_annotation_footnotes', array('footnoteListKey' => UUID_DISTRIBUTION)));
335 28c5c87a Andreas Kohlbecker
336
    return $block;
337
  }
338
339
340
  /**
341 6657531f Andreas Kohlbecker
 * @todo Please document this function.
342
 * @see http://drupal.org/node/1354
343
 */
344
function theme_FeatureTree_hierarchy($variables) {
345
346
  $FeatureTreeUuid = $variables['FeatureTreeUuid'];
347
  if (!is_uuid($FeatureTreeUuid)) {
348
    return;
349
  }
350
351
  $out = '';
352
  $featureTree = cdm_ws_get(CDM_WS_FEATURETREE, array(
353
    $FeatureTreeUuid,
354
  ));
355
356
  if (isset($featureTree) && isset($featureTree->root)) {
357
    $out = '<ul class="' . $featureTree->class . '">';
358
    $out .= theme('FeatureTree_hierarchy_children', array('node' => $featureTree->root));
359
    $out .= '</ul>';
360
  }
361
  return $out;
362
}
363
364
/**
365
 * @todo Please document this function.
366
 * @see http://drupal.org/node/1354
367
 */
368
function theme_FeatureTree_hierarchy_children($variables) {
369
370
  $node = $variables['node'];
371
  $out = '';
372 fae36a2a Andreas Kohlbecker
  if (isset($node->childNodes)) {
373 6657531f Andreas Kohlbecker
374 fae36a2a Andreas Kohlbecker
    foreach ($node->childNodes as $childNode) {
375 6657531f Andreas Kohlbecker
      $out .= '<li>' . check_plain($childNode->feature->representation_L10n);
376 fae36a2a Andreas Kohlbecker
      if (isset($childNode->childNodes) && count($childNode->childNodes) > 0) {
377 6657531f Andreas Kohlbecker
        $out .= '<ul>' . theme('FeatureTree_hierarchy_children', array('node' => $childNode)) . '</ul>';
378
      }
379
      $out .= '</li>';
380
    }
381
  }
382
  return $out;
383
}
384
385
/**
386 c367b0ab Andreas Kohlbecker
 * Returns HTML for the texts in a description $elements.
387 6657531f Andreas Kohlbecker
 *
388 c367b0ab Andreas Kohlbecker
 * Joins the texts in $elements and encloses with a HTML tag.
389 6657531f Andreas Kohlbecker
 *
390 c367b0ab Andreas Kohlbecker
 * @param  $elements
391
 * @param  feature:
392
 *  The feature to which the elements given in $elements are belonging to.
393
 * @param  glue:
394
 *  Defaults to empty string.
395
 * @param $sort
396
 *   Boolean Whether to sort the $elements alphabetically, default is FALSE
397
 * @param  $enclosing_tag
398 6657531f Andreas Kohlbecker
 *
399 c367b0ab Andreas Kohlbecker
 * @ingroup compose
400 6657531f Andreas Kohlbecker
 */
401 c367b0ab Andreas Kohlbecker
function compose_cdm_feature_block_elements($elements, $feature, $glue = '', $sort = FALSE, $enclosing_tag = 'ul') {
402
403 22f5e82d Andreas Kohlbecker
  $feature_block_settings = get_feature_block_settings($feature->uuid);
404 c367b0ab Andreas Kohlbecker
  if($feature_block_settings['as_list']){
405
    $enclosing_tag = $feature_block_settings['as_list'];
406
  }
407 28c5c87a Andreas Kohlbecker
408 c367b0ab Andreas Kohlbecker
  $out = '<' . $enclosing_tag . ' class="feature-block-elements" id="' . $feature->representation_L10n . '">';
409 6657531f Andreas Kohlbecker
410 c367b0ab Andreas Kohlbecker
  if ($sort) {
411
    sort($elements);
412 6657531f Andreas Kohlbecker
  }
413
414 c367b0ab Andreas Kohlbecker
  //TODO it would be nice if any element would get "feature-block-element" as additional class attribute
415
  //     this will become possible once all $elemets are real Drupal render arrays
416
  $out .= join($elements, $glue) ;
417 6657531f Andreas Kohlbecker
418 c367b0ab Andreas Kohlbecker
  $out .= '</' . $enclosing_tag . '>';
419 6f5c7f2a Andreas Kohlbecker
  return markup_to_render_array($out);
420 6657531f Andreas Kohlbecker
}
421
422
423
/**
424 ac8bfc49 Andreas Kohlbecker
 * Theme function to render CDM DescriptionElements of the type CategoricalData.
425
 *
426
 * @param array $variables
427
 *   An associative array containing:
428
 *  - element: the CategoricalData element
429
 * @return a html representation of the given CategoricalData element
430
 *
431
 * @ingroup themeable
432 2ba0f3bd Andreas Kohlbecker
 */
433 6657531f Andreas Kohlbecker
function theme_cdm_descriptionElement_CategoricalData($variables) {
434
  $element = $variables['element'];
435 e9bc1326 Andreas Kohlbecker
436 6657531f Andreas Kohlbecker
  $state_data_strings = array();
437 acf3a2e7 Andreas Kohlbecker
  if (isset($element->stateData)) {
438
    foreach ($element->stateData as $stateData) {
439 3445600f Andreas Kohlbecker
440 e9bc1326 Andreas Kohlbecker
      $state  = NULL;
441 3445600f Andreas Kohlbecker
442 e9bc1326 Andreas Kohlbecker
      if(isset($stateData->state)){
443 6657531f Andreas Kohlbecker
        $state = cdm_term_representation($stateData->state);
444 e9bc1326 Andreas Kohlbecker
      }
445 6657531f Andreas Kohlbecker
446 e9bc1326 Andreas Kohlbecker
      if (isset($stateData->modifyingText_L10n)) {
447 3445600f Andreas Kohlbecker
        $state = ' ' . $stateData->modifyingText_L10n;
448 e9bc1326 Andreas Kohlbecker
      }
449 6657531f Andreas Kohlbecker
450 3445600f Andreas Kohlbecker
      $modifiers_strings = cdm_modifers_representations($stateData);
451 6657531f Andreas Kohlbecker
452 3445600f Andreas Kohlbecker
      $state_data_strings[] = $state . ($modifiers_strings ? ' ' . $modifiers_strings : '');
453
454 6657531f Andreas Kohlbecker
    }
455
  }
456 acf3a2e7 Andreas Kohlbecker
457
  $footnote_key_list_str = cdm_create_description_element_footnotes($element);
458
459 f19f47fa Andreas Kohlbecker
  $out = '<span class="' . html_class_attribute_ref($element) . '">' . implode(', ', $state_data_strings) . '</span>';
460 acf3a2e7 Andreas Kohlbecker
  return $out . $footnote_key_list_str;
461 6657531f Andreas Kohlbecker
}
462
463 ac8bfc49 Andreas Kohlbecker
/**
464
 * Theme function to render CDM DescriptionElements of the type QuantitativeData.
465
 *
466
 * @param array $variables
467
 *   An associative array containing:
468
 *  - element: the QuantitativeData element
469
 * @return a html representation of the given QuantitativeData element
470
 *
471
 * @ingroup themeable
472
 */
473 3445600f Andreas Kohlbecker
function theme_cdm_descriptionElement_QuantitativeData($variables) {
474
  /*
475
   * - statisticalValues
476
   *   - value
477
   *   - modifiers
478
   *   - type
479
   * - unit->representation_L10n
480
   * - modifyingText
481
   * - modifiers
482
   * - sources
483
   */
484
  $element = $variables['element'];
485
486
  $out = '';
487
488
  $type_representation = NULL;
489
  $modifiers_strings = array();
490
491
492
  if (isset($element->statisticalValues)) {
493
    $value_array = array();
494
    foreach ($element->statisticalValues as $val) {
495
      if (isset($val->value)) {
496
        $value_array[] = $val->value;
497
      }
498
    }
499
500
    $out .= implode($value_array, ', ');
501
  }
502
503 f19f47fa Andreas Kohlbecker
  if (isset($element->unit)) {
504
    $out .= ' '. cdm_term_representation($element->unit);
505 3445600f Andreas Kohlbecker
  }
506
507
  if (isset($element->statisticalValues->modifyingText_L10n)) {
508
    $out .=  ' ' . $element->statisticalValues->modifyingText_L10n;
509
  }
510 28c5c87a Andreas Kohlbecker
  $modifiers_strings = cdm_modifers_representations($element->statisticalValues);
511
  $out .= ($modifiers_strings ? ' ' . cdm_modifers_representations($element->statisticalValues) : '');
512 3445600f Andreas Kohlbecker
513 1f11e206 Andreas Kohlbecker
  $footnote_key_list_str = cdm_create_description_element_footnotes($element);
514 3445600f Andreas Kohlbecker
515 1f11e206 Andreas Kohlbecker
  return $out . $footnote_key_list_str;
516 3445600f Andreas Kohlbecker
517
}
518
519 2ba0f3bd Andreas Kohlbecker
/**
520
 * Theme function to render CDM DescriptionElements of the type IndividualsAssociations.
521
 *
522 ac8bfc49 Andreas Kohlbecker
 * @param array $variables
523
 *   An associative array containing:
524
 *  - element: the IndividualsAssociations element
525
 * @return html representation of the given IndividualsAssociations element
526
 *
527
 * @ingroup themeable
528 2ba0f3bd Andreas Kohlbecker
 */
529
function theme_cdm_descriptionElement_IndividualsAssociation($variables) {
530
531
  $element = $variables['element'];
532
533
  $out = '';
534
535
  $render_array = compose_cdm_specimenOrObservation($element->associatedSpecimenOrObservation);
536
537
  if (isset($element->description_L10n)) {
538
    $out .=  ' ' . $element->description_L10n;
539
  }
540
541
  $out .= drupal_render($render_array);
542 1f11e206 Andreas Kohlbecker
543
  $footnote_key_list_str = cdm_create_description_element_footnotes($element);
544
545
  return $out . $footnote_key_list_str;
546 2ba0f3bd Andreas Kohlbecker
547
548
}
549
550
/**
551
 * Theme function to render CDM DescriptionElements of the type TaxonInteraction.
552
 *
553 ac8bfc49 Andreas Kohlbecker
 * @param array $variables
554
 *   An associative array containing:
555
 *  - element: the TaxonInteraction element
556
 * @return html representation of the given TaxonInteraction element
557
 *
558
 * @ingroup themeable
559 2ba0f3bd Andreas Kohlbecker
 */
560
function theme_cdm_descriptionElement_TaxonInteraction($variables) {
561
562
  $element = $variables['element'];
563
564
  $out = '';
565
566
  if (isset($element->description_L10n)) {
567
    $out .=  ' ' . $element->description_L10n;
568
  }
569
570
  if(isset($element->taxon2)){
571
    $out = theme('cdm_taxonName',
572
        array(
573 5b3557f9 Andreas Kohlbecker
            'taxonName' => $element->taxon2->name,
574 05e1b851 Andreas Kohlbecker
            'nameLink' => url(path_to_taxon($element->taxon2->uuid))
575 2ba0f3bd Andreas Kohlbecker
        )
576
      );
577
  }
578
579 1f11e206 Andreas Kohlbecker
  $footnote_key_list_str = cdm_create_description_element_footnotes($element);
580
581
  return $out . $footnote_key_list_str;
582 2ba0f3bd Andreas Kohlbecker
583
584
}
585
586 6657531f Andreas Kohlbecker
/**
587
 * Returns HTML for citations textdata elements.
588
 *
589
 * TODO: assign a new name to the function? Because it is used for the citations
590
 * textdata elements and not for all text data description elements.
591
 *
592
 * @param array $variables
593
 *   An associative array containing:
594
 *   - element: The description element which contains the text information.
595
 *   - asListElement: A boolean which determines whether the citations should
596
 *     be rendered as a list or not.
597
 *   - feature_uuid
598
 *
599
 * @ingroup themeable
600
 */
601
function theme_cdm_descriptionElementTextData($variables) {
602 235fc94b Andreas Kohlbecker
603 6657531f Andreas Kohlbecker
  $element = $variables['element'];
604
  $feature_uuid = $variables['feature_uuid'];
605 22f5e82d Andreas Kohlbecker
  $asListElement = $variables['asListElement']; // TODo remove and replace by $feature_block_settings['as_list']
606 6f5c7f2a Andreas Kohlbecker
  $footnote_list_key_suggestion = $feature_uuid;
607 22f5e82d Andreas Kohlbecker
608
  $sourceRefs = '';
609
  $out = '';
610 6f5c7f2a Andreas Kohlbecker
  $name_used_in_source = '';
611 22f5e82d Andreas Kohlbecker
612
  // FIXME $feature_block_settings should be passed as parameter!!!!!
613
  $feature_block_settings = get_feature_block_settings($feature_uuid);
614 6f5c7f2a Andreas Kohlbecker
  $bibliography_settings = get_bibliography_settings();
615
  $do_references_inline = $feature_block_settings['references_inline'] && $bibliography_settings['enabled'] !== 1;
616 22f5e82d Andreas Kohlbecker
617
  // FIXME remove this hack ---------------------------
618
  $default_theme = variable_get('theme_default', NULL);
619
  if($default_theme == 'garland_cichorieae' || $default_theme == 'cyprus'
620
    || $default_theme == 'flore_afrique_centrale' || $default_theme == 'flora_malesiana' || $default_theme == 'flore_gabon' ){
621
    $asListElement = $feature_block_settings['as_list'] == 'ul';
622
  }
623
  // --------------------------------------------------
624 235fc94b Andreas Kohlbecker
625 6657531f Andreas Kohlbecker
  $description = '';
626
  if (isset($element->multilanguageText_L10n->text)) {
627
    $description = str_replace("\n", "<br/>", $element->multilanguageText_L10n->text);
628
  }
629 28c5c87a Andreas Kohlbecker
630 22f5e82d Andreas Kohlbecker
  // original sources
631 6f5c7f2a Andreas Kohlbecker
  if($do_references_inline) {
632 6657531f Andreas Kohlbecker
    foreach ($element->sources as $source) {
633 22f5e82d Andreas Kohlbecker
      // ---------------------------------------------------------------------------
634
      // CUSTOM CODE (2) from cichorieae theme,
635
      // use nomref web service to combine reference with microreference, other way to combine these?
636
      // is this a general case for all features? >>> DISCUSS with Andreas M. FIXME
637
      if ($feature_uuid == UUID_CITATION) {
638
        $referenceCitation = cdm_ws_get(
639
          CDM_WS_NOMENCLATURAL_REFERENCE_CITATION,
640
          array($source->citation->uuid),
641
          "microReference=" . urlencode($source->citationMicroReference
642
          ));
643
        $referenceCitation = $referenceCitation->String;
644
645 6f5c7f2a Andreas Kohlbecker
        // END CUSTOM CODE (2)
646
        // ---------------------------------------------------------------------------
647 22f5e82d Andreas Kohlbecker
      } else {
648
        $referenceCitation = theme('cdm_OriginalSource', array('source' => $source));
649
      }
650
651 6657531f Andreas Kohlbecker
      if ($description && strlen($description) > 0 && $referenceCitation) {
652
        $sourceRefs .= ' (' . $referenceCitation . ')';
653
      }
654
      elseif ($referenceCitation) {
655
        $sourceRefs = $referenceCitation;
656
      }
657
658
      if (strlen($sourceRefs) > 0) {
659
        $sourceRefs = '<span class="sources">' . $sourceRefs . '</span>';
660
      }
661 22f5e82d Andreas Kohlbecker
662
      // link the nameUsedInSource to the according name page
663 6657531f Andreas Kohlbecker
      // Do a link to name page.
664
      if (isset($source->nameUsedInSource->uuid) && isset($source->nameUsedInSource->titleCache)) {
665 c367b0ab Andreas Kohlbecker
        // it is a DescriptionElementSource
666 22f5e82d Andreas Kohlbecker
        if($feature_block_settings['link_to_name_used_in_source']){
667 6f5c7f2a Andreas Kohlbecker
          $name_used_in_source = l(
668 22f5e82d Andreas Kohlbecker
            $source->nameUsedInSource->titleCache,
669
            path_to_name($source->nameUsedInSource->uuid),
670
            array(
671 6f5c7f2a Andreas Kohlbecker
              'attributes' => array(),
672
              'absolute' => TRUE,
673
              'html' => TRUE,
674
            ));
675 22f5e82d Andreas Kohlbecker
676
        } else {
677 6f5c7f2a Andreas Kohlbecker
          $name_used_in_source = $source->nameUsedInSource->titleCache;
678 22f5e82d Andreas Kohlbecker
        }
679 6657531f Andreas Kohlbecker
      }
680 c367b0ab Andreas Kohlbecker
      else if (isset($source->nameUsedInSource->originalNameString) && strlen($source->nameUsedInSource->originalNameString) > 0) {
681 22f5e82d Andreas Kohlbecker
        // TODO does this make sense? is $source->nameUsedInSource->originalNameString different from $source->nameUsedInSource->titleCache ?
682 c367b0ab Andreas Kohlbecker
        // it is NOT a DescriptionElementSource
683
        // Show a text without link.
684 6f5c7f2a Andreas Kohlbecker
        $name_used_in_source = $source->nameUsedInSource->originalNameString;
685 6657531f Andreas Kohlbecker
      }
686 6f5c7f2a Andreas Kohlbecker
    } // END of loop over sources
687
688
    // annotations footnotes separate.
689
    $foot_note_keys = theme('cdm_annotations_as_footnotekeys',
690
      array(
691
        'cdmBase_list' => $element,
692
        'footnote_list_key' => $footnote_list_key_suggestion,
693
      )
694
    );
695 6657531f Andreas Kohlbecker
696 6f5c7f2a Andreas Kohlbecker
  } // END of references inline
697
  else {
698
    $foot_note_keys = cdm_create_description_element_footnotes($element, ',', $footnote_list_key_suggestion);
699
  }
700 6657531f Andreas Kohlbecker
701 6f5c7f2a Andreas Kohlbecker
  if ($asListElement) {
702
703
    $out = '<li class="DescriptionElement DescriptionElement-' . $element->class . '
704
        ' .  html_class_attribute_ref($element)  . '">';
705
    // Adding ":" if necessary.
706
    if (!empty($name_used_in_source)) {
707
      if ( (!empty($description)|| !empty($sourceRefs)) && $feature_uuid != UUID_CHROMOSOMES_NUMBERS) {
708
        $out .= $name_used_in_source . ': ';
709
      } else {
710
        $out .= $name_used_in_source . ' ';
711 6657531f Andreas Kohlbecker
      }
712
    }
713 6f5c7f2a Andreas Kohlbecker
    $out .= $description . $sourceRefs . $foot_note_keys . '</li>';
714
  }
715 6657531f Andreas Kohlbecker
  else {
716 6f5c7f2a Andreas Kohlbecker
    if ($name_used_in_source) {
717
      $name_used_in_source = ' (name in source: ' . $name_used_in_source . ')';
718
    }
719
720
    $out = '<span class="DescriptionElement DescriptionElement-' . $element->class . '
721
        ' .  html_class_attribute_ref($element)  . '">'
722
      . $description . $sourceRefs . $name_used_in_source . $foot_note_keys . '</span>';
723 6657531f Andreas Kohlbecker
  }
724 092744e1 Andreas Kohlbecker
725 6657531f Andreas Kohlbecker
  return $out;
726
}
727
728
/**
729 28c5c87a Andreas Kohlbecker
 * Composes block of common names for the given DescriptionElements $elements which must be of the feature CommonName
730
 *
731
 * @parameter $elements
732
 *  an array of CDM DescriptionElements either of type CommonName or TextData
733
 * @parameter $feature
734
 *  the common feature of all $elements, must be CommonName
735
 *
736
 * @return
737
 *   A drupal render array
738
 *
739
 * @ingroup compose
740 6657531f Andreas Kohlbecker
 */
741 6f5c7f2a Andreas Kohlbecker
function compose_cdm_common_names($elements, $feature, $weight = FALSE) {
742 28c5c87a Andreas Kohlbecker
743 6657531f Andreas Kohlbecker
  $common_name_out = '';
744 28c5c87a Andreas Kohlbecker
  $common_name_feature_elements = array();
745 6657531f Andreas Kohlbecker
  $textData_commonNames = array();
746
747 28c5c87a Andreas Kohlbecker
  $footnote_key_suggestion = 'common-names-feature-block';
748
749 6657531f Andreas Kohlbecker
  if (is_array($elements)) {
750
    foreach ($elements as $element) {
751 28c5c87a Andreas Kohlbecker
752 6657531f Andreas Kohlbecker
      if ($element->class == 'CommonTaxonName') {
753 20143e0d Andreas Kohlbecker
754
        // common name without a language or area, should not happen but is possible
755
        $language_area_key = '';
756 6657531f Andreas Kohlbecker
        if (isset($element->language->representation_L10n)) {
757 20143e0d Andreas Kohlbecker
          $language_area_key .= '<b>' . $element->language->representation_L10n . '</b>';
758 6657531f Andreas Kohlbecker
        }
759 20143e0d Andreas Kohlbecker
        if(isset($element->area->titleCache) && strlen($element->area->titleCache) > 0){
760
          $language_area_key .= ($language_area_key ? ' '  : '') . '(' . $element->area->titleCache . ')';
761 ae0a5060 Andreas Kohlbecker
        }
762 20143e0d Andreas Kohlbecker
763 ae0a5060 Andreas Kohlbecker
        if(isset($common_names[$language_area_key][$element->name])) {
764
          // same name already exists for language and areae combination, se we merge the description elements
765
          cdm_merge_description_elements($common_names[$language_area_key][$element->name], $element);
766
        } else{
767
          // otherwise add as new entry
768
          $common_names[$language_area_key][$element->name] = $element;
769 6657531f Andreas Kohlbecker
        }
770 20143e0d Andreas Kohlbecker
771 6657531f Andreas Kohlbecker
      }
772
      elseif ($element->class == 'TextData') {
773
        $textData_commonNames[] = $element;
774
      }
775
    }
776
  }
777
  // Handling common names.
778
  if (isset($common_names) && count($common_names) > 0) {
779
    // Sorting the array based on the key (language, + area if set).
780
    // Comment @WA there are common names without a language, so this sorting
781
    // can give strange results.
782
    ksort($common_names);
783
784 28c5c87a Andreas Kohlbecker
    // loop over set of elements per language area
785
    foreach ($common_names as $language_area_key => $elements) {
786 ae0a5060 Andreas Kohlbecker
      ksort($elements); // sort names alphabetically
787 28c5c87a Andreas Kohlbecker
      $per_language_area_out = array();
788
      // loop over set of individual elements
789 6657531f Andreas Kohlbecker
      foreach ($elements as $element) {
790
        if ($element->name) {
791 28c5c87a Andreas Kohlbecker
          $per_language_area_out[] = '<span class="' . html_class_attribute_ref($element) . '">'
792
          . $element->name . cdm_create_description_element_footnotes($element, ',', $footnote_key_suggestion) . '</span>';
793 6657531f Andreas Kohlbecker
        }
794 28c5c87a Andreas Kohlbecker
      } // End of loop over set of individual elements
795 c367b0ab Andreas Kohlbecker
      $common_name_feature_elements[] = ($language_area_key ? $language_area_key . ': ' : '' ) . join(', ', $per_language_area_out);
796 28c5c87a Andreas Kohlbecker
    } // End of loop over set of elements per language area
797
798
799 6f5c7f2a Andreas Kohlbecker
    $common_name_feature_elements_render_array = compose_cdm_feature_block_elements(
800
      $common_name_feature_elements,
801
      $feature,
802
      '; ',
803
      FALSE,
804
      'div'
805 c367b0ab Andreas Kohlbecker
      );
806 6f5c7f2a Andreas Kohlbecker
    $common_name_out .= $common_name_feature_elements_render_array['#markup'];
807 28c5c87a Andreas Kohlbecker
808 6657531f Andreas Kohlbecker
  }
809 28c5c87a Andreas Kohlbecker
810 6657531f Andreas Kohlbecker
  // Handling commons names as text data.
811 28c5c87a Andreas Kohlbecker
  $text_data_out = array();
812
813 6657531f Andreas Kohlbecker
  foreach ($textData_commonNames as $text_data_element) {
814 28c5c87a Andreas Kohlbecker
    /* footnotes are not handled correctly in theme_cdm_descriptionElementTextData,
815
       need to set 'common-names-feature-block' as $footnote_key_suggestion */
816
    RenderHints::setFootnoteListKey($footnote_key_suggestion);
817
    $text_data_out[] = theme('cdm_descriptionElementTextData', array(
818 6657531f Andreas Kohlbecker
      'element' => $text_data_element,
819
      'asListElement' => TRUE,
820
      'feature_uuid' => $text_data_element->feature->uuid,
821
    ));
822
  }
823
824 c367b0ab Andreas Kohlbecker
  $common_name_out_text_data = compose_cdm_feature_block_elements(
825
        $text_data_out,
826
        $feature
827 28c5c87a Andreas Kohlbecker
      );
828 6657531f Andreas Kohlbecker
829 28c5c87a Andreas Kohlbecker
830
  $footnotes = theme('cdm_footnotes', array('footnoteListKey' => $footnote_key_suggestion)); // FIXME is this needed at all?
831
  $footnotes .= theme('cdm_annotation_footnotes', array('footnoteListKey' => $footnote_key_suggestion));
832
833
  return  markup_to_render_array(
834
    '<div class="common_names_as_common_names">' . $common_name_out . '</div>'
835 6f5c7f2a Andreas Kohlbecker
    .'<div class="common_names_as_text_data">' . $common_name_out_text_data['#markup'] . '</div>'
836
    .$footnotes,
837
    $weight
838 28c5c87a Andreas Kohlbecker
  );
839 6657531f Andreas Kohlbecker
}
840
841
/**
842
 * Return HTML for a list of description elements.
843
 *
844
 * Usually these are of a specific feature type.
845
 *
846 6f5c7f2a Andreas Kohlbecker
 * @param $descriptionElements
847
 *   array of descriptionElements which belong to the same feature.
848
 *   These descriptions elements of a Description must be ordered by the chosen feature tree by
849
 *   calling the function _mergeFeatureTreeDescriptions().
850
 *   @see _mergeFeatureTreeDescriptions()
851
 *  @param  $feature_uuid
852 6657531f Andreas Kohlbecker
 *
853 6f5c7f2a Andreas Kohlbecker
 * @ingroup compose
854 6657531f Andreas Kohlbecker
 */
855 6f5c7f2a Andreas Kohlbecker
function compose_cdm_descriptionElements($descriptionElements, $feature, $weight = FALSE) {
856
857 235fc94b Andreas Kohlbecker
858 6657531f Andreas Kohlbecker
  $outArray = array();
859 6f5c7f2a Andreas Kohlbecker
  $sortOutArray = FALSE;
860
  $distributionElements = array();
861
  $distribution_tree = null;
862 6657531f Andreas Kohlbecker
863
  /*
864 092744e1 Andreas Kohlbecker
  $userDefined = mixed_variable_get(LAYOUT_SETTING_PREFIX . $feature_uuid, FEATURE_TREE_LAYOUT_DEFAULTS);
865 bfb2b81a Andreas Kohlbecker
  if(variable_get('distribution_sort',
866
      'NO_SORT') != 'NO_SORT'){
867
      $glue = '';
868
      $enclosingTag = 'dl';
869
      $entryEnclosingTag = NULL;
870
  } else if($userDefined &&
871
      $userDefined['enabled']){
872
    $glue = $userDefined['glue'];
873
    $enclosingTag =  $userDefined['enclosingTag'];
874
    $entryEnclosingTag = $userDefined['entryEnclosingTag'];
875
  } else { // TODO remove once  LAYOUT_SETTING_PREFIX-{uuid} setting are configured to work for all portals(selenium test still missing!!!)
876
    $glue = ''; $enclosingTag = 'ul';
877
    $entryEnclosingTag = NULL ;
878
  }
879 6657531f Andreas Kohlbecker
  */
880
881 6f5c7f2a Andreas Kohlbecker
882 6657531f Andreas Kohlbecker
883
  RenderHints::pushToRenderStack('cdm_descriptionElements');
884
885 2fc97419 Andreas Kohlbecker
  if (is_array($descriptionElements)) {
886 092744e1 Andreas Kohlbecker
    // --- normal description element arrays
887 6657531f Andreas Kohlbecker
    foreach ($descriptionElements as $descriptionElement) {
888
889
      // --- IMAGE_SOURCES --- //
890 092744e1 Andreas Kohlbecker
      if ($descriptionElement->feature->uuid == UUID_IMAGE_SOURCES) {
891 6657531f Andreas Kohlbecker
        $image_sources[] = $descriptionElement;
892
      }
893
      // --- USE TEXTDATA --- //
894
      elseif ($descriptionElement->feature->uuid == UUID_USE) {
895
        // Do nothing to avoid rendering.
896
      } else {
897
        /* decide based on the description element class
898 22f5e82d Andreas Kohlbecker
         *
899
         * Features handled here:
900
         * all except DISTRIBUTION, COMMON_NAME, USES, IMAGES,
901
         *
902 6657531f Andreas Kohlbecker
         *
903
         * TODO provide api_hook as extension point for this
904
         */
905
        switch ($descriptionElement->class) {
906
          case 'TextData':
907
            $asListElement = TRUE;
908
            $outArray[] = theme('cdm_descriptionElementTextData', array(
909
              'element' => $descriptionElement,
910
              'asListElement' => $asListElement,
911
              'feature_uuid' => $descriptionElement->feature->uuid,
912
            ));
913
            break;
914
          case 'CategoricalData':
915
            $outArray[] = theme('cdm_descriptionElement_CategoricalData', array('element' => $descriptionElement));
916
            break;
917 f19f47fa Andreas Kohlbecker
          case 'QuantitativeData':
918
            $outArray[] = theme('cdm_descriptionElement_QuantitativeData', array('element' => $descriptionElement));
919 3445600f Andreas Kohlbecker
            break;
920 2ba0f3bd Andreas Kohlbecker
          case 'IndividualsAssociation':
921
            $outArray[] = theme('cdm_descriptionElement_IndividualsAssociation', array('element' => $descriptionElement));
922
            break;
923
          case 'TaxonInteraction':
924
            $outArray[] = theme('cdm_descriptionElement_TaxonInteraction', array('element' => $descriptionElement));
925
            break;
926 3445600f Andreas Kohlbecker
          case 'Uses':
927 29809fe3 Andreas Kohlbecker
          /* IGNORE Uses classes, these are handled completely in theme_cdm_UseDescription */
928 6657531f Andreas Kohlbecker
          break;
929
        default:
930
        $outArray[] = '<li>No method for rendering unknown description class: ' . $descriptionElement->class . '</li>';
931
      }
932
    }
933 092744e1 Andreas Kohlbecker
    } // --- END loop over normal description element arrays
934 6657531f Andreas Kohlbecker
935 c367b0ab Andreas Kohlbecker
    // If feature = CITATION sort the list of sources.
936 092744e1 Andreas Kohlbecker
    // This is ONLY for FLORA MALESIANA and FLORE d'AFRIQUE CENTRALE.
937 c367b0ab Andreas Kohlbecker
    if ($descriptionElement->feature->uuid == UUID_CITATION) {
938 092744e1 Andreas Kohlbecker
      sort($outArray);
939
    }
940 6657531f Andreas Kohlbecker
941 092744e1 Andreas Kohlbecker
    if (isset($image_sources)) {
942
      $outArray[] = theme('cdm_description_element_image_source', array('image_sources' => $image_sources, 'asListElement' => TRUE));
943
    }
944
  } // END normal description element arrays
945 6657531f Andreas Kohlbecker
946 6f5c7f2a Andreas Kohlbecker
  $render_array = compose_cdm_feature_block_elements(
947 c367b0ab Andreas Kohlbecker
    $outArray,
948 22f5e82d Andreas Kohlbecker
    $feature
949 c367b0ab Andreas Kohlbecker
  );
950 6657531f Andreas Kohlbecker
951
  RenderHints::popFromRenderStack();
952 6f5c7f2a Andreas Kohlbecker
  return $render_array;
953 6657531f Andreas Kohlbecker
}
954
955
/**
956
 * @todo Please document this function.
957
 * @see http://drupal.org/node/1354
958
 */
959
function compare_image_sources($a, $b) {
960
  if ($a->multilanguageText_L10n->text == $b->multilanguageText_L10n->text) {
961
    return 0;
962
  }
963
  return ($a->multilanguageText_L10n->text < $b->multilanguageText_L10n->text) ? -1 : 1;
964
}
965
966
/**
967
 * @todo Please document this function.
968
 * @see http://drupal.org/node/1354
969
 */
970
function theme_cdm_description_element_image_source($variables) {
971
  $image_sources = $variables['image_sources'];
972
  $asListElement = $variables['asListElement'];
973
  $out = '';
974
  $separator = ',';
975
  RenderHints::pushToRenderStack('descriptionElementImageSource');
976
  RenderHints::setFootnoteListKey(UUID_IMAGE_SOURCES);
977
978
  // Sorting the image sources.
979
  usort($image_sources, "compare_image_sources");
980
  // Generate the footnotes.
981
  foreach ($image_sources as $image_source) {
982
    $footNoteKeys = cdm_annotations_as_footnotekeys($image_source);
983
    foreach ($image_source->sources as $source) {
984
      if (_is_original_source_type($source)) {
985 f19f47fa Andreas Kohlbecker
        $fn_key = FootnoteManager::addNewFootnote(original_source_footnote_list_key(), theme('cdm_OriginalSource', array(
986 1b04a204 Andreas Kohlbecker
          'source' => $source,
987 6657531f Andreas Kohlbecker
          'doLink' => FALSE,
988
        )));
989
        // Ensure uniqueness of the footnote keys.
990
        cdm_add_footnote_to_array($footNoteKeys, $fn_key);
991
      }
992
    }
993
    // Sort and render footnote keys.
994 1f11e206 Andreas Kohlbecker
    $footnote_key_list_str = '';
995 6657531f Andreas Kohlbecker
    asort($footNoteKeys);
996
    foreach ($footNoteKeys as $footNoteKey) {
997 1f11e206 Andreas Kohlbecker
      $footnote_key_list_str .= theme('cdm_footnote_key', array('footnoteKey' => $footNoteKey, 'separator' => ($footnote_key_list_str ? $separator : '')));
998 6657531f Andreas Kohlbecker
    }
999
    // Return value!
1000 1f11e206 Andreas Kohlbecker
    $out .= '<span class="descriptionElement descriptionElement-' . $image_source->uuid . '">' . $image_source->multilanguageText_L10n->text . $footnote_key_list_str . '; </span>';
1001 6657531f Andreas Kohlbecker
  }
1002
1003
  RenderHints::popFromRenderStack();
1004
  return $out;
1005
}
1006
1007
/**
1008
 * @todo Please document this function.
1009
 * @see http://drupal.org/node/1354
1010
 */
1011 092744e1 Andreas Kohlbecker
function theme_cdm_descriptionElement_Distribution($variables) {
1012 6657531f Andreas Kohlbecker
  $descriptionElements = $variables['descriptionElements'];
1013
  $enclosingTag = $variables['enclosingTag'];
1014
  if (!$enclosingTag) {
1015
    $enclosingTag = "span";
1016
  }
1017
1018
  $out = '';
1019
  RenderHints::pushToRenderStack('descriptionElementDistribution');
1020
  RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
1021
1022
  foreach ($descriptionElements as $descriptionElement) {
1023
1024 1f11e206 Andreas Kohlbecker
    $footnote_key_list_str = cdm_create_description_element_footnotes($descriptionElement);
1025 6657531f Andreas Kohlbecker
1026 1f11e206 Andreas Kohlbecker
    $out .= '<' . $enclosingTag . ' class="descriptionElement descriptionElement-' . $descriptionElement->uuid . '">'
1027
        . $descriptionElement->area->representation_L10n . $footnote_key_list_str
1028
        . ' </' . $enclosingTag . '>';
1029 6657531f Andreas Kohlbecker
  }
1030
1031
  RenderHints::popFromRenderStack();
1032
  return $out;
1033
}
1034
1035 1f11e206 Andreas Kohlbecker
1036 6657531f Andreas Kohlbecker
/**
1037
 * Compare two different footnotes objects.
1038
 *
1039
 * The comparison is based on the footnote key. The one which is
1040
 * displayed as footnote number.
1041
 *
1042
 * @param mixed $a
1043
 *   Footnote object $a.
1044
 * @param mixed $b
1045
 *   Footnote object $b.
1046
 */
1047
function footnotes_key_compare($a, $b) {
1048
  $res = 0;
1049
  if (empty($a) || empty($b)) {
1050
    return $res;
1051
  }
1052
  if ($a->keyStr < $b->keyStr) {
1053
    $res = -1;
1054
  }
1055
  elseif ($a->keyStr > $b->keyStr) {
1056
    $res = 1;
1057
  }
1058
  return $res;
1059
}
1060
1061
/**
1062
 * @todo Please document this function.
1063
 * @see http://drupal.org/node/1354
1064
 */
1065
function theme_cdm_description_ordered_distributions($variables) {
1066 bfb2b81a Andreas Kohlbecker
1067 092744e1 Andreas Kohlbecker
  $distribution_tree = $variables['distribution_tree'];
1068 bfb2b81a Andreas Kohlbecker
1069 6657531f Andreas Kohlbecker
  // Returning NULL if there are no description elements.
1070 092744e1 Andreas Kohlbecker
  if ($distribution_tree == null) {
1071 bfb2b81a Andreas Kohlbecker
    return NULL;
1072 6657531f Andreas Kohlbecker
  }
1073 bfb2b81a Andreas Kohlbecker
1074 6657531f Andreas Kohlbecker
  // Initialization of some variables.
1075
  $out = '';
1076
  $separator = ',';
1077
  RenderHints::pushToRenderStack('descriptionElementDistribution');
1078
  RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
1079 bfb2b81a Andreas Kohlbecker
1080 092744e1 Andreas Kohlbecker
  $ordered_areas = $distribution_tree;
1081 6657531f Andreas Kohlbecker
  if (isset($ordered_areas->rootElement->children)) {
1082
    $ordered_areas = $ordered_areas->rootElement->children;
1083
  }
1084
1085
  // Printing the distributions.
1086
  if (is_array($ordered_areas) && count($ordered_areas) > 0) {
1087
    foreach ($ordered_areas as $element_level1) {
1088
      // Level1.
1089 85b65ccc Andreas Kohlbecker
      $out .= '<dt>' . $element_level1->nodeId->representation_L10n . ':</dt> ';
1090 6657531f Andreas Kohlbecker
      $out .= '<dd>';
1091
1092
      // Level3.
1093
      foreach ($element_level1->children as $element_level3) {
1094 85b65ccc Andreas Kohlbecker
        $text_l3 = $element_level3->nodeId->representation_L10n;
1095 6657531f Andreas Kohlbecker
        $fnKeysLevel3Str = '';
1096
        $fnKeysLevel3 = cdm_annotations_as_footnotekeys($element_level3->data);
1097 85b65ccc Andreas Kohlbecker
        if (isset($element_level3->data[0])) {
1098
          foreach ($element_level3->data as $description_level3){
1099
            foreach ($description_level3->sources as $source) {
1100
              if (_is_original_source_type($source)) {
1101 bdd7d687 Andreas Kohlbecker
                $fn_key3 = FootnoteManager::addNewFootnote(
1102
                  original_source_footnote_list_key(),
1103
                  theme('cdm_OriginalSource', array('source' => $source, 'doLink' => FALSE)
1104
                ));
1105 85b65ccc Andreas Kohlbecker
                cdm_add_footnote_to_array($fnKeysLevel3, $fn_key3);
1106
              }
1107
            }
1108 6657531f Andreas Kohlbecker
          }
1109
        }
1110
        // Level4.
1111
        $l4_regions = array();
1112
        foreach ($element_level3->children as $element_level4) {
1113 85b65ccc Andreas Kohlbecker
          if (isset($element_level4->data[0])) {
1114
            $text_l4 = $element_level4->nodeId->representation_L10n;
1115
            $l4_regions[$element_level3->nodeId->representation_L10n] = array();
1116 6657531f Andreas Kohlbecker
            $fnKeysLevel4Str = '';
1117 85b65ccc Andreas Kohlbecker
            foreach($element_level4->data as $description_level4) {
1118
              $fnKeysLevel4 = cdm_annotations_as_footnotekeys($description_level4);
1119
              foreach ($description_level4->sources as $source) {
1120
                if (_is_original_source_type($source)) {
1121
                  $fn_key4 = FootnoteManager::addNewFootnote(
1122 f19f47fa Andreas Kohlbecker
                      original_source_footnote_list_key(),
1123 85b65ccc Andreas Kohlbecker
                      theme('cdm_OriginalSource', array('source' => $source, 'doLink' => FALSE)));
1124
                  cdm_add_footnote_to_array($fnKeysLevel4, $fn_key4);
1125
                }
1126
              }
1127
              usort($fnKeysLevel4, "footnotes_key_compare");
1128
              if(!isset( $l4_regions[$text_l4])){
1129
                $l4_regions[$text_l4] = $fnKeysLevel4;
1130
              } else {
1131
                $l4_regions[$text_l4] = array_merge($l4_regions[$text_l4], $fnKeysLevel4);
1132 6657531f Andreas Kohlbecker
              }
1133
            }
1134
          }
1135
        }// Level4.
1136
        // Managing level3 and level4 for generating the right output.
1137
        usort($fnKeysLevel3, "footnotes_key_compare");
1138
        foreach ($fnKeysLevel3 as $key3) {
1139
          foreach ($l4_regions as $key4 => $value4) {
1140
            cdm_add_footnote_to_array($l4_regions[$key4], $key3);
1141
          }
1142
        }
1143 85b65ccc Andreas Kohlbecker
        if ($element_level3->numberOfChildren == 1 && $text_l3 == $element_level3->children[0]->nodeId->representation_L10n) {
1144 6657531f Andreas Kohlbecker
          // var_dump($element_level3->children[0]->data->area->representation_L10n);
1145
          $fnStr = '';
1146
          $region = array_pop($l4_regions);
1147
          foreach ($region as $key) {
1148
            $fnStr .= theme('cdm_footnote_key', array('footnoteKey' => $key, 'separator' => ($fnStr ? $separator : '')));
1149
          }
1150
          $out .= "$text_l3 $fnStr; ";
1151
          // Removing whitespaces when &fnStr is empty.
1152
          if (substr($out, -3) == ' ; ') {
1153
            $out = substr($out, 0, -3) . '; ';
1154
          }
1155 85b65ccc Andreas Kohlbecker
        } else {
1156 6657531f Andreas Kohlbecker
          $fnKeysLevel3Str = '';
1157
          foreach ($fnKeysLevel3 as $key) {
1158
            $fnKeysLevel3Str .= theme('cdm_footnote_key', array('footnoteKey' => $key, 'separator' => ($fnKeysLevel3Str ? $separator : '')));
1159
          }
1160
          $text_l4_aux = '';
1161
          foreach ($l4_regions as $key => $value) {
1162
            $fnKeysLevel4Str = '';
1163
            if (is_array($l4_regions[$key])) {
1164 85b65ccc Andreas Kohlbecker
              foreach ($l4_regions[$key] as $fnkey) {
1165 6657531f Andreas Kohlbecker
                $fnKeysLevel4Str .= theme('cdm_footnote_key', array('footnoteKey' => $fnkey, 'separator' => ($fnKeysLevel4Str ? $separator : '')));
1166
              }
1167
            }
1168
            // if ($key != $text_l3 || sizeof($l4_regions > 1)){
1169
            if ($key != $text_l3) {
1170
              $text_l4_aux .= "$key $fnKeysLevel4Str, ";
1171
            }
1172
          }
1173
          $text_l4_aux = substr($text_l4_aux, 0, -2);
1174
1175
          if (strlen($text_l4_aux) > 0) {
1176
            $out .= "$text_l3 $fnKeysLevel3Str ($text_l4_aux); ";
1177
          }
1178
          else {
1179
            $out .= "$text_l3 $fnKeysLevel3Str; ";
1180
          }
1181
        }
1182
      }// Level3.
1183
      $out = substr($out, 0, -2);
1184
      $out .= '.</dd>';
1185
    }// Level1.
1186
  }
1187
  RenderHints::popFromRenderStack();
1188
  return $out;
1189
}
1190 1b04a204 Andreas Kohlbecker
1191 6657531f Andreas Kohlbecker
1192
/*
1193 092744e1 Andreas Kohlbecker
function theme_cdm_descriptionElement_Distribution($descriptionElements){ $out
1194 6657531f Andreas Kohlbecker
  = ''; $separator = ',';
1195
  RenderHints::pushToRenderStack('descriptionElementDistribution');
1196
  RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
1197
  foreach($descriptionElements as $descriptionElement){ // annotations as
1198
  footnotes $annotationFootnoteKeys = theme('cdm_annotations_as_footnotekeys',
1199
  $descriptionElement); // source references as footnotes
1200
  $sourcesFootnoteKeyList = ''; foreach($descriptionElement->sources as
1201
  $source){ if(_is_original_source_type($source)){ $_fkey =
1202
  FootnoteManager::addNewFootnote(UUID_DISTRIBUTION,
1203 1b04a204 Andreas Kohlbecker
  theme('cdm_OriginalSource', $source, FALSE));
1204 6657531f Andreas Kohlbecker
  $sourcesFootnoteKeyList .= theme('cdm_footnote_key', $_fkey,
1205
  UUID_DISTRIBUTION, ($sourcesFootnoteKeyList ? $separator : '')); } }
1206
  if($annotationFootnoteKeys && $sourcesFootnoteKeyList){
1207
  $annotationFootnoteKeys .= $separator; } $out .=
1208
  $descriptionElement->area->representation_L10n . $annotationFootnoteKeys .
1209
  $sourcesFootnoteKeyList . ' '; } $out = substr($out, 0,
1210
  strlen($out)-strlen($separator) ); RenderHints::popFromRenderStack(); return
1211
  $out; }
1212
*/
1213
1214
/**
1215
 * Returns a list of a specific type of IdentificationKeys.
1216
 *
1217
 * The list can be restricteded by a taxon.
1218
 *
1219
 * @param string $type
1220
 *   The simple name of the cdm class implementing the interface
1221
 *   IdentificationKey, valid values are:
1222
 *   PolytomousKey, MediaKey, MultiAccessKey.
1223
 * @param string $taxonUuid
1224
 *   If given this parameter restrict the listed keys to those which have
1225
 *   the taxon identified be this uuid in scope.
1226
 *
1227
 * @return array
1228
 *   List with identification keys.
1229
 */
1230
function _list_IdentificationKeys($type, $taxonUuid = NULL, $pageSize = NULL, $pageNumber = NULL) {
1231
  if (!$type) {
1232
    drupal_set_message(t('Type parameter is missing'), 'error');
1233
    return;
1234
  }
1235
  $cdm_ws_pasepath = NULL;
1236
  switch ($type) {
1237
    case "PolytomousKey":
1238
      $cdm_ws_pasepath = CDM_WS_POLYTOMOUSKEY;
1239
      break;
1240
1241
    case "MediaKey":
1242
      $cdm_ws_pasepath = CDM_WS_MEDIAKEY;
1243
      break;
1244
1245
    case "MultiAccessKey":
1246
      $cdm_ws_pasepath = CDM_WS_MULTIACCESSKEY;
1247
      break;
1248
1249
  }
1250
1251
  if (!$cdm_ws_pasepath) {
1252
    drupal_set_message(t('Type parameter is not valid: ') . $type, 'error');
1253
  }
1254
1255
  $queryParameters = '';
1256
  if (is_numeric($pageSize)) {
1257
    $queryParameters = "pageSize=" . $pageSize;
1258
  }
1259
  else {
1260
    $queryParameters = "pageSize=0";
1261
  }
1262
1263
  if (is_numeric($pageNumber)) {
1264
    $queryParameters = "pageNumber=" . $pageNumber;
1265
  }
1266
  else {
1267
    $queryParameters = "pageNumber=0";
1268
  }
1269
  $queryParameters = NULL;
1270
  if ($taxonUuid) {
1271
    $queryParameters = "findByTaxonomicScope=$taxonUuid";
1272
  }
1273
  $pager = cdm_ws_get($cdm_ws_pasepath, NULL, $queryParameters);
1274
1275
  if (!$pager || $pager->count == 0) {
1276
    return array();
1277
  }
1278
  return $pager->records;
1279
}
1280
1281
/**
1282
 * @todo Please document this function.
1283
 * @see http://drupal.org/node/1354
1284
 */
1285
function theme_cdm_IdentificationKey($variables) {
1286
  $out = '';
1287
  $identificationKey = $variables['identificationKey'];
1288
  $doLinkToKeyPage = $variables['doLinkToKeyPage'];
1289
  $showIdentificationKeyTitle = $variables['showIdentificationKeyTitle'];
1290
  $parentRenderPath = RenderHints::getRenderPath();
1291
  RenderHints::pushToRenderStack("IdentificationKey");
1292
1293
  if ($showIdentificationKeyTitle) {
1294
    if ($doLinkToKeyPage) {
1295
      $out = l($identificationKey->titleCache, path_to_key($identificationKey->class, $identificationKey->uuid));
1296
    }
1297
    else {
1298
      $out = $identificationKey->titleCache;
1299
    }
1300
  }
1301
  if (isset($identificationKey->sources) && is_array($identificationKey->sources)) {
1302 c2486c6b Andreas Kohlbecker
    // order and display sources.
1303
    $sources = oder_sources($identificationKey->sources, TRUE);
1304 29809fe3 Andreas Kohlbecker
    $out .= '<div class="sources">';
1305 c2486c6b Andreas Kohlbecker
    $out .=  implode('', $sources);
1306 6657531f Andreas Kohlbecker
    $out .= '</div>';
1307
  }
1308
  // Display annotations.
1309
  $out .= theme('cdm_annotations', array('annotations' => cdm_ws_getAnnotationsFor($identificationKey), 'enclosingTag' => 'div'));
1310
  RenderHints::popFromRenderStack();
1311
  return $out;
1312
}
1313
1314
/**
1315
 * @todo Please document this function.
1316
 * @see http://drupal.org/node/1354
1317
 */
1318
function theme_cdm_polytomousKey($variables) {
1319
  $polytomousKey = $variables['polytomousKey'];
1320
1321
  // TODO settings needed.
1322
  // @see http://en.wikipedia.org/wiki/Single_access_key#Presentation_styles
1323
  // @see http://dev.e-taxonomy.eu/trac/ticket/2152
1324
  $keyStyle = "linkedStyle";
1325
1326
  RenderHints::pushToRenderStack("polytomousKey");
1327
  // Key nodes in linked style.
1328
  $out = '<table class="polytomousKey polytomousKey_' . $keyStyle . '">';
1329
  $out .= theme('cdm_polytomousKey_' . $keyStyle . '_subgraph', array('polytomousKeyNode' => $polytomousKey->root));
1330
  $out .= '</table>';
1331
  RenderHints::popFromRenderStack();
1332
  return $out;
1333
}
1334
1335
/**
1336
 * @todo Please document this function.
1337
 * @see http://drupal.org/node/1354
1338
 */
1339
function theme_cdm_polytomousKey_linkedStyle_subgraph($variables) {
1340
  $polytomousKeyNode = $variables['polytomousKeyNode'];
1341
  static $statementCountCharacter = '\'';
1342
  $out = "";
1343
1344
  if (is_array($polytomousKeyNode->children)) {
1345
    $childIndex = 0;
1346
1347
    // Render edges of the current node.
1348
    foreach ($polytomousKeyNode->children as &$child) {
1349
1350
      if (!isset($child->statement) && isset($child->taxon->uuid)) {
1351
        // Skip node with empty statements (see below for explanation: "Special
1352
        // case").
1353
        // this skipping here happens always in the next deeper level of iteration
1354
        // the check below is node on the level above
1355
        continue;
1356
      }
1357
1358
      /*
1359
       * Special case: Child nodes with empty statements but taxa as leaf are to
1360
       * treated as if all those taxa where direct children of the source node.
1361
       */
1362
      $islinkToManyTaxa = !isset($child->children[0]->statement) && isset($child->children[0]->taxon->uuid);
1363
      $islinkToTaxon = isset($child->taxon->uuid);
1364
      $islinkToSubKey = isset($child->subkey->uuid);
1365
      $islinkToOtherNode = isset($child->otherNode);
1366
      // Either NULL or 0.
1367
      $islinkToNode = $child->nodeNumber && !$islinkToManyTaxa && !$islinkToOtherNode;
1368 32dccd76 Andreas Kohlbecker
      $hasQuestion = !empty($polytomousKeyNode->question->label_l10n);
1369 6657531f Andreas Kohlbecker
      $hasFeature = isset($polytomousKeyNode->feature);
1370
1371
      // $indentEdge = $hasQuestion && $childIndex > 0;
1372
      // Question.
1373
      if ($hasQuestion && $childIndex == 0) {
1374
        // Place question, as extra table row.
1375
        $out .= '<tr class="question new_section">';
1376
        $out .= '<td class="nodeNumber">' . uuid_anchor($polytomousKeyNode->uuid, $polytomousKeyNode->nodeNumber) . "</td>";
1377
        $out .= '<td class="question">' . $polytomousKeyNode->question->label_l10n . '</td>';
1378
        $out .= '</tr>';
1379
      }
1380
1381
      $out .= '<tr class="childCount_' . $childIndex . (!$hasQuestion && $childIndex == 0 ? ' new_section' : '') . '">';
1382
1383
      if ($hasQuestion) {
1384
        $out .= '<td class="nodeNumber"></td>';
1385
      }
1386
      else {
1387
        $out .= '<td class="nodeNumber">' . uuid_anchor($polytomousKeyNode->uuid, $polytomousKeyNode->nodeNumber . str_pad("", $childIndex, $statementCountCharacter)) . "</td>";
1388
      }
1389
1390
      $out .= '<td ' . RenderHints::getHtmlElementID($child) . '  class="edge' . ($hasQuestion ? ' edge-indent' : '') . '">';
1391
1392
      // Feature.
1393
      if ($hasFeature) {
1394
        $out .= $polytomousKeyNode->feature->representation_L10n . ": ";
1395
      }
1396
1397
      // Statement.
1398
      $out .= $child->statement->label_l10n;
1399
1400
      // --- Links to nodes taxa and subkeys.
1401
      $out .= '<div class="nodeLink">';
1402
1403
      // Link to a PolytomousKeyNode.
1404
      if ($islinkToNode) {
1405
        $out .= '<div class="nodeLinkToNode">';
1406 1a2294c8 Andreas Kohlbecker
        if (isset($child->modifyingText)) {
1407 6657531f Andreas Kohlbecker
          $out .= theme('cdm_poytomousKeyNode_modifyingText', array('modifyingText' => $child->modifyingText));
1408
        }
1409
        $out .= l($child->nodeNumber, request_path(), array(
1410
          'attributes' => NULL,
1411
          'query' => NULL,
1412
          'fragment' => $child->uuid,
1413
        )) . '</div>';
1414
      }
1415
1416
      // Link to a PolytomousKeyNode.
1417
      if ($islinkToOtherNode) {
1418
        $out .= '<div class="nodeLinkToOtherNode">';
1419 1a2294c8 Andreas Kohlbecker
        if (isset($child->modifyingText)) {
1420 6657531f Andreas Kohlbecker
          $out .= theme('cdm_poytomousKeyNode_modifyingText', array('modifyingText' => $child->modifyingText));
1421
        }
1422
        $out .= l($child->otherNode->nodeNumber, $_REQUEST["q"], array(
1423
          'attributes' => NULL,
1424
          'query' => NULL,
1425
          'fragment' => $child->otherNode->uuid,
1426
        )) . '</div>';
1427
      }
1428
1429
      // Link to one or many taxa.
1430
      if ($islinkToTaxon || $islinkToManyTaxa) {
1431
1432
        if ($islinkToManyTaxa) {
1433
          $taxonChildren = $child->children;
1434
        }
1435
        else {
1436
          $taxonChildren = array(
1437
            $child,
1438
          );
1439
        }
1440
1441
        foreach ($taxonChildren as $taxonChild) {
1442
          // TODO many taxa $child->children->taxon.
1443
          $out .= '<div class="nodeLinkToTaxon">';
1444 1a2294c8 Andreas Kohlbecker
          if (isset($taxonChild->modifyingText)) {
1445 6657531f Andreas Kohlbecker
            $out .= theme('cdm_poytomousKeyNode_modifyingText', array('modifyingText' => $taxonChild->modifyingText));
1446
          }
1447
          $out .= theme("cdm_taxonName", array('taxonName' => $taxonChild->taxon->name, 'nameLink' => url(path_to_taxon($taxonChild->taxon->uuid))));
1448
          $out .= '</div>';
1449
        }
1450
1451
        // Link to a subkey.
1452
        if ($islinkToSubKey) {
1453
          $out .= '<div class="nodeLinkToSubkey">' . theme('cdm_IdentificationKey', array('identificationKey' => $child->subkey)) . '</div>';
1454
        }
1455
      }
1456
1457
      $out .= '</div>'; // End node link.
1458
      $out .= '</td>'; // End edge.
1459
      $out .= '</tr>';
1460
1461
      $childIndex++;
1462
    }
1463
1464
    // Recurse into child nodes.
1465
    foreach ($polytomousKeyNode->children as &$child) {
1466
      $out .= theme('cdm_polytomousKey_linkedStyle_subgraph', array('polytomousKeyNode' => $child));
1467
    }
1468
  }
1469
1470
  return $out;
1471
}
1472
1473
/**
1474
 * @todo Please document this function.
1475
 * @see http://drupal.org/node/1354
1476
 */
1477
function theme_cdm_poytomousKeyNode_modifyingText($variables) {
1478
  $out = '';
1479
  $modifyingText = $variables['modifyingText'];
1480
  if (is_object($modifyingText)) {
1481
    $i = 0;
1482
    foreach (get_object_vars($modifyingText) as $lang => $languageString) {
1483
      $out .= ($i++ > 0 ? ', ' : '') . '<span class="modifyingText">' . $languageString->text . '</span> ';
1484
    }
1485
  }
1486
  return $out;
1487
}
1488
1489
/**
1490
 * Returns HTML for a list of a specific type of IdentificationKeys.
1491
 *
1492
 * The list can be restricteded by a taxon.
1493
 *
1494
 * @param array $variables
1495
 *   An associative array containing:
1496
 *   - type: The simple name of the cdm class implementing the interface
1497
 *     IdentificationKey, valid values are:
1498
 *     PolytomousKey, MediaKey, MultiAccessKey
1499
 *   - taxonUuid: If given, this parameter restrict the listed keys to those
1500
 *     which have the taxon identified be this uuid in scope.
1501
 *
1502
 * @ingroup themeable
1503
 */
1504
function theme_cdm_list_IdentificationKeys($variables) {
1505
  $type = $variables['type'];
1506
  $taxonUuid = $variables['taxonUuid'];
1507
  $keyList = _list_IdentificationKeys($type, $taxonUuid);
1508
  if (!$keyList || count($keyList) == 0) {
1509
    return;
1510
  }
1511
1512
  RenderHints::pushToRenderStack('list_IdentificationKeys');
1513
  $out = '<ul>';
1514
  foreach ($keyList as $key) {
1515
    $out .= '<li>';
1516
    $out .= theme('cdm_IdentificationKey', array('identificationKey' => $key));
1517
    $out .= '</li>';
1518
  }
1519
  $out .= '</ul>';
1520
  $out .= theme("cdm_annotation_footnotes", array('footnoteListKey' => RenderHints::getRenderPath()));
1521
  RenderHints::popFromRenderStack();
1522
1523
  return $out;
1524
}
1525
1526
/**
1527
 * @todo Please document this function.
1528
 * @see http://drupal.org/node/1354
1529
 */
1530
function theme_cdm_block_IdentificationKeys($variables) {
1531
  $taxonUuid = $variables['taxonUuid'];
1532
  static $types = array(
1533
    "PolytomousKey" => "Polytomous",
1534
    "MediaKey" => "Media",
1535
    "MultiAccessKey" => "Multiaccess",
1536
  );
1537
  RenderHints::pushToRenderStack('block_IdentificationKeys');
1538
  $out = '';
1539
  foreach ($types as $type => $label) {
1540
    $keylist = theme('cdm_list_IdentificationKeys', array('type' => $type, 'taxonUuid' => $taxonUuid));
1541
    if (!$keylist) {
1542
      continue;
1543
    }
1544
    $out .= '<div class="' . $type . '">';
1545
    $out .= '<h3>' . t($label) . "</h3>";
1546
    $out .= $keylist;
1547
    $out .= '</div>';
1548
  }
1549
  RenderHints::popFromRenderStack();
1550
  return $out;
1551
}
1552
1553
/**
1554 ae0a5060 Andreas Kohlbecker
 * This theming function formats the use description and use record list for
1555
 * these descriptions.
1556
 *
1557 6657531f Andreas Kohlbecker
 * @see http://drupal.org/node/1354
1558
 */
1559
function theme_cdm_UseDescription($variables) {
1560
  $descriptions = $variables['description'];
1561
  $taxonUuid = $variables['taxonUuid'];
1562
  $out = '<div id="content"><ul id="Description" class ="description">';
1563
  if ($descriptions == NULL) {
1564
    return;
1565
  }
1566
  $descriptionSynonyms = '';
1567
  $descriptionOut = '';
1568
  $synonymOut = '';
1569
  $currentTaxon = cdm_ws_get(CDM_WS_PORTAL_TAXON, $taxonUuid);
1570
1571
  foreach ($descriptions as $description) {
1572 3daa3743 Andreas Kohlbecker
    $useSummary = '';
1573 6657531f Andreas Kohlbecker
    foreach ($description->elements as $element) {
1574
1575 3a5d0703 Andreas Kohlbecker
      if ($element->feature->uuid == UUID_USE && !(strlen($useSummary) > 0) && isset($element->multilanguageText_L10n)) {
1576 6657531f Andreas Kohlbecker
        $useSummary = $element->multilanguageText_L10n->text;
1577
      }
1578
    }
1579 3445600f Andreas Kohlbecker
    // uses will be ordered by source
1580 6657531f Andreas Kohlbecker
    foreach ($description->sources as $source) {
1581 3445600f Andreas Kohlbecker
      $is_about_current_taxon = FALSE;
1582 6657531f Andreas Kohlbecker
      $originalTaxonUsedInSource = NULL;
1583
      $originalTaxonPager = NULL;
1584
      if ($source->originalNameString) {
1585
        $request_params = array();
1586
        $request_params['query'] = $source->originalNameString;
1587
        $request_params['matchMode'] = "EXACT";
1588
        $originalTaxonPager = cdm_ws_get(CDM_WS_PORTAL_NAME_FINDBYNAME, NULL, queryString($request_params));
1589
        if ($originalTaxonPager->count > 0) {
1590
          $originalTaxonUsedInSource = $originalTaxonPager->records[0];
1591
        }
1592
        else {
1593
          $originalTaxonUsedInSource = $currentTaxon->name;
1594
        }
1595
      }
1596
      else {
1597
        $originalTaxonUsedInSource = $currentTaxon->name;
1598
      }
1599
1600 3445600f Andreas Kohlbecker
      $is_about_current_taxon = $currentTaxon->name->uuid == $originalTaxonUsedInSource->uuid;
1601 6657531f Andreas Kohlbecker
1602 3445600f Andreas Kohlbecker
      if (!$is_about_current_taxon) {
1603 6657531f Andreas Kohlbecker
        $descriptionOut .= '<li class="descriptionText DescriptionElement">';
1604
        $name_used_in_source_link_to_show_use = l($source->originalNameString, path_to_name($originalTaxonUsedInSource->uuid), array(
1605
          'absolute' => TRUE,
1606
          'html' => TRUE,
1607
        ));
1608
        $descriptionOut .= $name_used_in_source_link_to_show_use . ': ';
1609
        $descriptionOut .= $useSummary;
1610
        foreach ($description->sources as $source) {
1611 1b04a204 Andreas Kohlbecker
          $descriptionOut .= " (" . theme('cdm_OriginalSource', array('source' => $source, 'doLink' => TRUE)) . ")";
1612 6657531f Andreas Kohlbecker
        }
1613
        $hasUseRecords = FALSE;
1614
        $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>';
1615
        foreach ($description->elements as $descriptionElement) {
1616
          if ($descriptionElement->feature->uuid == UUID_USE_RECORD) {
1617
            $hasUseRecords = TRUE;
1618 3445600f Andreas Kohlbecker
            // FIXME localization hardcoded to English
1619 3a5d0703 Andreas Kohlbecker
            $useRecordTags = explode(';', $descriptionElement->modifyingText_l10n);
1620 6657531f Andreas Kohlbecker
            $descriptionUseRecordOut .= '<tr>';
1621
            $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>';
1622
            $descriptionUseRecordOut .= '</tr>';
1623
          }
1624
        }
1625
        $descriptionUseRecordOut .= '</table></div>';
1626
        if ($hasUseRecords) {
1627
          $descriptionOut .= $descriptionUseRecordOut . '</li>';
1628
        }
1629
      }
1630
      else {
1631 3445600f Andreas Kohlbecker
        // TODO +/- duplicate of above, unify this code
1632 6657531f Andreas Kohlbecker
        $synonymOut .= '<li class="descriptionText DescriptionElement">';
1633
        $name_used_in_source_link_to_show_use = l($source->originalNameString, path_to_name($originalTaxonUsedInSource->uuid), array(
1634
          'absolute' => TRUE,
1635
          'html' => TRUE,
1636
        ));
1637
1638
        $synonymOut .= $name_used_in_source_link_to_show_use . ': ';
1639
        $synonymOut .= $useSummary;
1640
        foreach ($description->sources as $source) {
1641 1b04a204 Andreas Kohlbecker
          $synonymOut .= " (" . theme('cdm_OriginalSource', array('source' => $source, 'doLink' => TRUE)) . ")";
1642 6657531f Andreas Kohlbecker
        }
1643
1644
        $hasUseRecords = FALSE;
1645
        $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>';
1646
        foreach ($description->elements as $descriptionElement) {
1647
          if ($descriptionElement->feature->uuid == UUID_USE_RECORD) {
1648
            $hasUseRecords = TRUE;
1649 3a5d0703 Andreas Kohlbecker
            $useRecordTags = explode(';', $descriptionElement->modifyingText_l10n);
1650 6657531f Andreas Kohlbecker
            $useRecordTableOut .= '<tr>';
1651
            $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>';
1652
            $useRecordTableOut .= '</tr>';
1653
          }
1654
        }
1655
        $useRecordTableOut .= '</table></div>';
1656
        if ($hasUseRecords) {
1657
          $synonymOut .= $useRecordTableOut . '</li>';
1658
        }
1659
      }
1660
1661
      // }
1662
    }
1663
  }
1664
  $out .= $descriptionOut . $synonymOut;
1665
  $out .= "</ul></div>";
1666
  return $out;
1667
}
1668
1669 db074558 Andreas Kohlbecker
1670 6657531f Andreas Kohlbecker
/**
1671 db074558 Andreas Kohlbecker
 * The theming function for a block of Uses Descriptions for a given taxon.
1672
 *
1673
 * The Uses block has been removed from the code but the according theme function
1674
 * is kept for compatibility reasons with existing code regarding palmweb.
1675
 *
1676 6657531f Andreas Kohlbecker
 */
1677
function theme_cdm_block_Uses($variables) {
1678
  $taxonUuid = $variables['taxonUuid'];
1679
  RenderHints::pushToRenderStack('block_Uses');
1680
1681
  if ($taxonUuid == NULL) {
1682
    return;
1683
  }
1684
  $out = '';
1685
  $markerTypes = array();
1686
  $markerTypes['markerTypes'] = UUID_MARKERTYPE_USE;
1687
  $useDescriptions = cdm_ws_get(CDM_WS_PORTAL_TAXON_DESCRIPTIONS, $taxonUuid, queryString($markerTypes));
1688
  if (!empty($useDescriptions)) {
1689 3445600f Andreas Kohlbecker
    // FIXME use theme_block instaed of hardcoding the block html here !!!!
1690 6657531f Andreas Kohlbecker
    $out .= '<div id="block-cdm_dataportal-feature-description" class="clear-block block block-cdm_dataportal-feature"><H2><a name="userecords"> </a> Uses </H2>';
1691
    $formatUseDescriptions = theme('cdm_UseDescription', array('description' => $useDescriptions, 'taxonUuid' => $taxonUuid));
1692
1693
    $out .= $formatUseDescriptions;
1694
    $out .= "</div>";
1695
  }
1696
1697
  return $out;
1698
}