Project

General

Profile

Download (46.4 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
    if(!variable_get('cdm_dataportal_specimen_derivate_tree')) {
62
        $pager = cdm_ws_get(CDM_WS_OCCURRENCE_BY_ASSOCIATEDTAXON,
63
            null,
64
            $by_associatedtaxon_query . '&taxonUuid=' . $taxon->uuid
65
        );
66
        $specimensOrObservations = array();
67
        if (isset($pager->records[0])) {
68
            $specimensOrObservations = $pager->records;
69
        }
70
    }
71
     // cdm_ws_get(CDM_WS_OCCURRENCE_FIELDUNIT_DTO_BY_ASSOCIATEDTAXON,
72
     // null,
73
     // $by_associatedtaxon_query . '&taxonUuid=' . $taxon->uuid
74
    // );
75

    
76
   // $specimensOrObservations = array();
77
   // if(isset($pager->records[0])){
78
    //    $specimensOrObservations =  $pager->records;
79
   // }
80

    
81
    // order occurrences by date but types should be on top of the list
82
    $type_specimens = array();
83
    $other_occurrences = array();
84
    foreach ($specimensOrObservations as $occurrence) {
85
        $typeDesignationsPager = cdm_ws_get(CDM_WS_OCCURRENCE . '/$0/specimenTypeDesignations', $occurrence->uuid);
86
        if (isset($typeDesignationsPager->count) && $typeDesignationsPager->count > 0) {
87
            $type_specimens[] = $occurrence;
88
        } else {
89
            $other_occurrences[] = $occurrence;
90
        }
91
    }
92
    $specimensOrObservations = array_merge($type_specimens, $other_occurrences);
93

    
94
    // Collect media (fieldObjectMedia, derivedUnitMedia) and add as a custom field
95

    
96
    foreach ($specimensOrObservations as &$occurrence) {
97
        $occurrence->_fieldObjectMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array(
98
            $occurrence->uuid,
99
            'fieldObjectMediaDTO',
100
        ));
101
        $occurrence->_derivedUnitMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array(
102
            $occurrence->uuid,
103
            'derivedUnitMedia',
104
        ));
105
    }
106

    
107
    // --- get map service HTTP query parameters
108

    
109
    if (count($specimensOrObservations) > 0) {
110
        if (count($specimensOrObservations) > 0) {
111
            $occurrence_queryDto = cdm_ws_get(CDM_WS_GEOSERVICE_OCCURRENCEMAP, $taxon->uuid,  $by_associatedtaxon_query);
112

    
113
            $map_visibility = variable_get(SPECIMEN_MAP_VISIBILITY, SPECIMEN_MAP_VISIBILITY_DEFAULT);
114
            if($map_visibility == 'always' ||
115
                variable_get(SPECIMEN_MAP_VISIBILITY, SPECIMEN_MAP_VISIBILITY_DEFAULT) == 'automatic' &&
116
                (isset($occurrence_queryDto->fieldUnitPoints[0]) || isset($occurrence_queryDto->derivedUnitPoints[0]))
117
            )
118
            {
119
                $occurrence_query = $occurrence_queryDto->occurrenceQuery;
120
                $legend_format_query = null;
121
                $distribution_query = NULL;
122
                $map_render_array = compose_map('specimens', $occurrence_query, $distribution_query, $legend_format_query, array());
123
            }
124
        }
125
    }
126

    
127
    // -------------------------------------------------------
128
    $render_array['map'] = $map_render_array;
129

    
130
    if(variable_get('cdm_dataportal_compressed_specimen_derivate_table')){
131

    
132
        //COMPRESSED SPECIMEN DERIVATE TABLE
133
        $associatedFieldUnitsQuery_parameters = array();
134
        if (isset($_REQUEST['pager']) && is_array($_REQUEST['pager'])) {
135
            $associatedFieldUnitsQuery_parameters = array_merge($associatedFieldUnitsQuery_parameters, $_REQUEST['pager']);
136
        }
137

    
138
        $by_associatedtaxon_query = http_build_query($associatedFieldUnitsQuery_parameters);
139
        $pager_field_units = cdm_ws_get(CDM_WS_PORTAL_TAXON,
140
            array($taxon->uuid, 'associatedFieldUnits'),
141
            $by_associatedtaxon_query . '&pageSize=' . variable_get('cdm_dataportal_compressed_specimen_derivate_table_page_size')
142
        );
143

    
144
        if (isset($pager_field_units->records[0])) {
145
          $field_unit_uuids = array();
146
          foreach ($pager_field_units->records as $field_unit) {
147
            $field_unit_uuids[] = $field_unit->uuid;
148
          }
149

    
150
          $render_array['derivate_hierarchy_table'] = compose_specimen_table($field_unit_uuids);
151
        }
152

    
153
        $render_array['pager'] = markup_to_render_array(
154
            theme('cdm_pager', array(
155
                'pager' => $pager_field_units,
156
                'path' => $_REQUEST['q'],
157
                'parameters' => $_REQUEST
158
            )),
159
            10 // weight
160
        );
161
    }
162
    else if(variable_get('cdm_dataportal_specimen_derivate_tree')){
163
        $specimen_table = array(
164
            '#theme' => 'table',
165
            '#weight' => 2,
166
            // prefix attributes and rows with '#' to let it pass toF the theme function,
167
            // otherwise it is handled as child render array
168
            '#attributes' => array('class' => 'specimens'),
169
            '#rows' => array(),
170
        );
171
        $specimen_array = create_specimen_array($specimensOrObservations);
172

    
173
        foreach($specimen_array as $value){
174
            $renderArray = array(
175
                '#theme' => 'item_list',
176
                '#items' => array($value),
177
                '#type' => 'ul');
178
            $output = drupal_render($renderArray);
179
//            $specimen_table['#rows'][] = array(
180
//                // An array of table rows. collabsible row
181
//                'data' => "",
182
//                'class' => array('expand_column')
183
//            );
184
            $specimen_table['#rows'][] = array(
185
                // An array of table rows. Every row is an array of cells, or an associative array
186
                'data' => array($output),
187
                'class' =>  array(
188
                    'descriptionElement',
189
                    'descriptionElement_IndividualsAssociation'
190
                ),
191
            );
192

    
193

    
194
        }
195

    
196
        $render_array['specimen_list'] = $specimen_table;
197

    
198

    
199
    }
200
    else{
201
        //BOTTOM-UP-SPECIMEN-TABLE
202
        // --- generate the specimen list as table
203
        $specimen_table = array(
204
            '#theme' => 'table',
205
            '#weight' => 2,
206
            // prefix attributes and rows with '#' to let it pass toF the theme function,
207
            // otherwise it is handled as child render array
208
            '#attributes' => array('class' => 'specimens'),
209
            '#rows' => array(),
210
        );
211

    
212
        if ($specimensOrObservations) {
213

    
214
            foreach ($specimensOrObservations as $specimenOrObservation) {
215

    
216
                $mediaList = array();
217
                if (is_array($specimenOrObservation->_fieldObjectMedia)) {
218
                    $mediaList = array_merge($mediaList, $specimenOrObservation->_fieldObjectMedia);
219
                }
220
                if (is_array($specimenOrObservation->_derivedUnitMedia)) {
221
                    $mediaList = array_merge($mediaList, $specimenOrObservation->_derivedUnitMedia);
222
                }
223

    
224

    
225
                // typelabel will contain the typeStatus
226
                $type_label = '';
227
                $typeDesignationPager = cdm_ws_get(CDM_WS_OCCURRENCE . '/$0/specimenTypeDesignations', $specimenOrObservation->uuid);
228
                if (isset($typeDesignationPager) and isset($typeDesignationPager->records)) {
229
                    $type_status = array();
230
                    foreach ($typeDesignationPager->records as $typeDesignation) {
231
                        if (isset($typeDesignation->typeStatus->representation_L10n)){
232
                            $type_status[] = $typeDesignation->typeStatus->representation_L10n;
233
                        }
234
                    }
235
                    $type_label = implode(', ', $type_status);
236
                    if($type_label){
237
                        $type_label .= ': ' ;
238
                    }
239
                }
240

    
241
                // --- Specimen entry as dynamic label:
242
                //     -> Dynabox for the specimenOrObservation
243
                $gallery_name = $specimenOrObservation->uuid;
244

    
245
                $derived_unit_ws_request = cdm_compose_url(CDM_WS_OCCURRENCE, array( $specimenOrObservation->uuid));
246
                // --- Render associated media.
247
                $gallery_html = '';
248
                if (count($mediaList) > 0) {
249
                    $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
250
                    $captionElements = array(
251
                        '#uri' => t('open media'),
252
                    );
253

    
254
                    $gallery_html = compose_cdm_media_gallerie(array(
255
                        'mediaList' => $mediaList,
256
                        'galleryName' => $gallery_name,
257
                        'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
258
                        'cols' => $gallery_settings['cdm_dataportal_media_cols'],
259
                        'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
260
                        'captionElements' => $captionElements,
261
                        'mediaLinkType' => 'LIGHTBOX',
262
                        'alternativeMediaUri' => NULL,
263
                        'galleryLinkUri' => NULL,
264
                    ));
265
                }
266
                //here we should use the data we already have
267
                $label_html = cdm_dynabox(
268
                  $specimenOrObservation->uuid,
269
                  $type_label . $specimenOrObservation->titleCache,
270
                  $derived_unit_ws_request,
271
                  'cdm_specimen_or_observation',
272
                  'Click for details',
273
                  array('div', 'div'),
274
                  array(),
275
                  null, // $content_element_selector
276
                  'function(){ jQuery(\'#media_gallery_' . $gallery_name . '\').hide(); }', // open_callback
277
                  'function(){ jQuery(\'#media_gallery_' . $gallery_name . '\').show(); }' // close_callback
278
                );
279

    
280
                // --- Render associated media.
281
                $gallery_html = '';
282
                if (count($mediaList) > 0) {
283
                    $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
284
                    $captionElements = array(
285
                        '#uri' => t('open media'),
286
                    );
287

    
288
                    $gallery_html = compose_cdm_media_gallerie(array(
289
                        'mediaList' => $mediaList,
290
                        'galleryName' => $gallery_name,
291
                        'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
292
                        'cols' => $gallery_settings['cdm_dataportal_media_cols'],
293
                        'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
294
                        'captionElements' => $captionElements,
295
                        'mediaLinkType' => 'LIGHTBOX',
296
                        'alternativeMediaUri' => NULL,
297
                        'galleryLinkUri' => NULL,
298
                    ));
299
                }
300

    
301
                $specimen_table['#rows'][] = array(
302
                    // An array of table rows. Every row is an array of cells, or an associative array
303
                    'data' => array(
304
                        // Each cell can be either a string or an associative array
305
                        $label_html . $gallery_html
306
                    ),
307
                    'class' =>  array(
308
                        'descriptionElement',
309
                        'descriptionElement_IndividualsAssociation'
310
                    ),
311
                );
312
            }
313
        }
314

    
315
        $render_array['specimen_list'] = $specimen_table;
316
        $render_array['pager'] = markup_to_render_array(
317
            theme('cdm_pager', array(
318
                'pager' => $pager,
319
                'path' => $_REQUEST['q'],
320
                'parameters' => $_REQUEST,
321
            )),
322
            10 // weight
323
        );
324
    }
325
    $render_array['pager'] = markup_to_render_array(
326
        theme('cdm_pager', array(
327
            'pager' => $pager,
328
            'path' => $_REQUEST['q'],
329
            'parameters' => $_REQUEST,
330
        )),
331
        10 // weight
332
    );
333
    RenderHints::popFromRenderStack();
334
    return $render_array;
335
}
336

    
337
/**
338
 * Creates the drupal render array for the table showing all derivated which are
339
 * derive from a common gathering event.
340
 *
341
 * @param $field_unit_uuids array
342
 *  An array of uuids for cdm FieldUnit entities.
343
 *
344
 * @return array
345
 *  A drupal render array for a table
346
 *
347
 * @ingroup compose
348
 */
349
function compose_specimen_table($field_unit_uuids)
350
{
351
// get icon images
352
  $expand_icon = font_awesome_icon_markup(
353
    'fa-plus-square-o',
354
    array(
355
      'alt' => 'Show details',
356
      'class' => array('expand_icon')
357
    )
358
  );
359
  $collapse_icon = font_awesome_icon_markup(
360
    'fa-minus-square-o',
361
    array(
362
      'alt' => 'Show details',
363
      'class' => array('collapse_icon')
364
    )
365
  );
366
  $detail_image_icon = '<img title="Detail Image" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/detail_image_derivate-16x16-32.png' . '"/>';
367
  $checked_box_icon = '<img src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/step_done.gif' . '"/>';
368
  $sequence_icon = '<img title="Molecular Data" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/sequence_derivate-16x16-32.png' . '"/>';
369
  $character_data_icon = '<img title="Character Data" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/character_data_derivate-16x16-32.png' . '"/>';
370

    
371
  $rowcount = 0;
372
  $rows = array();
373

    
374
  foreach ($field_unit_uuids as $field_unit_uuid) {
375

    
376
    //get derivate hierarchy for the FieldUnit
377
    $derivateHierarchy = cdm_ws_get(CDM_WS_PORTAL_OCCURRENCE, array($field_unit_uuid, 'derivateHierarchy'));
378
    if ($derivateHierarchy) {
379
      //summary row
380
      $rows[] = array(
381
        'data' => array(
382
          array(
383
            'data' => $expand_icon . $collapse_icon,
384
            'class' => array('summary_row_cell', 'summary_row_icon', 'expand_column')
385
          ),
386
          array(
387
            'data' => $derivateHierarchy->country,
388
            'class' => array('summary_row_cell')
389
          ),
390
          array(
391
            'data' => $derivateHierarchy->date,
392
            'class' => array('summary_row_cell')
393
          ),
394
          array(
395
            'data' => $derivateHierarchy->collection,
396
            'class' => array('summary_row_cell')
397
          ),
398
          array(
399
            'data' => $derivateHierarchy->herbarium,
400
            'class' => array('summary_row_cell')
401
          ),
402
          array(
403
            'data' => $derivateHierarchy->hasType ? $checked_box_icon : "",
404
            'class' => array('summary_row_cell', 'summary_row_icon')
405
          ),
406
          array(
407
            'data' => $derivateHierarchy->hasSpecimenScan ? $checked_box_icon : "",
408
            'class' => array('summary_row_cell', 'summary_row_icon')
409
          ),
410
          array(
411
            'data' => ($derivateHierarchy->hasDna ? $sequence_icon : "") . " "
412
              . ($derivateHierarchy->hasDetailImage ? $detail_image_icon : "") . " "
413
              . ($derivateHierarchy->hasCharacterData ? $character_data_icon : ""),
414
            'class' => array('summary_row_cell', 'summary_row_icon')
415
          )
416
        ),
417
        'id' => ('derivate_summary' . $rowcount), // summary row id
418
        'class' => array('summary_row'),
419
      );
420

    
421
      //assemble field unit details
422
      $detail_html = "";
423
      // - citation
424
      if ($derivateHierarchy->citation) {
425
        $detail_html .= create_label("Citation") . $derivateHierarchy->citation . "<br>";
426
      }
427
      //assemble specimen details
428
      if ($derivateHierarchy->derivates) {
429
        foreach ($derivateHierarchy->derivates as $preservedSpecimenDTO) {
430
          $detail_html .= "<br>";
431
          $detail_html .= render_cdm_specimen_page($preservedSpecimenDTO);
432
        }
433
      }
434
      $detail_html .= "<br>";
435
      //detail row resp. one BIG detail cell
436
      $rows[] = array(
437
        'data' => array(
438
          array(
439
            'data' => "", //empty first column
440
            'class' => array('expand_column')
441
          ),
442
          array(
443
            'data' => $detail_html,
444
            'colspan' => 7,
445
          ),
446
        ),
447
        'id' => ('derivate_details' . $rowcount),//details row ID
448
        'class' => array('detail_row'),
449
      );
450
      $rowcount++;
451
    }
452
  }
453

    
454
  $tableId = "derivate_hierarchy_table";
455
  $derivateHierarchyTable = array(
456
    "#theme" => "table",
457
    "#weight" => 2,
458
    "#header" => array(
459
      array(
460
        'data' => "",
461
        'class' => array('expand_column')
462
      ),
463
      "Country", "Date", "Collector + collecting number", "Herbaria", "Type", "Scan", "Derivatives"),
464
    "#rows" => $rows,
465
    "#attributes" => array(
466
      "id" => $tableId,
467
      "border" => 2
468
    )
469
  );
470

    
471
  //add toggle functionality to derivate hierarchy table
472
  drupal_add_js_rowToggle("#" . $tableId);
473

    
474
  return $derivateHierarchyTable;
475
}
476

    
477
function create_html_link($link, $openInExternalWindow=false){
478
    $html = "";
479
    if($link->uri && $link->uri!=""){
480
        $html .= '<a  href="' . $link->uri . '"';
481
        if($openInExternalWindow){
482
            $html .= ' target="_blank"';
483
        }
484
        $html .= '>' . $link->linkText . '</a>';
485
    }
486
    else{
487
        $html .= $link->linkText;
488
    }
489
    return $html;
490
}
491

    
492
/**
493
 * Creates HTML links from the given link list concatenated by default by a comma.
494
 * @param $linkList the list with Link objects having "uri" and "linkText" as members
495
 * @return string the assembled HTML string containing the links
496
 */
497
function create_html_links($linkList, $openInExternalWindow=false, $separator=", ")
498
{
499
    $html = "";
500
    if ($linkList) {
501
        foreach ($linkList as $link) {
502
            $html .= create_html_link($link, $openInExternalWindow).$separator;
503
        }
504
        $html = rtrim($html, $separator);
505
    }
506
    return $html;
507
}
508

    
509
/**
510
 * Composes a taxon page which can consist of multiple parts like
511
 * 'General', 'Synonymy', 'Images', 'Keys'. These parts can be displayed
512
 * as tabs or as sections of a single page.
513
 *
514
 * It is headed by the name of the accepted taxon without author and reference.
515
 *
516
 * @param $taxon
517
 *   The CDM Taxon Instance to compose the page for.
518
 * @param $page_part
519
 *   Name of the part to display, valid values are:
520
 *    - 'description' -  for the general part
521
 *    - 'images'
522
 *    - 'synonymy'
523
 *    - 'keys'
524
 *    - 'all'
525
 *
526
 * @return array
527
 *   A drupal render array
528
 *
529
 * @ingroup compose
530
 */
531
function compose_cdm_taxon_page($taxon, $page_part = 'description') {
532

    
533
  // we better cache here since drupal_get_query_parameters has no internal static cache variable
534
  $http_request_params = drupal_get_query_parameters();
535

    
536
  // add all mandatory js sources
537
  _add_js_footnotes();
538

    
539

    
540
  $render_array = array();
541
  $weight = 0; // the weight for the render array elements
542

    
543
  $tabsToDisplay = variable_get('cdm_taxonpage_tabs_visibility', unserialize(TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT));
544

    
545
  $page_part = variable_get('cdm_dataportal_taxonpage_tabs', 1) ? $page_part : 'all';
546

    
547
  $synonymy_as_tab = variable_get(CDM_SYNONYMY_AS_TAB, CDM_SYNONYMY_AS_TAB_DEFAULT) === 1;
548
  if(!$synonymy_as_tab){
549
    unset($tabsToDisplay["Synonymy"]);
550
    // the synonymy is located in the general part in this case
551
    if($page_part == 'synonymy'){
552
      $page_part = 'description';
553
    }
554
  }
555

    
556
  $media = _load_media_for_taxon($taxon);
557

    
558

    
559
  if (!isset($media[0]) || ($tabsToDisplay["Images"] == '0')) {
560
    taxon_page_tabs_hidden_add('images');
561
  }
562

    
563
  // --- GET specimensOrObservations --- //
564
  $specimensOrObservations = cdm_ws_get(CDM_WS_TAXON, array( $taxon->uuid, 'specimensOrObservationsCount'));
565

    
566
  $specimensOrObservationsCount = $specimensOrObservations != null ? $specimensOrObservations->result : 0;
567
  if ($specimensOrObservationsCount == 0 || ($tabsToDisplay["Specimens"] == '0')) {
568
    taxon_page_tabs_hidden_add('specimens');
569
  }
570

    
571
  // --- GET polytomousKeys --- //
572
  $polytomousKeysPager = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, NULL, "findByTaxonomicScope=$taxon->uuid");
573
  $identificationKeyCount = 0;
574
  if ($polytomousKeysPager) {
575
    $identificationKeyCount += $polytomousKeysPager->count;
576
  }
577
  if ($identificationKeyCount == 0 || ($tabsToDisplay["Keys"] == '0')) {
578
    taxon_page_tabs_hidden_add('keys');
579
  }
580

    
581
  // --- GET TaxonNodeAgentRelations --- //
582
  $current_classification_uuid = get_current_classification_uuid();
583
  $taxon_node_agent_relations_pager = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODEAGENTRELATIONS,
584
      array(
585
          $taxon->uuid,
586
          $current_classification_uuid,
587
      ),
588
      "pageSize=1&pageIndex=0"// we are only interested into the count so we are fetching only one item, o is not possible!
589
  );
590
  if (!$taxon_node_agent_relations_pager || $taxon_node_agent_relations_pager->count == 0){
591
      taxon_page_tabs_hidden_add('experts');
592
  }
593

    
594
  if (!isset($tabsToDisplay["Synonymy"]) || $tabsToDisplay["Synonymy"] == '0') {
595
    taxon_page_tabs_hidden_add('synonymy');
596
  }
597

    
598
  // -------------------------------------------- //
599

    
600
  if (variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR) && isset($_REQUEST['acceptedFor'])) {
601
    $render_array['accepted_for'] = markup_to_render_array(cdm_accepted_for($_REQUEST['acceptedFor']), $weight++);
602
  }
603

    
604
  // --- PAGE PART: DESCRIPTION --- //
605
  if (!taxon_page_tabs_hidden_check('description') && ($page_part == 'description' || $page_part == 'all')) {
606

    
607
    $merged_tree = merged_taxon_feature_tree($taxon);
608

    
609

    
610
    $render_array['general'] = compose_cdm_taxon_page_profile($taxon, $merged_tree, $media, !$synonymy_as_tab);
611
    $render_array['general']['#weight'] = $weight++;
612
    $render_array['general']['#prefix'] = '<div id="general" class="page-part">';
613
    $render_array['general']['#suffix'] = '</div>';
614
  }
615

    
616
  // --- PAGE PART: IMAGES --- //
617
  if (!taxon_page_tabs_hidden_check('images') && ($page_part == 'images' || $page_part == 'all')) {
618
    $images_html = '<div id="images" class="page-part">';
619
    if ($page_part == 'all') {
620
      $images_html .= '<h2>' . t(cdm_taxonpage_tab_label('Images')) . '</h2>';
621
    }
622
    // Get the image gallery as configured by the admin.
623
    $default_image_gallery = 'default';
624
    $configured_image_gallery_viewer = variable_get('image_gallery_viewer', 'default');
625
    $taxon_image_gallery = '<div class="error">No image gallery viewer configured</div>';
626
    if($configured_image_gallery_viewer == $default_image_gallery || $configured_image_gallery_viewer == 'fsi'){
627
      // the fsi_gallery requires a flash plugin, in case the client browser is not supporting
628
      // flash we also need to provide an the default gallery as alternative
629
      $taxon_image_gallery = '<div id="default-gallery-viewer">' .
630
        call_user_func_array('taxon_image_gallery_' . $default_image_gallery, array(
631
          $taxon,
632
          $media,
633
        ))
634
        . '</div>';
635
    }
636
    if($configured_image_gallery_viewer == 'fsi'){
637
      $taxon_image_gallery .= '<div id="'. $configured_image_gallery_viewer .'-gallery-viewer">' .
638
        call_user_func_array('taxon_image_gallery_' . $configured_image_gallery_viewer, array(
639
          $taxon,
640
          $media,
641
        ))
642
       . '</div>';
643
    }
644
    $images_html .= $taxon_image_gallery;
645
    $images_html .= '</div>';
646
    $render_array['images'] = markup_to_render_array($images_html, $weight++);
647
  }
648

    
649
  // --- PAGE PART: SYNONYMY --- //
650
  if (!taxon_page_tabs_hidden_check('synonymy') && (($page_part == 'synonymy' || $page_part == 'all') && $synonymy_as_tab)) {
651
    $synonymy_html = '<div id="synonymy" class="page-part">';
652
    if ($page_part == 'all') {
653
      $synonymy_html .= '<h2>' . t(cdm_taxonpage_tab_label('Synonymy')) . '</h2>';
654
    }
655
    $addAcceptedTaxon = variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE);
656

    
657
    $synonymy_html .= theme('cdm_taxon_page_synonymy', array('taxon' => $taxon, 'addAcceptedTaxon' => $addAcceptedTaxon));
658

    
659
    $synonymy_html .= '</div>';
660
    $render_array['synonymy'] = markup_to_render_array($synonymy_html, $weight++);
661

    
662
  }
663

    
664
  // --- PAGE PART: SPECIMENS --- //
665
  if (!taxon_page_tabs_hidden_check('specimens') && ($specimensOrObservationsCount > 0 && ($page_part == 'specimens' || $page_part == 'all'))) {
666
    $render_array['specimens'] = array(
667
        '#prefix' => '<div id="specimens" class="page-part">' . ($page_part == 'all' ? '<h2>' . t(cdm_taxonpage_tab_label('Specimens')) . '</h2>' : ''),
668
        'content' => cdm_dataportal_taxon_page_specimens($taxon), // returns render array
669
        '#suffix' => '</div>',
670
    );
671
  }
672

    
673
  // --- PAGE PART: KEYS --- //
674
  if(!taxon_page_tabs_hidden_check('keys')){
675
    if ($identificationKeyCount == 1 && $page_part == 'keys'){
676
      drupal_goto(path_to_key($polytomousKeysPager->records[0]->class, $polytomousKeysPager->records[0]->uuid));
677
    }
678
    else if ($identificationKeyCount > 0 && ($page_part == 'keys' || $page_part == 'all')) {
679
      $keys_html = '<div id="keys" class="page-part">';
680
      if ($page_part == 'all') {
681
        $keys_html .= '<h2>' . t(cdm_taxonpage_tab_label('Keys')) . '</h2>';
682
      }
683
      $keys_html .= theme('cdm_block_IdentificationKeys', array('taxonUuid' => $taxon->uuid));
684
      $keys_html .= '</div>';
685
      $render_array['keys'] = markup_to_render_array($keys_html, $weight++);
686
    }
687
  }
688

    
689
  // --- PAGE PART: EXPERTS --- //
690

    
691
  if (!taxon_page_tabs_hidden_check('experts') && ($page_part == 'experts' || $page_part == 'all')) {
692
    $render_array['experts'] = array(
693
        '#prefix' => '<div id="experts" class="page-part">' . ($page_part == 'all' ? '<h2>' . t(cdm_taxonpage_tab_label('Experts')) . '</h2>' : ''),
694
        'content' => compose_cdm_taxon_page_experts($taxon), // returns render array
695
        '#suffix' => '</div>',
696
    );
697
  }
698

    
699
  // ------------------ END OF PARTS -------------- //
700

    
701
  // adjust weights of page and toc elements according to the settings
702
  $taxontabs_weights = get_array_variable_merged(CDM_TAXONPAGE_TAB_WEIGHT, CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
703
  foreach($taxontabs_weights as $tab_key => $weight){
704
    if(isset($render_array[$tab_key])){
705
      $render_array[$tab_key]['#weight'] = $weight;
706
    }
707
  }
708

    
709

    
710
  // set up the TOC for the pages which contain all pageparts
711
  if($page_part == 'all') {
712

    
713
    asort($taxontabs_weights);
714
    foreach(array_keys($taxontabs_weights) as $tab_key){
715
      if(isset($render_array[$tab_key])){
716
        if($tab_key != 'general'){
717
          // add entry for page part
718
          $toc_elements[] = array(
719
              'data' => l(t(cdm_taxonpage_tab_label(ucfirst($tab_key))), $_GET['q'], array('fragment' => $tab_key, 'query' => $http_request_params)),
720
              'class' => array('page-part-toc-item-' . $tab_key)
721
          );
722
        } else {
723
          // add content of profile part instead
724
          if(isset($render_array['general'])) {
725
            // in case all tabs are shown at once the feature tocs
726
            // should be integrated into the tabs toc as sub list
727
            // and the profile image should be on top of the page
728
            if(isset($render_array['general']['taxon_description_feature_toc'])){;
729
            foreach ($render_array['general']['taxon_description_feature_toc']['#items'] as $profile_toc_item){
730
              $toc_elements[] = $profile_toc_item;
731
            }
732
            unset($render_array['general']['taxon_description_feature_toc']);
733
            }
734
          }
735
        }
736
      }
737
    }
738

    
739
    // move profile image in page structure
740
    if(isset($render_array['general']['taxon_profile_image'])){
741
      $render_array['profile_image'] = $render_array['general']['taxon_profile_image'];
742
      $render_array['profile_image']['#weight'] = -100;
743
      unset($render_array['general']['taxon_profile_image']);
744
    }
745

    
746
    // finally add the table of contents to the render array
747
    $render_array['toc'] = array(
748
        '#theme' => 'item_list',
749
        '#items' => $toc_elements,
750
        '#title' => t('Content'),
751
        '#weight' => -101,
752
        '#suffix' => '</div>',
753
        '#prefix'=> '<div id="page-toc">'
754
    );
755
  }
756

    
757

    
758
  return $render_array;
759
}
760

    
761
/**
762
 * TODO should this function really be a compose function?
763
 *     For a compose function must there always be a theme function with the same name? (ak 8.8.2013)
764
 *
765
 * composes and returns an render array containing the components of the taxon profile tab:
766
 *  - 'taxon_profile_image'
767
 *  - 'taxon_description_feature_toc'
768
 *  - 'taxon_description_features'
769
 *
770
 *
771
 * @param object taxon
772
 * @param object $merged_tree
773
 * @param object media
774
 * @param bool $add_synonymy
775
 *
776
 * @return array
777
 *   A Drupal render array with the following elements:
778
 *     - 'taxon_profile_image'
779
 *     - 'taxon_description_feature_toc'
780
 *     - 'taxon_description_features'
781
 *
782
 * @throws Exception
783
 *
784
 * @ingroup compose
785
 */
786
function compose_cdm_taxon_page_profile($taxon, $merged_tree, $media, $add_synonymy) {
787

    
788
  $render_array = array();
789

    
790
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
791

    
792
  $hide_taxon_profile_image = FALSE;
793
  if (variable_get('image_hide_rank', '0') != '0' && isset($taxon->name->rank->uuid)) {
794
    $rankCompare = rank_compare($taxon->name->rank->uuid, variable_get('image_hide_rank', '-99'));
795
    $hide_taxon_profile_image = ($rankCompare > -1);
796
  }
797

    
798
  if ($taxon_profile_image_settings['show'] && !$hide_taxon_profile_image) {
799

    
800
    $representationPart = new stdClass();
801
    $attributes = array();
802
    if (isset($media[0])) {
803
      // due to a bug the portal/taxon/{uuid}/media service only delivers a filtered media object
804
      // which only contains the thumbnail representation even if the height and width filters are not set.
805
      // -->
806
      $preferred_media = cdm_ws_get(CDM_WS_MEDIA, $media[0]->uuid);
807
      $preferred_representations = cdm_preferred_media_representations($preferred_media, array(
808
        'image/jpg',
809
        'image/jpeg',
810
        'image/png',
811
        'image/gif',
812
      ),
813
        $taxon_profile_image_settings['maxextend'],
814
        $taxon_profile_image_settings['maxextend']
815
      );
816
      if(count($preferred_representations) > 0){
817

    
818
        $representation = array_shift($preferred_representations);
819
        $representationPart = $representation->parts[0];
820
        $attributes['alt'] = $representationPart->uri;
821

    
822
        if (!empty($taxon_profile_image_settings['media_uri_query'])) {
823
          $representationPart->uri = $representationPart->uri
824
            . (strpos($representationPart->uri, '?') !== FALSE ? '&' : '?')
825
            . $taxon_profile_image_settings['media_uri_query'];
826
        }
827
      }
828
    }
829
    else {
830
      if ($taxon_profile_image_settings['custom_placeholder_enabled']) {
831
        // show placeholder image instead
832
        if (!empty($taxon_profile_image_settings['custom_placeholder_image_on']) && !empty($taxon_profile_image_settings['custom_placeholder_image_fid'])) {
833
          // use the user provided image
834
          $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
835
          $url = file_create_url($profile_image_file->uri);
836
          $image_info = image_get_info($profile_image_file->uri);
837
          $representationPart->width = $image_info['width'];
838
          $representationPart->height = $image_info['height'];
839
          $representationPart->uri = $url;
840
        }
841
        else {
842
          // use the hard coded default
843
          $representationPart->width = 184;
844
          $representationPart->height = 144;
845
          $representationPart->uri = base_path() . drupal_get_path('module',
846
              'cdm_dataportal') . '/images/no_picture.png';
847
        }
848
        $attributes['alt'] = "no image available";
849
      }
850
    }
851

    
852
    if (isset($representationPart->uri)) {
853
      $profile_image = cdm_media_gallerie_image($representationPart, $taxon_profile_image_settings['maxextend'], FALSE, $attributes);
854
      // NOTE: style="width:${maxextend}px' is needed for IE8 !!!
855
      $render_array['taxon_profile_image'] = markup_to_render_array('<div id="taxonProfileImage" style="width:' . $taxon_profile_image_settings['maxextend'] . 'px">' . $profile_image . '</div>',
856
        -101);
857
    }
858
  }
859

    
860
  if($add_synonymy){
861
    $render_array['synonymy'] = markup_to_render_array(
862
      theme('cdm_taxon_page_synonymy', array('taxon' => $taxon, 'addAcceptedTaxon' => true)),
863
      -102
864
    );
865
  }
866

    
867
  $pseudo_feature_blocks = array();
868
  $pseudo_feature_block_toc_items = array();
869

    
870

    
871
  // Render the sections for each real feature
872
  $feature_block_list = make_feature_block_list($merged_tree->root->childNodes, $taxon);
873

    
874
  // Bibliography
875
  $bibliography_settings = get_bibliography_settings();
876
  if($bibliography_settings['enabled'] == 1){
877
    $bibliography_markup = FootnoteManager::renderFootnoteList('BIBLIOGRAPHY', '');
878
    if($bibliography_markup) {
879
      $feature_bibliography = make_pseudo_feature('Bibliography', 'BIBLIOGRAPHY');
880
      $bibliography_block = feature_block(t('Bibliography'), $feature_bibliography);
881
      $bibliography_item = markup_to_render_array($bibliography_markup);
882
      $bibliography_block->content[] = compose_feature_block_wrap_elements(array($bibliography_item), $feature_bibliography);
883

    
884
      $pseudo_feature_block_toc_items['Bibliography']= 'bibliography';
885
      $pseudo_feature_blocks[] = $bibliography_block;
886
    }
887
  }
888

    
889
  $render_array['taxon_description_features'] = _block_get_renderable_array(
890
    array_merge($feature_block_list, $pseudo_feature_blocks)
891
  );
892

    
893
  if($pseudo_feature_block_toc_items){
894
    foreach ($pseudo_feature_block_toc_items as $label=>$fragment){
895
      cdm_toc_list_add_item($label, $fragment);
896
    }
897
  }
898

    
899
  // create the table of content
900
  $toc = array(
901
      '#theme' => 'item_list',
902
    '#items' => cdm_toc_list(),
903
      '#title' => t('Content'),
904
    '#weight' => -100,                  // move to the top
905
      '#suffix' => '</div>',
906
      '#prefix'=> '<div id="page-toc">'
907
  );
908
  $render_array['taxon_description_feature_toc'] = $toc;
909

    
910
  return $render_array;
911
}
912

    
913
/**
914
 * composes and returns an render array for the experts associated with the given taxon
915
 *
916
 * @param object taxon
917
 *
918
 * @return array
919
 *   A Drupal render array for a table with the experts
920
 *
921
 * @ingroup compose
922
 */
923
function compose_cdm_taxon_page_experts($taxon){
924

    
925
  $render_array = array();
926
  if(!isset($taxon->uuid)){
927
    return $render_array;
928
  }
929

    
930
  $current_classification_uuid = get_current_classification_uuid();
931
  // TODO use cdm_ws_fetchall below but this failes! needs fix!
932
  $taxon_node_agent_relations = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODEAGENTRELATIONS,
933
    array(
934
      $taxon->uuid,
935
      $current_classification_uuid
936
    )
937
  );
938

    
939
  $header = array(
940
    array('data' => t('Expert')),
941
    array('data' => t('Role'))
942
  );
943
  $rows = array();
944

    
945

    
946
  foreach($taxon_node_agent_relations->records as $taxon_node_agent_relation){
947

    
948

    
949
    $expert_role_id = $taxon_node_agent_relation->agent->uuid . '-' . $taxon_node_agent_relation->type->uuid;
950
    $expert_details_container_id = 'expert_details_' . $expert_role_id;
951

    
952
    $agent_label_markup = cdm_dynabox(
953
      'expert_' . $expert_role_id,
954
      $taxon_node_agent_relation->agent->titleCache,
955
      // specifying both ends of the relationship will return only one record in the pager
956
      cdm_compose_url(CDM_WS_PORTAL_AGENT,
957
         array($taxon_node_agent_relation->agent->uuid, 'taxonNodeAgentRelations'),
958
        'taxon_uuid=' . $taxon->uuid . '&relType_uuid=' . $taxon_node_agent_relation->type->uuid),
959
      'cdm_taxon_expert',
960
      'Click for details',
961
      array('div', 'div'),
962
      array(), // attributes
963
      '#' . $expert_details_container_id // $content_element_selector
964
    );
965

    
966
    // Expert and Role
967
    $rows[] = array(
968
      'data' => array(
969
        array(
970
          'data' => $agent_label_markup,
971
          'class' => array(html_class_attribute_ref($taxon_node_agent_relation->agent))
972
        ),
973
        array(
974
          'data' => $taxon_node_agent_relation->type->representation_L10n,
975
          'class' => array(html_class_attribute_ref($taxon_node_agent_relation->type))
976
        )
977
      )
978
    );
979
    // Agent details
980
    $rows[] = array(
981
      'data' => array(
982
        array(
983
          'data' => '<!-- expert_details_container -->',
984
          'id' => $expert_details_container_id,
985
          'colspan' => 2
986
        )
987
      )
988
    );
989

    
990
  }
991

    
992

    
993
  $render_array['experts_table'] = array(
994
    '#theme' => 'table',
995
    '#header' => $header,
996
    '#rows' => $rows,
997
  );
998

    
999

    
1000
  return $render_array;
1001
}
1002

    
1003

    
1004
/**
1005
 * Manages the tabs to be hidden in the taxon page.
1006
 *
1007
 * The tabs are identified by their last menu link path element:
1008
 *  - description
1009
 *  - synonymy
1010
 *  - images
1011
 *  - specimens
1012
 *  - key
1013
 *
1014
 * Internally the tabs are stored in a static variable which is
1015
 * managed by drupal_static().
1016
 *
1017
 * @param string $add_tab
1018
 *   Optional parameter. The given string will be added to the array of tabs
1019
 *
1020
 * @return
1021
 *   The array of tabs
1022
 */
1023
function taxon_page_tabs_hidden_add($add_tab = NULL) {
1024
  $tabs = &drupal_static('taxon_page_tabs_hidden');
1025

    
1026
  if(!isset($tabs)){
1027
    $tabs = array();
1028
  }
1029

    
1030
  if (isset($add_tab) && !array_key_exists($add_tab, $tabs)) {
1031
    $tabs[] = $add_tab;
1032
  }
1033

    
1034
  return $tabs;
1035
}
1036

    
1037
/**
1038
 * Manages the tabs to be hidden in the taxon page.
1039
 *
1040
 * The tabs names are identified by their last menu link path element:
1041
 *  - description
1042
 *  - synonymy
1043
 *  - images
1044
 *  - specimens
1045
 *  - key
1046
 *
1047
 * Internally the tabs are stored in a static variable which is
1048
 * managed by drupal_static().
1049
 *
1050
 * @param string $tabname
1051
 *   The name of the tab to check
1052
 *
1053
 * @return boolean
1054
 *   True if the tab or section is to be hidden
1055
 */
1056
function taxon_page_tabs_hidden_check($tabname) {
1057

    
1058
  $tabs = &drupal_static('taxon_page_tabs_hidden');
1059

    
1060
  if(!isset($tabs)){
1061
    $tabs = array();
1062
  }
1063

    
1064
  return array_search($tabname, $tabs) !== FALSE;
1065
}
1066

    
1067
/**
1068
 * Implements the hook_preprocess_HOOK() for theme_menu_local_tasks()
1069
 *
1070
 *  - Removes the tabs to be hidden, @see taxon_page_tabs_hidden_add()
1071
 *  - Renames tabs according to the settings // TODO (this will replace the theme_cdm_taxonpage_tab() function !!!)
1072
 *
1073
 * @param array $variables
1074
 *   The variables array
1075
 */
1076
function cdm_dataportal_preprocess_menu_local_tasks(&$variables) {
1077

    
1078
  $hidden_tabs = taxon_page_tabs_hidden_add();
1079

    
1080
  if (is_array($variables['primary'])) {
1081
    foreach ($variables['primary'] as $key => &$element) {
1082

    
1083
      // 1. Remove the tabs to be hidden
1084
      foreach ($hidden_tabs as $tab) {
1085
        if ($element['#link']['path'] == 'cdm_dataportal/taxon/%/' . $tab) {
1086
          // remove the tab
1087
          unset($variables['primary'][$key]);
1088
        }
1089
      }
1090
    }
1091
  }
1092
}
1093

    
1094

    
1095

    
1096
/**
1097
 * Implements the hook_preprocess_HOOK() for theme_menu_local_task()
1098
 *
1099
 *
1100
 * @param array $variables
1101
 *   An associative array containing:
1102
 *     - element: A render element containing:
1103
 *          #link: A menu link array with 'title', 'href', and 'localized_options' keys.
1104
 *          #active: A boolean indicating whether the local task is active.
1105
 *
1106
 */
1107
function cdm_dataportal_preprocess_menu_local_task(&$variables) {
1108

    
1109
  $link = $variables['element']['#link'];
1110
  if (preg_match('/cdm_dataportal\/.*\/refresh$/', $link['href'])) {
1111
    $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']) . '"/>';
1112
    $link['localized_options']['html'] = TRUE;
1113

    
1114
    $variables['element']['#link'] = $link;
1115
  }
1116
}
1117

    
1118
/* =================== block composition ===================== */
1119

    
1120
/**
1121
 * Composes and returns an render array for the classification breadcrumbs of the given taxon.
1122
 *
1123
 * @param taxon
1124
 *
1125
 * @return array
1126
 *   A Drupal render array for a table with the experts
1127
 *
1128
 * @ingroup compose
1129
 */
1130
function compose_classification_breadcrumbs($taxon_uuid) {
1131

    
1132
  _add_js_taxonomic_children('#classification-breadcrumbs .taxonomic-children-button');
1133

    
1134
  $render_array = array();
1135

    
1136
  $render_array['#theme'] = 'item_list';
1137
  $render_array['#type'] = 'ul';
1138
  $render_array['#attributes'] = array(
1139
    'id' => 'classification-breadcrumbs',
1140
    'class' => 'breadcrumbs inline',
1141
  );
1142

    
1143
  $items = array();
1144

    
1145
  $parent_taxon_nodes = null;
1146
  if($taxon_uuid){
1147
    $parent_taxon_nodes = cdm_ws_taxonomy_pathFromRoot($taxon_uuid);
1148
  }
1149

    
1150
  $classifications = cdm_ws_fetch_all(CDM_WS_PORTAL_TAXONOMY);
1151
  // find current classification in list
1152
  $classification = null;
1153
  $current_classification_uuid = get_current_classification_uuid();
1154
  foreach ($classifications as $classification){
1155
    if($classification->uuid == $current_classification_uuid){
1156
      break;
1157
    }
1158
  }
1159

    
1160
  $node_name = '';
1161
  if(count($classifications) > 1 ){
1162
    // need to add the current classification as first label
1163

    
1164
    $label = $classification->titleCache;
1165
    if(strlen($label) > 20){
1166
      $label = substr($label, 0, strpos($label, ' ', 15)) . '...';
1167
    }
1168
    $node_name = font_awesome_icon_markup('fa-th-list')  . ' ' . l($label, '#', array(
1169
      'attributes' => array(
1170
        'class' => 'taxonomic-children-button classification-chooser',
1171
        'data-destination-uri' => drupal_get_destination(),
1172
        'data-cdm-align-with' => array('prev')
1173
      ),
1174
      'html' => true
1175
    ));
1176
  }
1177

    
1178
  $rank_limit_uuid = variable_get(TAXONTREE_RANKLIMIT, TAXONTREE_RANKLIMIT_DEFAULT);
1179

    
1180
  $rank_separator = '<span> '
1181
    . font_awesome_icon_markup('fa-chevron-right')
1182
    . ' </span>';
1183
  $more_children_icon = font_awesome_icon_markup('fa-sitemap fa-rotate-270');
1184
  $more_children_label = '...';
1185

    
1186
  $items[] = $node_name;
1187

    
1188
  $more_children_for = null;
1189
  if($parent_taxon_nodes){
1190
    foreach ($parent_taxon_nodes as $node) {
1191

    
1192
      $is_first_item = count($items) == 0;
1193
      $is_last_item = count($items) == count($parent_taxon_nodes);
1194
      $node_name = cdm_dataportal_shortname_of($node);
1195
      $path = path_to_taxon($node->taxonUuid);
1196

    
1197
      if($node->taxonomicChildrenCount > 0) {
1198
        $more_children_for = $node->taxonUuid;
1199
      } else {
1200
        $more_children_for = null;
1201
      }
1202

    
1203
      // 'fa-sitemap'
1204

    
1205
      $items[] =
1206
        ($is_first_item ? '' : ' ')
1207
        . $rank_separator
1208
        . l(
1209
          '<span class="' . html_class_attribute_ref($node) . '">' . $node_name . '</span>',
1210
          $path,
1211
          array(
1212
            'attributes' => array(
1213
              'class' => array('taxonomic-children-button'),
1214
              'data-cdm-taxon-uuid' => array($node->taxonUuid),
1215
              'data-cdm-classification-mode' => array('siblings'),
1216
              'data-cdm-align-with' => array('prev')
1217
            ),
1218
            'html' => true
1219
          )
1220
        );
1221
      }
1222
    }
1223

    
1224
  // add more button to the end
1225
  if(!$parent_taxon_nodes) {
1226
    // not taxon focused yet, adding button to make  the root nodes available
1227
    $items[] = '<span>'
1228
      . $more_children_icon . '&nbsp;' .
1229
      '<span class="taxonomic-children-button" data-classification-uuid="' . $current_classification_uuid
1230
      . '" data-rank-limit-uuid="' . $rank_limit_uuid . '" data-cdm-align-with="prev"> ' . $more_children_label . '<span>'
1231
      . '</span>';
1232
  } else if($more_children_for){
1233
    // last parent item has child taxon nodes
1234
    $items[] = ' <span>'
1235
      . $more_children_icon . '&nbsp;' .
1236
      '<span class="taxonomic-children-button" data-cdm-taxon-uuid="' .$more_children_for
1237
      . '" data-cdm-classification-mode="children" data-cdm-align-with="prev"> ' . $more_children_label . '</span>'
1238
      . '</span>';
1239

    
1240
  }
1241

    
1242
  $render_array['#items'] = $items;
1243

    
1244
  return $render_array;
1245
}
1246

    
1247

    
1248
/**
1249
 * @param $specimen_uuid
1250
 * @return array
1251
 *    The drupal render array for the page
1252
 *
1253
 * @ingroup compose
1254
 */
1255
function compose_cdm_specimen_page($specimen_uuid)
1256
{
1257
  drupal_set_title("Specimen Details");
1258
  $specimen = cdm_ws_get(CDM_WS_PORTAL_OCCURRENCE, array($specimen_uuid, 'specimenDerivates'));
1259

    
1260
  $render_array = array();
1261
  RenderHints::pushToRenderStack('specimen_page');
1262

    
1263
  $detail_html = render_cdm_specimen_page($specimen, true);
1264
  $render_array['specimen_html'] = array(
1265
    '#markup' => $detail_html
1266
  );
1267

    
1268
  RenderHints::popFromRenderStack();
1269
  return $render_array;
1270
}
1271

    
1272
/**
1273
 * @param $named_area_uuid
1274
 * @return array
1275
 *    The drupal render array for the page
1276
 *
1277
 * @ingroup compose
1278
 */
1279
function compose_cdm_named_area_page($named_area_uuid)
1280
{
1281

    
1282
  $named_area = cdm_ws_get(CDM_WS_PORTAL_TERM, array($named_area_uuid));
1283

    
1284
  $render_array = array();
1285
  RenderHints::pushToRenderStack('named_area_page');
1286

    
1287
  $groups = array();
1288
  @_description_list_group_add($groups, t('Name') . ':', $named_area->representation_L10n);
1289
  @_description_list_group_add($groups, t('IdInVocabulary') . ':', $named_area->idInVocabulary);
1290
  if(isset($named_area->level)) {
1291
    @_description_list_group_add($groups, t('Level') . ':', $named_area->level->representation_L10n);
1292
  }
1293

    
1294
  $name_area_details_elements = array(
1295
   // '#title' => $title,
1296
    '#theme' => 'description_list',
1297
    '#groups' => $groups,
1298
    '#attributes' => array('class' => html_class_attribute_ref($named_area)),
1299
  );
1300

    
1301
  $render_array[] = $name_area_details_elements;
1302

    
1303
  RenderHints::popFromRenderStack();
1304
  return $render_array;
1305
}
1306

    
1307
/**
1308
 * Provides the the label string for taxon page tabs.
1309
 *
1310
 * The $tabname as passed to the method will be returned if no override
1311
 * label is configured in the settings.
1312
 */
1313
function cdm_taxonpage_tab_label($tabname) {
1314
  static $taxon_tabs_labels = null;
1315
  if($taxon_tabs_labels == null){
1316
    $taxon_tabs_labels = get_array_variable_merged(CDM_TAXONPAGE_TAB_LABELS, CDM_TAXONPAGE_TAB_LABELS_DEFAULT);
1317
  }
1318
  $tabname_key = strtolower($tabname);
1319
  if(isset($taxon_tabs_labels[$tabname_key]) && $taxon_tabs_labels[$tabname_key]){
1320
    return $taxon_tabs_labels[$tabname_key];
1321
  }
1322
  return $tabname;
1323
}
(7-7/10)