Project

General

Profile

Download (45 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
    $ws_string = 'specimensOrObservation';
54
    if (variable_get('cdm_dataportal_specimen_derivate_tree')){
55
        $ws_string .= "DTOs";
56
    }else{
57
        $ws_string .= "s";
58
    }
59

    
60
    $specimensOrObservations = cdm_ws_get(CDM_WS_TAXON, array( $taxon->uuid, $ws_string));
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

    
72
    // order occurrences by date but types should be on top of the list
73
    $type_specimens = array();
74
    $other_occurrences = array();
75
    foreach ($specimensOrObservations as $occurrence) {
76
        $typeDesignationsPager = cdm_ws_get(CDM_WS_OCCURRENCE . '/$0/specimenTypeDesignations', $occurrence->uuid);
77
        if (isset($typeDesignationsPager->count) && $typeDesignationsPager->count > 0) {
78
            $type_specimens[] = $occurrence;
79
        } else {
80
            $other_occurrences[] = $occurrence;
81
        }
82
    }
83
    $specimensOrObservations = array_merge($type_specimens, $other_occurrences);
84

    
85
    // Collect media (fieldObjectMedia, derivedUnitMedia) and add as a custom field
86
     $occurrence->_fieldObjectMedia;
87
    foreach ($specimensOrObservations as &$occurrence) {
88
        $occurrence->_fieldObjectMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array(
89
            $occurrence->uuid,
90
            'fieldObjectMediaDTO',
91
        ));
92
        $occurrence->_derivedUnitMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array(
93
            $occurrence->uuid,
94
            'derivedUnitMedia',
95
        ));
96
    }
97

    
98
    // --- get map service HTTP query parameters
99

    
100
    if (count($specimensOrObservations) > 0) {
101
        if (count($specimensOrObservations) > 0) {
102
            $occurrence_queryDto = cdm_ws_get(CDM_WS_GEOSERVICE_OCCURRENCEMAP, $taxon->uuid,  $by_associatedtaxon_query);
103

    
104
            $map_visibility = variable_get(SPECIMEN_MAP_VISIBILITY, SPECIMEN_MAP_VISIBILITY_DEFAULT);
105
            if($map_visibility == 'always' ||
106
                variable_get(SPECIMEN_MAP_VISIBILITY, SPECIMEN_MAP_VISIBILITY_DEFAULT) == 'automatic' &&
107
                (isset($occurrence_queryDto->fieldUnitPoints[0]) || isset($occurrence_queryDto->derivedUnitPoints[0]))
108
            )
109
            {
110
                $occurrence_query = $occurrence_queryDto->occurrenceQuery;
111
                $legend_format_query = null;
112
                $distribution_query = NULL;
113
                $map_render_array = compose_map('specimens', $occurrence_query, $distribution_query, $legend_format_query, array());
114
            }
115
        }
116
    }
117

    
118
    // -------------------------------------------------------
119
    $render_array['map'] = $map_render_array;
120

    
121
    if(variable_get('cdm_dataportal_compressed_specimen_derivate_table')){
122

    
123
        //COMPRESSED SPECIMEN DERIVATE TABLE
124
        $associatedFieldUnitsQuery_parameters = array();
125
        if (isset($_REQUEST['pager']) && is_array($_REQUEST['pager'])) {
126
            $associatedFieldUnitsQuery_parameters = array_merge($associatedFieldUnitsQuery_parameters, $_REQUEST['pager']);
127
        }
128

    
129
        $by_associatedtaxon_query = http_build_query($associatedFieldUnitsQuery_parameters);
130
        $pager_field_units = cdm_ws_get(CDM_WS_PORTAL_TAXON,
131
            array($taxon->uuid, 'associatedFieldUnits'),
132
            $by_associatedtaxon_query . '&pageSize=' . variable_get('cdm_dataportal_compressed_specimen_derivate_table_page_size')
133
        );
134

    
135
        if (isset($pager_field_units->records[0])) {
136
          $field_unit_uuids = array();
137
          foreach ($pager_field_units->records as $field_unit) {
138
            $field_unit_uuids[] = $field_unit->uuid;
139
          }
140
        }
141

    
142
        $render_array['derivate_hierarchy_table'] = compose_specimen_table($field_unit_uuids);
143

    
144
        $render_array['pager'] = markup_to_render_array(
145
            theme('cdm_pager', array(
146
                'pager' => $pager_field_units,
147
                'path' => $_REQUEST['q'],
148
                'parameters' => $_REQUEST
149
            )),
150
            10 // weight
151
        );
152
    }
153
    else if(variable_get('cdm_dataportal_specimen_derivate_tree')){
154
        $specimen_table = array(
155
            '#theme' => 'table',
156
            '#weight' => 2,
157
            // prefix attributes and rows with '#' to let it pass toF the theme function,
158
            // otherwise it is handled as child render array
159
            '#attributes' => array('class' => 'specimens'),
160
            '#rows' => array(),
161
        );
162
        $specimen_array = create_specimen_array($specimensOrObservations);
163

    
164
        foreach($specimen_array as $value){
165
            $renderArray = array(
166
                '#theme' => 'item_list',
167
                '#items' => array($value),
168
                '#type' => 'ul');
169
            $output = drupal_render($renderArray);
170
            $specimen_table['#rows'][] = array(
171
                // An array of table rows. Every row is an array of cells, or an associative array
172
                'data' => array($output),
173
                'class' =>  array(
174
                    'descriptionElement',
175
                    'descriptionElement_IndividualsAssociation'
176
                ),
177
            );
178
        }
179

    
180
        $render_array['specimen_list'] = $specimen_table;
181
      //  $render_array['specimen_list'] = $specimen_array;
182

    
183
    }
184
    else{
185
        //BOTTOM-UP-SPECIMEN-TABLE
186
        // --- generate the specimen list as table
187
        $specimen_table = array(
188
            '#theme' => 'table',
189
            '#weight' => 2,
190
            // prefix attributes and rows with '#' to let it pass toF the theme function,
191
            // otherwise it is handled as child render array
192
            '#attributes' => array('class' => 'specimens'),
193
            '#rows' => array(),
194
        );
195

    
196
        if ($specimensOrObservations) {
197

    
198
            foreach ($specimensOrObservations as $specimenOrObservation) {
199

    
200
                $mediaList = array();
201
                if (is_array($specimenOrObservation->listOfMedia)) {
202
                    $mediaList = array_merge($mediaList, $specimenOrObservation->listOfMedia);
203
                }
204
               if (is_array($specimenOrObservation->_derivedUnitMedia)) {
205
                    $mediaList = array_merge($mediaList, $specimenOrObservation->_derivedUnitMedia);
206
                }
207

    
208
                // typelabel will contain the typeStatus
209
                $type_label = '';
210
                $typeDesignationPager = cdm_ws_get(CDM_WS_OCCURRENCE . '/$0/specimenTypeDesignations', $specimenOrObservation->uuid);
211
                if (isset($typeDesignationPager) and isset($typeDesignationPager->records)) {
212
                    $type_status = array();
213
                    foreach ($typeDesignationPager->records as $typeDesignation) {
214
                        if (isset($typeDesignation->typeStatus->representation_L10n)){
215
                            $type_status[] = $typeDesignation->typeStatus->representation_L10n;
216
                        }
217
                    }
218
                    $type_label = implode(', ', $type_status);
219
                    if($type_label){
220
                        $type_label .= ': ' ;
221
                    }
222
                }
223

    
224
                // --- Specimen entry as dynamic label:
225
                //     -> Dynabox for the specimenOrObservation
226
                $gallery_name = $specimenOrObservation->uuid;
227

    
228
                $derived_unit_ws_request = cdm_compose_url(CDM_WS_OCCURRENCE,  array( $specimenOrObservation->taxonRelatedDerivedUnits[0], 'occurrencesDTO') );
229
                // --- Render associated media.
230
                $gallery_html = '';
231
                if (count($mediaList) > 0) {
232
                    $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
233
                    $captionElements = array(
234
                        '#uri' => t('open media'),
235
                    );
236

    
237
                    $gallery_html = compose_cdm_media_gallerie(array(
238
                        'mediaList' => $mediaList,
239
                        'galleryName' => $gallery_name,
240
                        'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
241
                        'cols' => $gallery_settings['cdm_dataportal_media_cols'],
242
                        'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
243
                        'captionElements' => $captionElements,
244
                        'mediaLinkType' => 'LIGHTBOX',
245
                        'alternativeMediaUri' => NULL,
246
                        'galleryLinkUri' => NULL,
247
                    ));
248
                }
249
                //here we should use the data we already have
250
                $label_html = cdm_dynabox(
251
                  $specimenOrObservation->uuid,
252
                  $type_label . $specimenOrObservation->titleCache,
253
                  $derived_unit_ws_request,
254
                  'cdm_specimen_or_observation',
255
                  'Click for details',
256
                  array('div', 'div'),
257
                  array(),
258
                  null, // $content_element_selector
259
                  'function(){ jQuery(\'#media_gallery_' . $gallery_name . '\').hide(); }', // open_callback
260
                  'function(){ jQuery(\'#media_gallery_' . $gallery_name . '\').show(); }' // close_callback
261
                );
262

    
263
                // --- Render associated media.
264
                $gallery_html = '';
265
                if (count($mediaList) > 0) {
266
                    $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
267
                    $captionElements = array(
268
                        '#uri' => t('open media'),
269
                    );
270

    
271
                    $gallery_html = compose_cdm_media_gallerie(array(
272
                        'mediaList' => $mediaList,
273
                        'galleryName' => $gallery_name,
274
                        'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
275
                        'cols' => $gallery_settings['cdm_dataportal_media_cols'],
276
                        'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
277
                        'captionElements' => $captionElements,
278
                        'mediaLinkType' => 'LIGHTBOX',
279
                        'alternativeMediaUri' => NULL,
280
                        'galleryLinkUri' => NULL,
281
                    ));
282
                }
283

    
284
                $specimen_table['#rows'][] = array(
285
                    // An array of table rows. Every row is an array of cells, or an associative array
286
                    'data' => array(
287
                        // Each cell can be either a string or an associative array
288
                        $label_html . $gallery_html
289
                    ),
290
                    'class' =>  array(
291
                        'descriptionElement',
292
                        'descriptionElement_IndividualsAssociation'
293
                    ),
294
                );
295
            }
296
        }
297

    
298
        $render_array['specimen_list'] = $specimen_table;
299
        $render_array['pager'] = markup_to_render_array(
300
            theme('cdm_pager', array(
301
                'pager' => $pager,
302
                'path' => $_REQUEST['q'],
303
                'parameters' => $_REQUEST,
304
            )),
305
            10 // weight
306
        );
307
    }
308
    $render_array['pager'] = markup_to_render_array(
309
        theme('cdm_pager', array(
310
            'pager' => $pager,
311
            'path' => $_REQUEST['q'],
312
            'parameters' => $_REQUEST,
313
        )),
314
        10 // weight
315
    );
316
    RenderHints::popFromRenderStack();
317
    return $render_array;
318
}
319

    
320
/**
321
 * Creates the drupal render array for the table showing all derivated which are
322
 * derive from a common gathering event.
323
 *
324
 * @param $field_unit_uuids array
325
 *  An array of uuids for cdm FieldUnit entities.
326
 *
327
 * @return array
328
 *  A drupal render array for a table
329
 *
330
 * @ingroup compose
331
 */
332
function compose_specimen_table($field_unit_uuids)
333
{
334
// get icon images
335
  $expand_icon = font_awesome_icon_markup(
336
    'fa-plus-square-o',
337
    array(
338
      'alt' => 'Show details',
339
      'class' => array('expand_icon')
340
    )
341
  );
342
  $collapse_icon = font_awesome_icon_markup(
343
    'fa-minus-square-o',
344
    array(
345
      'alt' => 'Show details',
346
      'class' => array('collapse_icon')
347
    )
348
  );
349
  $detail_image_icon = '<img title="Detail Image" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/detail_image_derivate-16x16-32.png' . '"/>';
350
  $checked_box_icon = '<img src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/step_done.gif' . '"/>';
351
  $sequence_icon = '<img title="Molecular Data" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/sequence_derivate-16x16-32.png' . '"/>';
352
  $character_data_icon = '<img title="Character Data" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/character_data_derivate-16x16-32.png' . '"/>';
353

    
354
  $rowcount = 0;
355
  $rows = array();
356

    
357
  foreach ($field_unit_uuids as $field_unit_uuid) {
358

    
359
    //get derivate hierarchy for the FieldUnit
360
    $derivateHierarchy = cdm_ws_get(CDM_WS_PORTAL_OCCURRENCE, array($field_unit_uuid, 'derivateHierarchy'));
361
    if ($derivateHierarchy) {
362
      //summary row
363
      $rows[] = array(
364
        'data' => array(
365
          array(
366
            'data' => $expand_icon . $collapse_icon,
367
            'class' => array('summary_row_cell', 'summary_row_icon', 'expand_column')
368
          ),
369
          array(
370
            'data' => $derivateHierarchy->country,
371
            'class' => array('summary_row_cell')
372
          ),
373
          array(
374
            'data' => $derivateHierarchy->date,
375
            'class' => array('summary_row_cell')
376
          ),
377
          array(
378
            'data' => $derivateHierarchy->collection,
379
            'class' => array('summary_row_cell')
380
          ),
381
          array(
382
            'data' => $derivateHierarchy->herbarium,
383
            'class' => array('summary_row_cell')
384
          ),
385
          array(
386
            'data' => $derivateHierarchy->hasType ? $checked_box_icon : "",
387
            'class' => array('summary_row_cell', 'summary_row_icon')
388
          ),
389
          array(
390
            'data' => $derivateHierarchy->hasSpecimenScan ? $checked_box_icon : "",
391
            'class' => array('summary_row_cell', 'summary_row_icon')
392
          ),
393
          array(
394
            'data' => ($derivateHierarchy->hasDna ? $sequence_icon : "") . " "
395
              . ($derivateHierarchy->hasDetailImage ? $detail_image_icon : "") . " "
396
              . ($derivateHierarchy->hasCharacterData ? $character_data_icon : ""),
397
            'class' => array('summary_row_cell', 'summary_row_icon')
398
          )
399
        ),
400
        'id' => ('derivate_summary' . $rowcount), // summary row id
401
        'class' => array('summary_row'),
402
      );
403

    
404
      //assemble field unit details
405
      $detail_html = "";
406
      // - citation
407
      if ($derivateHierarchy->citation) {
408
        $detail_html .= create_label("Citation") . $derivateHierarchy->citation . "<br>";
409
      }
410
      //assemble specimen details
411
      if ($derivateHierarchy->preservedSpecimenDTOs) {
412
        foreach ($derivateHierarchy->preservedSpecimenDTOs as $preservedSpecimenDTO) {
413
          $detail_html .= "<br>";
414
          $detail_html .= render_cdm_specimen_page($preservedSpecimenDTO);
415
        }
416
      }
417
      $detail_html .= "<br>";
418
      //detail row resp. one BIG detail cell
419
      $rows[] = array(
420
        'data' => array(
421
          array(
422
            'data' => "", //empty first column
423
            'class' => array('expand_column')
424
          ),
425
          array(
426
            'data' => $detail_html,
427
            'colspan' => 7,
428
          ),
429
        ),
430
        'id' => ('derivate_details' . $rowcount),//details row ID
431
        'class' => array('detail_row'),
432
      );
433
      $rowcount++;
434
    }
435
  }
436

    
437
  $tableId = "derivate_hierarchy_table";
438
  $derivateHierarchyTable = array(
439
    "#theme" => "table",
440
    "#weight" => 2,
441
    "#header" => array(
442
      array(
443
        'data' => "",
444
        'class' => array('expand_column')
445
      ),
446
      "Country", "Date", "Collector + collecting number", "Herbaria", "Type", "Scan", "Derivatives"),
447
    "#rows" => $rows,
448
    "#attributes" => array(
449
      "id" => $tableId,
450
      "border" => 2
451
    )
452
  );
453

    
454
  //add toggle functionality to derivate hierarchy table
455
  drupal_add_js_rowToggle("#" . $tableId);
456

    
457
  return $derivateHierarchyTable;
458
}
459

    
460
function create_html_link($link, $openInExternalWindow=false){
461
    $html = "";
462
    if($link->uri && $link->uri!=""){
463
        $html .= '<a  href="' . $link->uri . '"';
464
        if($openInExternalWindow){
465
            $html .= ' target="_blank"';
466
        }
467
        $html .= '>' . $link->linkText . '</a>';
468
    }
469
    else{
470
        $html .= $link->linkText;
471
    }
472
    return $html;
473
}
474

    
475
/**
476
 * Creates HTML links from the given link list concatenated by default by a comma.
477
 * @param $linkList the list with Link objects having "uri" and "linkText" as members
478
 * @return string the assembled HTML string containing the links
479
 */
480
function create_html_links($linkList, $openInExternalWindow=false, $separator=", ")
481
{
482
    $html = "";
483
    if ($linkList) {
484
        foreach ($linkList as $link) {
485
            $html .= create_html_link($link, $openInExternalWindow).$separator;
486
        }
487
        $html = rtrim($html, $separator);
488
    }
489
    return $html;
490
}
491

    
492
/**
493
 * Composes a taxon page which can consist of multiple parts like
494
 * 'General', 'Synonymy', 'Images', 'Keys'. These parts can be displayed
495
 * as tabs or as sections of a single page.
496
 *
497
 * It is headed by the name of the accepted taxon without author and reference.
498
 *
499
 * @param $taxon
500
 *   The CDM Taxon Instance to compose the page for.
501
 * @param $page_part
502
 *   Name of the part to display, valid values are:
503
 *    - 'description' -  for the general part
504
 *    - 'images'
505
 *    - 'synonymy'
506
 *    - 'keys'
507
 *    - 'all'
508
 *
509
 * @return array
510
 *   A drupal render array
511
 *
512
 * @ingroup compose
513
 */
514
function compose_cdm_taxon_page($taxon, $page_part = 'description') {
515

    
516
  // we better cache here since drupal_get_query_parameters has no internal static cache variable
517
  $http_request_params = drupal_get_query_parameters();
518

    
519
  // add all mandatory js sources
520
  _add_js_footnotes();
521

    
522

    
523
  $render_array = array();
524
  $weight = 0; // the weight for the render array elements
525

    
526
  $tabsToDisplay = variable_get('cdm_taxonpage_tabs_visibility', unserialize(TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT));
527

    
528
  $page_part = variable_get('cdm_dataportal_taxonpage_tabs', 1) ? $page_part : 'all';
529

    
530
  $synonymy_as_tab = variable_get(CDM_SYNONYMY_AS_TAB, CDM_SYNONYMY_AS_TAB_DEFAULT) === 1;
531
  if(!$synonymy_as_tab){
532
    unset($tabsToDisplay["Synonymy"]);
533
    // the synonymy is located in the general part in this case
534
    if($page_part == 'synonymy'){
535
      $page_part = 'description';
536
    }
537
  }
538

    
539
  $media = _load_media_for_taxon($taxon);
540

    
541

    
542
  if (!isset($media[0]) || ($tabsToDisplay["Images"] == '0')) {
543
    taxon_page_tabs_hidden('images');
544
  }
545

    
546
  // --- GET specimensOrObservations --- //
547
  $specimensOrObservations = cdm_ws_get(CDM_WS_TAXON, array( $taxon->uuid, 'specimensOrObservationsCount'));
548

    
549
  $specimensOrObservationsCount = $specimensOrObservations != null ? $specimensOrObservations->result : 0;
550
  if ($specimensOrObservationsCount == 0 || ($tabsToDisplay["Specimens"] == '0')) {
551
    taxon_page_tabs_hidden('specimens');
552
  }
553

    
554
  // --- GET polytomousKeys --- //
555
  $polytomousKeysPager = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, NULL, "findByTaxonomicScope=$taxon->uuid");
556
  $identificationKeyCount = 0;
557
  if ($polytomousKeysPager) {
558
    $identificationKeyCount += $polytomousKeysPager->count;
559
  }
560
  if ($identificationKeyCount == 0 || ($tabsToDisplay["Keys"] == '0')) {
561
    taxon_page_tabs_hidden('keys');
562
  }
563

    
564
  // --- GET TaxonNodeAgentRelations --- //
565
  $current_classification_uuid = get_current_classification_uuid();
566
  $taxon_node_agent_relations_pager = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODEAGENTRELATIONS,
567
      array(
568
          $taxon->uuid,
569
          $current_classification_uuid,
570
      ),
571
      "pageSize=1&pageIndex=0"// we are only interested into the count so we are fetching only one item, o is not possible!
572
  );
573
  if (!$taxon_node_agent_relations_pager || $taxon_node_agent_relations_pager->count == 0){
574
      taxon_page_tabs_hidden('experts');
575
  }
576

    
577
  if (!isset($tabsToDisplay["Synonymy"]) || $tabsToDisplay["Synonymy"] == '0') {
578
    taxon_page_tabs_hidden('synonymy');
579
  }
580

    
581
  // -------------------------------------------- //
582

    
583
  if (variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR) && isset($_REQUEST['acceptedFor'])) {
584
    $render_array['accepted_for'] = markup_to_render_array(cdm_accepted_for($_REQUEST['acceptedFor']), $weight++);
585
  }
586

    
587
  // --- PAGE PART: DESCRIPTION --- //
588
  if ($page_part == 'description' || $page_part == 'all') {
589

    
590
    $merged_tree = merged_taxon_feature_tree($taxon);
591

    
592

    
593
    $render_array['general'] = compose_cdm_taxon_page_profile($taxon, $merged_tree, $media, !$synonymy_as_tab);
594
    $render_array['general']['#weight'] = $weight++;
595
    $render_array['general']['#prefix'] = '<div id="general" class="page-part">';
596
    $render_array['general']['#suffix'] = '</div>';
597
  }
598

    
599
  // --- PAGE PART: IMAGES --- //
600
  if (array_search('images', taxon_page_tabs_hidden()) === FALSE && ($page_part == 'images' || $page_part == 'all')) {
601
    $images_html = '<div id="images" class="page-part">';
602
    if ($page_part == 'all') {
603
      $images_html .= '<h2>' . t(cdm_taxonpage_tab_label('Images')) . '</h2>';
604
    }
605
    // Get the image gallery as configured by the admin.
606
    $default_image_gallery = 'default';
607
    $configured_image_gallery_viewer = variable_get('image_gallery_viewer', 'default');
608
    $taxon_image_gallery = '<div class="error">No image gallery viewer configured</div>';
609
    if($configured_image_gallery_viewer == $default_image_gallery || $configured_image_gallery_viewer == 'fsi'){
610
      // the fsi_gallery requires a flash plugin, in case the client browser is not supporting
611
      // flash we also need to provide an the default gallery as alternative
612
      $taxon_image_gallery = '<div id="default-gallery-viewer">' .
613
        call_user_func_array('taxon_image_gallery_' . $default_image_gallery, array(
614
          $taxon,
615
          $media,
616
        ))
617
        . '</div>';
618
    }
619
    if($configured_image_gallery_viewer == 'fsi'){
620
      $taxon_image_gallery .= '<div id="'. $configured_image_gallery_viewer .'-gallery-viewer">' .
621
        call_user_func_array('taxon_image_gallery_' . $configured_image_gallery_viewer, array(
622
          $taxon,
623
          $media,
624
        ))
625
       . '</div>';
626
    }
627
    $images_html .= $taxon_image_gallery;
628
    $images_html .= '</div>';
629
    $render_array['images'] = markup_to_render_array($images_html, $weight++);
630
  }
631

    
632
  // --- PAGE PART: SYNONYMY --- //
633
  if ((($page_part == 'synonymy' || $page_part == 'all') && $synonymy_as_tab)) {
634
    $synonymy_html = '<div id="synonymy" class="page-part">';
635
    if ($page_part == 'all') {
636
      $synonymy_html .= '<h2>' . t(cdm_taxonpage_tab_label('Synonymy')) . '</h2>';
637
    }
638
    $addAcceptedTaxon = variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE);
639

    
640
    $synonymy_html .= theme('cdm_taxon_page_synonymy', array('taxon' => $taxon, 'addAcceptedTaxon' => $addAcceptedTaxon));
641

    
642
    $synonymy_html .= '</div>';
643
    $render_array['synonymy'] = markup_to_render_array($synonymy_html, $weight++);
644

    
645
  }
646

    
647
  // --- PAGE PART: SPECIMENS --- //
648
  if ($specimensOrObservationsCount > 0 && ($page_part == 'specimens' || $page_part == 'all')) {
649
    $render_array['specimens'] = array(
650
        '#prefix' => '<div id="specimens" class="page-part">' . ($page_part == 'all' ? '<h2>' . t(cdm_taxonpage_tab_label('Specimens')) . '</h2>' : ''),
651
        'content' => cdm_dataportal_taxon_page_specimens($taxon), // returns render array
652
        '#suffix' => '</div>',
653
    );
654
  }
655

    
656
  // --- PAGE PART: KEYS --- //
657
  if ($identificationKeyCount == 1 && $page_part == 'keys'){
658
    drupal_goto(path_to_key($polytomousKeysPager->records[0]->class, $polytomousKeysPager->records[0]->uuid));
659
  }
660
  else if ($identificationKeyCount > 0 && ($page_part == 'keys' || $page_part == 'all')) {
661
    $keys_html = '<div id="keys" class="page-part">';
662
    if ($page_part == 'all') {
663
      $keys_html .= '<h2>' . t(cdm_taxonpage_tab_label('Keys')) . '</h2>';
664
    }
665
    $keys_html .= theme('cdm_block_IdentificationKeys', array('taxonUuid' => $taxon->uuid));
666
    $keys_html .= '</div>';
667
    $render_array['keys'] = markup_to_render_array($keys_html, $weight++);
668
  }
669

    
670
  // --- PAGE PART: EXPERTS --- //
671

    
672
  if (array_search('experts', taxon_page_tabs_hidden()) === FALSE && ($page_part == 'experts' || $page_part == 'all')) {
673
    $render_array['experts'] = array(
674
        '#prefix' => '<div id="experts" class="page-part">' . ($page_part == 'all' ? '<h2>' . t(cdm_taxonpage_tab_label('Experts')) . '</h2>' : ''),
675
        'content' => compose_cdm_taxon_page_experts($taxon), // returns render array
676
        '#suffix' => '</div>',
677
    );
678
  }
679

    
680
  // ------------------ END OF PARTS -------------- //
681

    
682
  // adjust weights of page and toc elements according to the settings
683
  $taxontabs_weights = get_array_variable_merged(CDM_TAXONPAGE_TAB_WEIGHT, CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
684
  foreach($taxontabs_weights as $tab_key => $weight){
685
    if(isset($render_array[$tab_key])){
686
      $render_array[$tab_key]['#weight'] = $weight;
687
    }
688
  }
689

    
690

    
691
  // set up the TOC for the pages which contain all pageparts
692
  if($page_part == 'all') {
693

    
694
    asort($taxontabs_weights);
695
    foreach(array_keys($taxontabs_weights) as $tab_key){
696
      if(isset($render_array[$tab_key])){
697
        if($tab_key != 'general'){
698
          // add entry for page part
699
          $toc_elements[] = array(
700
              'data' => l(t(cdm_taxonpage_tab_label(ucfirst($tab_key))), $_GET['q'], array('fragment' => $tab_key, 'query' => $http_request_params)),
701
              'class' => array('page-part-toc-item-' . $tab_key)
702
          );
703
        } else {
704
          // add content of profile part instead
705
          if(isset($render_array['general'])) {
706
            // in case all tabs are shown at once the feature tocs
707
            // should be integrated into the tabs toc as sub list
708
            // and the profile image should be on top of the page
709
            if(isset($render_array['general']['taxon_description_feature_toc'])){;
710
            foreach ($render_array['general']['taxon_description_feature_toc']['#items'] as $profile_toc_item){
711
              $toc_elements[] = $profile_toc_item;
712
            }
713
            unset($render_array['general']['taxon_description_feature_toc']);
714
            }
715
          }
716
        }
717
      }
718
    }
719

    
720
    // move profile image in page structure
721
    if(isset($render_array['general']['taxon_profile_image'])){
722
      $render_array['profile_image'] = $render_array['general']['taxon_profile_image'];
723
      $render_array['profile_image']['#weight'] = -100;
724
      unset($render_array['general']['taxon_profile_image']);
725
    }
726

    
727
    // finally add the table of contents to the render array
728
    $render_array['toc'] = array(
729
        '#theme' => 'item_list',
730
        '#items' => $toc_elements,
731
        '#title' => t('Content'),
732
        '#weight' => -101,
733
        '#suffix' => '</div>',
734
        '#prefix'=> '<div id="page-toc">'
735
    );
736
  }
737

    
738

    
739
  return $render_array;
740
}
741

    
742
/**
743
 * TODO should this function really be a compose function?
744
 *     For a compose function must there always be a theme function with the same name? (ak 8.8.2013)
745
 *
746
 * composes and returns an render array containing the components of the taxon profile tab:
747
 *  - 'taxon_profile_image'
748
 *  - 'taxon_description_feature_toc'
749
 *  - 'taxon_description_features'
750
 *
751
 *
752
 * @param taxon
753
 * @param mergedTrees
754
 * @param media
755
 *
756
 * @return array
757
 *   A Drupal render array with the following elements:
758
 *     - 'taxon_profile_image'
759
 *     - 'taxon_description_feature_toc'
760
 *     - 'taxon_description_features'
761
 *
762
 * @ingroup compose
763
 */
764
function compose_cdm_taxon_page_profile($taxon, $merged_tree, $media, $add_synonymy) {
765

    
766
  $render_array = array();
767

    
768
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
769

    
770
  $hide_taxon_profile_image = FALSE;
771
  if (variable_get('image_hide_rank', '0') != '0' && isset($taxon->name->rank->uuid)) {
772
    $rankCompare = rank_compare($taxon->name->rank->uuid, variable_get('image_hide_rank', '-99'));
773
    $hide_taxon_profile_image = ($rankCompare > -1);
774
  }
775

    
776
  if ($taxon_profile_image_settings['show'] && !$hide_taxon_profile_image) {
777

    
778
    $representationPart = new stdClass();
779
    $attributes = array();
780
    if (isset($media[0])) {
781
      // due to a bug the portal/taxon/{uuid}/media service only delivers a filtered media object
782
      // which only contains the thumbnail representation even if the height and width filters are not set.
783
      // -->
784
      $preferred_media = cdm_ws_get(CDM_WS_MEDIA, $media[0]->uuid);
785
      $preferred_representations = cdm_preferred_media_representations($preferred_media, array(
786
        'image/jpg',
787
        'image/jpeg',
788
        'image/png',
789
        'image/gif',
790
      ),
791
        $taxon_profile_image_settings['maxextend'],
792
        $taxon_profile_image_settings['maxextend']
793
      );
794
      if(count($preferred_representations) > 0){
795

    
796
        $representation = array_shift($preferred_representations);
797
        $representationPart = $representation->parts[0];
798
        $attributes['alt'] = $representationPart->uri;
799

    
800
        if (!empty($taxon_profile_image_settings['media_uri_query'])) {
801
          $representationPart->uri = $representationPart->uri
802
            . (strpos($representationPart->uri, '?') !== FALSE ? '&' : '?')
803
            . $taxon_profile_image_settings['media_uri_query'];
804
        }
805
      }
806
    }
807
    else {
808
      if ($taxon_profile_image_settings['custom_placeholder_enabled']) {
809
        // show placeholder image instead
810
        if (!empty($taxon_profile_image_settings['custom_placeholder_image_on']) && !empty($taxon_profile_image_settings['custom_placeholder_image_fid'])) {
811
          // use the user provided image
812
          $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
813
          $url = file_create_url($profile_image_file->uri);
814
          $image_info = image_get_info($profile_image_file->uri);
815
          $representationPart->width = $image_info['width'];
816
          $representationPart->height = $image_info['height'];
817
          $representationPart->uri = $url;
818
        }
819
        else {
820
          // use the hard coded default
821
          $representationPart->width = 184;
822
          $representationPart->height = 144;
823
          $representationPart->uri = base_path() . drupal_get_path('module',
824
              'cdm_dataportal') . '/images/no_picture.png';
825
        }
826
        $attributes['alt'] = "no image available";
827
      }
828
    }
829

    
830
    if (isset($representationPart->uri)) {
831
      $profile_image = cdm_media_gallerie_image($representationPart, $taxon_profile_image_settings['maxextend'], FALSE, $attributes);
832
      // NOTE: style="width:${maxextend}px' is needed for IE8 !!!
833
      $render_array['taxon_profile_image'] = markup_to_render_array('<div id="taxonProfileImage" style="width:' . $taxon_profile_image_settings['maxextend'] . 'px">' . $profile_image . '</div>',
834
        -101);
835
    }
836
  }
837

    
838
  if($add_synonymy){
839
    $render_array['synonymy'] = markup_to_render_array(
840
      theme('cdm_taxon_page_synonymy', array('taxon' => $taxon, 'addAcceptedTaxon' => true)),
841
      -102
842
    );
843
  }
844

    
845
  $pseudo_feature_blocks = array();
846
  $pseudo_feature_block_toc_items = array();
847

    
848

    
849
  // Render the sections for each real feature
850
  $feature_block_list = make_feature_block_list($merged_tree->root->childNodes, $taxon);
851

    
852
  // Bibliography
853
  $bibliography_settings = get_bibliography_settings();
854
  if($bibliography_settings['enabled'] == 1){
855
    $feature_bibliography = make_pseudo_feature('Bibliography', 'BIBLIOGRAPHY');
856
    $bibliography_block = feature_block(t('Bibliography'), $feature_bibliography);
857
    $bibliography_item = markup_to_render_array(FootnoteManager::renderFootnoteList('BIBLIOGRAPHY', ''));
858
    $bibliography_block->content[] = compose_feature_block_wrap_elements(array($bibliography_item), $feature_bibliography);
859

    
860
    if(!empty($bibliography_block->content)){
861
      $pseudo_feature_block_toc_items['Bibliography']= 'bibliography';
862
      $pseudo_feature_blocks[] = $bibliography_block;
863
    }
864
  }
865

    
866
  $render_array['taxon_description_features'] = _block_get_renderable_array(
867
    array_merge($feature_block_list, $pseudo_feature_blocks)
868
  );
869

    
870
  if($pseudo_feature_block_toc_items){
871
    foreach ($pseudo_feature_block_toc_items as $label=>$fragment){
872
      cdm_toc_list_add_item($label, $fragment);
873
    }
874
  }
875

    
876
  // create the table of content
877
  $toc = array(
878
      '#theme' => 'item_list',
879
    '#items' => cdm_toc_list(),
880
      '#title' => t('Content'),
881
    '#weight' => -100,                  // move to the top
882
      '#suffix' => '</div>',
883
      '#prefix'=> '<div id="page-toc">'
884
  );
885
  $render_array['taxon_description_feature_toc'] = $toc;
886

    
887
  return $render_array;
888
}
889

    
890
/**
891
 * composes and returns an render array for the experts associated with the given taxon
892
 *
893
 * @param taxon
894
 *
895
 * @return array
896
 *   A Drupal render array for a table with the experts
897
 *
898
 * @ingroup compose
899
 */
900
function compose_cdm_taxon_page_experts($taxon){
901

    
902
  $render_array = array();
903
  if(!isset($taxon->uuid)){
904
    return $render_array;
905
  }
906

    
907
  $current_classification_uuid = get_current_classification_uuid();
908
  // TODO use cdm_ws_fetchall below but this failes! needs fix!
909
  $taxon_node_agent_relations = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODEAGENTRELATIONS,
910
    array(
911
      $taxon->uuid,
912
      $current_classification_uuid
913
    )
914
  );
915

    
916
  $header = array(
917
    array('data' => t('Expert')),
918
    array('data' => t('Role'))
919
  );
920
  $rows = array();
921

    
922

    
923
  foreach($taxon_node_agent_relations->records as $taxon_node_agent_relation){
924

    
925

    
926
    $expert_role_id = $taxon_node_agent_relation->agent->uuid . '-' . $taxon_node_agent_relation->type->uuid;
927
    $expert_details_container_id = 'expert_details_' . $expert_role_id;
928

    
929
    $agent_label_markup = cdm_dynabox(
930
      'expert_' . $expert_role_id,
931
      $taxon_node_agent_relation->agent->titleCache,
932
      // specifying both ends of the relationship will return only one record in the pager
933
      cdm_compose_url(CDM_WS_PORTAL_AGENT,
934
         array($taxon_node_agent_relation->agent->uuid, 'taxonNodeAgentRelations'),
935
        'taxon_uuid=' . $taxon->uuid . '&relType_uuid=' . $taxon_node_agent_relation->type->uuid),
936
      'cdm_taxon_expert',
937
      'Click for details',
938
      array('div', 'div'),
939
      array(), // attributes
940
      '#' . $expert_details_container_id // $content_element_selector
941
    );
942

    
943
    // Expert and Role
944
    $rows[] = array(
945
      'data' => array(
946
        array(
947
          'data' => $agent_label_markup,
948
          'class' => array(html_class_attribute_ref($taxon_node_agent_relation->agent))
949
        ),
950
        array(
951
          'data' => $taxon_node_agent_relation->type->representation_L10n,
952
          'class' => array(html_class_attribute_ref($taxon_node_agent_relation->type))
953
        )
954
      )
955
    );
956
    // Agent details
957
    $rows[] = array(
958
      'data' => array(
959
        array(
960
          'data' => '<!-- expert_details_container -->',
961
          'id' => $expert_details_container_id,
962
          'colspan' => 2
963
        )
964
      )
965
    );
966

    
967
  }
968

    
969

    
970
  $render_array['experts_table'] = array(
971
    '#theme' => 'table',
972
    '#header' => $header,
973
    '#rows' => $rows,
974
  );
975

    
976

    
977
  return $render_array;
978
}
979

    
980

    
981
/**
982
 * Manages the tabs to be hidden in the taxon page.
983
 *
984
 * The tabs are identified by their last menu link path element:
985
 *  - description
986
 *  - synonymy
987
 *  - images
988
 *  - specimens
989
 *  - key
990
 *
991
 * Internally the tabs are stored in a static variable which is
992
 * managed by drupal_static().
993
 *
994
 * @param string $add_tab
995
 *   Optional parameter. The given string will be added to the array of tabs
996
 *
997
 * @return
998
 *   The array of tabs
999
 */
1000
function taxon_page_tabs_hidden($add_tab = NULL) {
1001
  $tabs = &drupal_static(__FUNCTION__);
1002

    
1003
  if(!isset($tabs)){
1004
    $tabs = array();
1005
  }
1006

    
1007
  if (isset($add_tab) && !array_key_exists($add_tab, $tabs)) {
1008
    $tabs[] = $add_tab;
1009
  }
1010

    
1011
  return $tabs;
1012
}
1013

    
1014
/**
1015
 * Implements the hook_preprocess_HOOK() for theme_menu_local_tasks()
1016
 *
1017
 *  - Removes the tabs to be hidden, @see taxon_page_tabs_hidden()
1018
 *  - Renames tabs according to the settings // TODO (this will replace the theme_cdm_taxonpage_tab() function !!!)
1019
 *
1020
 * @param array $variables
1021
 *   The variables array
1022
 */
1023
function cdm_dataportal_preprocess_menu_local_tasks(&$variables) {
1024

    
1025
  $hidden_tabs = taxon_page_tabs_hidden();
1026

    
1027
  if (is_array($variables['primary'])) {
1028
    foreach ($variables['primary'] as $key => &$element) {
1029

    
1030
      // 1. Remove the tabs to be hidden
1031
      foreach ($hidden_tabs as $tab) {
1032
        if ($element['#link']['path'] == 'cdm_dataportal/taxon/%/' . $tab) {
1033
          // remove the tab
1034
          unset($variables['primary'][$key]);
1035
        }
1036
      }
1037
    }
1038
  }
1039
}
1040

    
1041

    
1042

    
1043
/**
1044
 * Implements the hook_preprocess_HOOK() for theme_menu_local_task()
1045
 *
1046
 *
1047
 * @param array $variables
1048
 *   An associative array containing:
1049
 *     - element: A render element containing:
1050
 *          #link: A menu link array with 'title', 'href', and 'localized_options' keys.
1051
 *          #active: A boolean indicating whether the local task is active.
1052
 *
1053
 */
1054
function cdm_dataportal_preprocess_menu_local_task(&$variables) {
1055

    
1056
  $link = $variables['element']['#link'];
1057
  if (preg_match('/cdm_dataportal\/.*\/refresh$/', $link['href'])) {
1058
    $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']) . '"/>';
1059
    $link['localized_options']['html'] = TRUE;
1060

    
1061
    $variables['element']['#link'] = $link;
1062
  }
1063
}
1064

    
1065
/* =================== block composition ===================== */
1066

    
1067
/**
1068
 * Composes and returns an render array for the classification breadcrumbs of the given taxon.
1069
 *
1070
 * @param taxon
1071
 *
1072
 * @return array
1073
 *   A Drupal render array for a table with the experts
1074
 *
1075
 * @ingroup compose
1076
 */
1077
function compose_classification_breadcrumbs($taxon_uuid) {
1078

    
1079
  _add_js_taxonomic_children('#classification-breadcrumbs .taxonomic-children-button');
1080

    
1081
  $render_array = array();
1082

    
1083
  $render_array['#theme'] = 'item_list';
1084
  $render_array['#type'] = 'ul';
1085
  $render_array['#attributes'] = array(
1086
    'id' => 'classification-breadcrumbs',
1087
    'class' => 'breadcrumbs inline',
1088
  );
1089

    
1090
  $items = array();
1091

    
1092
  $parent_taxon_nodes = null;
1093
  if($taxon_uuid){
1094
    $parent_taxon_nodes = cdm_ws_taxonomy_pathFromRoot($taxon_uuid);
1095
  }
1096

    
1097
  $classifications = cdm_ws_fetch_all(CDM_WS_PORTAL_TAXONOMY);
1098
  // find current classification in list
1099
  $classification = null;
1100
  $current_classification_uuid = get_current_classification_uuid();
1101
  foreach ($classifications as $classification){
1102
    if($classification->uuid == $current_classification_uuid){
1103
      break;
1104
    }
1105
  }
1106

    
1107
  $node_name = '';
1108
  if(count($classifications) > 1 ){
1109
    // need to add the current classification as first label
1110

    
1111
    $label = $classification->titleCache;
1112
    if(strlen($label) > 20){
1113
      $label = substr($label, 0, strpos($label, ' ', 15)) . '...';
1114
    }
1115
    $node_name = font_awesome_icon_markup('fa-th-list')  . ' ' . l($label, '#', array(
1116
      'attributes' => array(
1117
        'class' => 'taxonomic-children-button classification-chooser',
1118
        'data-destination-uri' => drupal_get_destination(),
1119
        'data-cdm-align-with' => array('prev')
1120
      ),
1121
      'html' => true
1122
    ));
1123
  }
1124

    
1125
  $rank_limit_uuid = variable_get(TAXONTREE_RANKLIMIT, TAXONTREE_RANKLIMIT_DEFAULT);
1126

    
1127
  $rank_separator = '<span> '
1128
    . font_awesome_icon_markup('fa-chevron-right')
1129
    . ' </span>';
1130
  $more_children_icon = font_awesome_icon_markup('fa-sitemap fa-rotate-270');
1131
  $more_children_label = '...';
1132

    
1133
  $items[] = $node_name;
1134

    
1135
  $more_children_for = null;
1136
  if($parent_taxon_nodes){
1137
    foreach ($parent_taxon_nodes as $node) {
1138

    
1139
      $is_first_item = count($items) == 0;
1140
      $is_last_item = count($items) == count($parent_taxon_nodes);
1141
      $node_name = cdm_dataportal_shortname_of($node);
1142
      $path = path_to_taxon($node->taxonUuid);
1143

    
1144
      if($node->taxonomicChildrenCount > 0) {
1145
        $more_children_for = $node->taxonUuid;
1146
      } else {
1147
        $more_children_for = null;
1148
      }
1149

    
1150
      // 'fa-sitemap'
1151

    
1152
      $items[] =
1153
        ($is_first_item ? '' : ' ')
1154
        . $rank_separator
1155
        . l(
1156
          '<span class="' . html_class_attribute_ref($node) . '">' . $node_name . '</span>',
1157
          $path,
1158
          array(
1159
            'attributes' => array(
1160
              'class' => array('taxonomic-children-button'),
1161
              'data-cdm-taxon-uuid' => array($node->taxonUuid),
1162
              'data-cdm-classification-mode' => array('siblings'),
1163
              'data-cdm-align-with' => array('prev')
1164
            ),
1165
            'html' => true
1166
          )
1167
        );
1168
      }
1169
    }
1170

    
1171
  // add more button to the end
1172
  if(!$parent_taxon_nodes) {
1173
    // not taxon focused yet, adding button to make  the root nodes available
1174
    $items[] = '<span>'
1175
      . $more_children_icon . '&nbsp;' .
1176
      '<span class="taxonomic-children-button" data-classification-uuid="' . $current_classification_uuid
1177
      . '" data-rank-limit-uuid="' . $rank_limit_uuid . '" data-cdm-align-with="prev"> ' . $more_children_label . '<span>'
1178
      . '</span>';
1179
  } else if($more_children_for){
1180
    // last parent item has child taxon nodes
1181
    $items[] = ' <span>'
1182
      . $more_children_icon . '&nbsp;' .
1183
      '<span class="taxonomic-children-button" data-cdm-taxon-uuid="' .$more_children_for
1184
      . '" data-cdm-classification-mode="children" data-cdm-align-with="prev"> ' . $more_children_label . '</span>'
1185
      . '</span>';
1186

    
1187
  }
1188

    
1189
  $render_array['#items'] = $items;
1190

    
1191
  return $render_array;
1192
}
1193

    
1194

    
1195
/**
1196
 * @param $specimen_uuid
1197
 * @return array
1198
 *    The drupal render array for the page
1199
 *
1200
 * @ingroup compose
1201
 */
1202
function compose_cdm_specimen_page($specimen_uuid)
1203
{
1204
  drupal_set_title("Specimen Details");
1205
  $specimen = cdm_ws_get(CDM_WS_PORTAL_OCCURRENCE, array($specimen_uuid, 'specimenDerivates'));
1206

    
1207
  $render_array = array();
1208
  RenderHints::pushToRenderStack('specimen_page');
1209

    
1210
  $detail_html = render_cdm_specimen_page($specimen, true);
1211
  $render_array['specimen_html'] = array(
1212
    '#markup' => $detail_html
1213
  );
1214

    
1215
  RenderHints::popFromRenderStack();
1216
  return $render_array;
1217
}
1218

    
1219
/**
1220
 * @param $named_area_uuid
1221
 * @return array
1222
 *    The drupal render array for the page
1223
 *
1224
 * @ingroup compose
1225
 */
1226
function compose_cdm_named_area_page($named_area_uuid)
1227
{
1228

    
1229
  $named_area = cdm_ws_get(CDM_WS_PORTAL_TERM, array($named_area_uuid));
1230

    
1231
  $render_array = array();
1232
  RenderHints::pushToRenderStack('named_area_page');
1233

    
1234
  $groups = array();
1235
  @_description_list_group_add($groups, t('Name') . ':', $named_area->representation_L10n);
1236
  @_description_list_group_add($groups, t('IdInVocabulary') . ':', $named_area->idInVocabulary);
1237
  if(isset($named_area->level)) {
1238
    @_description_list_group_add($groups, t('Level') . ':', $named_area->level->representation_L10n);
1239
  }
1240

    
1241
  $name_area_details_elements = array(
1242
   // '#title' => $title,
1243
    '#theme' => 'description_list',
1244
    '#groups' => $groups,
1245
    '#attributes' => array('class' => html_class_attribute_ref($named_area)),
1246
  );
1247

    
1248
  $render_array[] = $name_area_details_elements;
1249

    
1250
  RenderHints::popFromRenderStack();
1251
  return $render_array;
1252
}
1253

    
1254
/**
1255
 * Provides the the label string for taxon page tabs.
1256
 *
1257
 * The $tabname as passed to the method will be returned if no override
1258
 * label is configured in the settings.
1259
 */
1260
function cdm_taxonpage_tab_label($tabname) {
1261
  static $taxon_tabs_labels = null;
1262
  if($taxon_tabs_labels == null){
1263
    $taxon_tabs_labels = get_array_variable_merged(CDM_TAXONPAGE_TAB_LABELS, CDM_TAXONPAGE_TAB_LABELS_DEFAULT);
1264
  }
1265
  $tabname_key = strtolower($tabname);
1266
  if(isset($taxon_tabs_labels[$tabname_key]) && $taxon_tabs_labels[$tabname_key]){
1267
    return $taxon_tabs_labels[$tabname_key];
1268
  }
1269
  return $tabname;
1270
}
(7-7/10)