Project

General

Profile

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