Project

General

Profile

Download (48.3 KB) Statistics
| Branch: | Tag: | Revision:
1 c70b93c3 Andreas Kohlbecker
<?php
2 f19f47fa Andreas Kohlbecker
/**
3
 * @file
4
 * Page 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 c70b93c3 Andreas Kohlbecker
 * @see http://www.mozilla.org/MPL/MPL-1.1.html
14
 *
15
 * @author
16 f19f47fa Andreas Kohlbecker
 *   - Andreas Kohlbecker <a.kohlbecker@BGBM.org>
17
 */
18
19
20
/**
21 02e8615c Andreas Kohlbecker
 * Composes a render array representing the ocurrences associetad with the $taxon.
22 f19f47fa Andreas Kohlbecker
 *
23
 * The resulting render array contains two elements:
24
 *  - 'map': A map showing all point locations of the occurences is availabale
25
 *  - 'specimen_list': the list of occurences prepated as table for theme_table()
26
 *
27
 * @param object $taxon
28
 *   A cdm Taxon object
29
 * @return
30
 *   A render array suitable for drupal_render()
31
 *
32 02e8615c Andreas Kohlbecker
 * @ingroup Compose
33
 *
34 c70b93c3 Andreas Kohlbecker
 */
35 02e8615c Andreas Kohlbecker
function compose_cdm_taxon_page_specimens($taxon) {
36 f19f47fa Andreas Kohlbecker
37 1ce9afb7 Patric Plitzner
    $render_array = array();
38
    RenderHints::pushToRenderStack('taxon_page_specimens');
39 30f78c59 Andreas Kohlbecker
40 961319fe Andreas Kohlbecker
    $fieldUnitDTOs = null;
41 46a93d1e Andreas Kohlbecker
    $specimensOrObservations = array();
42 44458b04 Andreas Kohlbecker
    if (variable_get(CDM_SPECIMEN_LIST_VIEW_MODE, CDM_SPECIMEN_LIST_VIEW_MODE_DEFAULT) == CDM_SPECIMEN_LIST_VIEW_MODE_OPTION_DERIVATE_TREE){
43 961319fe Andreas Kohlbecker
      // get fieldUnitDTOs
44 a0be8d7e Andreas Kohlbecker
      $fieldUnitDTOs = cdm_ws_get(CDM_WS_TAXON_FIELDUNIT_DTOS, array( $taxon->uuid));
45 961319fe Andreas Kohlbecker
      $fieldUnitDTOs = order_fieldUnitDtos_by_date_and_type($fieldUnitDTOs);
46
    } else {
47
      // $specimensOrObservations = cdm_ws_get(CDM_WS_TAXON, array( $taxon->uuid, 'specimensOrObservations'));
48
      // extend by associated taxas occurrences
49
      $relationship_filter_query_parameters = relationship_filter_query_parameters();
50
51
      if (isset($_REQUEST['pager']) && is_array($_REQUEST['pager'])) {
52
        $relationship_filter_query_parameters = array_merge($relationship_filter_query_parameters, $_REQUEST['pager']);
53
      }
54
      $by_associatedtaxon_query = http_build_query($relationship_filter_query_parameters);
55
      $pager = cdm_ws_get(CDM_WS_OCCURRENCE_BY_ASSOCIATEDTAXON,
56
        null,
57
        $by_associatedtaxon_query . '&taxonUuid=' . $taxon->uuid
58
      );
59
      if (isset($pager->records[0])) {
60
        $specimensOrObservations = $pager->records;
61
      }
62
      // cdm_ws_get(CDM_WS_OCCURRENCE_FIELDUNIT_DTO_BY_ASSOCIATEDTAXON,
63
      // null,
64
      // $by_associatedtaxon_query . '&taxonUuid=' . $taxon->uuid
65
      // );
66
67
      // $specimensOrObservations = array();
68
      // if(isset($pager->records[0])){
69
      //    $specimensOrObservations =  $pager->records;
70
      // }
71
      // Collect media (fieldObjectMedia, derivedUnitMedia) and add as a custom field
72
      foreach ($specimensOrObservations as &$occurrence) {
73
        $occurrence->_fieldObjectMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array(
74
          $occurrence->uuid,
75
          'fieldObjectMediaDTO',
76
        ));
77
        $occurrence->_derivedUnitMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array(
78
          $occurrence->uuid,
79
          'derivedUnitMedia',
80
        ));
81
      }
82
      $specimensOrObservations = order_specimens_or_observations_by_date_and_type($specimensOrObservations);
83 7965ef92 Katja Luther
    }
84 b8afc4bb Patric Plitzner
85 b5c89485 Patric Plitzner
    // --- get map service HTTP query parameters
86 961319fe Andreas Kohlbecker
    if (count($specimensOrObservations) > 0 || $fieldUnitDTOs > 0) {
87
        $render_array['map'] = occurrence_map_query_parameters($taxon);
88 b8afc4bb Patric Plitzner
    }
89 db725031 Andreas Kohlbecker
90
    // -------------------------------------------------------
91 106e1cf9 Katja Luther
92 44458b04 Andreas Kohlbecker
    if((variable_get(CDM_SPECIMEN_LIST_VIEW_MODE, CDM_SPECIMEN_LIST_VIEW_MODE_DEFAULT) == CDM_SPECIMEN_LIST_VIEW_MODE_OPTION_DERIVATE_TABLE)){
93 1ce9afb7 Patric Plitzner
94
        //COMPRESSED SPECIMEN DERIVATE TABLE
95 44458b04 Andreas Kohlbecker
        $pager_field_units = cdm_ws_page(
96
          cdm_compose_url(CDM_WS_PORTAL_TAXON, [
97
            $taxon->uuid,
98
            'associatedFieldUnits'
99
          ]),
100
          variable_get(CDM_SEARCH_RESULT_PAGE_SIZE, CDM_SEARCH_RESULT_PAGE_SIZE_DEFAULT) * 2,
101
          isset($_REQUEST['pager']['pageNumber']) ? isset($_REQUEST['pager']['pageNumber']) : 0
102 2e82a602 Patrick Plitzner
        );
103 1e87f89f Andreas Kohlbecker
104 09f028e2 Andreas Kohlbecker
        if (isset($pager_field_units->records[0])) {
105
          $field_unit_uuids = array();
106
          foreach ($pager_field_units->records as $field_unit) {
107
            $field_unit_uuids[] = $field_unit->uuid;
108
          }
109
110 961319fe Andreas Kohlbecker
          $render_array['derivate_hierarchy_table'] = compose_compressed_specimen_derivate_table($field_unit_uuids);
111 02f3768c Andreas Kohlbecker
        }
112 f19f47fa Andreas Kohlbecker
113 1e87f89f Andreas Kohlbecker
        $render_array['pager'] = markup_to_render_array(
114
            theme('cdm_pager', array(
115
                'pager' => $pager_field_units,
116
                'path' => $_REQUEST['q'],
117
                'parameters' => $_REQUEST
118
            )),
119
            10 // weight
120
        );
121 f19f47fa Andreas Kohlbecker
    }
122 44458b04 Andreas Kohlbecker
    else if((variable_get(CDM_SPECIMEN_LIST_VIEW_MODE, CDM_SPECIMEN_LIST_VIEW_MODE_DEFAULT) == CDM_SPECIMEN_LIST_VIEW_MODE_OPTION_DERIVATE_TREE)){ // FIXME this seems to be wrong
123 961319fe Andreas Kohlbecker
      $render_array['specimen_list'] = compose_specimen_table_top_down($fieldUnitDTOs);
124 ae177dac Andreas Kohlbecker
      $render_array['specimen_list']['#weight'] = 2;
125 961319fe Andreas Kohlbecker
    } else {
126 84849c31 Andreas Kohlbecker
      $specimen_table = compose_specimens_table_bottom_up($specimensOrObservations);
127
128
      $render_array['specimen_list'] = $specimen_table;
129
      $render_array['pager'] = markup_to_render_array(
130
        theme('cdm_pager', array(
131
          'pager' => $pager,
132
          'path' => $_REQUEST['q'],
133
          'parameters' => $_REQUEST,
134
        )),
135
        10 // weight
136
      );
137
    }
138 f19f47fa Andreas Kohlbecker
139 84849c31 Andreas Kohlbecker
    RenderHints::popFromRenderStack();
140
    return $render_array;
141
}
142
143 1e87f89f Andreas Kohlbecker
/**
144
 * @return array
145
 *
146 961319fe Andreas Kohlbecker
 * TODO move to cdm_dataportal.module or api.module?
147 1e87f89f Andreas Kohlbecker
 */
148 961319fe Andreas Kohlbecker
function relationship_filter_query_parameters()
149 1e87f89f Andreas Kohlbecker
{
150 961319fe Andreas Kohlbecker
  $relationship_choice = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
151
  $relationship_choice['direct'] = get_selection($relationship_choice['direct']);
152
  $relationship_choice['invers'] = get_selection($relationship_choice['invers']);
153 1e87f89f Andreas Kohlbecker
154 961319fe Andreas Kohlbecker
  $by_associatedtaxon_query_parameters = array(
155
    'relationshipsInvers' => implode(',', $relationship_choice['invers']),
156
    'relationships' => implode(',', $relationship_choice['direct']),
157 1e87f89f Andreas Kohlbecker
  );
158 961319fe Andreas Kohlbecker
  return $by_associatedtaxon_query_parameters;
159 1e87f89f Andreas Kohlbecker
}
160
161 961319fe Andreas Kohlbecker
162 65a4de51 Patrick Plitzner
function create_html_link($link, $openInExternalWindow=false){
163 7d8ef9fa Patric Plitzner
    $html = "";
164 65a4de51 Patrick Plitzner
    if($link->uri && $link->uri!=""){
165
        $html .= '<a  href="' . $link->uri . '"';
166
        if($openInExternalWindow){
167
            $html .= ' target="_blank"';
168
        }
169
        $html .= '>' . $link->linkText . '</a>';
170 7d8ef9fa Patric Plitzner
    }
171
    else{
172
        $html .= $link->linkText;
173
    }
174
    return $html;
175
}
176
177
/**
178 65a4de51 Patrick Plitzner
 * Creates HTML links from the given link list concatenated by default by a comma.
179 7d8ef9fa Patric Plitzner
 * @param $linkList the list with Link objects having "uri" and "linkText" as members
180
 * @return string the assembled HTML string containing the links
181
 */
182 65a4de51 Patrick Plitzner
function create_html_links($linkList, $openInExternalWindow=false, $separator=", ")
183 7d8ef9fa Patric Plitzner
{
184
    $html = "";
185
    if ($linkList) {
186
        foreach ($linkList as $link) {
187 65a4de51 Patrick Plitzner
            $html .= create_html_link($link, $openInExternalWindow).$separator;
188 7d8ef9fa Patric Plitzner
        }
189 65a4de51 Patrick Plitzner
        $html = rtrim($html, $separator);
190 7d8ef9fa Patric Plitzner
    }
191
    return $html;
192
}
193
194 00a8e4b6 Andreas Kohlbecker
/**
195
 * Composes a taxon page which can consist of multiple parts like
196
 * 'General', 'Synonymy', 'Images', 'Keys'. These parts can be displayed
197
 * as tabs or as sections of a single page.
198
 *
199
 * It is headed by the name of the accepted taxon without author and reference.
200
 *
201
 * @param $taxon
202
 *   The CDM Taxon Instance to compose the page for.
203
 * @param $page_part
204
 *   Name of the part to display, valid values are:
205
 *    - 'description' -  for the general part
206
 *    - 'images'
207
 *    - 'synonymy'
208
 *    - 'keys'
209
 *    - 'all'
210
 *
211
 * @return array
212
 *   A drupal render array
213
 *
214
 * @ingroup compose
215
 */
216
function compose_cdm_taxon_page($taxon, $page_part = 'description') {
217
218 0ae57522 Patric Plitzner
  // we better cache here since drupal_get_query_parameters has no internal static cache variable
219
  $http_request_params = drupal_get_query_parameters();
220 00a8e4b6 Andreas Kohlbecker
221 0ae57522 Patric Plitzner
  // add all mandatory js sources
222
  _add_js_footnotes();
223 00a8e4b6 Andreas Kohlbecker
224
225 0ae57522 Patric Plitzner
  $render_array = array();
226
  $weight = 0; // the weight for the render array elements
227 00a8e4b6 Andreas Kohlbecker
228 0ae57522 Patric Plitzner
  $tabsToDisplay = variable_get('cdm_taxonpage_tabs_visibility', unserialize(TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT));
229 00a8e4b6 Andreas Kohlbecker
230 0ae57522 Patric Plitzner
  $page_part = variable_get('cdm_dataportal_taxonpage_tabs', 1) ? $page_part : 'all';
231 00a8e4b6 Andreas Kohlbecker
232 22383f95 Andreas Kohlbecker
  $synonymy_as_tab = variable_get(CDM_SYNONYMY_AS_TAB, CDM_SYNONYMY_AS_TAB_DEFAULT) === 1;
233
  if(!$synonymy_as_tab){
234
    unset($tabsToDisplay["Synonymy"]);
235 3e6dfbb3 Andreas Kohlbecker
    // the synonymy is located in the general part in this case
236
    if($page_part == 'synonymy'){
237
      $page_part = 'description';
238
    }
239 22383f95 Andreas Kohlbecker
  }
240
241 0ae57522 Patric Plitzner
  $media = _load_media_for_taxon($taxon);
242 00a8e4b6 Andreas Kohlbecker
243
244 0ae57522 Patric Plitzner
  if (!isset($media[0]) || ($tabsToDisplay["Images"] == '0')) {
245 48a6d7e8 Andreas Kohlbecker
    taxon_page_tabs_hidden_add('images');
246 0ae57522 Patric Plitzner
  }
247 00a8e4b6 Andreas Kohlbecker
248 0ae57522 Patric Plitzner
  // --- GET specimensOrObservations --- //
249 c10f70e4 Katja Luther
  $specimensOrObservations = cdm_ws_get(CDM_WS_TAXON, array( $taxon->uuid, 'specimensOrObservationsCount'));
250 00a8e4b6 Andreas Kohlbecker
251 c10f70e4 Katja Luther
  $specimensOrObservationsCount = $specimensOrObservations != null ? $specimensOrObservations->result : 0;
252 0ae57522 Patric Plitzner
  if ($specimensOrObservationsCount == 0 || ($tabsToDisplay["Specimens"] == '0')) {
253 48a6d7e8 Andreas Kohlbecker
    taxon_page_tabs_hidden_add('specimens');
254 0ae57522 Patric Plitzner
  }
255 00a8e4b6 Andreas Kohlbecker
256 0ae57522 Patric Plitzner
  // --- GET polytomousKeys --- //
257
  $polytomousKeysPager = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, NULL, "findByTaxonomicScope=$taxon->uuid");
258
  $identificationKeyCount = 0;
259
  if ($polytomousKeysPager) {
260
    $identificationKeyCount += $polytomousKeysPager->count;
261
  }
262
  if ($identificationKeyCount == 0 || ($tabsToDisplay["Keys"] == '0')) {
263 48a6d7e8 Andreas Kohlbecker
    taxon_page_tabs_hidden_add('keys');
264 0ae57522 Patric Plitzner
  }
265 092744e1 Andreas Kohlbecker
266 22383f95 Andreas Kohlbecker
  // --- GET TaxonNodeAgentRelations --- //
267
  $current_classification_uuid = get_current_classification_uuid();
268
  $taxon_node_agent_relations_pager = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODEAGENTRELATIONS,
269
      array(
270
          $taxon->uuid,
271
          $current_classification_uuid,
272
      ),
273
      "pageSize=1&pageIndex=0"// we are only interested into the count so we are fetching only one item, o is not possible!
274
  );
275
  if (!$taxon_node_agent_relations_pager || $taxon_node_agent_relations_pager->count == 0){
276 48a6d7e8 Andreas Kohlbecker
      taxon_page_tabs_hidden_add('experts');
277 22383f95 Andreas Kohlbecker
  }
278 7663cd0b Andreas Kohlbecker
279 22383f95 Andreas Kohlbecker
  if (!isset($tabsToDisplay["Synonymy"]) || $tabsToDisplay["Synonymy"] == '0') {
280 48a6d7e8 Andreas Kohlbecker
    taxon_page_tabs_hidden_add('synonymy');
281 0ae57522 Patric Plitzner
  }
282 00a8e4b6 Andreas Kohlbecker
283 0ae57522 Patric Plitzner
  // -------------------------------------------- //
284 00a8e4b6 Andreas Kohlbecker
285 fe169cb6 Andreas Kohlbecker
  if(variable_get(CDM_TAXONPAGE_TAXON_NODE_SHOW_STATES, 1) && ( $page_part == 'description' || $page_part == 'synonymy' || $page_part == 'all')){
286 bd56cbc1 Andreas Kohlbecker
    $taxon_nodes = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODES, array($taxon->uuid));
287
    $render_array['taxon_node_status'] = compose_taxon_node_status($taxon_nodes);
288
    $render_array['taxon_node_status']['#weight'] = -100;
289
  }
290
291 0ae57522 Patric Plitzner
  if (variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR) && isset($_REQUEST['acceptedFor'])) {
292 7272d19c Andreas Kohlbecker
    $render_array['accepted_for'] = markup_to_render_array(cdm_accepted_for($_REQUEST['acceptedFor']), $weight++);
293 0ae57522 Patric Plitzner
  }
294 00a8e4b6 Andreas Kohlbecker
295 0ae57522 Patric Plitzner
  // --- PAGE PART: DESCRIPTION --- //
296 48a6d7e8 Andreas Kohlbecker
  if (!taxon_page_tabs_hidden_check('description') && ($page_part == 'description' || $page_part == 'all')) {
297 00a8e4b6 Andreas Kohlbecker
298 0ae57522 Patric Plitzner
    $merged_tree = merged_taxon_feature_tree($taxon);
299 00a8e4b6 Andreas Kohlbecker
300 7d8ef9fa Patric Plitzner
301 22383f95 Andreas Kohlbecker
    $render_array['general'] = compose_cdm_taxon_page_profile($taxon, $merged_tree, $media, !$synonymy_as_tab);
302 0ae57522 Patric Plitzner
    $render_array['general']['#weight'] = $weight++;
303
    $render_array['general']['#prefix'] = '<div id="general" class="page-part">';
304
    $render_array['general']['#suffix'] = '</div>';
305
  }
306 7d8ef9fa Patric Plitzner
307 0ae57522 Patric Plitzner
  // --- PAGE PART: IMAGES --- //
308 48a6d7e8 Andreas Kohlbecker
  if (!taxon_page_tabs_hidden_check('images') && ($page_part == 'images' || $page_part == 'all')) {
309 0ae57522 Patric Plitzner
    $images_html = '<div id="images" class="page-part">';
310
    if ($page_part == 'all') {
311 4feeabc7 Andreas Kohlbecker
      $images_html .= '<h2>' . t(cdm_taxonpage_tab_label('Images')) . '</h2>';
312 7d8ef9fa Patric Plitzner
    }
313 0ae57522 Patric Plitzner
    // Get the image gallery as configured by the admin.
314 a1f7edc0 Andreas Kohlbecker
    $configured_image_gallery_viewer = variable_get(CDM_MEDIA_GALLERY_VIEWER, CDM_MEDIA_GALLERY_VIEWER_DEFAULT);
315
    if($configured_image_gallery_viewer != 'fsi'){
316
      $images_html .= render_taxon_media_gallery($taxon, $configured_image_gallery_viewer, $media);
317
    } else {
318 8f4eb9ce Andreas Kohlbecker
      // the fsi_gallery requires a flash plugin, in case the client browser is not supporting
319
      // flash we also need to provide an the default gallery as alternative
320 a1f7edc0 Andreas Kohlbecker
      $images_html .= render_taxon_media_gallery($taxon, CDM_MEDIA_GALLERY_VIEWER_DEFAULT, $media);
321
      $images_html .= render_taxon_media_gallery($taxon, $configured_image_gallery_viewer, $media);
322 8f4eb9ce Andreas Kohlbecker
    }
323 a1f7edc0 Andreas Kohlbecker
    $images_html .= '</div>'; // END of <div id="images">
324 0ae57522 Patric Plitzner
    $render_array['images'] = markup_to_render_array($images_html, $weight++);
325
  }
326 7d8ef9fa Patric Plitzner
327 0ae57522 Patric Plitzner
  // --- PAGE PART: SYNONYMY --- //
328 48a6d7e8 Andreas Kohlbecker
  if (!taxon_page_tabs_hidden_check('synonymy') && (($page_part == 'synonymy' || $page_part == 'all') && $synonymy_as_tab)) {
329 0ae57522 Patric Plitzner
    $synonymy_html = '<div id="synonymy" class="page-part">';
330
    if ($page_part == 'all') {
331 4feeabc7 Andreas Kohlbecker
      $synonymy_html .= '<h2>' . t(cdm_taxonpage_tab_label('Synonymy')) . '</h2>';
332 00a8e4b6 Andreas Kohlbecker
    }
333 aec9ca7d Andreas Kohlbecker
    $addAcceptedTaxon = variable_get(CDM_DATAPORTAL_NOMREF_IN_TITLE, CDM_DATAPORTAL_NOMREF_IN_TITLE_DEFAULT);
334 41b4bfc9 Andreas Kohlbecker
335 1cda248c Andreas Kohlbecker
    $synonym_a = compose_cdm_taxon_page_synonymy($taxon, $addAcceptedTaxon);
336
    $synonymy_html .= drupal_render($synonym_a);
337 00a8e4b6 Andreas Kohlbecker
338 0ae57522 Patric Plitzner
    $synonymy_html .= '</div>';
339
    $render_array['synonymy'] = markup_to_render_array($synonymy_html, $weight++);
340 00a8e4b6 Andreas Kohlbecker
341 0ae57522 Patric Plitzner
  }
342 00a8e4b6 Andreas Kohlbecker
343 0ae57522 Patric Plitzner
  // --- PAGE PART: SPECIMENS --- //
344 48a6d7e8 Andreas Kohlbecker
  if (!taxon_page_tabs_hidden_check('specimens') && ($specimensOrObservationsCount > 0 && ($page_part == 'specimens' || $page_part == 'all'))) {
345 0ae57522 Patric Plitzner
    $render_array['specimens'] = array(
346 4feeabc7 Andreas Kohlbecker
        '#prefix' => '<div id="specimens" class="page-part">' . ($page_part == 'all' ? '<h2>' . t(cdm_taxonpage_tab_label('Specimens')) . '</h2>' : ''),
347 02e8615c Andreas Kohlbecker
        'content' => compose_cdm_taxon_page_specimens($taxon), // returns render array
348 0ae57522 Patric Plitzner
        '#suffix' => '</div>',
349
    );
350
  }
351
352
  // --- PAGE PART: KEYS --- //
353 48a6d7e8 Andreas Kohlbecker
  if(!taxon_page_tabs_hidden_check('keys')){
354
    if ($identificationKeyCount == 1 && $page_part == 'keys'){
355
      drupal_goto(path_to_key($polytomousKeysPager->records[0]->class, $polytomousKeysPager->records[0]->uuid));
356
    }
357
    else if ($identificationKeyCount > 0 && ($page_part == 'keys' || $page_part == 'all')) {
358
      $keys_html = '<div id="keys" class="page-part">';
359
      if ($page_part == 'all') {
360
        $keys_html .= '<h2>' . t(cdm_taxonpage_tab_label('Keys')) . '</h2>';
361
      }
362
      $keys_html .= theme('cdm_block_IdentificationKeys', array('taxonUuid' => $taxon->uuid));
363
      $keys_html .= '</div>';
364
      $render_array['keys'] = markup_to_render_array($keys_html, $weight++);
365 0ae57522 Patric Plitzner
    }
366
  }
367
368 7663cd0b Andreas Kohlbecker
  // --- PAGE PART: EXPERTS --- //
369
370 48a6d7e8 Andreas Kohlbecker
  if (!taxon_page_tabs_hidden_check('experts') && ($page_part == 'experts' || $page_part == 'all')) {
371 7663cd0b Andreas Kohlbecker
    $render_array['experts'] = array(
372 4feeabc7 Andreas Kohlbecker
        '#prefix' => '<div id="experts" class="page-part">' . ($page_part == 'all' ? '<h2>' . t(cdm_taxonpage_tab_label('Experts')) . '</h2>' : ''),
373 7663cd0b Andreas Kohlbecker
        'content' => compose_cdm_taxon_page_experts($taxon), // returns render array
374
        '#suffix' => '</div>',
375
    );
376
  }
377
378
  // ------------------ END OF PARTS -------------- //
379 0ae57522 Patric Plitzner
380
  // adjust weights of page and toc elements according to the settings
381 4feeabc7 Andreas Kohlbecker
  $taxontabs_weights = get_array_variable_merged(CDM_TAXONPAGE_TAB_WEIGHT, CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
382 0ae57522 Patric Plitzner
  foreach($taxontabs_weights as $tab_key => $weight){
383
    if(isset($render_array[$tab_key])){
384
      $render_array[$tab_key]['#weight'] = $weight;
385
    }
386
  }
387
388
389 2203967c Andreas Kohlbecker
  // set up the TOC and pseudo feature blocks for the pages which contain all page parts
390
  if($page_part == 'all' && (!isset( $render_array['general']) || count($render_array['general']) == 0 )) {
391 9b8eb609 Andreas Kohlbecker
392
    $bibliography_block = make_bibliography_feature_block();
393
    if($bibliography_block){
394 2203967c Andreas Kohlbecker
      $render_array['bibliography_block'] = _block_get_renderable_array([$bibliography_block]);
395 9b8eb609 Andreas Kohlbecker
      $render_array['bibliography_block']['#weight'] = 100;
396
      cdm_toc_list_add_item('Bibliography', 'bibliography', null, false, $render_array['bibliography_block']['#weight']);
397
    }
398
399 aec9ca7d Andreas Kohlbecker
    $toc_elements = [];
400 0ae57522 Patric Plitzner
    asort($taxontabs_weights);
401
    foreach(array_keys($taxontabs_weights) as $tab_key){
402
      if(isset($render_array[$tab_key])){
403
        if($tab_key != 'general'){
404
          // add entry for page part
405
          $toc_elements[] = array(
406 4feeabc7 Andreas Kohlbecker
              'data' => l(t(cdm_taxonpage_tab_label(ucfirst($tab_key))), $_GET['q'], array('fragment' => $tab_key, 'query' => $http_request_params)),
407 0ae57522 Patric Plitzner
              'class' => array('page-part-toc-item-' . $tab_key)
408
          );
409
        } else {
410
          // add content of profile part instead
411
          if(isset($render_array['general'])) {
412
            // in case all tabs are shown at once the feature tocs
413
            // should be integrated into the tabs toc as sub list
414
            // and the profile image should be on top of the page
415
            if(isset($render_array['general']['taxon_description_feature_toc'])){;
416
            foreach ($render_array['general']['taxon_description_feature_toc']['#items'] as $profile_toc_item){
417
              $toc_elements[] = $profile_toc_item;
418 7d8ef9fa Patric Plitzner
            }
419 0ae57522 Patric Plitzner
            unset($render_array['general']['taxon_description_feature_toc']);
420
            }
421
          }
422 7d8ef9fa Patric Plitzner
        }
423 0ae57522 Patric Plitzner
      }
424
    }
425 7d8ef9fa Patric Plitzner
426 0ae57522 Patric Plitzner
    // move profile image in page structure
427
    if(isset($render_array['general']['taxon_profile_image'])){
428
      $render_array['profile_image'] = $render_array['general']['taxon_profile_image'];
429
      $render_array['profile_image']['#weight'] = -100;
430
      unset($render_array['general']['taxon_profile_image']);
431 7d8ef9fa Patric Plitzner
    }
432
433 0ae57522 Patric Plitzner
    // finally add the table of contents to the render array
434
    $render_array['toc'] = array(
435
        '#theme' => 'item_list',
436
        '#items' => $toc_elements,
437
        '#title' => t('Content'),
438
        '#weight' => -101,
439
        '#suffix' => '</div>',
440
        '#prefix'=> '<div id="page-toc">'
441
    );
442 aec9ca7d Andreas Kohlbecker
443 0ae57522 Patric Plitzner
  }
444
445 7d8ef9fa Patric Plitzner
446 0ae57522 Patric Plitzner
  return $render_array;
447 00a8e4b6 Andreas Kohlbecker
}
448
449 1ce9afb7 Patric Plitzner
/**
450 22f5e82d Andreas Kohlbecker
 * TODO should this function really be a compose function?
451
 *     For a compose function must there always be a theme function with the same name? (ak 8.8.2013)
452 bf97c2e8 Andreas Kohlbecker
 *
453
 * composes and returns an render array containing the components of the taxon profile tab:
454
 *  - 'taxon_profile_image'
455
 *  - 'taxon_description_feature_toc'
456
 *  - 'taxon_description_features'
457
 *
458
 *
459 8a1b451e Andreas Kohlbecker
 * @param object taxon
460
 * @param object $merged_tree
461
 * @param object media
462
 * @param bool $add_synonymy
463 bf97c2e8 Andreas Kohlbecker
 *
464
 * @return array
465 f78fda81 Andreas Kohlbecker
 *   A Drupal render array with the following elements:
466 bf97c2e8 Andreas Kohlbecker
 *     - 'taxon_profile_image'
467
 *     - 'taxon_description_feature_toc'
468
 *     - 'taxon_description_features'
469
 *
470 8a1b451e Andreas Kohlbecker
 * @throws Exception
471
 *
472 bf97c2e8 Andreas Kohlbecker
 * @ingroup compose
473
 */
474 22383f95 Andreas Kohlbecker
function compose_cdm_taxon_page_profile($taxon, $merged_tree, $media, $add_synonymy) {
475 bf97c2e8 Andreas Kohlbecker
476 0ae57522 Patric Plitzner
  $render_array = array();
477
478
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
479
480
  $hide_taxon_profile_image = FALSE;
481
  if (variable_get('image_hide_rank', '0') != '0' && isset($taxon->name->rank->uuid)) {
482
    $rankCompare = rank_compare($taxon->name->rank->uuid, variable_get('image_hide_rank', '-99'));
483
    $hide_taxon_profile_image = ($rankCompare > -1);
484
  }
485
486
  if ($taxon_profile_image_settings['show'] && !$hide_taxon_profile_image) {
487
488
    $representationPart = new stdClass();
489
    $attributes = array();
490 02faa087 Andreas Kohlbecker
    if (isset($media[0])) {
491
      // due to a bug the portal/taxon/{uuid}/media service only delivers a filtered media object
492
      // which only contains the thumbnail representation even if the height and width filters are not set.
493 673929dd Andreas Kohlbecker
      // -->
494 02faa087 Andreas Kohlbecker
      $preferred_media = cdm_ws_get(CDM_WS_MEDIA, $media[0]->uuid);
495
      $preferred_representations = cdm_preferred_media_representations($preferred_media, array(
496
        'image/jpg',
497
        'image/jpeg',
498
        'image/png',
499
        'image/gif',
500
      ),
501
        $taxon_profile_image_settings['maxextend'],
502
        $taxon_profile_image_settings['maxextend']
503
      );
504
      if(count($preferred_representations) > 0){
505
506
        $representation = array_shift($preferred_representations);
507
        $representationPart = $representation->parts[0];
508
        $attributes['alt'] = $representationPart->uri;
509
510
        if (!empty($taxon_profile_image_settings['media_uri_query'])) {
511
          $representationPart->uri = $representationPart->uri
512
            . (strpos($representationPart->uri, '?') !== FALSE ? '&' : '?')
513
            . $taxon_profile_image_settings['media_uri_query'];
514
        }
515 0ae57522 Patric Plitzner
      }
516
    }
517
    else {
518 9506fd1f Andreas Kohlbecker
      if ($taxon_profile_image_settings['custom_placeholder_enabled']) {
519 ca47ea76 Andreas Kohlbecker
        // show placeholder image instead
520
        if (!empty($taxon_profile_image_settings['custom_placeholder_image_on']) && !empty($taxon_profile_image_settings['custom_placeholder_image_fid'])) {
521
          // use the user provided image
522
          $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
523
          $url = file_create_url($profile_image_file->uri);
524
          $image_info = image_get_info($profile_image_file->uri);
525
          $representationPart->width = $image_info['width'];
526
          $representationPart->height = $image_info['height'];
527
          $representationPart->uri = $url;
528
        }
529
        else {
530
          // use the hard coded default
531
          $representationPart->width = 184;
532
          $representationPart->height = 144;
533
          $representationPart->uri = base_path() . drupal_get_path('module',
534
              'cdm_dataportal') . '/images/no_picture.png';
535
        }
536
        $attributes['alt'] = "no image available";
537 0ae57522 Patric Plitzner
      }
538
    }
539
540 ca47ea76 Andreas Kohlbecker
    if (isset($representationPart->uri)) {
541 a9815578 Andreas Kohlbecker
      $profile_image = cdm_media_gallerie_image($representationPart, $taxon_profile_image_settings['maxextend'], FALSE, $attributes);
542 ca47ea76 Andreas Kohlbecker
      // NOTE: style="width:${maxextend}px' is needed for IE8 !!!
543 84849c31 Andreas Kohlbecker
      $max_extend_with = $taxon_profile_image_settings['maxextend'] . 'px';
544 062686a1 Andreas Kohlbecker
      $render_array['taxon_profile_image'] = markup_to_render_array('<div id="taxonProfileImage" style="width:' . $max_extend_with . '">' . $profile_image . '</div>',
545 ca47ea76 Andreas Kohlbecker
        -101);
546
    }
547 0ae57522 Patric Plitzner
  }
548
549 22383f95 Andreas Kohlbecker
  if($add_synonymy){
550 1cda248c Andreas Kohlbecker
    $synonymy_a = compose_cdm_taxon_page_synonymy($taxon, true);
551
    $synonymy_a['#weight'] = -102;
552 aec9ca7d Andreas Kohlbecker
    $synonymy_a['#prefix'] = '<div id="synonymy">';
553
    $synonymy_a['#suffix'] = '</div>';
554 1cda248c Andreas Kohlbecker
    $render_array['synonymy'] = $synonymy_a;
555 22383f95 Andreas Kohlbecker
  }
556
557 7ccb6888 Andreas Kohlbecker
  //  $pseudo_feature_block_toc_items = array();
558 0ae57522 Patric Plitzner
559 1b756c5f Andreas Kohlbecker
  // Render the sections for each real feature
560
  $feature_block_list = make_feature_block_list($merged_tree->root->childNodes, $taxon);
561
562 bf8aea21 Andreas Kohlbecker
  // >>>>>>>>>>>>>>>>>>> PSEUDO FEATURES >>>>>>>>>>>>>>>>>>>
563 c3a41ddb Andreas Kohlbecker
  $pseudo_feature_weights = get_array_variable_merged(CDM_PSEUDO_FEATURE_BLOCK_WEIGHTS, CDM_PSEUDO_FEATURE_BLOCK_WEIGHTS_DEFAULT);
564 0ae57522 Patric Plitzner
565 9b8eb609 Andreas Kohlbecker
  // Bibliography
566
  $bibliography_block = make_bibliography_feature_block();
567
  if($bibliography_block){
568
    $feature_block_list[$pseudo_feature_weights[PSEUDO_FEATURE_BIBLIOGRAPHY]] = $bibliography_block;
569
    cdm_toc_list_add_item('Bibliography', 'bibliography', null, false, $pseudo_feature_weights[PSEUDO_FEATURE_BIBLIOGRAPHY]);
570 1b756c5f Andreas Kohlbecker
  }
571
572 bf8aea21 Andreas Kohlbecker
  // Descriptions (aggregated)
573
  $descriptionTypes = array();
574
  $descriptionTypes['descriptionTypes'] = ("AGGREGATED_STRUC_DESC");
575
  $aggregatedDescriptions = cdm_ws_fetch_all(CDM_WS_PORTAL_TAXON . '/' . $taxon->uuid . '/descriptions', $descriptionTypes);
576
  if (isset($aggregatedDescriptions) and !empty($aggregatedDescriptions)) {
577
      // if($feature_block_list) ....TODO
578
      $feature_description = make_pseudo_feature('Descriptions (aggregated)', PSEUDO_FEATURE_AGGREGATION_DESCRIPTIONS);
579
      $description_item = '';
580
      foreach ($aggregatedDescriptions as $description) {
581 92e522db Andreas Kohlbecker
        $description_item = '<div class="' . html_class_attribute_ref($description) . '">';
582 2527a83c Andreas Kohlbecker
        $description_item .= render_description_string(get_root_nodes_for_dataset($description));
583 92e522db Andreas Kohlbecker
        $description_item .= ' ' . icon_link(path_to_description($description->uuid));
584 cd3ea2e8 Andreas Kohlbecker
        $description_item .= '<div class="content-caption">'. statistical_values_explanation() . '</div>';
585 92e522db Andreas Kohlbecker
        $description_item .= '</div>';
586 bf8aea21 Andreas Kohlbecker
      }
587
      $description_block = feature_block(t('Descriptions (aggregated)'), $feature_description);
588
      $description_block->content = [];
589
      $description_block->content[] = compose_feature_block_wrap_elements([$description_item], $feature_description);
590 e170a53e Patrick Plitzner
591 c3a41ddb Andreas Kohlbecker
      $feature_block_list[$pseudo_feature_weights[PSEUDO_FEATURE_AGGREGATION_DESCRIPTIONS]] = $description_block;
592 089fb6ea Andreas Kohlbecker
      cdm_toc_list_add_item('Descriptions (aggregated)', 'aggregation_descriptions', null, false, $pseudo_feature_weights[PSEUDO_FEATURE_AGGREGATION_DESCRIPTIONS]);
593 c3a41ddb Andreas Kohlbecker
594 0ae57522 Patric Plitzner
595 bf8aea21 Andreas Kohlbecker
  }
596 9d88232c Patrick Plitzner
597 c3a41ddb Andreas Kohlbecker
  // sort by weight
598
  ksort($feature_block_list);
599
  $render_array['taxon_description_features'] = _block_get_renderable_array($feature_block_list);
600
601
/*  // update TOC
602 bf8aea21 Andreas Kohlbecker
  if ($pseudo_feature_block_toc_items){
603 1b756c5f Andreas Kohlbecker
    foreach ($pseudo_feature_block_toc_items as $label=>$fragment){
604
      cdm_toc_list_add_item($label, $fragment);
605
    }
606 0ae57522 Patric Plitzner
  }
607 c3a41ddb Andreas Kohlbecker
*/
608 bf8aea21 Andreas Kohlbecker
  // <<<<<<<<<<<<<<<<<<< PSEUDO FEATURES <<<<<<<<<<<<<<<<<<<
609
610 0ae57522 Patric Plitzner
  // create the table of content
611
  $toc = array(
612
      '#theme' => 'item_list',
613
    '#items' => cdm_toc_list(),
614
      '#title' => t('Content'),
615
    '#weight' => -100,                  // move to the top
616
      '#suffix' => '</div>',
617
      '#prefix'=> '<div id="page-toc">'
618
  );
619
  $render_array['taxon_description_feature_toc'] = $toc;
620
621
  return $render_array;
622 bf97c2e8 Andreas Kohlbecker
}
623
624 9b8eb609 Andreas Kohlbecker
/**
625
 * @return object|\stdclass
626
 */
627
function make_bibliography_feature_block() {
628
  $bibliography_block = null;
629
  $bibliography_settings = get_bibliography_settings();
630
  if ($bibliography_settings['enabled'] == 1) {
631
    $bibliography_markup = FootnoteManager::renderFootnoteList(PSEUDO_FEATURE_BIBLIOGRAPHY, '');
632
    if ($bibliography_markup) {
633
      $feature_bibliography = make_pseudo_feature('Bibliography', PSEUDO_FEATURE_BIBLIOGRAPHY);
634
      $bibliography_item = markup_to_render_array($bibliography_markup);
635
      $bibliography_block = feature_block(t('Bibliography'), $feature_bibliography);
636
      $bibliography_block->content = [];
637
      $bibliography_block->content[] = compose_feature_block_wrap_elements([$bibliography_item], $feature_bibliography);
638
    }
639
  }
640
  return $bibliography_block;
641
}
642
643 a38c0718 Patrick Plitzner
644 67ce7111 Patrick Plitzner
/**
645
 * Renders the link which will lead to the specimen detail page
646 55236f7f Andreas Kohlbecker
 * @param object $specimen
647
 *    the cdm specimen entity which will be linked to
648 67ce7111 Patrick Plitzner
 *
649 55236f7f Andreas Kohlbecker
 * @return string
650
 *     the markup for the link
651 67ce7111 Patrick Plitzner
 */
652
function render_cdm_specimen_link($specimen) {
653
  $path = path_to_specimen($specimen->uuid);
654
  $attributes['class'][] = html_class_attribute_ref($specimen);
655 ab025781 Andreas Kohlbecker
  return $specimen->titleCache.icon_link($path);
656 67ce7111 Patrick Plitzner
}
657
658 57dabcba Andreas Kohlbecker
/**
659
 * Returns HTML containing the synonymy for the accepted taxon.
660
 *
661
 * Shows the whole synonymy for the accepted taxon.
662
 * The synonymy list is headed by the complete scientific name
663
 * of the accepted taxon with nomenclatural reference.
664
 *
665
 * @param object $taxon
666
 * @param boolean $add_accepted_taxon
667
 *
668
 * @return array
669
 *  Drupal render array for the synonymy
670
 *
671
 * @throws Exception
672
 *
673
 * @ingroup compose
674
 */
675
function compose_cdm_taxon_page_synonymy($taxon, $add_accepted_taxon) {
676
677
  RenderHints::pushToRenderStack('taxon_page_synonymy');
678
679
  // footnote key for the homotypic group and accepted taxon,
680
  // both should have the same footnote key
681
  RenderHints::setFootnoteListKey(RenderHints::getRenderPath());
682
683
  $synomymie = cdm_ws_get(CDM_WS_PORTAL_TAXON_SYNONYMY, array($taxon->uuid));
684
685
  $out = '';
686
687
  // Render accepted taxon.
688
  //
689
  // foonotes of the accepted taxon will be rendered in the homotypic group section
690
  // even if there are not synonyms in the homotypic group
691
  // homotypic group and accepted taxon should have the same footnote key
692
  $referenceUri = '';
693
  if ($add_accepted_taxon) {
694
    // set new render path for the accepted taxon so
695
    // it can be styled differently via the name render part definitions
696
    RenderHints::pushToRenderStack('accepted_taxon');
697
    $accepted_name = '';
698
    if (variable_get(CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE, 0)) {
699
      $label = variable_get(CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL, CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL_DEFAULT);
700
      $accepted_name .= '<div class="secReference"><span class="label">' . t($label) . ':</span> ' . $taxon->sec->titleCache . '</div>';
701
    }
702 6679207a Andreas Kohlbecker
    if (isset($taxon->name->nomenclaturalSource->citation)) {
703
      $referenceUri = url(path_to_reference($taxon->name->nomenclaturalSource->citation->uuid));
704 57dabcba Andreas Kohlbecker
    }
705
706
    $accepted_name .= '<div class="accepted-name">';
707
    $accepted_name .= render_taxon_or_name($taxon, NULL, $referenceUri);
708
709
    $name_relations = cdm_name_relationships_for_taxon($taxon);
710
    $name_relationships = compose_name_relationships_inline($name_relations, $taxon->name->uuid, $taxon->uuid);
711
    // Render relationships of accepted name.
712
    if(isset($name_relationships['list']['items'][0])){
713
      $accepted_name .= ' ' . drupal_render($name_relationships);
714
    }
715 39ae8ca4 Andreas Kohlbecker
    $accepted_name .= render_taxon_and_name_footnotes($taxon);
716 57dabcba Andreas Kohlbecker
    $accepted_name .= '</div>';
717
    RenderHints::popFromRenderStack();
718
  }
719
720
  // --- Render homotypic synonymy group
721
  if (!empty($accepted_name)) {
722
    $out .= $accepted_name;
723
  }
724
725
  // Render the homotypicSynonymyGroup including the type information.
726
  $out .= theme(
727
    'cdm_homotypicSynonymyGroup',
728
    array(
729
      'synonymList' => $synomymie->homotypicSynonymsByHomotypicGroup,
730
      'accepted_taxon_name_uuid' => $taxon->name->uuid
731
    )
732
  );
733
734
735
  // Render accepted taxon heterotypic synonymy groups.
736
  if ($synomymie->heterotypicSynonymyGroups) {
737
    foreach ($synomymie->heterotypicSynonymyGroups as $homotypicalGroup) {
738
      $out .= theme('cdm_heterotypicSynonymyGroup', array('homotypicalGroup' => $homotypicalGroup));
739
    }
740
  }
741
  // Render taxon relationships.
742
  if (variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT)) {
743
    $taxonRelationshipsDTO = cdm_ws_get(CDM_WS_PORTAL_TAXON_RELATIONS_DTO, $taxon->uuid);
744
    $out .= cdm_taxonRelationships($taxonRelationshipsDTO, $taxon);
745
  }
746
747
  RenderHints::popFromRenderStack();
748
749
  return markup_to_render_array($out);
750
}
751
752 61658f41 Andreas Kohlbecker
/**
753
 * Provides the default configuration for handle_annotations_and_sources() in the
754
 * synonymy.
755
 *
756
 * @return bool[]
757
 */
758
function synonymy_annotations_and_source_config() {
759
  static $annotations_and_sources_config = null;
760
  if(!$annotations_and_sources_config){
761
    $bibliography_settings = get_bibliography_settings();
762
    $annotations_and_sources_config = [
763
      'sources_as_content' => FALSE,
764
      'link_to_name_used_in_source' => TRUE,
765
      'link_to_reference' => TRUE,
766
      'add_footnote_keys' => TRUE,
767
      'bibliography_aware' => $bibliography_settings['enabled'] == 1
768
    ];
769
  }
770
  return $annotations_and_sources_config;
771
}
772
773 57dabcba Andreas Kohlbecker
774 f9a3d0f6 Andreas Kohlbecker
/**
775
 * composes and returns an render array for the experts associated with the given taxon
776
 *
777 8a1b451e Andreas Kohlbecker
 * @param object taxon
778 f9a3d0f6 Andreas Kohlbecker
 *
779
 * @return array
780
 *   A Drupal render array for a table with the experts
781
 *
782
 * @ingroup compose
783
 */
784 7663cd0b Andreas Kohlbecker
function compose_cdm_taxon_page_experts($taxon){
785
786
  $render_array = array();
787
  if(!isset($taxon->uuid)){
788
    return $render_array;
789
  }
790
791
  $current_classification_uuid = get_current_classification_uuid();
792
  // TODO use cdm_ws_fetchall below but this failes! needs fix!
793
  $taxon_node_agent_relations = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODEAGENTRELATIONS,
794
    array(
795
      $taxon->uuid,
796
      $current_classification_uuid
797
    )
798
  );
799
800
  $header = array(
801
    array('data' => t('Expert')),
802
    array('data' => t('Role'))
803
  );
804
  $rows = array();
805
806
807
  foreach($taxon_node_agent_relations->records as $taxon_node_agent_relation){
808
809 d9763fd3 Andreas Kohlbecker
810
    $expert_role_id = $taxon_node_agent_relation->agent->uuid . '-' . $taxon_node_agent_relation->type->uuid;
811
    $expert_details_container_id = 'expert_details_' . $expert_role_id;
812
813
    $agent_label_markup = cdm_dynabox(
814
      'expert_' . $expert_role_id,
815
      $taxon_node_agent_relation->agent->titleCache,
816
      // specifying both ends of the relationship will return only one record in the pager
817 44458b04 Andreas Kohlbecker
      cdm_compose_ws_url(CDM_WS_PORTAL_AGENT,
818 d9763fd3 Andreas Kohlbecker
         array($taxon_node_agent_relation->agent->uuid, 'taxonNodeAgentRelations'),
819
        'taxon_uuid=' . $taxon->uuid . '&relType_uuid=' . $taxon_node_agent_relation->type->uuid),
820
      'cdm_taxon_expert',
821
      'Click for details',
822
      array('div', 'div'),
823
      array(), // attributes
824 cea412e7 Andreas Kohlbecker
      '#' . $expert_details_container_id // $content_element_selector
825 d9763fd3 Andreas Kohlbecker
    );
826
827
    // Expert and Role
828
    $rows[] = array(
829
      'data' => array(
830
        array(
831
          'data' => $agent_label_markup,
832
          'class' => array(html_class_attribute_ref($taxon_node_agent_relation->agent))
833 7663cd0b Andreas Kohlbecker
        ),
834 d9763fd3 Andreas Kohlbecker
        array(
835
          'data' => $taxon_node_agent_relation->type->representation_L10n,
836
          'class' => array(html_class_attribute_ref($taxon_node_agent_relation->type))
837
        )
838
      )
839
    );
840
    // Agent details
841
    $rows[] = array(
842
      'data' => array(
843
        array(
844
          'data' => '<!-- expert_details_container -->',
845
          'id' => $expert_details_container_id,
846
          'colspan' => 2
847
        )
848
      )
849 7663cd0b Andreas Kohlbecker
    );
850 d9763fd3 Andreas Kohlbecker
851 7663cd0b Andreas Kohlbecker
  }
852
853
854
  $render_array['experts_table'] = array(
855
    '#theme' => 'table',
856
    '#header' => $header,
857
    '#rows' => $rows,
858
  );
859
860
861
  return $render_array;
862
}
863
864 bf97c2e8 Andreas Kohlbecker
865 3f259ca3 Andreas Kohlbecker
/**
866 7663cd0b Andreas Kohlbecker
 * Manages the tabs to be hidden in the taxon page.
867 3f259ca3 Andreas Kohlbecker
 *
868
 * The tabs are identified by their last menu link path element:
869
 *  - description
870
 *  - synonymy
871
 *  - images
872
 *  - specimens
873
 *  - key
874
 *
875
 * Internally the tabs are stored in a static variable which is
876
 * managed by drupal_static().
877
 *
878
 * @param string $add_tab
879 7663cd0b Andreas Kohlbecker
 *   Optional parameter. The given string will be added to the array of tabs
880 3f259ca3 Andreas Kohlbecker
 *
881
 * @return
882
 *   The array of tabs
883
 */
884 48a6d7e8 Andreas Kohlbecker
function taxon_page_tabs_hidden_add($add_tab = NULL) {
885
  $tabs = &drupal_static('taxon_page_tabs_hidden');
886 3f259ca3 Andreas Kohlbecker
887 0ae57522 Patric Plitzner
  if(!isset($tabs)){
888
    $tabs = array();
889
  }
890 3f259ca3 Andreas Kohlbecker
891 0ae57522 Patric Plitzner
  if (isset($add_tab) && !array_key_exists($add_tab, $tabs)) {
892
    $tabs[] = $add_tab;
893
  }
894 3f259ca3 Andreas Kohlbecker
895 0ae57522 Patric Plitzner
  return $tabs;
896 3f259ca3 Andreas Kohlbecker
}
897
898 48a6d7e8 Andreas Kohlbecker
/**
899
 * Manages the tabs to be hidden in the taxon page.
900
 *
901
 * The tabs names are identified by their last menu link path element:
902
 *  - description
903
 *  - synonymy
904
 *  - images
905
 *  - specimens
906
 *  - key
907
 *
908
 * Internally the tabs are stored in a static variable which is
909
 * managed by drupal_static().
910
 *
911
 * @param string $tabname
912
 *   The name of the tab to check
913
 *
914
 * @return boolean
915
 *   True if the tab or section is to be hidden
916
 */
917
function taxon_page_tabs_hidden_check($tabname) {
918
919
  $tabs = &drupal_static('taxon_page_tabs_hidden');
920
921
  if(!isset($tabs)){
922
    $tabs = array();
923
  }
924
925
  return array_search($tabname, $tabs) !== FALSE;
926
}
927
928 3f259ca3 Andreas Kohlbecker
/**
929
 * Implements the hook_preprocess_HOOK() for theme_menu_local_tasks()
930
 *
931 48a6d7e8 Andreas Kohlbecker
 *  - Removes the tabs to be hidden, @see taxon_page_tabs_hidden_add()
932 9438ad3a Andreas Kohlbecker
 *  - Renames tabs according to the settings // TODO (this will replace the theme_cdm_taxonpage_tab() function !!!)
933 3f259ca3 Andreas Kohlbecker
 *
934
 * @param array $variables
935
 *   The variables array
936
 */
937
function cdm_dataportal_preprocess_menu_local_tasks(&$variables) {
938
939 48a6d7e8 Andreas Kohlbecker
  $hidden_tabs = taxon_page_tabs_hidden_add();
940 3f259ca3 Andreas Kohlbecker
941 868be375 Katja Luther
  if (!variable_get(CDM_SEARCH_BLAST_ENABLED)) {
942 6f6f79f6 Katja Luther
      if (is_array($variables['primary'])) {
943
          foreach ($variables['primary'] as $key => &$element) {
944
              if ($element['#link']['path'] == 'cdm_dataportal/search/blast') {
945
                  // remove the tab
946
                  unset($variables['primary'][$key]);
947
              }
948 868be375 Katja Luther
949 6f6f79f6 Katja Luther
          }
950 868be375 Katja Luther
      }
951
  }
952 0ae57522 Patric Plitzner
  if (is_array($variables['primary'])) {
953
    foreach ($variables['primary'] as $key => &$element) {
954 6f1a217c Andreas Kohlbecker
955 0ae57522 Patric Plitzner
      // 1. Remove the tabs to be hidden
956
      foreach ($hidden_tabs as $tab) {
957
        if ($element['#link']['path'] == 'cdm_dataportal/taxon/%/' . $tab) {
958
          // remove the tab
959
          unset($variables['primary'][$key]);
960 9438ad3a Andreas Kohlbecker
        }
961 0ae57522 Patric Plitzner
      }
962 3f259ca3 Andreas Kohlbecker
    }
963 0ae57522 Patric Plitzner
  }
964 6f1a217c Andreas Kohlbecker
}
965
966
967
968
/**
969
 * Implements the hook_preprocess_HOOK() for theme_menu_local_task()
970
 *
971
 *
972
 * @param array $variables
973
 *   An associative array containing:
974
 *     - element: A render element containing:
975
 *          #link: A menu link array with 'title', 'href', and 'localized_options' keys.
976
 *          #active: A boolean indicating whether the local task is active.
977
 *
978
 */
979
function cdm_dataportal_preprocess_menu_local_task(&$variables) {
980
981 0ae57522 Patric Plitzner
  $link = $variables['element']['#link'];
982
  if (preg_match('/cdm_dataportal\/.*\/refresh$/', $link['href'])) {
983
    $link['title'] = '<img class="refresh" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/view-refresh.png' . '" alt="' . check_plain($link['title']) . '" title="' . check_plain($link['title']) . '"/>';
984
    $link['localized_options']['html'] = TRUE;
985 6f1a217c Andreas Kohlbecker
986 0ae57522 Patric Plitzner
    $variables['element']['#link'] = $link;
987
  }
988 f19f47fa Andreas Kohlbecker
}
989 f9a3d0f6 Andreas Kohlbecker
990
/* =================== block composition ===================== */
991
992
/**
993 23ad16a1 Andreas Kohlbecker
 * Composes and returns an render array for the classification breadcrumbs of the given taxon.
994 f9a3d0f6 Andreas Kohlbecker
 *
995
 * @param taxon
996
 *
997
 * @return array
998
 *   A Drupal render array for a table with the experts
999
 *
1000
 * @ingroup compose
1001
 */
1002
function compose_classification_breadcrumbs($taxon_uuid) {
1003
1004 b0adfd32 Andreas Kohlbecker
  _add_js_taxonomic_children('#classification-breadcrumbs .taxonomic-children-button');
1005 d0d23caa Andreas Kohlbecker
1006 f9a3d0f6 Andreas Kohlbecker
  $render_array = array();
1007
1008
  $render_array['#theme'] = 'item_list';
1009
  $render_array['#type'] = 'ul';
1010
  $render_array['#attributes'] = array(
1011
    'id' => 'classification-breadcrumbs',
1012
    'class' => 'breadcrumbs inline',
1013
  );
1014
1015
  $items = array();
1016
1017 38da4e54 Andreas Kohlbecker
  $parent_taxon_nodes = null;
1018
  if($taxon_uuid){
1019
    $parent_taxon_nodes = cdm_ws_taxonomy_pathFromRoot($taxon_uuid);
1020
  }
1021 f9a3d0f6 Andreas Kohlbecker
1022 38da4e54 Andreas Kohlbecker
  $classifications = cdm_ws_fetch_all(CDM_WS_PORTAL_TAXONOMY);
1023
  // find current classification in list
1024
  $classification = null;
1025
  $current_classification_uuid = get_current_classification_uuid();
1026
  foreach ($classifications as $classification){
1027
    if($classification->uuid == $current_classification_uuid){
1028
      break;
1029 b0adfd32 Andreas Kohlbecker
    }
1030 38da4e54 Andreas Kohlbecker
  }
1031 b0adfd32 Andreas Kohlbecker
1032 38da4e54 Andreas Kohlbecker
  $node_name = '';
1033
  if(count($classifications) > 1 ){
1034
    // need to add the current classification as first label
1035 0af3ce28 Andreas Kohlbecker
1036
    $label = $classification->titleCache;
1037
    if(strlen($label) > 20){
1038
      $label = substr($label, 0, strpos($label, ' ', 15)) . '...';
1039
    }
1040
    $node_name = font_awesome_icon_markup('fa-th-list')  . ' ' . l($label, '#', array(
1041
      'attributes' => array(
1042
        'class' => 'taxonomic-children-button classification-chooser',
1043
        'data-destination-uri' => drupal_get_destination(),
1044
        'data-cdm-align-with' => array('prev')
1045
      ),
1046
      'html' => true
1047
    ));
1048 f9a3d0f6 Andreas Kohlbecker
  }
1049 b0adfd32 Andreas Kohlbecker
1050 38da4e54 Andreas Kohlbecker
  $rank_limit_uuid = variable_get(TAXONTREE_RANKLIMIT, TAXONTREE_RANKLIMIT_DEFAULT);
1051 0af3ce28 Andreas Kohlbecker
1052
  $rank_separator = '<span> '
1053 38da4e54 Andreas Kohlbecker
    . font_awesome_icon_markup('fa-chevron-right')
1054
    . ' </span>';
1055 0af3ce28 Andreas Kohlbecker
  $more_children_icon = font_awesome_icon_markup('fa-sitemap fa-rotate-270');
1056 69fb3dbb Andreas Kohlbecker
  $more_children_label = '...';
1057 38da4e54 Andreas Kohlbecker
1058 0af3ce28 Andreas Kohlbecker
  $items[] = $node_name;
1059 38da4e54 Andreas Kohlbecker
1060 0af3ce28 Andreas Kohlbecker
  $more_children_for = null;
1061 e3235962 Andreas Kohlbecker
  if($parent_taxon_nodes){
1062 0af3ce28 Andreas Kohlbecker
    foreach ($parent_taxon_nodes as $node) {
1063 38da4e54 Andreas Kohlbecker
1064
      $is_first_item = count($items) == 0;
1065 0af3ce28 Andreas Kohlbecker
      $is_last_item = count($items) == count($parent_taxon_nodes);
1066 38da4e54 Andreas Kohlbecker
      $node_name = cdm_dataportal_shortname_of($node);
1067
      $path = path_to_taxon($node->taxonUuid);
1068
1069 0af3ce28 Andreas Kohlbecker
      if($node->taxonomicChildrenCount > 0) {
1070
        $more_children_for = $node->taxonUuid;
1071
      } else {
1072
        $more_children_for = null;
1073 38da4e54 Andreas Kohlbecker
      }
1074
1075 0af3ce28 Andreas Kohlbecker
      // 'fa-sitemap'
1076
1077 38da4e54 Andreas Kohlbecker
      $items[] =
1078 0af3ce28 Andreas Kohlbecker
        ($is_first_item ? '' : ' ')
1079
        . $rank_separator
1080
        . l(
1081 4b3be949 Andreas Kohlbecker
          '<span class="' . html_class_attribute_ref($node) . '">' . $node_name . '</span>',
1082 0af3ce28 Andreas Kohlbecker
          $path,
1083
          array(
1084
            'attributes' => array(
1085
              'class' => array('taxonomic-children-button'),
1086
              'data-cdm-taxon-uuid' => array($node->taxonUuid),
1087
              'data-cdm-classification-mode' => array('siblings'),
1088
              'data-cdm-align-with' => array('prev')
1089 4b3be949 Andreas Kohlbecker
            ),
1090
            'html' => true
1091 0af3ce28 Andreas Kohlbecker
          )
1092
        );
1093
      }
1094 38da4e54 Andreas Kohlbecker
    }
1095 0af3ce28 Andreas Kohlbecker
1096
  // add more button to the end
1097
  if(!$parent_taxon_nodes) {
1098
    // not taxon focused yet, adding button to make  the root nodes available
1099 69fb3dbb Andreas Kohlbecker
    $items[] = '<span>'
1100
      . $more_children_icon . '&nbsp;' .
1101
      '<span class="taxonomic-children-button" data-classification-uuid="' . $current_classification_uuid
1102 53c705d4 Andreas Kohlbecker
      . '" data-rank-limit-uuid="' . $rank_limit_uuid . '" data-cdm-align-with="prev"> ' . $more_children_label . '<span>'
1103 69fb3dbb Andreas Kohlbecker
      . '</span>';
1104 0af3ce28 Andreas Kohlbecker
  } else if($more_children_for){
1105
    // last parent item has child taxon nodes
1106 69fb3dbb Andreas Kohlbecker
    $items[] = ' <span>'
1107
      . $more_children_icon . '&nbsp;' .
1108
      '<span class="taxonomic-children-button" data-cdm-taxon-uuid="' .$more_children_for
1109 53c705d4 Andreas Kohlbecker
      . '" data-cdm-classification-mode="children" data-cdm-align-with="prev"> ' . $more_children_label . '</span>'
1110 69fb3dbb Andreas Kohlbecker
      . '</span>';
1111 0af3ce28 Andreas Kohlbecker
1112 e3235962 Andreas Kohlbecker
  }
1113 b0adfd32 Andreas Kohlbecker
1114 30845bda Andreas Kohlbecker
  $render_array['#items'] = $items;
1115 0af3ce28 Andreas Kohlbecker
1116 30845bda Andreas Kohlbecker
  return $render_array;
1117
}
1118 0af3ce28 Andreas Kohlbecker
1119 69fb3dbb Andreas Kohlbecker
1120 30845bda Andreas Kohlbecker
/**
1121
 * @param $specimen_uuid
1122
 * @return array
1123
 *    The drupal render array for the page
1124
 *
1125
 * @ingroup compose
1126
 */
1127 e89c1115 Katja Luther
function compose_cdm_specimen_page($specimen_uuid)
1128 30845bda Andreas Kohlbecker
{
1129
  drupal_set_title("Specimen Details");
1130
  RenderHints::pushToRenderStack('specimen_page');
1131 f9a3d0f6 Andreas Kohlbecker
1132 78a42a9b Katja Luther
  $specimen_table = array(
1133
      '#theme' => 'table',
1134
      '#weight' => 2,
1135 2527a83c Andreas Kohlbecker
      // prefix attributes and rows with '#' to let it pass to the theme function,
1136 78a42a9b Katja Luther
      // otherwise it is handled as child render array
1137 489f7610 Katja Luther
1138
    '#attributes' => array('class' => 'specimens'),
1139 78a42a9b Katja Luther
      '#rows' => array(),
1140 93fb962c Katja Luther
      '#prefix' => '<div id="specimens">',
1141
      '#suffix' => '</div>',
1142
1143 489f7610 Katja Luther
1144 78a42a9b Katja Luther
  );
1145
  $specimen = compose_cdm_specimen_or_observation($specimen_uuid, true);
1146 44f44469 Andreas Kohlbecker
  /*
1147 961319fe Andreas Kohlbecker
  $render_array = array(
1148 78a42a9b Katja Luther
          '#theme' => 'item_list',
1149
          '#items' => array($specimen),
1150
          '#type' => 'ul');
1151 961319fe Andreas Kohlbecker
  $output = drupal_render($render_array);
1152 44f44469 Andreas Kohlbecker
 */
1153 78a42a9b Katja Luther
  $specimen_table['#rows'][] = array(
1154
          // An array of table rows. Every row is an array of cells, or an associative array
1155 961319fe Andreas Kohlbecker
          'data' => $specimen,
1156 78a42a9b Katja Luther
          'class' =>  array(
1157
              'descriptionElement',
1158
              'descriptionElement_IndividualsAssociation'
1159
          ),
1160
  );
1161 e89c1115 Katja Luther
1162
1163 78a42a9b Katja Luther
 // $detail_html = compose_cdm_specimen_or_observation($specimen_uuid, true);
1164 93fb962c Katja Luther
//    $render_array['markup'] = array(
1165
//        '#prefix' => '<div id="specimens" class="page">',
1166
//        'content' => $specimen_table,
1167
//        '#suffix' => '</div>',
1168
//    );
1169 2527a83c Andreas Kohlbecker
  $render_array['specimen_table'] =  $specimen_table;
1170 e89c1115 Katja Luther
1171 30845bda Andreas Kohlbecker
  RenderHints::popFromRenderStack();
1172 961319fe Andreas Kohlbecker
  return $specimen; // $render_array;
1173 30845bda Andreas Kohlbecker
}
1174 f9a3d0f6 Andreas Kohlbecker
1175 30845bda Andreas Kohlbecker
/**
1176
 * @param $named_area_uuid
1177
 * @return array
1178
 *    The drupal render array for the page
1179
 *
1180
 * @ingroup compose
1181
 */
1182
function compose_cdm_named_area_page($named_area_uuid)
1183
{
1184
1185
  $named_area = cdm_ws_get(CDM_WS_PORTAL_TERM, array($named_area_uuid));
1186
1187
  $render_array = array();
1188
  RenderHints::pushToRenderStack('named_area_page');
1189
1190
  $groups = array();
1191
  @_description_list_group_add($groups, t('Name') . ':', $named_area->representation_L10n);
1192
  @_description_list_group_add($groups, t('IdInVocabulary') . ':', $named_area->idInVocabulary);
1193
  if(isset($named_area->level)) {
1194
    @_description_list_group_add($groups, t('Level') . ':', $named_area->level->representation_L10n);
1195
  }
1196
1197
  $name_area_details_elements = array(
1198
   // '#title' => $title,
1199
    '#theme' => 'description_list',
1200
    '#groups' => $groups,
1201
    '#attributes' => array('class' => html_class_attribute_ref($named_area)),
1202
  );
1203
1204
  $render_array[] = $name_area_details_elements;
1205
1206
  RenderHints::popFromRenderStack();
1207
  return $render_array;
1208 f9a3d0f6 Andreas Kohlbecker
}
1209 4feeabc7 Andreas Kohlbecker
1210 57dabcba Andreas Kohlbecker
1211
/**
1212
 * Returns a drupal render array for a single reference page.
1213
 *
1214
 * Composes a page with all data on a single reference.
1215
 *
1216
 * @param string $uuid
1217
 *   An uuid for a cdm reference.
1218
 *
1219
 * @return array
1220
 *  A drupal render array
1221
 *
1222
 * @throws Exception
1223
 *
1224
 * @ingroup compose
1225
 */
1226
function compose_cdm_reference_page($uuid) {
1227
1228
  $pathelement = "reference_page";
1229
  RenderHints::pushToRenderStack($pathelement);
1230
  $reference = cdm_ws_get(CDM_WS_REFERENCE, $uuid);
1231 4d9660ef Andreas Kohlbecker
  if (!$reference) {
1232
    drupal_set_title(t('Reference does not exist'), PASS_THROUGH);
1233 de017852 Andreas Kohlbecker
    return "";
1234 4d9660ef Andreas Kohlbecker
  }
1235 57dabcba Andreas Kohlbecker
  if (isset($reference->titleCache)) {
1236
    drupal_set_title($reference->titleCache, PASS_THROUGH);
1237
  }
1238
1239
  $field_order = array(
1240
    "title",
1241
    "abbrevTitle",
1242
    // "titleCache" abbrevTitleCache
1243
    // "citation",
1244
    "authorship",
1245
    "editor",
1246
    "publisher",
1247
    "placePublished",
1248
    "datePublished",
1249
    "year",
1250
    "edition",// Class Book.
1251
    "volume",// Class Article.
1252
    "seriesPart",
1253
    "inReference",
1254
    "nomRefBase", // Class BookSection, Book, Article.
1255
    "pages",// Class Article.
1256
    "series",// Class Article, PrintSeries.
1257
    "school",// Class Thesis.
1258
    "institution",// Class Report.
1259
    "organization",// Class Proceedings.
1260
    "nextVersion",
1261
    "previousVersion",
1262
    "isbn",// Class Book.
1263
    "issn",// Class Journal.
1264
    "doi",
1265
    "uri"
1266
  );
1267
1268
  $table_rows = array();
1269
1270
  if (!isset($reference->authorship)) {
1271
    $authorship = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $reference->uuid);
1272
    $reference->authorship = isset($authorship->titleCache) ? $authorship->titleCache : '';
1273
  }
1274
1275
  if (!isset($reference->inReference)) {
1276
    $reference->inReference = cdm_ws_get(CDM_WS_REFERENCE, array(
1277
      $reference->uuid,
1278
      "inReference",
1279
    ));
1280
  }
1281
1282
  foreach ($field_order as $fieldname) {
1283
1284
    if (isset($reference->$fieldname)) {
1285
1286
      if ($fieldname == "datePublished") {
1287
        $period = $reference->$fieldname;
1288
        $datePublished = timePeriodToString($period);
1289
        if (isset($datePublished) && $datePublished != '') {
1290
          $table_rows[] = array(
1291
            t("Date published"),
1292
            $datePublished,
1293
          );
1294
        }
1295
      }
1296
      elseif ($fieldname == "doi" && is_object($reference->doi)) {
1297
        $table_rows[] = array(
1298
          t('@fieldname', array('@fieldname' => ucfirst(strtolower($fieldname)))),
1299
          cdm_doi($reference->doi, false)
1300
        );
1301
      }
1302
      elseif ($fieldname == "uri" && isset($reference->uri) && $reference->uri) {
1303
        $table_rows[] = array(
1304
          t('@fieldname', array('@fieldname' => ucfirst(strtolower($fieldname)))),
1305
          cdm_external_uri($reference->uri, false)
1306
        );
1307
      }
1308
      elseif (is_object($reference->$fieldname)) {
1309
        if ($fieldname == "authorship") {
1310
          $dump = $reference->$fieldname;
1311
          $teammembers = "teamMembers";
1312
          $team = $dump->$teammembers;
1313
          $nameArray = array();
1314
1315
          foreach ($team as $member) {
1316
            if (strlen($member->lastname) > 0) {
1317
              $nname = $member->lastname;
1318
              $name = $nname;
1319
              if (strlen($member->firstname) > 0) {
1320
                $vname = $member->firstname;
1321
                $name = $vname . " " . $nname;
1322
              }
1323
              $nameArray[] = $name;
1324
            }
1325
            else {
1326
              if (strlen($member->titleCache) > 0) {
1327
                $nameArray[] = $member->titleCache;
1328
              }
1329
            }
1330
          }
1331
          $value = join($nameArray, ", ");
1332
        }
1333
        elseif ($fieldname == "inReference") {
1334
          $type = $reference->$fieldname->type;
1335
          $value = l($reference->$fieldname->titleCache, path_to_reference($reference->$fieldname->uuid));
1336
          switch ($type) {
1337
            case "Book":
1338
              $fieldname = "in book";
1339
              break;
1340
            case "Journal":
1341
              $fieldname = "in journal";
1342
              break;
1343
            case "Proceedings":
1344
              $fieldname = "in proceedings";
1345
              break;
1346
          }
1347
        }
1348
        else {
1349
          $value = $reference->$fieldname->titleCache;
1350
        }
1351
1352
1353
        if (isset($value) && $value != '') {
1354
          $table_rows[] = array(
1355
            t('@fieldname', array('@fieldname' => ucfirst(strtolower($fieldname)))),
1356
            $value,
1357
          );
1358
        }
1359
1360
      }
1361
      else {
1362
        if (isset($reference->$fieldname) && $reference->$fieldname != '') {
1363
          $table_rows[] = array(
1364
            t('@fieldname', array('@fieldname' => ucfirst(strtolower($fieldname)))),
1365
            $reference->$fieldname,
1366
          );
1367
        }
1368
      }
1369
    }
1370
  }
1371
1372
  $out = theme_table(array(
1373
    'header' => array(),
1374
    'rows' => $table_rows,
1375
    'attributes' => array(
1376
      'class' => html_class_attribute_ref($reference)
1377
    ),
1378
    'caption' => NULL,
1379
    'colgroups' => NULL,
1380
    'sticky' => NULL,
1381
    'empty' => NULL,
1382
  ));
1383
1384
  if(isset($reference->referenceAbstract)){
1385
    $out .= '<h2 class="block-title">Abstract</h2><div class="abstract">' . $reference->referenceAbstract . '</div>';
1386
  }
1387
1388
1389
  // Annotations below the table
1390
  $annotations = cdm_fetch_visible_annotations($reference);
1391 e9cc637a Andreas Kohlbecker
  $out .= cdm_annotations($annotations);
1392 57dabcba Andreas Kohlbecker
1393
  $registration_working_set = cdm_ws_get("registrationWorkingSetDTO", array($uuid));
1394
  if($registration_working_set && count($registration_working_set->registrationDTOs) > 0){
1395
    $out .= "<h3>Nomenclatural acts:</h3><div class=\"cdm-item-list registration-item-list\">";
1396
    foreach($registration_working_set->registrationDTOs as $registration_dto){
1397
      if($registration_dto->status == "PUBLISHED"){
1398
        $registration_render_a = compose_registration_dto_compact($registration_dto, 'citation');
1399
        $registration_render_a["#prefix"] = "<div class=\"item item-registration\">";
1400
        $registration_render_a["#suffix"] = "</div>";
1401
        $out .= drupal_render($registration_render_a);
1402
      }
1403
    }
1404
    $out .= "</div>";
1405
  }
1406
1407
  RenderHints::popFromRenderStack();
1408
1409
  return markup_to_render_array($out);
1410
}
1411
1412 4feeabc7 Andreas Kohlbecker
/**
1413
 * Provides the the label string for taxon page tabs.
1414
 *
1415
 * The $tabname as passed to the method will be returned if no override
1416
 * label is configured in the settings.
1417
 */
1418
function cdm_taxonpage_tab_label($tabname) {
1419
  static $taxon_tabs_labels = null;
1420
  if($taxon_tabs_labels == null){
1421
    $taxon_tabs_labels = get_array_variable_merged(CDM_TAXONPAGE_TAB_LABELS, CDM_TAXONPAGE_TAB_LABELS_DEFAULT);
1422
  }
1423
  $tabname_key = strtolower($tabname);
1424
  if(isset($taxon_tabs_labels[$tabname_key]) && $taxon_tabs_labels[$tabname_key]){
1425
    return $taxon_tabs_labels[$tabname_key];
1426
  }
1427
  return $tabname;
1428
}