Project

General

Profile

Download (65.5 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2

    
3
/**
4
 * Returns the localized representations of the modifiers hold by the
5
 * supplied cdm instance concatenated into one string.
6
 *
7
 * @param object $iModifieable
8
 *   cdm instance of an class implementing the interface IModifieable:
9
 *   DescriptionElementBase, StateDate, State
10
 *
11
 * @return String
12
 *   localized representations of the modifiers hold by the
13
 *   supplied cdm instance concatenated into one string
14
 */
15
function cdm_modifers_representations($iModifieable, $glue = ', ') {
16
  $modifiers_strings = array();
17
  if (isset($iModifieable->modifiers)) {
18
    foreach ($iModifieable->modifiers as $modifier) {
19
      $modifiers_strings[] = cdm_term_representation($modifier);
20
    }
21
  }
22
  return implode(', ', $modifiers_strings);
23
}
24

    
25
/**
26
 * Filters the given set of description elements and prefers computed elements over others.
27
 *
28
 * Computed description elements
29
 * are identified by the MarkerType.COMPUTED()
30
 *
31
 * If the given set contains at least one computed element only
32
 * the computed elements are returned.
33
 *
34
 * @param array $description_elements
35
 *   An array of CDM DescriptionElementBase instances
36
 *
37
 * @return array
38
 *   only the computed description elements otherwise all others.
39
 *
40
 * @deprecated this is replaced by the cdmlib DistributionUtil class!!!
41
 */
42
function cdm_description_elements_prefer_computed($description_elements){
43

    
44
  $computed_elements = array();
45
  $other_elements = array();
46

    
47
  if (!empty($description_elements)) {
48
    foreach ($description_elements as $element) {
49
      if (cdm_entity_has_marker($element, UUID_MARKERTYPE_COMPUTED)) {
50
        $computed_elements[] = $element;
51
      }
52
      else {
53
        $other_elements[] = $element;
54
      }
55
    }
56
  }
57

    
58
  if (count($computed_elements) > 0) {
59
    return $computed_elements;
60
  }
61
  else {
62
    return $other_elements;
63
  }
64
}
65

    
66
/**
67
 * Creates a query parameter array based on the setting stored in the drupal variable CDM_DISTRIBUTION_FILTER.
68
 *
69
 * @return array
70
 *   An array with distribution filter query parameters
71
 */
72
function cdm_distribution_filter_query() {
73
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
74
  $query = array();
75

    
76
  $feature_block_settings = get_feature_block_settings(UUID_DISTRIBUTION);
77
  if($feature_block_settings['sort_elements'] == SORT_HIERARCHICAL){
78
    $query['distributionOrder'] = 'AREA_ORDER';
79
  }
80

    
81
  $query['recipe'] = variable_get(DISTRIBUTION_CONDENSED_RECIPE, DISTRIBUTION_CONDENSED_RECIPE_DEFAULT);
82

    
83

    
84

    
85
  if ($cdm_distribution_filter['filter_rules']['statusOrderPreference']) {
86
    $query['statusOrderPreference'] = 1;
87
  }
88
  if ($cdm_distribution_filter['filter_rules']['subAreaPreference']) {
89
    $query['subAreaPreference'] = 1;
90
  }
91
  if (is_array($cdm_distribution_filter['hiddenAreaMarkerType']) && count($cdm_distribution_filter['hiddenAreaMarkerType']) > 0) {
92
    $query['hiddenAreaMarkerType'] = '';
93
    foreach ($cdm_distribution_filter['hiddenAreaMarkerType'] as $marker_type => $enabled) {
94
      if ($enabled) {
95
        $query['hiddenAreaMarkerType'] .= ($query['hiddenAreaMarkerType'] ? ',' : '') . $marker_type;
96
      }
97
    }
98
  }
99

    
100
  return $query;
101
}
102

    
103
/**
104
 * Merge the fields 'annotations', 'markers', 'sources', 'media' from the source CDM DescriptionElement into  the target.
105
 *
106
 * @param object $target
107
 *   The source CDM DescriptionElement
108
 * @param object $source
109
 *   The target CDM DescriptionElement
110
 */
111
function cdm_merge_description_elements(&$target, &$source) {
112
  static $fields_to_merge = array('annotations', 'markers', 'sources', 'media');
113

    
114
  foreach ($fields_to_merge as $field) {
115
    if (is_array($source->$field)) {
116
      if (!is_array($target->$field)) {
117
        $target->$field = $source->$field;
118
      }
119
      else {
120
        $target->$field = array_merge($target->$field, $source->$field);
121
      }
122
    }
123
  }
124
}
125

    
126
/**
127
 * Adds an entry to the end of the table of content items list
128
 *
129
 * The  table of content items are crated internally by calling
130
 * toc_list_item() the resulting item is added to the statically cached
131
 * list of toc elements
132
 *
133
 * @param string $label
134
 *   The label of toc entry
135
 * @param $class_attribute_suffix
136
 *   The suffix to be appended to the class attribute prefix: "feature-toc-item-"
137
 * @param string $fragment
138
 *   Optional parameter to define a url fragment different from the $label,
139
 *   if the $fragment is not defined the $label will be used
140
 */
141
function cdm_toc_list_add_item($label, $class_attribute_suffix, $fragment = NULL, $as_first_element = FALSE) {
142
  $toc_list_items = &cdm_toc_list();
143

    
144
  if (!$fragment) {
145
    $fragment = $label;
146
  }
147
  $fragment = generalizeString($fragment);
148

    
149
  $class_attributes = 'feature-toc-item-' . $class_attribute_suffix;
150

    
151
  $new_item = toc_list_item(
152
    theme(
153
      'cdm_feature_name',
154
      array('feature_name' => $label)),
155
      array('class' => $class_attributes),
156
      $fragment
157
    );
158

    
159
  if ($as_first_element) {
160
    array_unshift($toc_list_items, $new_item);
161
  }
162
  else {
163
    $toc_list_items[] = $new_item;
164
  }
165

    
166
}
167

    
168
/**
169
 * Returns the statically cached table of content items as render array.
170
 *
171
 * @see cdm_toc_list_add_item()
172
 *
173
 * @return array
174
 *   a render array of table of content items suitable for theme_item_list()
175
 */
176
function &cdm_toc_list(){
177
  $toc_list_items = &drupal_static('toc_list_items', array());
178

    
179
  return $toc_list_items;
180
}
181

    
182
/**
183
 * Prepares an empty Drupal block for displaying description elements of a specific CDM Feature.
184
 *
185
 * The block can also be used for pseudo Features like a bibliography. Pseudo features are
186
 * derived from other data on the fly and so not exist as such in the cdm data. In case
187
 * of pseudo features the $feature is left empty
188
 *
189
 * @param $feature_name
190
 *   A label describing the feature, usually the localized feature representation.
191
 * @param object $feature
192
 *   The CDM Feature for which the block is created. (optional)
193
 * @return object
194
 *   A Drupal block object
195
 */
196
function feature_block($feature_name, $feature = NULL) {
197
  $block = new stdclass(); // Empty object.
198
  $block->module = 'cdm_dataportal';
199
  $block->delta = generalizeString($feature_name);
200
  $block->region = NULL;
201
  $block->subject = '<a name="' . $block->delta . '"></a><span class="' . html_class_attribute_ref($feature) . '">'
202
    . theme('cdm_feature_name', array('feature_name' => $feature_name))
203
    . '</span>';
204
  $block->module = "cdm_dataportal-feature";
205
  $block->content = '';
206
  return $block;
207
}
208

    
209

    
210
/**
211
 * Returns a list of a specific type of IdentificationKeys.
212
 *
213
 * The list can be restricted by a taxon.
214
 *
215
 * @param string $type
216
 *   The simple name of the cdm class implementing the interface
217
 *   IdentificationKey, valid values are:
218
 *   PolytomousKey, MediaKey, MultiAccessKey.
219
 * @param string $taxonUuid
220
 *   If given this parameter restrict the listed keys to those which have
221
 *   the taxon identified be this uuid in scope.
222
 *
223
 * @return array
224
 *   List with identification keys.
225
 */
226
function _list_IdentificationKeys($type, $taxonUuid = NULL, $pageSize = NULL, $pageNumber = NULL) {
227
  if (!$type) {
228
    drupal_set_message(t('Type parameter is missing'), 'error');
229
    return;
230
  }
231
  $cdm_ws_pasepath = NULL;
232
  switch ($type) {
233
    case "PolytomousKey":
234
      $cdm_ws_pasepath = CDM_WS_POLYTOMOUSKEY;
235
      break;
236

    
237
    case "MediaKey":
238
      $cdm_ws_pasepath = CDM_WS_MEDIAKEY;
239
      break;
240

    
241
    case "MultiAccessKey":
242
      $cdm_ws_pasepath = CDM_WS_MULTIACCESSKEY;
243
      break;
244

    
245
  }
246

    
247
  if (!$cdm_ws_pasepath) {
248
    drupal_set_message(t('Type parameter is not valid: ') . $type, 'error');
249
  }
250

    
251
  $queryParameters = '';
252
  if (is_numeric($pageSize)) {
253
    $queryParameters = "pageSize=" . $pageSize;
254
  }
255
  else {
256
    $queryParameters = "pageSize=0";
257
  }
258

    
259
  if (is_numeric($pageNumber)) {
260
    $queryParameters = "pageNumber=" . $pageNumber;
261
  }
262
  else {
263
    $queryParameters = "pageNumber=0";
264
  }
265
  $queryParameters = NULL;
266
  if ($taxonUuid) {
267
    $queryParameters = "findByTaxonomicScope=$taxonUuid";
268
  }
269
  $pager = cdm_ws_get($cdm_ws_pasepath, NULL, $queryParameters);
270

    
271
  if (!$pager || $pager->count == 0) {
272
    return array();
273
  }
274
  return $pager->records;
275
}
276

    
277

    
278
/**
279
 * Creates a list item for a table of content, suitable as data element for a themed list
280
 *
281
 * @see theme_list()
282
 *
283
 * @param $label
284
 * @param $http_request_params
285
 * @param $attributes
286
 * @return array
287
 */
288
function toc_list_item($label, $attributes = array(), $fragment = null) {
289

    
290
  // we better cache here since drupal_get_query_parameters has no internal static cache variable
291
  $http_request_params = drupal_static('http_request_params', drupal_get_query_parameters());
292

    
293
  $item =  array(
294
    'data' => l(
295
      $label,
296
      $_GET['q'],
297
      array(
298
        'attributes' => array('class' => array('toc')),
299
        'fragment' => generalizeString($label),
300
        'query' => $http_request_params,
301
      )
302
    ),
303
  );
304
  $item['attributes'] = $attributes;
305
  return $item;
306
}
307

    
308
/**
309
 * Creates the footnotes for the given CDM DescriptionElement instance.
310
 *
311
 * Footnotes are created for annotations and original sources,
312
 * optionally the sources are put into a separate bibliography.
313
 *
314
 * @param $descriptionElement
315
 *   A CDM DescriptionElement instance
316
 * @param $separator
317
 *   Optional parameter. The separator string to concatenate the footnote ids, default is ','
318
 * @param $footnote_list_key_suggestion
319
 *   will be overridden for original sources if the bibliography block is enabled
320
 *
321
 * @return String
322
 *   The foot note keys
323
 */
324
function cdm_create_description_element_footnotes($description_element, $separator = ',',
325
          $footnote_list_key_suggestion = null, $do_link_to_reference = FALSE,
326
          $do_link_to_name_used_in_source = FALSE
327
    ){
328

    
329

    
330
  // Annotations as footnotes.
331
  $footNoteKeys = cdm_annotations_as_footnotekeys($description_element, $footnote_list_key_suggestion);
332

    
333
  // Source references as footnotes.
334
  $bibliography_settings = get_bibliography_settings();
335
  $original_source_footnote_tag = $bibliography_settings['enabled'] == 1 ? 'div' : null; // null will cause original_source_footnote_list_key to use the default
336

    
337
  usort($description_element->sources, 'compare_original_sources');
338
  foreach ($description_element->sources as $source) {
339
    if (_is_original_source_type($source)) {
340
      $fn_key = FootnoteManager::addNewFootnote(
341
        original_source_footnote_list_key($footnote_list_key_suggestion),
342
        theme('cdm_OriginalSource', array(
343
          'source' => $source,
344
          'doLink' => $do_link_to_reference,
345
          'do_link_to_name_used_in_source' => $do_link_to_name_used_in_source
346

    
347
        )),
348
        $original_source_footnote_tag
349
      );
350
      // Ensure uniqueness of the footnote keys.
351
      cdm_add_footnote_to_array($footNoteKeys, $fn_key);
352
    }
353
  }
354
  // Sort and render footnote keys.
355
  $footnoteKeyListStr = '';
356
  asort($footNoteKeys);
357
  foreach ($footNoteKeys as $footNoteKey) {
358
    $footnoteKeyListStr .= theme('cdm_footnote_key',
359
      array(
360
        'footnoteKey' => $footNoteKey,
361
        'separator' => ($footnoteKeyListStr ? $separator : '')));
362
  }
363
  return $footnoteKeyListStr;
364
}
365

    
366

    
367
/**
368
 * Compare callback to be used in usort() to sort render arrays produced by compose_description_element().
369
 *
370
 * @param $a
371
 * @param $b
372
 */
373
function compare_description_element_render_arrays($a, $b){
374
  if ($a['#value'].$a['#value-suffix'] == $b['#value'].$b['#value-suffix']) {
375
    return 0;
376
  }
377
  return ($a['#value'].$a['#value-suffix'] < $b['#value'].$b['#value-suffix']) ? -1 : 1;
378

    
379
}
380

    
381

    
382
/**
383
 * @param $render_array
384
 * @param $element
385
 * @param $feature_block_settings
386
 * @param $element_markup
387
 * @param $footnote_list_key_suggestion
388
 */
389
function compose_description_element($element, $feature_block_settings, $element_markup, $footnote_list_key_suggestion, $prepend_feature_label = FALSE)
390
{
391

    
392
  $render_array = array(
393
    '#type' => 'html_tag',
394
    '#tag' => cdm_feature_block_element_tag_name($feature_block_settings),
395

    
396
    '#attributes' => array(
397
      'class' => array(
398
        'DescriptionElement',
399
        'DescriptionElement-' . $element->class,
400
        html_class_attribute_ref($element)
401
      )
402
    ),
403

    
404
    '#value' => '',
405
    '#value_suffix' => NULL
406

    
407
  );
408

    
409
  $annotations_and_sources = handle_annotations_and_sources($element, $feature_block_settings, $element_markup, $footnote_list_key_suggestion);
410

    
411
  // handle the special case were the TextData is used as container for original source with name
412
  // used in source information without any text stored in it.
413
  $names_used_in_source_markup = '';
414
  if (!empty($annotations_and_sources['names_used_in_source']) && empty($element_markup)) {
415
    $names_used_in_source_markup = join(', ', $annotations_and_sources['names_used_in_source']) . ': ';
416
    // remove all <span class="nameUsedInSource">...</span> from all source_references
417
    // these are expected to be at the end of the strings
418
    $pattern = '/ <span class="nameUsedInSource">.*$/';
419
    foreach( $annotations_and_sources['source_references'] as &$source_reference){
420
      $source_reference = preg_replace($pattern , '', $source_reference);
421
    }
422
  }
423

    
424

    
425
  $source_references_markup = '';
426
  if (!empty($annotations_and_sources['source_references'])) {
427
    $source_references_markup = '<span class="sources">' . join(' ', $annotations_and_sources['source_references']) . '<span>';
428
  }
429

    
430
  $feature_label = '';
431
  if ($prepend_feature_label) {
432
    $feature_label = '<span class="nested-feature-tree-feature-label">' . $element->feature->representation_L10n . ':</span> ';
433
  }
434
  $render_array['#value'] = $feature_label . $names_used_in_source_markup . $element_markup . $source_references_markup;
435
  $render_array['#value_suffix'] = $annotations_and_sources['foot_note_keys'];
436

    
437
  return $render_array;
438
}
439

    
440

    
441
  /**
442
   * @param $element
443
   * @param $feature_block_settings
444
   * @param $element_text
445
   *   used to decide if the source references should be enclosed in brackets or not
446
   * @param $footnote_list_key_suggestion
447
   * @return array
448
   *   an associative array with the following elements:
449
   *   - foot_note_keys: all footnote keys as markup
450
   *   - source_references: an array of the source references citations
451
   *   - names used in source: an associative array of the names in source,
452
   *        the name in source strings are de-duplicated
453
   *        !!!NOTE!!!!: this field will most probably be removed soon (TODO)
454
   *
455
   *
456
   */
457
  function handle_annotations_and_sources($element, $feature_block_settings, $element_text, $footnote_list_key_suggestion) {
458
    $annotations_and_sources = array(
459
      'foot_note_keys' => NULL,
460
      'source_references' => array(),
461
      'names_used_in_source' => array()
462
    );
463

    
464
    usort($element->sources, 'compare_original_sources');
465

    
466
    if ($feature_block_settings['sources_as_content'] == 1) {
467
      foreach ($element->sources as $source) {
468

    
469
        $referenceCitation = theme('cdm_OriginalSource',
470
          array(
471
            'source' => $source,
472
            'doLink' => $feature_block_settings['link_to_reference'] == 1,
473
            'do_link_to_name_used_in_source' => $feature_block_settings['link_to_name_used_in_source'] == 1,
474
          )
475
        );
476

    
477
        if ($referenceCitation) {
478
          if (empty($element_text)) {
479
            $annotations_and_sources['source_references'][] = $referenceCitation;
480
          }
481
          else {
482
            $annotations_and_sources['source_references'][] = ' (' . $referenceCitation . ')';
483
          }
484
        }
485

    
486
        $name_in_source_render_array = compose_name_in_source(
487
          $source,
488
          $feature_block_settings['link_to_name_used_in_source'] == 1
489
        );
490

    
491
        if(!empty($name_in_source_render_array)){
492
          $annotations_and_sources['names_used_in_source'][$name_in_source_render_array['#_plaintext']] = drupal_render($name_in_source_render_array);
493
        }
494
      } // END of loop over sources
495

    
496
      // annotations footnotes separate.
497
      $annotations_and_sources['foot_note_keys'] = theme('cdm_annotations_as_footnotekeys',
498
        array(
499
          'cdmBase_list' => $element,
500
          'footnote_list_key' => $footnote_list_key_suggestion,
501
        )
502
      );
503

    
504
    } // END of references inline
505

    
506
    // put sources into bibliography if requested ...
507
    if ($feature_block_settings['sources_as_content'] !== 1 || $feature_block_settings['sources_as_content_to_bibliography'] == 1) {
508
      $annotations_and_sources['foot_note_keys'] = cdm_create_description_element_footnotes(
509
        $element, ',',
510
        $footnote_list_key_suggestion,
511
        $feature_block_settings['link_to_reference'] == 1,
512
        $feature_block_settings['link_to_name_used_in_source'] == 1
513
      );
514
    }
515

    
516
    return $annotations_and_sources;
517
  }
518

    
519

    
520
  /**
521
   *
522
   *
523
   * @return string
524
   *  the footnote_list_key
525
   */
526
  function original_source_footnote_list_key($key_suggestion = null) {
527
    if(!$key_suggestion){
528
      $key_suggestion = RenderHints::getFootnoteListKey();
529
    }
530
    $bibliography_settings = get_bibliography_settings();
531
    $footnote_list_key = $bibliography_settings['enabled'] == 1 ? 'BIBLIOGRAPHY' : 'BIBLIOGRAPHY-' . $key_suggestion;
532
    return $footnote_list_key;
533
  }
534

    
535
  /**
536
   * Provides the according tag name for the description element markup which fits the  $feature_block_settings['as_list'] value
537
   *
538
   * @param $feature_block_settings
539
   *   A feature_block_settings array, for details, please see get_feature_block_settings($feature_uuid = 'DEFAULT')
540
   */
541
  function cdm_feature_block_element_tag_name($feature_block_settings){
542
    switch ($feature_block_settings['as_list']){
543
      case 'ul':
544
      case 'ol':
545
        return 'li';
546
      case 'div':
547
        if(isset($feature_block_settings['element_tag'])){
548
          return $feature_block_settings['element_tag'];
549
        }
550
        return 'span';
551
      case 'dl':
552
        return 'dd';
553
      default:
554
        return 'div'; // should never happen, throw error instead?
555
    }
556
  }
557

    
558

    
559
/* ==================== COMPOSE FUNCTIONS =============== */
560

    
561
  /**
562
   * Returns a set of feature blocks for a taxon profile from the $mergedFeatureNodes of a given $taxon.
563
   *
564
   * The taxon profile consists of drupal block elements, one for the description elements
565
   * of a specific feature. The structure is defined by specific FeatureTree.
566
   * The chosen FeatureTree is merged with the list of description elements prior to using this method.
567
   *
568
   * The merged nodes can be obtained by making use of the
569
   * function cdm_ws_descriptions_by_featuretree().
570
   *
571
   * @see cdm_ws_descriptions_by_featuretree()
572
   *
573
   * @param $mergedFeatureNodes
574
   *
575
   * @param $taxon
576
   *
577
   * @return array
578
   *  A Drupal render array containing feature blocks and the table of content
579
   *
580
   * @ingroup compose
581
   */
582
  function compose_feature_blocks($mergedFeatureNodes, $taxon) {
583

    
584
    $block_list = array();
585

    
586
    RenderHints::pushToRenderStack('feature_nodes');
587

    
588
    $gallery_settings = getGallerySettings(CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME);
589

    
590
    // Create a drupal block for each feature
591
    foreach ($mergedFeatureNodes as $node) {
592

    
593
      if ((isset($node->descriptionElements['#type']) ||
594
          has_feature_node_description_elements($node)) && $node->feature->uuid != UUID_IMAGE) { // skip empty or suppressed features
595

    
596
        $feature_name = cdm_term_representation($node->feature, 'Unnamed Feature');
597
        $feature_block_settings = get_feature_block_settings($node->feature->uuid);
598

    
599
        $block = feature_block($feature_name, $node->feature);
600
        $block->content = array();
601
        $block_content_is_empty = TRUE;
602

    
603
        /*
604
         * Content/DISTRIBUTION.
605
         */
606

    
607
        if ($node->feature->uuid == UUID_DISTRIBUTION) {
608
          $block = compose_feature_block_distribution($taxon, $node->descriptionElements, $node->feature);
609
          $block_content_is_empty = FALSE;
610
        }
611
        /*
612
         * Content/COMMON_NAME.
613
         */
614
        else if ($node->feature->uuid == UUID_COMMON_NAME) {
615
          $common_names_render_array = compose_feature_block_items_feature_common_name($node->descriptionElements, $node->feature);
616
          $block->content[] = $common_names_render_array;
617
          $block_content_is_empty = FALSE;
618
        }
619

    
620
        else if ($node->feature->uuid == UUID_USE_RECORD) {
621
          $block_uses_content_html = theme('cdm_block_Uses', array('taxonUuid' => $taxon->uuid));
622
          $block->content[] = markup_to_render_array($block_uses_content_html);
623
          $block_content_is_empty = FALSE;
624
        }
625

    
626
        /*
627
         * Content/ALL OTHER FEATURES.
628
         */
629
        else {
630

    
631
          $media_list = array();
632
          $elements_render_array = array();
633
          $child_elements_render_array = null;
634

    
635
          if (isset($node->descriptionElements[0])) {
636
            $elements_render_array = compose_feature_block_items_generic($node->descriptionElements, $node->feature);
637
          }
638

    
639
          // Content/ALL OTHER FEATURES/Subordinate Features
640
          // subordinate features are printed inline in one floating text,
641
          // it is expected hat subordinate features can "contain" TextData,
642
          // Qualitative- and Qualitative- DescriptionElements
643
          if (isset($node->childNodes[0])) {
644
            $child_elements_render_array = compose_feature_block_items_nested($node, $media_list, $feature_block_settings);
645
            $elements_render_array = array_merge($elements_render_array, $child_elements_render_array);
646
          }
647
          $block_content_is_empty = $block_content_is_empty && empty($media_list) && empty($elements_render_array);
648
          if(!$block_content_is_empty){
649
            $block->content[] = compose_feature_block_wrap_elements($elements_render_array, $node->feature);
650
            $block->content[] = compose_feature_media_gallery($node, $media_list, $gallery_settings);
651
            /*
652
             * Footnotes for the feature block
653
             */
654
            $block->content[] = markup_to_render_array(theme('cdm_footnotes', array('footnoteListKey' => 'BIBLIOGRAPHY-' . $node->feature->uuid)));
655
            $block->content[] = markup_to_render_array(theme('cdm_footnotes', array('footnoteListKey' => $node->feature->uuid)));
656
            $block->content[] = markup_to_render_array(theme('cdm_annotation_footnotes', array('footnoteListKey' => $node->feature->uuid)));
657
          }
658
        } // END all other features
659

    
660
        // allows modifying the block contents via a the hook_cdm_feature_node_block_content_alter
661
        drupal_alter('cdm_feature_node_block_content', $block->content, $node->feature, $node->descriptionElements);
662

    
663
        if(!$block_content_is_empty){ // skip empty block content
664
          $block_list[] = $block;
665
          cdm_toc_list_add_item(cdm_term_representation($node->feature), $node->feature->uuid);
666
        } // END: skip empty block content
667
      } // END: skip empty or suppressed features
668
    } // END: creating a block per feature
669

    
670
    drupal_alter('cdm_feature_node_blocks', $block_list, $taxon);
671

    
672
    RenderHints::popFromRenderStack();
673

    
674
    return _block_get_renderable_array($block_list);
675
  }
676

    
677
/**
678
 * Creates a render array of description elements  held by child nodes of the given feature node.
679
 *
680
 * This function is called recursively!
681
 *
682
 * @param $node
683
 *   The feature node.
684
 * @param array $media_list
685
 *   List of CDM Media entities. All media of subordinate elements should be passed to the main feature.ä
686
 * @param $feature_block_settings
687
 *   The feature block settings.
688
 * @param $main_feature
689
 *  Only used internally in recursive calls.
690
 *
691
 * @return array
692
 *  A Drupal render array
693
 *
694
 * @ingroup compose
695
 */
696
function compose_feature_block_items_nested($node, &$media_list, $feature_block_settings, $main_feature = NULL)
697
{
698

    
699
  if(!$main_feature){
700
    $main_feature = $node->feature;
701
  }
702
  /*
703
   * TODO should be configurable, options; YES, NO, AUTOMATIC
704
   * (automatic will only place the label if the first word of the description element text is not the same)
705
   */
706
  $prepend_feature_label = false;
707

    
708
  $render_arrays = array();
709
  foreach ($node->childNodes as $child_node) {
710
    if (isset($child_node->descriptionElements[0])) {
711
      foreach ($child_node->descriptionElements as $element) {
712

    
713
        if (isset($element->media[0])) {
714
          // Append media of subordinate elements to list of main
715
          // feature.
716
          $media_list = array_merge($media_list, $element->media);
717
        }
718

    
719
        $child_node_element = null;
720
        switch ($element->class) {
721
          case 'TextData':
722
            $child_node_element = compose_description_element_text_data($element, $element->feature->uuid, $feature_block_settings, $prepend_feature_label);
723
            break;
724
          case 'CategoricalData':
725
            $child_node_element = compose_description_element_categorical_data($element, $feature_block_settings, $prepend_feature_label);
726
            break;
727
          case 'QuantitativeData':
728
            $child_node_element = compose_description_element_quantitative_data($element, $feature_block_settings, $prepend_feature_label);
729

    
730
        }
731
        if (is_array($child_node_element)) {
732
          $render_arrays[] = $child_node_element;
733
        }
734
      }
735
    }
736

    
737
    if(isset($child_node->childNodes[0])){
738
      $render_arrays = array_merge($render_arrays, compose_feature_block_items_nested($child_node, $media_list, $feature_block_settings, $main_feature ));
739
    }
740
  }
741

    
742
  return $render_arrays;
743
}
744

    
745
  /**
746
   *
747
   * @param $node
748
   *  The merged feature three node which potentially contains media in its description elements.
749
   * @param $media_list
750
   *    Additional media to be merged witht the media contained in the nodes description elements
751
   * @param $gallery_settings
752
   * @return array
753
   *
754
   * @ingroup compose
755
   */
756
  function compose_feature_media_gallery($node, $media_list, $gallery_settings) {
757

    
758
    if (isset($node->descriptionElements)) {
759
      $media_list = array_merge($media_list, cdm_dataportal_media_from_descriptionElements($node->descriptionElements));
760
    }
761

    
762
    $captionElements = array('title', 'rights');
763

    
764
    if (isset($media_list[0]) && isset($gallery_settings['cdm_dataportal_media_maxextend']) && isset($gallery_settings['cdm_dataportal_media_cols'])) {
765
      $gallery = theme('cdm_media_gallerie', array(
766
        'mediaList' => $media_list,
767
        'galleryName' => CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME . '_' . $node->feature->uuid,
768
        'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
769
        'cols' => $gallery_settings['cdm_dataportal_media_cols'],
770
        'captionElements' => $captionElements,
771
      ));
772
      return markup_to_render_array($gallery);
773
    }
774

    
775
    return markup_to_render_array('');
776
  }
777

    
778
  /**
779
   * Composes the distribution feature block for a taxon
780
   *
781
   * @param $taxon
782
   * @param $descriptionElements
783
   *   an associative array with two elements:
784
   *   - '#type': must be 'DTO'
785
   *   - 'DistributionInfoDTO': a CDM DistributionInfoDTO object as returned by the DistributionInfo web service
786
   * @param $feature
787
   *
788
   * @return array
789
   *  A drupal render array
790
   *
791
   * @ingroup compose
792
   */
793
  function compose_feature_block_distribution($taxon, $descriptionElements, $feature) {
794
    $text_data_glue = '';
795
    $text_data_sortOutArray = FALSE;
796
    $text_data_enclosingTag = 'ul';
797
    $text_data_out_array = array();
798

    
799
    $distributionElements = NULL;
800
    $distribution_info_dto = NULL;
801
    $distribution_sortOutArray = FALSE;
802

    
803
    $feature_block_settings = get_feature_block_settings(UUID_DISTRIBUTION);
804

    
805
    // TODO use feature_block_settings instead of DISTRIBUTION_ORDER_MODE
806
    if (variable_get(DISTRIBUTION_ORDER_MODE, DISTRIBUTION_ORDER_MODE_DEFAULT) != 'TREE') {
807
      $distribution_glue = '';
808
      $distribution_enclosingTag = 'dl';
809
    } else {
810
      $distribution_glue = '';
811
      $distribution_enclosingTag = 'ul';
812
    }
813

    
814
    if (!isset($descriptionElements['#type']) || !$descriptionElements['#type'] == 'DTO') {
815
      // skip the DISTRIBUTION section if there is no DTO type element
816
      return array(); // FIXME is it ok to return an empty array?
817
    }
818

    
819
    $block = feature_block(
820
      cdm_term_representation($feature, 'Unnamed Feature'),
821
      $feature
822
    );
823

    
824
    // $$descriptionElements['TextData'] is added to to the feature node in merged_taxon_feature_tree()
825
    if (isset($descriptionElements['TextData'])) {
826
      // --- TextData
827
      foreach ($descriptionElements['TextData'] as $text_data_element) {
828
        $text_data_render_array = compose_description_element_text_data($text_data_element, $text_data_element->feature->uuid, $feature_block_settings);
829
        $repr = drupal_render($text_data_render_array);
830

    
831
        if (!array_search($repr, $text_data_out_array)) { // de-duplication !!
832
          $text_data_out_array[] = $repr;
833
          // TODO HINT: sorting in compose_feature_block_wrap_elements will
834
          // not work since this array contains html attributes with uuids
835
          // and what is about cases like the bibliography where
836
          // any content can be prefixed with some foot-note anchors?
837
          $text_data_sortOutArray = TRUE;
838
          $text_data_glue = '<br/> ';
839
          $text_data_enclosingTag = 'p';
840
        }
841
      }
842
    }
843

    
844

    
845
    if ($text_data_out_array && variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0)) {
846
      $block->content[] = compose_feature_block_wrap_elements(
847
        $text_data_out_array, $feature, $text_data_glue, $text_data_sortOutArray
848
      );
849
    }
850

    
851
    // --- Distribution map
852
    $distribution_map_query_parameters = NULL;
853
    if (isset($descriptionElements['DistributionInfoDTO'])) {
854
      $distribution_map_query_parameters = $descriptionElements['DistributionInfoDTO']->mapUriParams;
855
    }
856
    $map_render_element = compose_distribution_map($taxon, $distribution_map_query_parameters);
857
    $block->content[] = $map_render_element;
858

    
859
    $dto_out_array = array();
860

    
861
    // --- Condensed Distribution
862
    if(variable_get(DISTRIBUTION_CONDENSED) && isset($descriptionElements['DistributionInfoDTO']->condensedDistribution)){
863
      $condensed_distribution_markup = '<p class="condensed_distribution">';
864

    
865
      $isFirst = true;
866
      if(isset($descriptionElements['DistributionInfoDTO']->condensedDistribution->indigenous[0])){
867
        foreach($descriptionElements['DistributionInfoDTO']->condensedDistribution->indigenous as $cdItem){
868
          if(!$isFirst){
869
            $condensed_distribution_markup .= ' ';
870
          }
871
          $condensed_distribution_markup .= '<span class="status_' . $cdItem->status->idInVocabulary . '">'
872
          . $cdItem->areaStatusLabel . '</span>';
873
          $isFirst = false;
874
        }
875
      }
876

    
877
      if(isset($descriptionElements['DistributionInfoDTO']->condensedDistribution->foreign[0])) {
878
        if(!$isFirst){
879
          $condensed_distribution_markup .= ' ';
880
        }
881
        $isFirst = TRUE;
882
        $condensed_distribution_markup .= '[';
883
        foreach ($descriptionElements['DistributionInfoDTO']->condensedDistribution->foreign as $cdItem) {
884
          if (!$isFirst) {
885
            $condensed_distribution_markup .= ' ';
886
          }
887
          $condensed_distribution_markup .= '<span class="status_' . $cdItem->status->titleCache . '">'
888
            . $cdItem->areaStatusLabel . '</span>';
889
          $isFirst = false;
890
        }
891
        $condensed_distribution_markup .= ']';
892
      }
893

    
894
      $condensed_distribution_markup .= '&nbsp;' . l(
895
          font_awesome_icon_markup(
896
            'fa-info-circle',
897
            array(
898
              'alt'=>'help',
899
              'class' => array('superscript')
900
            )
901
          ),
902
          variable_get(DISTRIBUTION_CONDENSED_INFO_PATH, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT) ,
903
          array('html' => TRUE));
904
      $condensed_distribution_markup .= '</p>';
905
      $dto_out_array[] = $condensed_distribution_markup;
906
    }
907

    
908
    // --- tree or list
909
    if (isset($descriptionElements['DistributionInfoDTO'])) {
910
      $distribution_info_dto = $descriptionElements['DistributionInfoDTO'];
911

    
912
      // --- tree
913
      if (is_object($distribution_info_dto->tree)) {
914
        $distribution_tree_render_array = compose_distribution_hierarchy($distribution_info_dto->tree, $feature_block_settings);
915
        $dto_out_array[] = $distribution_tree_render_array;
916
      }
917

    
918
      // --- sorted element list
919
      if (is_array($distribution_info_dto->elements) && count($distribution_info_dto->elements) > 0) {
920
        foreach ($distribution_info_dto->elements as $descriptionElement) {
921
          if (is_object($descriptionElement->area)) {
922
            $sortKey = $descriptionElement->area->representation_L10n;
923
            $distributionElements[$sortKey] = $descriptionElement;
924
          }
925
        }
926
        ksort($distributionElements);
927
        $distribution_element_render_array = compose_description_elements_distribution($distributionElements);
928
        $dto_out_array[] = $distribution_element_render_array;
929

    
930
      }
931
      //
932
      $block->content[] = compose_feature_block_wrap_elements(
933
        $dto_out_array, $feature, $distribution_glue, $distribution_sortOutArray
934
      );
935
    }
936

    
937
    // --- TextData at the bottom
938
    if ($text_data_out_array && !variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0)) {
939
      $block->content[] = compose_feature_block_wrap_elements(
940
        $text_data_out_array, $feature, $text_data_glue, $text_data_sortOutArray
941
      );
942
    }
943

    
944
    $block->content[] = markup_to_render_array(theme('cdm_footnotes', array('footnoteListKey' => 'BIBLIOGRAPHY-' . UUID_DISTRIBUTION)));
945
    $block->content[] = markup_to_render_array(theme('cdm_footnotes', array('footnoteListKey' => UUID_DISTRIBUTION)));
946
    $block->content[] = markup_to_render_array(theme('cdm_annotation_footnotes', array('footnoteListKey' => UUID_DISTRIBUTION)));
947

    
948
    return $block;
949
  }
950

    
951

    
952
  /**
953
   * Composes a drupal render array for single CDM TextData description element.
954
   *
955
   * @param $element
956
   *    The CDM TextData description element.
957
   *  @param $feature_uuid
958
   * @param bool $prepend_feature_label
959
   *   Used in nested feature trees to put the feature as label in front of the description element text representation.
960
   *
961
   * @return array
962
   *   A drupal render array with the following elements being used:
963
   *    - #tag: either 'div', 'li', ...
964
   *    ⁻ #attributes: class attributes
965
   *    - #value_prefix: (optionally) contains footnote anchors
966
   *    - #value: contains the textual content
967
   *    - #value_suffix: (optionally) contains footnote keys
968
   *
969
   * @ingroup compose
970
   */
971
  function compose_description_element_text_data($element, $feature_uuid, $feature_block_settings, $prepend_feature_label = FALSE) {
972

    
973
    $footnote_list_key_suggestion = $feature_uuid;
974

    
975
    $element_markup = '';
976
    if (isset($element->multilanguageText_L10n->text)) {
977
      // TODO replacement of \n by <br> should be configurable
978
      $element_markup = str_replace("\n", "<br/>", $element->multilanguageText_L10n->text);
979
    }
980

    
981
    $render_array = compose_description_element($element, $feature_block_settings, $element_markup, $footnote_list_key_suggestion, $prepend_feature_label);
982

    
983
    return $render_array;
984
  }
985

    
986

    
987
/**
988
 * Theme function to render CDM DescriptionElements of the type TaxonInteraction.
989
 *
990
 * @param $element
991
 *  The CDM TaxonInteraction entity
992
 *
993
 * @return
994
 *  A drupal render array
995
 *
996
 * @ingroup compose
997
 */
998
function compose_description_element_taxon_interaction($element, $feature_block_settings) {
999

    
1000
  $out = '';
1001

    
1002

    
1003
  if (isset($element->description_L10n)) {
1004
    $out .=  ' ' . $element->description_L10n;
1005
  }
1006

    
1007
  if(isset($element->taxon2)){
1008
    $out = render_taxon_or_name($element->taxon2, url(path_to_taxon($element->taxon2->uuid)));
1009
  }
1010

    
1011
  $render_array = compose_description_element($element, $feature_block_settings, $out, $element->feature->uuid);
1012

    
1013
  return $render_array;
1014
}
1015

    
1016

    
1017
/**
1018
 * Renders a single instance of the type IndividualsAssociations.
1019
 *
1020
 * @param $element
1021
 *   The CDM IndividualsAssociations entity.
1022
 * @param $feature_block_settings
1023
 *
1024
 * @return array
1025
 *   Drupal render array
1026
 *
1027
 * @ingroup compose
1028
 */
1029
function compose_description_element_individuals_association($element, $feature_block_settings) {
1030

    
1031
  $out = '';
1032

    
1033
  $render_array = compose_cdm_specimenOrObservation($element->associatedSpecimenOrObservation);
1034

    
1035
  if (isset($element->description_L10n)) {
1036
    $out .=  ' ' . $element->description_L10n;
1037
  }
1038

    
1039
  $out .= drupal_render($render_array);
1040

    
1041
  $render_array = compose_description_element($element, $feature_block_settings, $out, $element->feature->uuid);
1042

    
1043
  return $render_array;
1044
}
1045

    
1046
/**
1047
 * Renders a single instance of the type CategoricalData.
1048
 *
1049
 * @param $element
1050
 *  The CDM CategoricalData entity
1051
 *
1052
 * @param $feature_block_settings
1053
 *
1054
 * @param bool $prepend_feature_label
1055
 *   Used in nested feature trees to put the feature as label in front of the description element text representation.
1056
 *
1057
 * @return string
1058
 *   a html representation of the given CategoricalData element
1059
 *
1060
 * @ingroup compose
1061
 */
1062
function compose_description_element_categorical_data($element, $feature_block_settings, $prepend_feature_label = FALSE) {
1063

    
1064
  $enclosing_tag = cdm_feature_block_element_tag_name($feature_block_settings);
1065

    
1066
  $state_data_strings = array();
1067
  if (isset($element->stateData)) {
1068
    foreach ($element->stateData as $state_data) {
1069

    
1070
      $state  = NULL;
1071

    
1072
      if (isset($state_data->state)) {
1073
        $state = cdm_term_representation($state_data->state);
1074
      }
1075

    
1076
      if (isset($state_data->modifyingText_L10n)) {
1077
        $state = ' ' . $state_data->modifyingText_L10n;
1078
      }
1079

    
1080
      $modifiers_strings = cdm_modifers_representations($state_data);
1081

    
1082
      $state_data_strings[] = $state . ($modifiers_strings ? ' ' . $modifiers_strings : '');
1083

    
1084
    }
1085
  }
1086

    
1087
  $out = '<span class="' . html_class_attribute_ref($element) . '">' . implode(', ', $state_data_strings) . '</span>';
1088

    
1089
  $render_array = compose_description_element($element, $feature_block_settings, $out, $element->feature->uuid, $prepend_feature_label);
1090

    
1091
  return $render_array;
1092
}
1093

    
1094

    
1095
/**
1096
 * Theme function to render CDM DescriptionElements of the type QuantitativeData.
1097
 *
1098
 * The function renders the statisticalValues contained in the QuantitativeData
1099
 * entity according to the following scheme:
1100
 *
1101
 * (ExtremeMin)-Min-Average-Max-(ExtremeMax)
1102
 *
1103
 * All modifiers of these values are appended.
1104
 *
1105
 * If the QuantitativeData is containing more statisticalValues with further
1106
 * statisticalValue types, these additional measures will be appended to the
1107
 * above string separated by whitespace.
1108
 *
1109
 * Special cases;
1110
 * 1. Min==Max: this will be interpreted as Average
1111
 *
1112
 * @param $element
1113
 *  The CDM QuantitativeData entity
1114
 *
1115
 * @param $feature_block_settings
1116
 *
1117
 * @param bool $prepend_feature_label
1118
 *   Used in nested feature trees to put the feature as label in front of the description element text representation.
1119
 *
1120
 *
1121
 * @return string
1122
 *   a html representation of the given QuantitativeData element
1123
 *
1124
 * @ingroup themeable
1125
 */
1126
function compose_description_element_quantitative_data($element, $feature_block_settings, $prepend_feature_label = FALSE) {
1127
  /*
1128
   * - statisticalValues
1129
   *   - value
1130
   *   - modifiers
1131
   *   - type
1132
   * - unit->representation_L10n
1133
   * - modifyingText
1134
   * - modifiers
1135
   * - sources
1136
   */
1137

    
1138
  $out = '';
1139
  $type_representation = NULL;
1140
  $min_max = min_max_array();
1141

    
1142

    
1143
  $other_values = array();
1144

    
1145
  if (isset($element->statisticalValues)) {
1146
    $other_values_markup = array();
1147
    foreach ($element->statisticalValues as $statistical_val) {
1148

    
1149
      // compile the full value string which also may contain modifiers
1150
      if (isset($statistical_val->value)) {
1151
        $statistical_val->_value = $statistical_val->value;
1152
      }
1153
      $val_modifiers_strings = cdm_modifers_representations($statistical_val);
1154
      if ($val_modifiers_strings) {
1155
        $statistical_val->_value = ' ' . $val_modifiers_strings . ' ' . $statistical_val->_value;
1156
      }
1157

    
1158
      // either put into min max array or into $other_values
1159
      // for generic output to be appended to 'min-max' string
1160
      if (array_key_exists($statistical_val->type->titleCache, $min_max)) {
1161
        $min_max[$statistical_val->type->titleCache] = $statistical_val;
1162
      }
1163
      else {
1164
        $other_values[] = $statistical_val;
1165
      }
1166
    } // end of loop over statisticalValues
1167

    
1168
    // create markup
1169

    
1170
    $min_max_markup = min_max_markup($min_max);
1171

    
1172

    
1173
    foreach ($other_values as $statistical_val) {
1174
      $statistical_val_type_representation = NULL;
1175
      if (isset($statistical_val->type)) {
1176
        $statistical_val_type_representation = cdm_term_representation($statistical_val->type);
1177
        // $statistical_val->type->termType;
1178
        // $statistical_val->type->userFriendlyTypeName;
1179
      }
1180
      $value_markup = '<span class="' . html_class_attribute_ref($statistical_val) . ' ' . $statistical_val->type->termType . ' ">'
1181
        . $statistical_val->_value . '</span>';
1182
      $value_markup = $value_markup .
1183
        ($statistical_val_type_representation ? ' <span class="type">' . $statistical_val_type_representation . '</span>' : '');
1184
      $other_values_markup[] = $value_markup;
1185
    }
1186

    
1187

    
1188
    $out .= $min_max_markup . ' ' . implode($other_values_markup, ', ');
1189
  }
1190

    
1191
  if (isset($element->unit)) {
1192
    $out .= ' <span class="unit" title="'
1193
      . cdm_term_representation($element->unit) . '">'
1194
      . cdm_term_representation_abbreviated($element->unit)
1195
      . '</span>';
1196
  }
1197

    
1198
  // modifiers of the description element itself
1199
  $modifier_string = cdm_modifers_representations($element);
1200
  $out .= ($modifier_string ? ' ' . $modifier_string : '');
1201
  if (isset($element->modifyingText_L10n)) {
1202
    $out = $element->modifyingText_L10n . ' ' . $out;
1203
  }
1204

    
1205
  $render_array = compose_description_element($element, $feature_block_settings, $out, $element->feature->uuid, $prepend_feature_label);
1206

    
1207
  return $render_array;
1208
}
1209

    
1210

    
1211
/**
1212
 * Wraps the render array for the given feature into an enclosing html tag.
1213
 *
1214
 * Optionally the elements can be sorted and glued together by a separator string.
1215
 *
1216
 * @param array $description_element_render_arrays
1217
 *   An list of render arrays. Which are usually are produced by the compose_description_element()
1218
 *   function. The render arrays should be of #type=html_tag, so that they can understand the #attribute property.
1219
 * @param  $feature :
1220
 *  The feature to which the elements given in $elements are belonging to.
1221
 * @param string $glue :
1222
 *  Defaults to empty string.
1223
 * @param bool $sort
1224
 *   Boolean Whether to sort the $elements alphabetically, default is FALSE
1225
 *
1226
 * @return array
1227
 *    A Drupal render array
1228
 *
1229
 * @ingroup compose
1230
 */
1231
  function compose_feature_block_wrap_elements(array $description_element_render_arrays, $feature, $glue = '', $sort = FALSE)
1232
  {
1233

    
1234
    $feature_block_settings = get_feature_block_settings($feature->uuid);
1235
    $enclosing_tag = $feature_block_settings['as_list'];
1236

    
1237
    if ($sort) { // TODO remove parameter and replace by $feature_block_settings['sort_elements']
1238
      usort($description_element_render_arrays, 'compare_description_element_render_arrays');
1239
    }
1240

    
1241
    $is_first = true;
1242
    foreach($description_element_render_arrays as &$element_render_array){
1243
      if(!is_array($element_render_array)){
1244
        $element_render_array = markup_to_render_array($element_render_array);
1245
      }
1246
      $element_render_array['#attributes']['class'][] = "feature-block-element";
1247

    
1248
      // add the glue!
1249
      if(!$is_first) {
1250
        if (isset($element_render_array['#value'])) {
1251
          $element_render_array['#value'] = $glue . $element_render_array['#value'];
1252
        } elseif (isset($element_render_array['#markup'])) {
1253
          $element_render_array['#markup'] = $glue . $element_render_array['#markup'];
1254
        }
1255
      }
1256
      $is_first = false;
1257
    }
1258

    
1259
    $render_array['elements']['children'] = $description_element_render_arrays;
1260

    
1261
    $render_array['elements']['#prefix'] = '<' . $enclosing_tag . ' class="feature-block-elements" id="' . $feature->representation_L10n . '">';
1262
    $render_array['elements']['#suffix'] = '</' . $enclosing_tag . '>';
1263

    
1264
    return $render_array;
1265
  }
1266

    
1267

    
1268
  /* compose nameInSource or originalNameString as markup
1269
   *
1270
   * @param $source
1271
   * @param $do_link_to_name_used_in_source
1272
   * @param $suppress_for_shown_taxon
1273
   *    the nameInSource will be suppressed when it has the same name as the accepted taxon
1274
   *    for which the taxon page is being created, Defaults to TRUE
1275
   *
1276
   * @return array
1277
   *    A Drupal render array with an additional element, the render array is empty
1278
   *    if the source had no name in source information
1279
   *    - #_plaintext: contains the plaintext version of the name (custom element)
1280
   *
1281
   * @ingroup compose
1282
   */
1283
  function compose_name_in_source($source, $do_link_to_name_used_in_source, $suppress_for_shown_taxon = TRUE) {
1284

    
1285
    $plaintext = NULL;
1286
    $markup = NULL;
1287
    $name_in_source_render_array = array();
1288

    
1289
    static $taxon_page_accepted_name = '';
1290
    if($suppress_for_shown_taxon && arg(1) == 'taxon' && empty($taxon_page_accepted_name)){
1291

    
1292
      $current_taxon = cdm_ws_get(CDM_WS_PORTAL_TAXON, arg(2));
1293
      $taxon_page_accepted_name = $current_taxon->name->titleCache;
1294
    }
1295

    
1296
    if (isset($source->nameUsedInSource->uuid) && isset($source->nameUsedInSource->titleCache)) {
1297
      // it is a DescriptionElementSource !
1298
      $plaintext = $source->nameUsedInSource->titleCache;
1299
      if($suppress_for_shown_taxon && $taxon_page_accepted_name == $plaintext){
1300
        return $name_in_source_render_array; // SKIP this name
1301
      }
1302
      $markup = render_taxon_or_name($source->nameUsedInSource);
1303
      if ($do_link_to_name_used_in_source) {
1304
        $markup = l(
1305
          $markup,
1306
          path_to_name($source->nameUsedInSource->uuid),
1307
          array(
1308
            'attributes' => array(),
1309
            'absolute' => TRUE,
1310
            'html' => TRUE,
1311
          ));
1312
      }
1313
    }
1314
    else if (isset($source->originalNameString) && !empty($source->originalNameString)) {
1315
      // the name used in source can not be expressed as valid taxon name,
1316
      // so the editor has chosen to put the freetext name into ReferencedEntityBase.originalNameString
1317
      // field
1318
      // using the originalNameString as key to avoid duplicate entries
1319
      $plaintext = $source->originalNameString;
1320
      if($suppress_for_shown_taxon && $taxon_page_accepted_name == $plaintext){
1321
        return $name_in_source_render_array; // SKIP this name
1322
      }
1323
      $markup = $source->originalNameString;
1324
    }
1325

    
1326
    if ($plaintext) { // checks if we have any content
1327
      $name_in_source_render_array = markup_to_render_array($markup);
1328
      $name_in_source_render_array['#_plaintext'] = $plaintext;
1329
    }
1330

    
1331
    return $name_in_source_render_array;
1332
  }
1333

    
1334

    
1335

    
1336
  /**
1337
   * Return HTML for a list of description elements.
1338
   *
1339
   * Usually these are of a specific feature type.
1340
   *
1341
   * @param $description_elements
1342
   *   array of descriptionElements which belong to the same feature.
1343
   *   These descriptions elements of a Description must be ordered by the chosen feature tree by
1344
   *   calling the function _mergeFeatureTreeDescriptions().
1345
   *   @see _mergeFeatureTreeDescriptions()
1346
   *
1347
   * @param  $feature_uuid
1348
   *
1349
   * @return
1350
   *    A drupal render array for the $descriptionElements, may be an empty array if the textual content was empty.
1351
   *    Footnote key or anchors are not considered to be textual content.
1352
   *
1353
   * @ingroup compose
1354
   */
1355
  function compose_feature_block_items_generic($description_elements, $feature) {
1356

    
1357
    $elements_out_array = array();
1358
    $distribution_tree = null;
1359

    
1360
    /*
1361
     * $feature_block_has_content will be set true if at least one of the
1362
     * $descriptionElements contains some text which makes up some content
1363
     * for the feature block. Footnote keys are not considered
1364
     * to be content in this sense.
1365
     */
1366
    $feature_block_has_content = false;
1367

    
1368
    if (is_array($description_elements)) {
1369
      foreach ($description_elements as $description_element) {
1370
          /* decide based on the description element class
1371
           *
1372
           * Features handled here:
1373
           * all except DISTRIBUTION, COMMON_NAME, USES, IMAGES,
1374
           *
1375
           * TODO provide api_hook as extension point for this?
1376
           */
1377
        $feature_block_settings = get_feature_block_settings($description_element->feature->uuid);
1378
        switch ($description_element->class) {
1379
          case 'TextData':
1380
            $elements_out_array[] = compose_description_element_text_data($description_element, $description_element->feature->uuid, $feature_block_settings);
1381
            break;
1382
          case 'CategoricalData':
1383
            $elements_out_array[] = compose_description_element_categorical_data($description_element, $feature_block_settings);
1384
            break;
1385
          case 'QuantitativeData':
1386
            $elements_out_array[] = compose_description_element_quantitative_data($description_element, $feature_block_settings);
1387
            break;
1388
          case 'IndividualsAssociation':
1389
            $elements_out_array[] = compose_description_element_individuals_association($description_element, $feature_block_settings);
1390
            break;
1391
          case 'TaxonInteraction':
1392
            $elements_out_array[] = compose_description_element_taxon_interaction($description_element, $feature_block_settings);
1393
            break;
1394
          case 'CommonTaxonName':
1395
            $elements_out_array[] = compose_description_element_common_taxon_name($description_element, $feature_block_settings);
1396
            break;
1397
          case 'Uses':
1398
            /* IGNORE Uses classes, these are handled completely in theme_cdm_UseDescription */
1399
            break;
1400
          default:
1401
            $feature_block_has_content = true;
1402
            $elements_out_array[] = markup_to_render_array('<li>No method for rendering unknown description class: ' . $description_element->class . '</li>');
1403
        }
1404
        $elements_out_array_last_item = $elements_out_array[count($elements_out_array) - 1];
1405
        // considering not empty as long as the last item added is a render array
1406
        $feature_block_has_content = $feature_block_has_content || !empty($elements_out_array_last_item['#type']);
1407
      }
1408

    
1409
      // If feature = CITATION sort the list of sources.
1410
      // This is ONLY for FLORA MALESIANA and FLORE d'AFRIQUE CENTRALE.
1411
      if (isset($description_element) && $description_element->feature->uuid == UUID_CITATION) {
1412
        sort($elements_out_array);
1413
      }
1414
    }
1415

    
1416
    return $elements_out_array;
1417
  }
1418

    
1419
/**
1420
 * Composes block of common names for the given DescriptionElements $elements which must be of the feature CommonName
1421
 *
1422
 * @parameter $elements
1423
 *  an array of CDM DescriptionElements either of type CommonName or TextData
1424
 * @parameter $feature
1425
 *  the common feature of all $elements, must be CommonName
1426
 *
1427
 * @return
1428
 *   A drupal render array
1429
 *
1430
 * @ingroup compose
1431
 */
1432
function compose_feature_block_items_feature_common_name($elements, $feature, $weight = FALSE) {
1433

    
1434
  $common_name_out = '';
1435
  $common_name_feature_elements = array();
1436
  $textData_commonNames = array();
1437

    
1438
  $footnote_key_suggestion = 'common-names-feature-block';
1439

    
1440
  $feature_block_settings = get_feature_block_settings(UUID_COMMON_NAME);
1441

    
1442
  if (is_array($elements)) {
1443
    foreach ($elements as $element) {
1444

    
1445
      if ($element->class == 'CommonTaxonName') {
1446

    
1447
        // common name without a language or area, should not happen but is possible
1448
        $language_area_key = '';
1449
        if (isset($element->language->representation_L10n)) {
1450
          $language_area_key .= '<span class="language-label">' . $element->language->representation_L10n . '</span>';
1451
        }
1452
        if(isset($element->area->titleCache) && strlen($element->area->titleCache) > 0){
1453
          $language_area_key .= ($language_area_key ? ' '  : '') . '(' . $element->area->titleCache . ')';
1454
        }
1455

    
1456
        if(isset($common_names[$language_area_key][$element->name])) {
1457
          // same name already exists for language and area combination, se we merge the description elements
1458
          cdm_merge_description_elements($common_names[$language_area_key][$element->name], $element);
1459
        } else{
1460
          // otherwise add as new entry
1461
          $common_names[$language_area_key][$element->name] = $element;
1462
        }
1463

    
1464
      }
1465
      elseif ($element->class == 'TextData') {
1466
        $textData_commonNames[] = $element;
1467
      }
1468
    }
1469
  }
1470
  // Handling common names.
1471
  if (isset($common_names) && count($common_names) > 0) {
1472
    // Sorting the array based on the key (language, + area if set).
1473
    // Comment @WA there are common names without a language, so this sorting
1474
    // can give strange results.
1475
    ksort($common_names);
1476

    
1477
    // loop over set of elements per language area
1478
    foreach ($common_names as $language_area_key => $elements) {
1479
      ksort($elements); // sort names alphabetically
1480
      $per_language_area_out = array();
1481

    
1482
      foreach ($elements as $element) {
1483
        $common_name_render_array = compose_description_element_common_taxon_name($element, $feature_block_settings, $footnote_key_suggestion);
1484
        $common_name_markup = drupal_render($common_name_render_array);
1485
        // IMPORTANT!
1486
        // during the above drupal_render the theme_html_tag function is executed, which adds a "\n" character to the end of the markup
1487
        // this is an error and the trailing whitespace needs to be removed
1488
        if(str_endsWith($common_name_markup, "\n")){
1489
          $common_name_markup = substr($common_name_markup, 0, strlen($common_name_markup) - 1);
1490
        }
1491
        $per_language_area_out[] = $common_name_markup;
1492
      }
1493

    
1494
      $common_name_feature_elements[] = ($language_area_key ? $language_area_key . ': ' : '' ) . join(', ', $per_language_area_out);
1495
    } // End of loop over set of elements per language area
1496

    
1497

    
1498
    $common_name_feature_elements_render_array = compose_feature_block_wrap_elements(
1499
      $common_name_feature_elements, $feature, '; ', FALSE
1500
    );
1501
    $common_name_out .= drupal_render($common_name_feature_elements_render_array); // FIXME should this be a render array instead?
1502

    
1503
  }
1504

    
1505
  // Handling commons names as text data.
1506
  $text_data_out = array();
1507

    
1508
  foreach ($textData_commonNames as $text_data_element) {
1509
    /* footnotes are not handled correctly in compose_description_element_text_data,
1510
       need to set 'common-names-feature-block' as $footnote_key_suggestion */
1511
    RenderHints::setFootnoteListKey($footnote_key_suggestion);
1512
    $text_data_render_array = compose_description_element_text_data($text_data_element, $text_data_element->feature->uuid, $feature_block_settings);
1513
    $text_data_out[] = drupal_render($text_data_render_array);
1514
  }
1515

    
1516
  $common_name_out_text_data = compose_feature_block_wrap_elements(
1517
    $text_data_out, $feature
1518
  );
1519

    
1520
  $footnotes = theme('cdm_footnotes', array('footnoteListKey' => 'BIBLIOGRAPHY-' . $footnote_key_suggestion));
1521
  $footnotes .= theme('cdm_footnotes', array('footnoteListKey' => $footnote_key_suggestion)); // FIXME is this needed at all?
1522
  $footnotes .= theme('cdm_annotation_footnotes', array('footnoteListKey' => $footnote_key_suggestion));
1523

    
1524
  return  markup_to_render_array(  // FIXME markup_to_render_array should no longer be needed
1525
    '<div class="common-taxon-name">' . $common_name_out . '</div>'
1526
    .'<div class="text-data">' . drupal_render($common_name_out_text_data) . '</div>'
1527
    .$footnotes,
1528
    $weight
1529
  );
1530
}
1531

    
1532
/**
1533
 * Renders a single instance of the type CommonTaxonName.
1534
 *
1535
 * @param $element
1536
 *   The CDM CommonTaxonName entity.
1537
 * @param $feature_block_settings
1538
 *
1539
 * @param $footnote_key_suggestion
1540
 *
1541
 * @param $element_tag_name
1542
 *
1543
 * @return array
1544
 *   Drupal render array
1545
 *
1546
 * @ingroup compose
1547
 */
1548
function compose_description_element_common_taxon_name($element, $feature_block_settings, $footnote_key_suggestion = NULL)
1549
{
1550

    
1551
  if(!$footnote_key_suggestion) {
1552
    $footnote_key_suggestion = $element->feature->uuid;
1553
  }
1554

    
1555
  $name = '';
1556
  if(isset($element->name)){
1557
    $name = $element->name;
1558
  }
1559

    
1560

    
1561
  return compose_description_element($element, $feature_block_settings, $name, $footnote_key_suggestion);
1562
}
1563

    
1564
/**
1565
 * Composes the render array for a CDM Distribution description element
1566
 *
1567
 * @param array $description_elements
1568
 *   Array of CDM Distribution instances
1569
 * @param $enclosingTag
1570
 *   The html tag to be use for the enclosing element
1571
 *
1572
 * @return array
1573
 *   A Drupal render array
1574
 *
1575
 * @ingroup compose
1576
 */
1577
function compose_description_elements_distribution($description_elements){
1578

    
1579
  $out = '';
1580
  RenderHints::pushToRenderStack('descriptionElementDistribution');
1581
  RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
1582

    
1583
  $feature_block_settings = get_feature_block_settings(UUID_DISTRIBUTION);
1584
  $enclosingTag = cdm_feature_block_element_tag_name($feature_block_settings);
1585

    
1586
  foreach ($description_elements as $description_element) {
1587
    $annotations_and_sources = handle_annotations_and_sources(
1588
      $description_element,
1589
      $feature_block_settings,
1590
      $description_element->area->representation_L10n,
1591
      UUID_DISTRIBUTION
1592
    );
1593

    
1594

    
1595
    list($status_label, $status_markup) = distribution_status_label_and_markup($description_element);
1596

    
1597
    $out .= '<' . $enclosingTag . ' class="descriptionElement descriptionElement-' . $description_element->uuid
1598
      . ' " title="' . $status_label. '">'
1599
      . $description_element->area->representation_L10n
1600
      . $status_markup;
1601
    if(!empty($annotations_and_sources['source_references'])){
1602
      $out .= ' ' . join(' ', $annotations_and_sources['source_references'] );
1603
    }
1604
    $out .= $annotations_and_sources['foot_note_keys']   . ' </' . $enclosingTag . '>';
1605
  }
1606

    
1607
  RenderHints::popFromRenderStack();
1608
  return markup_to_render_array($out);
1609
}
1610

    
1611
  /**
1612
   * @param $descriptionElement
1613
   * @return array
1614
   */
1615
  function distribution_status_label_and_markup($descriptionElement) {
1616
    $status_markup = '';
1617
    $status_label = '';
1618

    
1619
    if (isset($descriptionElement->status)) {
1620
      $status_label = $descriptionElement->status->representation_L10n;
1621
      $status_markup = '<span class="distributionStatus distributionStatus-' . $descriptionElement->status->idInVocabulary . '"> '
1622
        . $status_label . ' </span>';
1623

    
1624
    };
1625
    return array($status_label, $status_markup);
1626
  }
1627

    
1628

    
1629
  /**
1630
   * Provides the merged feature tree for a taxon profile page.
1631
   *
1632
   * The merging of the profile feature tree is actully done in
1633
   * _mergeFeatureTreeDescriptions(). See this method  for details
1634
   * on the structure of the merged tree.
1635
   *
1636
   * This method provides t hook which can be used to modify the
1637
   * merged feature tree after it has been created, see
1638
   * hook_merged_taxon_feature_tree_alter()
1639
   *
1640
   * @param $taxon
1641
   *   A CDM Taxon instance
1642
   *
1643
   * @return object
1644
   *  The merged feature tree
1645
   *
1646
   */
1647
  function merged_taxon_feature_tree($taxon) {
1648

    
1649
    // 1. fetch descriptions_by_featuretree but exclude the distribution feature
1650
    $merged_tree = cdm_ws_descriptions_by_featuretree(get_profile_feature_tree(), $taxon->uuid, array(UUID_DISTRIBUTION));
1651

    
1652

    
1653
    // 2. find the distribution feature node
1654
    $distribution_node =& cdm_feature_tree_find_node($merged_tree->root->childNodes, UUID_DISTRIBUTION);
1655

    
1656
    if ($distribution_node) {
1657
      // 3. get the distributionInfoDTO
1658
      $query_parameters = cdm_distribution_filter_query();
1659
      $query_parameters['part'] = array('mapUriParams');
1660
      if(variable_get(DISTRIBUTION_CONDENSED)){
1661
        $query_parameters['part'][] = 'condensedDistribution';
1662
      }
1663
      if (variable_get(DISTRIBUTION_ORDER_MODE, DISTRIBUTION_ORDER_MODE_DEFAULT) == 'TREE') {
1664
        $query_parameters['part'][] = 'tree';
1665
      }
1666
      else {
1667
        $query_parameters['part'][] = 'elements';
1668
      }
1669
      $query_parameters['omitLevels'] = array();
1670
      foreach(variable_get(DISTRIBUTION_TREE_OMIT_LEVELS, array()) as $uuid){
1671
        if(is_uuid($uuid)){
1672
          $query_parameters['omitLevels'][] = $uuid;
1673
        }
1674
      }
1675
      $customStatusColorsJson = variable_get(DISTRIBUTION_STATUS_COLORS, NULL);
1676
      if ($customStatusColorsJson) {
1677
        $query_parameters['statusColors'] = $customStatusColorsJson;
1678
      }
1679

    
1680
      $distribution_info_dto = cdm_ws_get(CDM_WS_PORTAL_DESCRIPTION_DISTRIBUTION_INFO_FOR, $taxon->uuid, queryString($query_parameters));
1681
      // 4. get distribution TextData is there are any
1682
      $distribution_text_data = cdm_ws_fetch_all(CDM_WS_DESCRIPTIONELEMENT_BY_TAXON,
1683
        array(
1684
          'taxon' => $taxon->uuid,
1685
          'type' => 'TextData',
1686
          'features' => UUID_DISTRIBUTION
1687
        )
1688
      );
1689

    
1690
      // 5. put all distribution data into the distribution feature node
1691
      if ($distribution_text_data //if text data exists
1692
        || ($distribution_info_dto && isset($distribution_info_dto->tree) && $distribution_info_dto->tree->rootElement->numberOfChildren > 0) // OR if tree element has distribution elements
1693
        || ($distribution_info_dto && !empty($distribution_info_dto->elements))
1694
      ) { // OR if DTO has distribution elements
1695
        $distribution_node->descriptionElements = array('#type' => 'DTO');
1696
        if ($distribution_text_data) {
1697
          $distribution_node->descriptionElements['TextData'] = $distribution_text_data;
1698
        }
1699
        if ($distribution_info_dto) {
1700
          $distribution_node->descriptionElements['DistributionInfoDTO'] = $distribution_info_dto;
1701
        }
1702
      }
1703
    }
1704

    
1705
    // allows modifying the merged tree via a the hook_cdm_feature_node_block_content_alter
1706
    drupal_alter('merged_taxon_feature_tree', $taxon, $merged_tree);
1707

    
1708
    return $merged_tree;
1709
  }
1710

    
1711

    
1712
  function compose_distribution_hierarchy($distribution_tree, $feature_block_settings){
1713

    
1714
    static $hierarchy_style;
1715
    // TODO expose $hierarchy_style to administration of provide a hook
1716
    if( !isset($hierarchy_style)){
1717
      $hierarchy_style = array(
1718
        // level 2
1719
        array(
1720
          'label_suffix' => '',
1721
          'element_glue' => ', ',
1722
          'element_set_pre' => '(',
1723
          'element_set_post' => ')'
1724
        ),
1725
        // level 1
1726
        array(
1727
          'label_suffix' => '',
1728
          'element_glue' => '; ',
1729
          'element_set_pre' => '',
1730
          'element_set_post' => ''
1731
        ),
1732
        // level 0
1733
        array(
1734
          'label_suffix' => ':',
1735
          'element_glue' => ' ',
1736
          'element_set_pre' => '',
1737
          'element_set_post' => ''
1738
        ),
1739
      );
1740
    }
1741

    
1742
    $render_array = array();
1743

    
1744
    RenderHints::pushToRenderStack('descriptionElementDistribution');
1745
    RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
1746

    
1747
    // Returning NULL if there are no description elements.
1748
    if ($distribution_tree == null) {
1749
      return $render_array;
1750
    }
1751
    // for now we are not using a render array internally to avoid performance problems
1752
    $markup = '';
1753
    if (isset($distribution_tree->rootElement->children)) {
1754
      $tree_nodes = $distribution_tree->rootElement->children;
1755
      _compose_distribution_hierarchy($tree_nodes, $feature_block_settings, $markup, $hierarchy_style);
1756
    }
1757

    
1758
    $render_array['distribution_hierarchy'] = markup_to_render_array(
1759
      $markup,
1760
      0,
1761
      '<div id="distribution_hierarchy" class="distribution_hierarchy">',
1762
      '</div>'
1763
    );
1764

    
1765
    return $render_array;
1766
  }
1767

    
1768
  /**
1769
   * this function should produce markup as the compose_description_elements_distribution()
1770
   * function.
1771
   *
1772
   * @see compose_description_elements_distribution()
1773
   *
1774
   * @param $distribution_tree
1775
   * @param $feature_block_settings
1776
   * @param $tree_nodes
1777
   * @param $markup
1778
   * @param $hierarchy_style
1779
   */
1780
  function _compose_distribution_hierarchy($tree_nodes, $feature_block_settings, &$markup, $hierarchy_style, $level_index = -1){
1781

    
1782
    $level_index++;
1783
    static $enclosingTag = "span";
1784

    
1785
    $level_style = array_pop($hierarchy_style);
1786
    if(count($hierarchy_style) == 0){
1787
      // lowest defined level style will be reused for all following levels
1788
      $hierarchy_style[] = $level_style;
1789
    }
1790

    
1791
    $node_index = -1;
1792
    $per_node_markup = array();
1793
    foreach ($tree_nodes as $node){
1794

    
1795
      $per_node_markup[++$node_index] = '';
1796

    
1797
      $label = $node->nodeId->representation_L10n;
1798

    
1799
      $distributions = $node->data;
1800
      $distribution_uuids = array();
1801
      $distribution_aggregate = NULL;
1802
        foreach($distributions as $distribution){
1803

    
1804
          $distribution_uuids[] = $distribution->uuid;
1805

    
1806
          // if there is more than one distribution we aggregate the sources and
1807
          // annotations into a synthetic distribution so that the footnote keys
1808
          // can be rendered consistently
1809
          if(!$distribution_aggregate) {
1810
            $distribution_aggregate = $distribution;
1811
            if(!isset($distribution_aggregate->sources[0])){
1812
              $distribution_aggregate->sources = array();
1813
            }
1814
            if(!isset($distribution_aggregate->annotations[0])){
1815
              $distribution_aggregate->annotations = array();
1816
            }
1817
          } else {
1818
            if(isset($distribution->sources[0])) {
1819
              $distribution_aggregate->sources = array_merge($distribution_aggregate->sources,
1820
                $distribution->sources);
1821
            }
1822
            if(isset($distribution->annotations[0])) {
1823
              $distribution_aggregate->annotations = array_merge($distribution_aggregate->annotations,
1824
                $distribution->annotations);
1825
            }
1826
          }
1827
        }
1828

    
1829
      $status_label= '';
1830
      $status_markup = '';
1831
      $annotations_and_sources =  null;
1832
      if($distribution_aggregate) {
1833
        $annotations_and_sources = handle_annotations_and_sources(
1834
          $distribution_aggregate,
1835
          $feature_block_settings,
1836
          $label,
1837
          UUID_DISTRIBUTION
1838
        );
1839

    
1840
        list($status_label, $status_markup) = distribution_status_label_and_markup($distribution);
1841
      }
1842

    
1843
      $per_node_markup[$node_index] .= '<' . $enclosingTag . ' class="descriptionElement'
1844
        . join(' descriptionElement-', $distribution_uuids)
1845
        . ' level_index_' . $level_index
1846
        . ' " title="' . $status_label . '">'
1847
        . '<span class="area_label">' . $label
1848
        . $level_style['label_suffix'] . ' </span>'
1849
        .  $status_markup
1850
      ;
1851

    
1852
      if(isset($annotations_and_sources)){
1853
        if(!empty($annotations_and_sources['source_references'])){
1854
          $per_node_markup[$node_index] .= ' ' . join(', ' , $annotations_and_sources['source_references']);
1855
        }
1856
        if($annotations_and_sources['foot_note_keys']) {
1857
          $per_node_markup[$node_index] .= $annotations_and_sources['foot_note_keys'];
1858
        }
1859
      }
1860

    
1861
      if(isset($node->children[0])){
1862
        _compose_distribution_hierarchy(
1863
          $node->children,
1864
          $feature_block_settings,
1865
          $per_node_markup[$node_index],
1866
          $hierarchy_style,
1867
          $level_index
1868
        );
1869
      }
1870

    
1871
      $per_node_markup[$node_index] .= '</' . $enclosingTag . '>';
1872
    }
1873
    $markup .= $level_style['element_set_pre']  . join( $level_style['element_glue'], $per_node_markup) . $level_style['element_set_post'];
1874
  }
1875

    
1876

    
(2-2/8)