Project

General

Profile

Download (3.01 KB) Statistics
| Branch: | Tag: | Revision:
1 bd56cbc1 Andreas Kohlbecker
<?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 95e00758 Andreas Kohlbecker
  RenderHints::pushToRenderStack("taxon_nodes");
31
  RenderHints::setFootnoteListKey('taxon_nodes');
32 bd56cbc1 Andreas Kohlbecker
  if($taxon_nodes && count($taxon_nodes) > 0){
33
    $label_plural = false;
34 95e00758 Andreas Kohlbecker
    $status_markup_tokens = [];
35 9b8eb609 Andreas Kohlbecker
    $bibliography_settings = get_bibliography_settings();
36 bd56cbc1 Andreas Kohlbecker
    foreach ($taxon_nodes as $taxon_node){
37 95e00758 Andreas Kohlbecker
38
      $annotations_and_sources = handle_annotations_and_sources($taxon_node,
39
        array(
40
        'sources_as_content' => false,
41
        'link_to_name_used_in_source' => false,
42
        'link_to_reference' => true,
43 178d1ae6 Andreas Kohlbecker
        'add_footnote_keys' => true,
44 9b8eb609 Andreas Kohlbecker
        'bibliography_aware' => $bibliography_settings['enabled'] == 1),
45 95e00758 Andreas Kohlbecker
        '',
46
        null);
47
48 54164245 Andreas Kohlbecker
      if(isset($taxon_node->status)){
49
        $state_label = strtolower($taxon_node->status->message_L10n);
50
        if(isset($taxon_node->statusNote_L10n)){
51
          $state_label .= ' <span class="status-note">(' . $taxon_node->statusNote_L10n . ')</span>';
52 95e00758 Andreas Kohlbecker
        }
53 64cfdac1 Andreas Kohlbecker
        $classification = cdm_ws_get(CDM_WS_CLASSIFICATION, array($taxon_node->classificationUUID));
54 281ec7b2 Andreas Kohlbecker
        $status_markup_tokens[$state_label . '-' . $taxon_node->uuid]  = [
55 95e00758 Andreas Kohlbecker
          '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 '',
56 64cfdac1 Andreas Kohlbecker
          'classification' => ' <span class="' . html_class_attribute_ref($classification) .'">[' . $classification->titleCache . ']</span>'
57 bd56cbc1 Andreas Kohlbecker
        ];
58
      }
59 95e00758 Andreas Kohlbecker
60 bd56cbc1 Andreas Kohlbecker
    }
61 95e00758 Andreas Kohlbecker
    if(count($status_markup_tokens) > 0){
62 281ec7b2 Andreas Kohlbecker
      ksort($status_markup_tokens);
63 95e00758 Andreas Kohlbecker
      $status_markup = [];
64
      $label_plural |= count($status_markup_tokens) > 1;
65 31bb0452 Andreas Kohlbecker
      $label = $label_plural ? t('Placement status') : t('Placement status');
66 95e00758 Andreas Kohlbecker
      if(count($status_markup_tokens) > 1){
67
        foreach ($status_markup_tokens as $tokes){
68
          $status_markup[] = sprintf($tokes['status'], $tokes['classification']);
69 bd56cbc1 Andreas Kohlbecker
        }
70
      } else {
71 95e00758 Andreas Kohlbecker
        foreach ($status_markup_tokens as $tokes){
72
          $status_markup[] = sprintf($tokes['status'], '');
73 bd56cbc1 Andreas Kohlbecker
        }
74
      }
75 d8069342 Andreas Kohlbecker
      $render_array['taxon-node-status'] = markup_to_render_array($label . ': ' . join('; ', $status_markup) . render_footnotes(RenderHints::getFootnoteListKey()));
76 bd56cbc1 Andreas Kohlbecker
      $render_array['taxon-node-status']['#prefix'] = '<div class="taxon-node-status">';
77
      $render_array['taxon-node-status']['#suffix'] = '</div>';
78
    }
79
  }
80 178d1ae6 Andreas Kohlbecker
  RenderHints::setFootnoteListKey(null);
81 95e00758 Andreas Kohlbecker
  RenderHints::popFromRenderStack();
82 bd56cbc1 Andreas Kohlbecker
  return $render_array;
83
}