Project

General

Profile

Download (42.8 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/**
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
 * @see http://www.mozilla.org/MPL/MPL-1.1.html
14
 *
15
 * @author
16
 *   - Andreas Kohlbecker <a.kohlbecker@BGBM.org>
17
 */
18

    
19

    
20
/**
21
 * Creates a render array representing the ocurrences associetad with the $taxon.
22
 *
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
 */
33
function cdm_dataportal_taxon_page_specimens($taxon) {
34

    
35
    $render_array = array();
36
    RenderHints::pushToRenderStack('taxon_page_specimens');
37

    
38
    $relationship_choice = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
39
    $relationship_choice['direct'] = get_selection($relationship_choice['direct']);
40
    $relationship_choice['invers'] = get_selection($relationship_choice['invers']);
41

    
42
    $by_associatedtaxon_query_parameters = array(
43
        'relationshipsInvers' => implode(',', $relationship_choice['invers']),
44
        'relationships' => implode(',', $relationship_choice['direct']),
45
    );
46

    
47
    if (isset($_REQUEST['pager']) && is_array($_REQUEST['pager'])) {
48
        $by_associatedtaxon_query_parameters = array_merge($by_associatedtaxon_query_parameters, $_REQUEST['pager']);
49
    }
50

    
51
    $by_associatedtaxon_query = http_build_query($by_associatedtaxon_query_parameters);
52

    
53
    $pager = cdm_ws_get(CDM_WS_OCCURRENCE_BY_ASSOCIATEDTAXON,
54
        null,
55
        $by_associatedtaxon_query . '&taxonUuid=' . $taxon->uuid
56
    );
57

    
58
    $specimensOrObservations = array();
59
    if(isset($pager->records[0])){
60
        $specimensOrObservations =  $pager->records;
61
    }
62

    
63
    // order occurrences by date but types should be on top of the list
64
    $type_specimens = array();
65
    $other_occurrences = array();
66
    foreach ($specimensOrObservations as &$occurrence) {
67
        $typeDesignationsPager = cdm_ws_get(CDM_WS_OCCURRENCE . '/$0/specimenTypeDesignations', $occurrence->uuid);
68
        if (isset($typeDesignationsPager->count) && $typeDesignationsPager->count > 0) {
69
            $type_specimens[] = $occurrence;
70
        } else {
71
            $other_occurrences[] = $occurrence;
72
        }
73
    }
74
    $specimensOrObservations = array_merge($type_specimens, $other_occurrences);
75

    
76
    // Collect media (fieldObjectMedia, derivedUnitMedia) and add as a custom field
77
    // $occurrence->_fieldObjectMedia
78
    foreach ($specimensOrObservations as &$occurrence) {
79
        $occurrence->_fieldObjectMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array(
80
            $occurrence->uuid,
81
            'fieldObjectMedia',
82
        ));
83
        $occurrence->_derivedUnitMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array(
84
            $occurrence->uuid,
85
            'derivedUnitMedia',
86
        ));
87
    }
88

    
89
    // --- get map service HTTP query parameters
90
    if (count($specimensOrObservations) > 0) {
91
        $occurrence_queryDto = cdm_ws_get(CDM_WS_GEOSERVICE_OCCURRENCEMAP, $taxon->uuid,  $by_associatedtaxon_query);
92

    
93
      $map_visibility = variable_get(SPECIMEN_MAP_VISIBILITY, SPECIMEN_MAP_VISIBILITY_DEFAULT);
94
      if($map_visibility == 'always' ||
95
        variable_get(SPECIMEN_MAP_VISIBILITY, SPECIMEN_MAP_VISIBILITY_DEFAULT) == 'automatic' &&
96
          (isset($occurrence_queryDto->fieldUnitPoints[0]) || isset($occurrence_queryDto->derivedUnitPoints[0]))
97
        )
98
      {
99
        $occurrence_query = $occurrence_queryDto->occurrenceQuery;
100
        $legend_format_query = null;
101
        $distribution_query = NULL;
102
        $map_render_array = compose_map('specimens', $occurrence_query, $distribution_query, $legend_format_query, array());
103
      }
104
    }
105

    
106
    // -------------------------------------------------------
107
    $render_array['map'] = $map_render_array;
108

    
109
    if(variable_get('cdm_dataportal_compressed_specimen_derivate_table')){
110

    
111
        //COMPRESSED SPECIMEN DERIVATE TABLE
112
        $associatedFieldUnitsQuery_parameters = array();
113
        if (isset($_REQUEST['pager']) && is_array($_REQUEST['pager'])) {
114
            $associatedFieldUnitsQuery_parameters = array_merge($associatedFieldUnitsQuery_parameters, $_REQUEST['pager']);
115
        }
116

    
117
        $by_associatedtaxon_query = http_build_query($associatedFieldUnitsQuery_parameters);
118
        $pager_field_units = cdm_ws_get(CDM_WS_PORTAL_TAXON,
119
            array($taxon->uuid, 'associatedFieldUnits'),
120
            $by_associatedtaxon_query . '&pageSize=' . variable_get('cdm_dataportal_compressed_specimen_derivate_table_page_size')
121
        );
122

    
123
        if (isset($pager_field_units->records[0])) {
124
          $field_unit_uuids = array();
125
          foreach ($pager_field_units->records as $field_unit) {
126
            $field_unit_uuids[] = $field_unit->uuid;
127
          }
128
        }
129

    
130
        $render_array['derivate_hierarchy_table'] = compose_specimen_table($field_unit_uuids);
131

    
132
        $render_array['pager'] = markup_to_render_array(
133
            theme('cdm_pager', array(
134
                'pager' => $pager_field_units,
135
                'path' => $_REQUEST['q'],
136
                'parameters' => $_REQUEST
137
            )),
138
            10 // weight
139
        );
140
    }
141
    else{
142
        //BOTTOM-UP-SPECIMEN-TABLE
143
        // --- generate the specimen list as table
144
        $specimen_table = array(
145
            '#theme' => 'table',
146
            '#weight' => 2,
147
            // prefix attributes and rows with '#' to let it pass toF the theme function,
148
            // otherwise it is handled as child render array
149
            '#attributes' => array('class' => 'specimens'),
150
            '#rows' => array(),
151
        );
152

    
153
        if ($specimensOrObservations) {
154

    
155
            foreach ($specimensOrObservations as $specimenOrObservation) {
156

    
157
                $mediaList = array();
158
                if (is_array($specimenOrObservation->_fieldObjectMedia)) {
159
                    $mediaList = array_merge($mediaList, $specimenOrObservation->_fieldObjectMedia);
160
                }
161
                if (is_array($specimenOrObservation->_derivedUnitMedia)) {
162
                    $mediaList = array_merge($mediaList, $specimenOrObservation->_derivedUnitMedia);
163
                }
164

    
165
                // typelabel will contain the typeStatus
166
                $type_label = '';
167
                $typeDesignationPager = cdm_ws_get(CDM_WS_OCCURRENCE . '/$0/specimenTypeDesignations', $specimenOrObservation->uuid);
168
                if (isset($typeDesignationPager) and isset($typeDesignationPager->records)) {
169
                    $type_status = array();
170
                    foreach ($typeDesignationPager->records as $typeDesignation) {
171
                        if (isset($typeDesignation->typeStatus->representation_L10n)){
172
                            $type_status[] = $typeDesignation->typeStatus->representation_L10n;
173
                        }
174
                    }
175
                    $type_label = implode(', ', $type_status);
176
                    if($type_label){
177
                        $type_label .= ': ' ;
178
                    }
179
                }
180

    
181
                // --- Specimen entry as dynamic label:
182
                //     -> Dynabox for the specimenOrObservation
183
                $gallery_name = $specimenOrObservation->uuid;
184

    
185
                $derived_unit_ws_request = cdm_compose_url(CDM_WS_OCCURRENCE, array( $specimenOrObservation->uuid));
186
                $label_html = cdm_dynabox(
187
                  $specimenOrObservation->uuid,
188
                  $type_label . $specimenOrObservation->titleCache,
189
                  $derived_unit_ws_request,
190
                  'cdm_specimen_or_observation',
191
                  'Click for details',
192
                  array('div', 'div'),
193
                  array(),
194
                  null, // $content_element_selector
195
                  'function(){ jQuery(\'#media_gallery_' . $gallery_name . '\').hide(); }', // open_callback
196
                  'function(){ jQuery(\'#media_gallery_' . $gallery_name . '\').show(); }' // close_callback
197
                );
198

    
199
                // --- Render associated media.
200
                $gallery_html = '';
201
                if (count($mediaList) > 0) {
202
                    $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
203
                    $captionElements = array(
204
                        '#uri' => t('open media'),
205
                    );
206

    
207
                    $gallery_html = compose_cdm_media_gallerie(array(
208
                        'mediaList' => $mediaList,
209
                        'galleryName' => $gallery_name,
210
                        'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
211
                        'cols' => $gallery_settings['cdm_dataportal_media_cols'],
212
                        'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
213
                        'captionElements' => $captionElements,
214
                        'mediaLinkType' => 'LIGHTBOX',
215
                        'alternativeMediaUri' => NULL,
216
                        'galleryLinkUri' => NULL,
217
                    ));
218
                }
219

    
220
                $specimen_table['#rows'][] = array(
221
                    // An array of table rows. Every row is an array of cells, or an associative array
222
                    'data' => array(
223
                        // Each cell can be either a string or an associative array
224
                        $label_html . $gallery_html
225
                    ),
226
                    'class' =>  array(
227
                        'descriptionElement',
228
                        'descriptionElement_IndividualsAssociation'
229
                    ),
230
                );
231
            }
232
        }
233

    
234
        $render_array['specimen_list'] = $specimen_table;
235
        $render_array['pager'] = markup_to_render_array(
236
            theme('cdm_pager', array(
237
                'pager' => $pager,
238
                'path' => $_REQUEST['q'],
239
                'parameters' => $_REQUEST,
240
            )),
241
            10 // weight
242
        );
243
    }
244
    RenderHints::popFromRenderStack();
245
    return $render_array;
246
}
247

    
248
/**
249
 * Creates the drupal render array for the table showing all derivated which are
250
 * derive from a common gathering event.
251
 *
252
 * @param $field_unit_uuids array
253
 *  An array of uuids for cdm FieldUnit entities.
254
 *
255
 * @return array
256
 *  A drupal render array for a table
257
 *
258
 * @ingroup compose
259
 */
260
function compose_specimen_table($field_unit_uuids)
261
{
262
// get icon images
263
  $expand_icon = font_awesome_icon_markup(
264
    'fa-plus-square-o',
265
    array(
266
      'alt' => 'Show details',
267
      'class' => array('expand_icon')
268
    )
269
  );
270
  $collapse_icon = font_awesome_icon_markup(
271
    'fa-minus-square-o',
272
    array(
273
      'alt' => 'Show details',
274
      'class' => array('collapse_icon')
275
    )
276
  );
277
  $detail_image_icon = '<img title="Detail Image" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/detail_image_derivate-16x16-32.png' . '"/>';
278
  $checked_box_icon = '<img src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/step_done.gif' . '"/>';
279
  $sequence_icon = '<img title="Molecular Data" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/sequence_derivate-16x16-32.png' . '"/>';
280
  $character_data_icon = '<img title="Character Data" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/character_data_derivate-16x16-32.png' . '"/>';
281

    
282
  $rowcount = 0;
283
  $rows = array();
284

    
285
  foreach ($field_unit_uuids as $field_unit_uuid) {
286

    
287
    //get derivate hierarchy for the FieldUnit
288
    $derivateHierarchy = cdm_ws_get(CDM_WS_PORTAL_OCCURRENCE, array($field_unit_uuid, 'derivateHierarchy'));
289
    if ($derivateHierarchy) {
290
      //summary row
291
      $rows[] = array(
292
        'data' => array(
293
          array(
294
            'data' => $expand_icon . $collapse_icon,
295
            'class' => array('summary_row_cell', 'summary_row_icon', 'expand_column')
296
          ),
297
          array(
298
            'data' => $derivateHierarchy->country,
299
            'class' => array('summary_row_cell')
300
          ),
301
          array(
302
            'data' => $derivateHierarchy->date,
303
            'class' => array('summary_row_cell')
304
          ),
305
          array(
306
            'data' => $derivateHierarchy->collection,
307
            'class' => array('summary_row_cell')
308
          ),
309
          array(
310
            'data' => $derivateHierarchy->herbarium,
311
            'class' => array('summary_row_cell')
312
          ),
313
          array(
314
            'data' => $derivateHierarchy->hasType ? $checked_box_icon : "",
315
            'class' => array('summary_row_cell', 'summary_row_icon')
316
          ),
317
          array(
318
            'data' => $derivateHierarchy->hasSpecimenScan ? $checked_box_icon : "",
319
            'class' => array('summary_row_cell', 'summary_row_icon')
320
          ),
321
          array(
322
            'data' => ($derivateHierarchy->hasDna ? $sequence_icon : "") . " "
323
              . ($derivateHierarchy->hasDetailImage ? $detail_image_icon : "") . " "
324
              . ($derivateHierarchy->hasCharacterData ? $character_data_icon : ""),
325
            'class' => array('summary_row_cell', 'summary_row_icon')
326
          )
327
        ),
328
        'id' => ('derivate_summary' . $rowcount), // summary row id
329
        'class' => array('summary_row'),
330
      );
331

    
332
      //assemble field unit details
333
      $detail_html = "";
334
      // - citation
335
      if ($derivateHierarchy->citation) {
336
        $detail_html .= create_label("Citation") . $derivateHierarchy->citation . "<br>";
337
      }
338
      //assemble specimen details
339
      if ($derivateHierarchy->derivates) {
340
        foreach ($derivateHierarchy->derivates as $preservedSpecimenDTO) {
341
          $detail_html .= "<br>";
342
          $detail_html .= render_cdm_specimen_page($preservedSpecimenDTO);
343
        }
344
      }
345
      $detail_html .= "<br>";
346
      //detail row resp. one BIG detail cell
347
      $rows[] = array(
348
        'data' => array(
349
          array(
350
            'data' => "", //empty first column
351
            'class' => array('expand_column')
352
          ),
353
          array(
354
            'data' => $detail_html,
355
            'colspan' => 7,
356
          ),
357
        ),
358
        'id' => ('derivate_details' . $rowcount),//details row ID
359
        'class' => array('detail_row'),
360
      );
361
      $rowcount++;
362
    }
363
  }
364

    
365
  $tableId = "derivate_hierarchy_table";
366
  $derivateHierarchyTable = array(
367
    "#theme" => "table",
368
    "#weight" => 2,
369
    "#header" => array(
370
      array(
371
        'data' => "",
372
        'class' => array('expand_column')
373
      ),
374
      "Country", "Date", "Collector + collecting number", "Herbaria", "Type", "Scan", "Derivatives"),
375
    "#rows" => $rows,
376
    "#attributes" => array(
377
      "id" => $tableId,
378
      "border" => 2
379
    )
380
  );
381

    
382
  //add toggle functionality to derivate hierarchy table
383
  drupal_add_js_rowToggle("#" . $tableId);
384

    
385
  return $derivateHierarchyTable;
386
}
387

    
388
function create_html_link($link, $openInExternalWindow=false){
389
    $html = "";
390
    if($link->uri && $link->uri!=""){
391
        $html .= '<a  href="' . $link->uri . '"';
392
        if($openInExternalWindow){
393
            $html .= ' target="_blank"';
394
        }
395
        $html .= '>' . $link->linkText . '</a>';
396
    }
397
    else{
398
        $html .= $link->linkText;
399
    }
400
    return $html;
401
}
402

    
403
/**
404
 * Creates HTML links from the given link list concatenated by default by a comma.
405
 * @param $linkList the list with Link objects having "uri" and "linkText" as members
406
 * @return string the assembled HTML string containing the links
407
 */
408
function create_html_links($linkList, $openInExternalWindow=false, $separator=", ")
409
{
410
    $html = "";
411
    if ($linkList) {
412
        foreach ($linkList as $link) {
413
            $html .= create_html_link($link, $openInExternalWindow).$separator;
414
        }
415
        $html = rtrim($html, $separator);
416
    }
417
    return $html;
418
}
419

    
420
/**
421
 * Composes a taxon page which can consist of multiple parts like
422
 * 'General', 'Synonymy', 'Images', 'Keys'. These parts can be displayed
423
 * as tabs or as sections of a single page.
424
 *
425
 * It is headed by the name of the accepted taxon without author and reference.
426
 *
427
 * @param $taxon
428
 *   The CDM Taxon Instance to compose the page for.
429
 * @param $page_part
430
 *   Name of the part to display, valid values are:
431
 *    - 'description' -  for the general part
432
 *    - 'images'
433
 *    - 'synonymy'
434
 *    - 'keys'
435
 *    - 'all'
436
 *
437
 * @return array
438
 *   A drupal render array
439
 *
440
 * @ingroup compose
441
 */
442
function compose_cdm_taxon_page($taxon, $page_part = 'description') {
443

    
444
  // we better cache here since drupal_get_query_parameters has no internal static cache variable
445
  $http_request_params = drupal_get_query_parameters();
446

    
447
  // add all mandatory js sources
448
  _add_js_footnotes();
449

    
450

    
451
  $render_array = array();
452
  $weight = 0; // the weight for the render array elements
453

    
454
  $tabsToDisplay = variable_get('cdm_taxonpage_tabs_visibility', unserialize(TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT));
455

    
456
  $page_part = variable_get('cdm_dataportal_taxonpage_tabs', 1) ? $page_part : 'all';
457

    
458
  $synonymy_as_tab = variable_get(CDM_SYNONYMY_AS_TAB, CDM_SYNONYMY_AS_TAB_DEFAULT) === 1;
459
  if(!$synonymy_as_tab){
460
    unset($tabsToDisplay["Synonymy"]);
461
    // the synonymy is located in the general part in this case
462
    if($page_part == 'synonymy'){
463
      $page_part = 'description';
464
    }
465
  }
466

    
467
  $media = _load_media_for_taxon($taxon);
468

    
469

    
470
  if (!isset($media[0]) || ($tabsToDisplay["Images"] == '0')) {
471
    taxon_page_tabs_hidden_add('images');
472
  }
473

    
474
  // --- GET specimensOrObservations --- //
475
  $specimensOrObservations = cdm_ws_get(CDM_WS_TAXON, array( $taxon->uuid, 'specimensOrObservations'));
476

    
477
  $specimensOrObservationsCount = is_array($specimensOrObservations) ? count($specimensOrObservations) : 0;
478
  if ($specimensOrObservationsCount == 0 || ($tabsToDisplay["Specimens"] == '0')) {
479
    taxon_page_tabs_hidden_add('specimens');
480
  }
481

    
482
  // --- GET polytomousKeys --- //
483
  $polytomousKeysPager = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, NULL, "findByTaxonomicScope=$taxon->uuid");
484
  $identificationKeyCount = 0;
485
  if ($polytomousKeysPager) {
486
    $identificationKeyCount += $polytomousKeysPager->count;
487
  }
488
  if ($identificationKeyCount == 0 || ($tabsToDisplay["Keys"] == '0')) {
489
    taxon_page_tabs_hidden_add('keys');
490
  }
491

    
492
  // --- GET TaxonNodeAgentRelations --- //
493
  $current_classification_uuid = get_current_classification_uuid();
494
  $taxon_node_agent_relations_pager = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODEAGENTRELATIONS,
495
      array(
496
          $taxon->uuid,
497
          $current_classification_uuid,
498
      ),
499
      "pageSize=1&pageIndex=0"// we are only interested into the count so we are fetching only one item, o is not possible!
500
  );
501
  if (!$taxon_node_agent_relations_pager || $taxon_node_agent_relations_pager->count == 0){
502
      taxon_page_tabs_hidden_add('experts');
503
  }
504

    
505
  if (!isset($tabsToDisplay["Synonymy"]) || $tabsToDisplay["Synonymy"] == '0') {
506
    taxon_page_tabs_hidden_add('synonymy');
507
  }
508

    
509
  // -------------------------------------------- //
510

    
511
  if (variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR) && isset($_REQUEST['acceptedFor'])) {
512
    $render_array['accepted_for'] = markup_to_render_array(cdm_accepted_for($_REQUEST['acceptedFor']), $weight++);
513
  }
514

    
515
  // --- PAGE PART: DESCRIPTION --- //
516
  if (!taxon_page_tabs_hidden_check('description') && ($page_part == 'description' || $page_part == 'all')) {
517

    
518
    $merged_tree = merged_taxon_feature_tree($taxon);
519

    
520

    
521
    $render_array['general'] = compose_cdm_taxon_page_profile($taxon, $merged_tree, $media, !$synonymy_as_tab);
522
    $render_array['general']['#weight'] = $weight++;
523
    $render_array['general']['#prefix'] = '<div id="general" class="page-part">';
524
    $render_array['general']['#suffix'] = '</div>';
525
  }
526

    
527
  // --- PAGE PART: IMAGES --- //
528
  if (!taxon_page_tabs_hidden_check('images') && ($page_part == 'images' || $page_part == 'all')) {
529
    $images_html = '<div id="images" class="page-part">';
530
    if ($page_part == 'all') {
531
      $images_html .= '<h2>' . t(cdm_taxonpage_tab_label('Images')) . '</h2>';
532
    }
533
    // Get the image gallery as configured by the admin.
534
    $default_image_gallery = 'default';
535
    $configured_image_gallery_viewer = variable_get('image_gallery_viewer', 'default');
536
    $taxon_image_gallery = '<div class="error">No image gallery viewer configured</div>';
537
    if($configured_image_gallery_viewer == $default_image_gallery || $configured_image_gallery_viewer == 'fsi'){
538
      // the fsi_gallery requires a flash plugin, in case the client browser is not supporting
539
      // flash we also need to provide an the default gallery as alternative
540
      $taxon_image_gallery = '<div id="default-gallery-viewer">' .
541
        call_user_func_array('taxon_image_gallery_' . $default_image_gallery, array(
542
          $taxon,
543
          $media,
544
        ))
545
        . '</div>';
546
    }
547
    if($configured_image_gallery_viewer == 'fsi'){
548
      $taxon_image_gallery .= '<div id="'. $configured_image_gallery_viewer .'-gallery-viewer">' .
549
        call_user_func_array('taxon_image_gallery_' . $configured_image_gallery_viewer, array(
550
          $taxon,
551
          $media,
552
        ))
553
       . '</div>';
554
    }
555
    $images_html .= $taxon_image_gallery;
556
    $images_html .= '</div>';
557
    $render_array['images'] = markup_to_render_array($images_html, $weight++);
558
  }
559

    
560
  // --- PAGE PART: SYNONYMY --- //
561
  if (!taxon_page_tabs_hidden_check('synonymy') && (($page_part == 'synonymy' || $page_part == 'all') && $synonymy_as_tab)) {
562
    $synonymy_html = '<div id="synonymy" class="page-part">';
563
    if ($page_part == 'all') {
564
      $synonymy_html .= '<h2>' . t(cdm_taxonpage_tab_label('Synonymy')) . '</h2>';
565
    }
566
    $addAcceptedTaxon = variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE);
567

    
568
    $synonymy_html .= theme('cdm_taxon_page_synonymy', array('taxon' => $taxon, 'addAcceptedTaxon' => $addAcceptedTaxon));
569

    
570
    $synonymy_html .= '</div>';
571
    $render_array['synonymy'] = markup_to_render_array($synonymy_html, $weight++);
572

    
573
  }
574

    
575
  // --- PAGE PART: SPECIMENS --- //
576
  if (!taxon_page_tabs_hidden_check('specimens') && ($specimensOrObservationsCount > 0 && ($page_part == 'specimens' || $page_part == 'all'))) {
577
    $render_array['specimens'] = array(
578
        '#prefix' => '<div id="specimens" class="page-part">' . ($page_part == 'all' ? '<h2>' . t(cdm_taxonpage_tab_label('Specimens')) . '</h2>' : ''),
579
        'content' => cdm_dataportal_taxon_page_specimens($taxon), // returns render array
580
        '#suffix' => '</div>',
581
    );
582
  }
583

    
584
  // --- PAGE PART: KEYS --- //
585
  if(!taxon_page_tabs_hidden_check('keys')){
586
    if ($identificationKeyCount == 1 && $page_part == 'keys'){
587
      drupal_goto(path_to_key($polytomousKeysPager->records[0]->class, $polytomousKeysPager->records[0]->uuid));
588
    }
589
    else if ($identificationKeyCount > 0 && ($page_part == 'keys' || $page_part == 'all')) {
590
      $keys_html = '<div id="keys" class="page-part">';
591
      if ($page_part == 'all') {
592
        $keys_html .= '<h2>' . t(cdm_taxonpage_tab_label('Keys')) . '</h2>';
593
      }
594
      $keys_html .= theme('cdm_block_IdentificationKeys', array('taxonUuid' => $taxon->uuid));
595
      $keys_html .= '</div>';
596
      $render_array['keys'] = markup_to_render_array($keys_html, $weight++);
597
    }
598
  }
599

    
600
  // --- PAGE PART: EXPERTS --- //
601

    
602
  if (!taxon_page_tabs_hidden_check('experts') && ($page_part == 'experts' || $page_part == 'all')) {
603
    $render_array['experts'] = array(
604
        '#prefix' => '<div id="experts" class="page-part">' . ($page_part == 'all' ? '<h2>' . t(cdm_taxonpage_tab_label('Experts')) . '</h2>' : ''),
605
        'content' => compose_cdm_taxon_page_experts($taxon), // returns render array
606
        '#suffix' => '</div>',
607
    );
608
  }
609

    
610
  // ------------------ END OF PARTS -------------- //
611

    
612
  // adjust weights of page and toc elements according to the settings
613
  $taxontabs_weights = get_array_variable_merged(CDM_TAXONPAGE_TAB_WEIGHT, CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
614
  foreach($taxontabs_weights as $tab_key => $weight){
615
    if(isset($render_array[$tab_key])){
616
      $render_array[$tab_key]['#weight'] = $weight;
617
    }
618
  }
619

    
620

    
621
  // set up the TOC for the pages which contain all pageparts
622
  if($page_part == 'all') {
623

    
624
    asort($taxontabs_weights);
625
    foreach(array_keys($taxontabs_weights) as $tab_key){
626
      if(isset($render_array[$tab_key])){
627
        if($tab_key != 'general'){
628
          // add entry for page part
629
          $toc_elements[] = array(
630
              'data' => l(t(cdm_taxonpage_tab_label(ucfirst($tab_key))), $_GET['q'], array('fragment' => $tab_key, 'query' => $http_request_params)),
631
              'class' => array('page-part-toc-item-' . $tab_key)
632
          );
633
        } else {
634
          // add content of profile part instead
635
          if(isset($render_array['general'])) {
636
            // in case all tabs are shown at once the feature tocs
637
            // should be integrated into the tabs toc as sub list
638
            // and the profile image should be on top of the page
639
            if(isset($render_array['general']['taxon_description_feature_toc'])){;
640
            foreach ($render_array['general']['taxon_description_feature_toc']['#items'] as $profile_toc_item){
641
              $toc_elements[] = $profile_toc_item;
642
            }
643
            unset($render_array['general']['taxon_description_feature_toc']);
644
            }
645
          }
646
        }
647
      }
648
    }
649

    
650
    // move profile image in page structure
651
    if(isset($render_array['general']['taxon_profile_image'])){
652
      $render_array['profile_image'] = $render_array['general']['taxon_profile_image'];
653
      $render_array['profile_image']['#weight'] = -100;
654
      unset($render_array['general']['taxon_profile_image']);
655
    }
656

    
657
    // finally add the table of contents to the render array
658
    $render_array['toc'] = array(
659
        '#theme' => 'item_list',
660
        '#items' => $toc_elements,
661
        '#title' => t('Content'),
662
        '#weight' => -101,
663
        '#suffix' => '</div>',
664
        '#prefix'=> '<div id="page-toc">'
665
    );
666
  }
667

    
668

    
669
  return $render_array;
670
}
671

    
672
/**
673
 * TODO should this function really be a compose function?
674
 *     For a compose function must there always be a theme function with the same name? (ak 8.8.2013)
675
 *
676
 * composes and returns an render array containing the components of the taxon profile tab:
677
 *  - 'taxon_profile_image'
678
 *  - 'taxon_description_feature_toc'
679
 *  - 'taxon_description_features'
680
 *
681
 *
682
 * @param object taxon
683
 * @param object $merged_tree
684
 * @param object media
685
 * @param bool $add_synonymy
686
 *
687
 * @return array
688
 *   A Drupal render array with the following elements:
689
 *     - 'taxon_profile_image'
690
 *     - 'taxon_description_feature_toc'
691
 *     - 'taxon_description_features'
692
 *
693
 * @throws Exception
694
 *
695
 * @ingroup compose
696
 */
697
function compose_cdm_taxon_page_profile($taxon, $merged_tree, $media, $add_synonymy) {
698

    
699
  $render_array = array();
700

    
701
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
702

    
703
  $hide_taxon_profile_image = FALSE;
704
  if (variable_get('image_hide_rank', '0') != '0' && isset($taxon->name->rank->uuid)) {
705
    $rankCompare = rank_compare($taxon->name->rank->uuid, variable_get('image_hide_rank', '-99'));
706
    $hide_taxon_profile_image = ($rankCompare > -1);
707
  }
708

    
709
  if ($taxon_profile_image_settings['show'] && !$hide_taxon_profile_image) {
710

    
711
    $representationPart = new stdClass();
712
    $attributes = array();
713
    if (isset($media[0])) {
714
      // due to a bug the portal/taxon/{uuid}/media service only delivers a filtered media object
715
      // which only contains the thumbnail representation even if the height and width filters are not set.
716
      // -->
717
      $preferred_media = cdm_ws_get(CDM_WS_MEDIA, $media[0]->uuid);
718
      $preferred_representations = cdm_preferred_media_representations($preferred_media, array(
719
        'image/jpg',
720
        'image/jpeg',
721
        'image/png',
722
        'image/gif',
723
      ),
724
        $taxon_profile_image_settings['maxextend'],
725
        $taxon_profile_image_settings['maxextend']
726
      );
727
      if(count($preferred_representations) > 0){
728

    
729
        $representation = array_shift($preferred_representations);
730
        $representationPart = $representation->parts[0];
731
        $attributes['alt'] = $representationPart->uri;
732

    
733
        if (!empty($taxon_profile_image_settings['media_uri_query'])) {
734
          $representationPart->uri = $representationPart->uri
735
            . (strpos($representationPart->uri, '?') !== FALSE ? '&' : '?')
736
            . $taxon_profile_image_settings['media_uri_query'];
737
        }
738
      }
739
    }
740
    else {
741
      if ($taxon_profile_image_settings['custom_placeholder_enabled']) {
742
        // show placeholder image instead
743
        if (!empty($taxon_profile_image_settings['custom_placeholder_image_on']) && !empty($taxon_profile_image_settings['custom_placeholder_image_fid'])) {
744
          // use the user provided image
745
          $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
746
          $url = file_create_url($profile_image_file->uri);
747
          $image_info = image_get_info($profile_image_file->uri);
748
          $representationPart->width = $image_info['width'];
749
          $representationPart->height = $image_info['height'];
750
          $representationPart->uri = $url;
751
        }
752
        else {
753
          // use the hard coded default
754
          $representationPart->width = 184;
755
          $representationPart->height = 144;
756
          $representationPart->uri = base_path() . drupal_get_path('module',
757
              'cdm_dataportal') . '/images/no_picture.png';
758
        }
759
        $attributes['alt'] = "no image available";
760
      }
761
    }
762

    
763
    if (isset($representationPart->uri)) {
764
      $profile_image = cdm_media_gallerie_image($representationPart, $taxon_profile_image_settings['maxextend'], FALSE, $attributes);
765
      // NOTE: style="width:${maxextend}px' is needed for IE8 !!!
766
      $render_array['taxon_profile_image'] = markup_to_render_array('<div id="taxonProfileImage" style="width:' . $taxon_profile_image_settings['maxextend'] . 'px">' . $profile_image . '</div>',
767
        -101);
768
    }
769
  }
770

    
771
  if($add_synonymy){
772
    $render_array['synonymy'] = markup_to_render_array(
773
      theme('cdm_taxon_page_synonymy', array('taxon' => $taxon, 'addAcceptedTaxon' => true)),
774
      -102
775
    );
776
  }
777

    
778
  $pseudo_feature_blocks = array();
779
  $pseudo_feature_block_toc_items = array();
780

    
781

    
782
  // Render the sections for each real feature
783
  $feature_block_list = make_feature_block_list($merged_tree->root->childNodes, $taxon);
784

    
785
  // Bibliography
786
  $bibliography_settings = get_bibliography_settings();
787
  if($bibliography_settings['enabled'] == 1){
788
    $feature_bibliography = make_pseudo_feature('Bibliography', 'BIBLIOGRAPHY');
789
    $bibliography_block = feature_block(t('Bibliography'), $feature_bibliography);
790
    $bibliography_item = markup_to_render_array(FootnoteManager::renderFootnoteList('BIBLIOGRAPHY', ''));
791
    $bibliography_block->content[] = compose_feature_block_wrap_elements(array($bibliography_item), $feature_bibliography);
792

    
793
    if(!empty($bibliography_block->content)){
794
      $pseudo_feature_block_toc_items['Bibliography']= 'bibliography';
795
      $pseudo_feature_blocks[] = $bibliography_block;
796
    }
797
  }
798

    
799
  $render_array['taxon_description_features'] = _block_get_renderable_array(
800
    array_merge($feature_block_list, $pseudo_feature_blocks)
801
  );
802

    
803
  if($pseudo_feature_block_toc_items){
804
    foreach ($pseudo_feature_block_toc_items as $label=>$fragment){
805
      cdm_toc_list_add_item($label, $fragment);
806
    }
807
  }
808

    
809
  // create the table of content
810
  $toc = array(
811
      '#theme' => 'item_list',
812
    '#items' => cdm_toc_list(),
813
      '#title' => t('Content'),
814
    '#weight' => -100,                  // move to the top
815
      '#suffix' => '</div>',
816
      '#prefix'=> '<div id="page-toc">'
817
  );
818
  $render_array['taxon_description_feature_toc'] = $toc;
819

    
820
  return $render_array;
821
}
822

    
823
/**
824
 * composes and returns an render array for the experts associated with the given taxon
825
 *
826
 * @param object taxon
827
 *
828
 * @return array
829
 *   A Drupal render array for a table with the experts
830
 *
831
 * @ingroup compose
832
 */
833
function compose_cdm_taxon_page_experts($taxon){
834

    
835
  $render_array = array();
836
  if(!isset($taxon->uuid)){
837
    return $render_array;
838
  }
839

    
840
  $current_classification_uuid = get_current_classification_uuid();
841
  // TODO use cdm_ws_fetchall below but this failes! needs fix!
842
  $taxon_node_agent_relations = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODEAGENTRELATIONS,
843
    array(
844
      $taxon->uuid,
845
      $current_classification_uuid
846
    )
847
  );
848

    
849
  $header = array(
850
    array('data' => t('Expert')),
851
    array('data' => t('Role'))
852
  );
853
  $rows = array();
854

    
855

    
856
  foreach($taxon_node_agent_relations->records as $taxon_node_agent_relation){
857

    
858

    
859
    $expert_role_id = $taxon_node_agent_relation->agent->uuid . '-' . $taxon_node_agent_relation->type->uuid;
860
    $expert_details_container_id = 'expert_details_' . $expert_role_id;
861

    
862
    $agent_label_markup = cdm_dynabox(
863
      'expert_' . $expert_role_id,
864
      $taxon_node_agent_relation->agent->titleCache,
865
      // specifying both ends of the relationship will return only one record in the pager
866
      cdm_compose_url(CDM_WS_PORTAL_AGENT,
867
         array($taxon_node_agent_relation->agent->uuid, 'taxonNodeAgentRelations'),
868
        'taxon_uuid=' . $taxon->uuid . '&relType_uuid=' . $taxon_node_agent_relation->type->uuid),
869
      'cdm_taxon_expert',
870
      'Click for details',
871
      array('div', 'div'),
872
      array(), // attributes
873
      '#' . $expert_details_container_id // $content_element_selector
874
    );
875

    
876
    // Expert and Role
877
    $rows[] = array(
878
      'data' => array(
879
        array(
880
          'data' => $agent_label_markup,
881
          'class' => array(html_class_attribute_ref($taxon_node_agent_relation->agent))
882
        ),
883
        array(
884
          'data' => $taxon_node_agent_relation->type->representation_L10n,
885
          'class' => array(html_class_attribute_ref($taxon_node_agent_relation->type))
886
        )
887
      )
888
    );
889
    // Agent details
890
    $rows[] = array(
891
      'data' => array(
892
        array(
893
          'data' => '<!-- expert_details_container -->',
894
          'id' => $expert_details_container_id,
895
          'colspan' => 2
896
        )
897
      )
898
    );
899

    
900
  }
901

    
902

    
903
  $render_array['experts_table'] = array(
904
    '#theme' => 'table',
905
    '#header' => $header,
906
    '#rows' => $rows,
907
  );
908

    
909

    
910
  return $render_array;
911
}
912

    
913

    
914
/**
915
 * Manages the tabs to be hidden in the taxon page.
916
 *
917
 * The tabs are identified by their last menu link path element:
918
 *  - description
919
 *  - synonymy
920
 *  - images
921
 *  - specimens
922
 *  - key
923
 *
924
 * Internally the tabs are stored in a static variable which is
925
 * managed by drupal_static().
926
 *
927
 * @param string $add_tab
928
 *   Optional parameter. The given string will be added to the array of tabs
929
 *
930
 * @return
931
 *   The array of tabs
932
 */
933
function taxon_page_tabs_hidden_add($add_tab = NULL) {
934
  $tabs = &drupal_static('taxon_page_tabs_hidden');
935

    
936
  if(!isset($tabs)){
937
    $tabs = array();
938
  }
939

    
940
  if (isset($add_tab) && !array_key_exists($add_tab, $tabs)) {
941
    $tabs[] = $add_tab;
942
  }
943

    
944
  return $tabs;
945
}
946

    
947
/**
948
 * Manages the tabs to be hidden in the taxon page.
949
 *
950
 * The tabs names are identified by their last menu link path element:
951
 *  - description
952
 *  - synonymy
953
 *  - images
954
 *  - specimens
955
 *  - key
956
 *
957
 * Internally the tabs are stored in a static variable which is
958
 * managed by drupal_static().
959
 *
960
 * @param string $tabname
961
 *   The name of the tab to check
962
 *
963
 * @return boolean
964
 *   True if the tab or section is to be hidden
965
 */
966
function taxon_page_tabs_hidden_check($tabname) {
967

    
968
  $tabs = &drupal_static('taxon_page_tabs_hidden');
969

    
970
  if(!isset($tabs)){
971
    $tabs = array();
972
  }
973

    
974
  return array_search($tabname, $tabs) !== FALSE;
975
}
976

    
977
/**
978
 * Implements the hook_preprocess_HOOK() for theme_menu_local_tasks()
979
 *
980
 *  - Removes the tabs to be hidden, @see taxon_page_tabs_hidden_add()
981
 *  - Renames tabs according to the settings // TODO (this will replace the theme_cdm_taxonpage_tab() function !!!)
982
 *
983
 * @param array $variables
984
 *   The variables array
985
 */
986
function cdm_dataportal_preprocess_menu_local_tasks(&$variables) {
987

    
988
  $hidden_tabs = taxon_page_tabs_hidden_add();
989

    
990
  if (is_array($variables['primary'])) {
991
    foreach ($variables['primary'] as $key => &$element) {
992

    
993
      // 1. Remove the tabs to be hidden
994
      foreach ($hidden_tabs as $tab) {
995
        if ($element['#link']['path'] == 'cdm_dataportal/taxon/%/' . $tab) {
996
          // remove the tab
997
          unset($variables['primary'][$key]);
998
        }
999
      }
1000
    }
1001
  }
1002
}
1003

    
1004

    
1005

    
1006
/**
1007
 * Implements the hook_preprocess_HOOK() for theme_menu_local_task()
1008
 *
1009
 *
1010
 * @param array $variables
1011
 *   An associative array containing:
1012
 *     - element: A render element containing:
1013
 *          #link: A menu link array with 'title', 'href', and 'localized_options' keys.
1014
 *          #active: A boolean indicating whether the local task is active.
1015
 *
1016
 */
1017
function cdm_dataportal_preprocess_menu_local_task(&$variables) {
1018

    
1019
  $link = $variables['element']['#link'];
1020
  if (preg_match('/cdm_dataportal\/.*\/refresh$/', $link['href'])) {
1021
    $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']) . '"/>';
1022
    $link['localized_options']['html'] = TRUE;
1023

    
1024
    $variables['element']['#link'] = $link;
1025
  }
1026
}
1027

    
1028
/* =================== block composition ===================== */
1029

    
1030
/**
1031
 * Composes and returns an render array for the classification breadcrumbs of the given taxon.
1032
 *
1033
 * @param taxon
1034
 *
1035
 * @return array
1036
 *   A Drupal render array for a table with the experts
1037
 *
1038
 * @ingroup compose
1039
 */
1040
function compose_classification_breadcrumbs($taxon_uuid) {
1041

    
1042
  _add_js_taxonomic_children('#classification-breadcrumbs .taxonomic-children-button');
1043

    
1044
  $render_array = array();
1045

    
1046
  $render_array['#theme'] = 'item_list';
1047
  $render_array['#type'] = 'ul';
1048
  $render_array['#attributes'] = array(
1049
    'id' => 'classification-breadcrumbs',
1050
    'class' => 'breadcrumbs inline',
1051
  );
1052

    
1053
  $items = array();
1054

    
1055
  $parent_taxon_nodes = null;
1056
  if($taxon_uuid){
1057
    $parent_taxon_nodes = cdm_ws_taxonomy_pathFromRoot($taxon_uuid);
1058
  }
1059

    
1060
  $classifications = cdm_ws_fetch_all(CDM_WS_PORTAL_TAXONOMY);
1061
  // find current classification in list
1062
  $classification = null;
1063
  $current_classification_uuid = get_current_classification_uuid();
1064
  foreach ($classifications as $classification){
1065
    if($classification->uuid == $current_classification_uuid){
1066
      break;
1067
    }
1068
  }
1069

    
1070
  $node_name = '';
1071
  if(count($classifications) > 1 ){
1072
    // need to add the current classification as first label
1073

    
1074
    $label = $classification->titleCache;
1075
    if(strlen($label) > 20){
1076
      $label = substr($label, 0, strpos($label, ' ', 15)) . '...';
1077
    }
1078
    $node_name = font_awesome_icon_markup('fa-th-list')  . ' ' . l($label, '#', array(
1079
      'attributes' => array(
1080
        'class' => 'taxonomic-children-button classification-chooser',
1081
        'data-destination-uri' => drupal_get_destination(),
1082
        'data-cdm-align-with' => array('prev')
1083
      ),
1084
      'html' => true
1085
    ));
1086
  }
1087

    
1088
  $rank_limit_uuid = variable_get(TAXONTREE_RANKLIMIT, TAXONTREE_RANKLIMIT_DEFAULT);
1089

    
1090
  $rank_separator = '<span> '
1091
    . font_awesome_icon_markup('fa-chevron-right')
1092
    . ' </span>';
1093
  $more_children_icon = font_awesome_icon_markup('fa-sitemap fa-rotate-270');
1094
  $more_children_label = '...';
1095

    
1096
  $items[] = $node_name;
1097

    
1098
  $more_children_for = null;
1099
  if($parent_taxon_nodes){
1100
    foreach ($parent_taxon_nodes as $node) {
1101

    
1102
      $is_first_item = count($items) == 0;
1103
      $is_last_item = count($items) == count($parent_taxon_nodes);
1104
      $node_name = cdm_dataportal_shortname_of($node);
1105
      $path = path_to_taxon($node->taxonUuid);
1106

    
1107
      if($node->taxonomicChildrenCount > 0) {
1108
        $more_children_for = $node->taxonUuid;
1109
      } else {
1110
        $more_children_for = null;
1111
      }
1112

    
1113
      // 'fa-sitemap'
1114

    
1115
      $items[] =
1116
        ($is_first_item ? '' : ' ')
1117
        . $rank_separator
1118
        . l(
1119
          '<span class="' . html_class_attribute_ref($node) . '">' . $node_name . '</span>',
1120
          $path,
1121
          array(
1122
            'attributes' => array(
1123
              'class' => array('taxonomic-children-button'),
1124
              'data-cdm-taxon-uuid' => array($node->taxonUuid),
1125
              'data-cdm-classification-mode' => array('siblings'),
1126
              'data-cdm-align-with' => array('prev')
1127
            ),
1128
            'html' => true
1129
          )
1130
        );
1131
      }
1132
    }
1133

    
1134
  // add more button to the end
1135
  if(!$parent_taxon_nodes) {
1136
    // not taxon focused yet, adding button to make  the root nodes available
1137
    $items[] = '<span>'
1138
      . $more_children_icon . '&nbsp;' .
1139
      '<span class="taxonomic-children-button" data-classification-uuid="' . $current_classification_uuid
1140
      . '" data-rank-limit-uuid="' . $rank_limit_uuid . '" data-cdm-align-with="prev"> ' . $more_children_label . '<span>'
1141
      . '</span>';
1142
  } else if($more_children_for){
1143
    // last parent item has child taxon nodes
1144
    $items[] = ' <span>'
1145
      . $more_children_icon . '&nbsp;' .
1146
      '<span class="taxonomic-children-button" data-cdm-taxon-uuid="' .$more_children_for
1147
      . '" data-cdm-classification-mode="children" data-cdm-align-with="prev"> ' . $more_children_label . '</span>'
1148
      . '</span>';
1149

    
1150
  }
1151

    
1152
  $render_array['#items'] = $items;
1153

    
1154
  return $render_array;
1155
}
1156

    
1157

    
1158
/**
1159
 * @param $specimen_uuid
1160
 * @return array
1161
 *    The drupal render array for the page
1162
 *
1163
 * @ingroup compose
1164
 */
1165
function compose_cdm_specimen_page($specimen_uuid)
1166
{
1167
  drupal_set_title("Specimen Details");
1168
  $specimen = cdm_ws_get(CDM_WS_PORTAL_OCCURRENCE, array($specimen_uuid, 'specimenDerivates'));
1169

    
1170
  $render_array = array();
1171
  RenderHints::pushToRenderStack('specimen_page');
1172

    
1173
  $detail_html = render_cdm_specimen_page($specimen, true);
1174
  $render_array['specimen_html'] = array(
1175
    '#markup' => $detail_html
1176
  );
1177

    
1178
  RenderHints::popFromRenderStack();
1179
  return $render_array;
1180
}
1181

    
1182
/**
1183
 * @param $named_area_uuid
1184
 * @return array
1185
 *    The drupal render array for the page
1186
 *
1187
 * @ingroup compose
1188
 */
1189
function compose_cdm_named_area_page($named_area_uuid)
1190
{
1191

    
1192
  $named_area = cdm_ws_get(CDM_WS_PORTAL_TERM, array($named_area_uuid));
1193

    
1194
  $render_array = array();
1195
  RenderHints::pushToRenderStack('named_area_page');
1196

    
1197
  $groups = array();
1198
  @_description_list_group_add($groups, t('Name') . ':', $named_area->representation_L10n);
1199
  @_description_list_group_add($groups, t('IdInVocabulary') . ':', $named_area->idInVocabulary);
1200
  if(isset($named_area->level)) {
1201
    @_description_list_group_add($groups, t('Level') . ':', $named_area->level->representation_L10n);
1202
  }
1203

    
1204
  $name_area_details_elements = array(
1205
   // '#title' => $title,
1206
    '#theme' => 'description_list',
1207
    '#groups' => $groups,
1208
    '#attributes' => array('class' => html_class_attribute_ref($named_area)),
1209
  );
1210

    
1211
  $render_array[] = $name_area_details_elements;
1212

    
1213
  RenderHints::popFromRenderStack();
1214
  return $render_array;
1215
}
1216

    
1217
/**
1218
 * Provides the the label string for taxon page tabs.
1219
 *
1220
 * The $tabname as passed to the method will be returned if no override
1221
 * label is configured in the settings.
1222
 */
1223
function cdm_taxonpage_tab_label($tabname) {
1224
  static $taxon_tabs_labels = null;
1225
  if($taxon_tabs_labels == null){
1226
    $taxon_tabs_labels = get_array_variable_merged(CDM_TAXONPAGE_TAB_LABELS, CDM_TAXONPAGE_TAB_LABELS_DEFAULT);
1227
  }
1228
  $tabname_key = strtolower($tabname);
1229
  if(isset($taxon_tabs_labels[$tabname_key]) && $taxon_tabs_labels[$tabname_key]){
1230
    return $taxon_tabs_labels[$tabname_key];
1231
  }
1232
  return $tabname;
1233
}
(7-7/10)