Project

General

Profile

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

    
3
/**
4
 * @file
5
 * Taxon Node functions.
6
 *
7
 * @copyright
8
 *   (C) 2007-2020 EDIT
9
 *   European Distributed Institute of Taxonomy
10
 *   http://www.e-taxonomy.eu
11
 *
12
 *   The contents of this module are subject to the Mozilla
13
 *   Public License Version 1.1.
14
 * @see http://www.mozilla.org/MPL/MPL-1.1.html
15
 *
16
 * @author
17
 *   - Andreas Kohlbecker <a.kohlbecker@BGBM.org>
18
 */
19

    
20
/**
21
 * Created a render array with taxon node information like states.
22
 *
23
 * @param array $taxon_nodes
24
 *
25
 * @gropup compose
26
 */
27
function compose_taxon_node_status(array $taxon_nodes){
28

    
29
  $render_array = [];
30
  RenderHints::pushToRenderStack("taxon_nodes");
31
  RenderHints::setFootnoteListKey('taxon_nodes');
32
  if($taxon_nodes && count($taxon_nodes) > 0){
33
    $label_plural = false;
34
    $status_markup_tokens = [];
35
    foreach ($taxon_nodes as $taxon_node){
36

    
37
      RenderHints::setAnnotationsAndSourceConfig(annotation_and_source_config_taxon_node());
38
      $annotations_and_sources = handle_annotations_and_sources($taxon_node);
39

    
40
      if(isset($taxon_node->status)){
41
        $state_label = strtolower($taxon_node->status->representation_L10n);
42
        if(isset($taxon_node->statusNote_L10n)){
43
          $state_label .= ' <span class="status-note">(' . $taxon_node->statusNote_L10n . ')</span>';
44
        }
45
        $classification = cdm_ws_get(CDM_WS_CLASSIFICATION, array($taxon_node->classificationUUID));
46
        $status_markup_tokens[$state_label . '-' . $taxon_node->uuid]  = [
47
          'status' => '<span class="' . html_class_attribute_ref($taxon_node) .'">' . $state_label . $annotations_and_sources->footNoteKeysMarkup()  .  '%s</span>', // %s will be replaced by the $classification_markup or by '',
48
          'classification' => ' <span class="' . html_class_attribute_ref($classification) .'">[' . $classification->titleCache . ']</span>'
49
        ];
50
      }
51

    
52
    }
53
    if(count($status_markup_tokens) > 0){
54
      ksort($status_markup_tokens);
55
      $status_markup = [];
56
      $label_plural |= count($status_markup_tokens) > 1;
57
      $label = $label_plural ? t('Placement status') : t('Placement status');
58
      if(count($status_markup_tokens) > 1){
59
        foreach ($status_markup_tokens as $tokes){
60
          $status_markup[] = sprintf($tokes['status'], $tokes['classification']);
61
        }
62
      } else {
63
        foreach ($status_markup_tokens as $tokes){
64
          $status_markup[] = sprintf($tokes['status'], '');
65
        }
66
      }
67
      $render_array['taxon-node-status'] = markup_to_render_array($label . ': ' . join('; ', $status_markup) . render_footnotes(RenderHints::getFootnoteListKey()));
68
      $render_array['taxon-node-status']['#prefix'] = '<div class="taxon-node-status">';
69
      $render_array['taxon-node-status']['#suffix'] = '</div>';
70
    }
71
  }
72
  RenderHints::setFootnoteListKey(null);
73
  RenderHints::popFromRenderStack();
74
  return $render_array;
75
}
(13-13/15)