Project

General

Profile

Download (2.98 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
      $annotations_and_sources = handle_annotations_and_sources($taxon_node,
38
        array(
39
        'sources_as_content' => false,
40
        'link_to_name_used_in_source' => false,
41
        'link_to_reference' => true,
42
        'add_footnote_keys' => true,
43
        'bibliography_aware' => false),
44
        '',
45
        null);
46

    
47
      if(isset($taxon_node->nodeStatus)){
48
        $state_label = strtolower($taxon_node->nodeStatus->message_L10n);
49
        if(isset($taxon_node->statusNote_L10n->text)){
50
          $state_label .= ' <span class="status-note">(' . $taxon_node->statusNote_L10n->text . ')</span>';
51
        }
52
        $classification = cdm_ws_get(CDM_WS_CLASSIFICATION, array($taxon_node->classificationUUID));
53
        $status_markup_tokens[$state_label . '-' . $taxon_node->uuid]  = [
54
          'status' => '<span class="' . html_class_attribute_ref($taxon_node) .'">' . $state_label . $annotations_and_sources['foot_note_keys']  .  '%s</span>', // %s will be replaced by the $classification_markup or by '',
55
          'classification' => ' <span class="' . html_class_attribute_ref($classification) .'">[' . $classification->titleCache . ']</span>'
56
        ];
57
      }
58

    
59
    }
60
    if(count($status_markup_tokens) > 0){
61
      ksort($status_markup_tokens);
62
      $status_markup = [];
63
      $label_plural |= count($status_markup_tokens) > 1;
64
      $label = $label_plural ? t('Placement status') : t('Placement status');
65
      if(count($status_markup_tokens) > 1){
66
        foreach ($status_markup_tokens as $tokes){
67
          $status_markup[] = sprintf($tokes['status'], $tokes['classification']);
68
        }
69
      } else {
70
        foreach ($status_markup_tokens as $tokes){
71
          $status_markup[] = sprintf($tokes['status'], '');
72
        }
73
      }
74
      $render_array['taxon-node-status'] = markup_to_render_array($label . ': ' . join('; ', $status_markup) . theme('cdm_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey())));
75
      $render_array['taxon-node-status']['#prefix'] = '<div class="taxon-node-status">';
76
      $render_array['taxon-node-status']['#suffix'] = '</div>';
77
    }
78
  }
79
  RenderHints::setFootnoteListKey(null);
80
  RenderHints::popFromRenderStack();
81
  return $render_array;
82
}
(11-11/13)