Project

General

Profile

Download (46 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
          $render_array['derivate_hierarchy_table'] = compose_specimen_table($field_unit_uuids);
142
        }
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. collabsible row
172
//                'data' => "",
173
//                'class' => array('expand_column')
174
//            );
175
            $specimen_table['#rows'][] = array(
176
                // An array of table rows. Every row is an array of cells, or an associative array
177
                'data' => array($output),
178
                'class' =>  array(
179
                    'descriptionElement',
180
                    'descriptionElement_IndividualsAssociation'
181
                ),
182
            );
183

    
184

    
185
        }
186

    
187
        $render_array['specimen_list'] = $specimen_table;
188

    
189

    
190
    }
191
    else{
192
        //BOTTOM-UP-SPECIMEN-TABLE
193
        // --- generate the specimen list as table
194
        $specimen_table = array(
195
            '#theme' => 'table',
196
            '#weight' => 2,
197
            // prefix attributes and rows with '#' to let it pass toF the theme function,
198
            // otherwise it is handled as child render array
199
            '#attributes' => array('class' => 'specimens'),
200
            '#rows' => array(),
201
        );
202

    
203
        if ($specimensOrObservations) {
204

    
205
            foreach ($specimensOrObservations as $specimenOrObservation) {
206

    
207
                $mediaList = array();
208
                if (is_array($specimenOrObservation->listOfMedia)) {
209
                    $mediaList = array_merge($mediaList, $specimenOrObservation->listOfMedia);
210
                }
211
               if (is_array($specimenOrObservation->_derivedUnitMedia)) {
212
                    $mediaList = array_merge($mediaList, $specimenOrObservation->_derivedUnitMedia);
213
                }
214

    
215
                // typelabel will contain the typeStatus
216
                $type_label = '';
217
                $typeDesignationPager = cdm_ws_get(CDM_WS_OCCURRENCE . '/$0/specimenTypeDesignations', $specimenOrObservation->uuid);
218
                if (isset($typeDesignationPager) and isset($typeDesignationPager->records)) {
219
                    $type_status = array();
220
                    foreach ($typeDesignationPager->records as $typeDesignation) {
221
                        if (isset($typeDesignation->typeStatus->representation_L10n)){
222
                            $type_status[] = $typeDesignation->typeStatus->representation_L10n;
223
                        }
224
                    }
225
                    $type_label = implode(', ', $type_status);
226
                    if($type_label){
227
                        $type_label .= ': ' ;
228
                    }
229
                }
230

    
231
                // --- Specimen entry as dynamic label:
232
                //     -> Dynabox for the specimenOrObservation
233
                $gallery_name = $specimenOrObservation->uuid;
234

    
235
                $derived_unit_ws_request = cdm_compose_url(CDM_WS_OCCURRENCE, array( $specimenOrObservation->uuid));
236
                // --- Render associated media.
237
                $gallery_html = '';
238
                if (count($mediaList) > 0) {
239
                    $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
240
                    $captionElements = array(
241
                        '#uri' => t('open media'),
242
                    );
243

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

    
270
                // --- Render associated media.
271
                $gallery_html = '';
272
                if (count($mediaList) > 0) {
273
                    $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
274
                    $captionElements = array(
275
                        '#uri' => t('open media'),
276
                    );
277

    
278
                    $gallery_html = compose_cdm_media_gallerie(array(
279
                        'mediaList' => $mediaList,
280
                        'galleryName' => $gallery_name,
281
                        'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
282
                        'cols' => $gallery_settings['cdm_dataportal_media_cols'],
283
                        'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
284
                        'captionElements' => $captionElements,
285
                        'mediaLinkType' => 'LIGHTBOX',
286
                        'alternativeMediaUri' => NULL,
287
                        'galleryLinkUri' => NULL,
288
                    ));
289
                }
290

    
291
                $specimen_table['#rows'][] = array(
292
                    // An array of table rows. Every row is an array of cells, or an associative array
293
                    'data' => array(
294
                        // Each cell can be either a string or an associative array
295
                        $label_html . $gallery_html
296
                    ),
297
                    'class' =>  array(
298
                        'descriptionElement',
299
                        'descriptionElement_IndividualsAssociation'
300
                    ),
301
                );
302
            }
303
        }
304

    
305
        $render_array['specimen_list'] = $specimen_table;
306
        $render_array['pager'] = markup_to_render_array(
307
            theme('cdm_pager', array(
308
                'pager' => $pager,
309
                'path' => $_REQUEST['q'],
310
                'parameters' => $_REQUEST,
311
            )),
312
            10 // weight
313
        );
314
    }
315
    $render_array['pager'] = markup_to_render_array(
316
        theme('cdm_pager', array(
317
            'pager' => $pager,
318
            'path' => $_REQUEST['q'],
319
            'parameters' => $_REQUEST,
320
        )),
321
        10 // weight
322
    );
323
    RenderHints::popFromRenderStack();
324
    return $render_array;
325
}
326

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

    
361
  $rowcount = 0;
362
  $rows = array();
363

    
364
  foreach ($field_unit_uuids as $field_unit_uuid) {
365

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

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

    
444
  $tableId = "derivate_hierarchy_table";
445
  $derivateHierarchyTable = array(
446
    "#theme" => "table",
447
    "#weight" => 2,
448
    "#header" => array(
449
      array(
450
        'data' => "",
451
        'class' => array('expand_column')
452
      ),
453
      "Country", "Date", "Collector + collecting number", "Herbaria", "Type", "Scan", "Derivatives"),
454
    "#rows" => $rows,
455
    "#attributes" => array(
456
      "id" => $tableId,
457
      "border" => 2
458
    )
459
  );
460

    
461
  //add toggle functionality to derivate hierarchy table
462
  drupal_add_js_rowToggle("#" . $tableId);
463

    
464
  return $derivateHierarchyTable;
465
}
466

    
467
function create_html_link($link, $openInExternalWindow=false){
468
    $html = "";
469
    if($link->uri && $link->uri!=""){
470
        $html .= '<a  href="' . $link->uri . '"';
471
        if($openInExternalWindow){
472
            $html .= ' target="_blank"';
473
        }
474
        $html .= '>' . $link->linkText . '</a>';
475
    }
476
    else{
477
        $html .= $link->linkText;
478
    }
479
    return $html;
480
}
481

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

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

    
523
  // we better cache here since drupal_get_query_parameters has no internal static cache variable
524
  $http_request_params = drupal_get_query_parameters();
525

    
526
  // add all mandatory js sources
527
  _add_js_footnotes();
528

    
529

    
530
  $render_array = array();
531
  $weight = 0; // the weight for the render array elements
532

    
533
  $tabsToDisplay = variable_get('cdm_taxonpage_tabs_visibility', unserialize(TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT));
534

    
535
  $page_part = variable_get('cdm_dataportal_taxonpage_tabs', 1) ? $page_part : 'all';
536

    
537
  $synonymy_as_tab = variable_get(CDM_SYNONYMY_AS_TAB, CDM_SYNONYMY_AS_TAB_DEFAULT) === 1;
538
  if(!$synonymy_as_tab){
539
    unset($tabsToDisplay["Synonymy"]);
540
    // the synonymy is located in the general part in this case
541
    if($page_part == 'synonymy'){
542
      $page_part = 'description';
543
    }
544
  }
545

    
546
  $media = _load_media_for_taxon($taxon);
547

    
548

    
549
  if (!isset($media[0]) || ($tabsToDisplay["Images"] == '0')) {
550
    taxon_page_tabs_hidden_add('images');
551
  }
552

    
553
  // --- GET specimensOrObservations --- //
554
  $specimensOrObservations = cdm_ws_get(CDM_WS_TAXON, array( $taxon->uuid, 'specimensOrObservationsCount'));
555

    
556
  $specimensOrObservationsCount = $specimensOrObservations != null ? $specimensOrObservations->result : 0;
557
  if ($specimensOrObservationsCount == 0 || ($tabsToDisplay["Specimens"] == '0')) {
558
    taxon_page_tabs_hidden_add('specimens');
559
  }
560

    
561
  // --- GET polytomousKeys --- //
562
  $polytomousKeysPager = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, NULL, "findByTaxonomicScope=$taxon->uuid");
563
  $identificationKeyCount = 0;
564
  if ($polytomousKeysPager) {
565
    $identificationKeyCount += $polytomousKeysPager->count;
566
  }
567
  if ($identificationKeyCount == 0 || ($tabsToDisplay["Keys"] == '0')) {
568
    taxon_page_tabs_hidden_add('keys');
569
  }
570

    
571
  // --- GET TaxonNodeAgentRelations --- //
572
  $current_classification_uuid = get_current_classification_uuid();
573
  $taxon_node_agent_relations_pager = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODEAGENTRELATIONS,
574
      array(
575
          $taxon->uuid,
576
          $current_classification_uuid,
577
      ),
578
      "pageSize=1&pageIndex=0"// we are only interested into the count so we are fetching only one item, o is not possible!
579
  );
580
  if (!$taxon_node_agent_relations_pager || $taxon_node_agent_relations_pager->count == 0){
581
      taxon_page_tabs_hidden_add('experts');
582
  }
583

    
584
  if (!isset($tabsToDisplay["Synonymy"]) || $tabsToDisplay["Synonymy"] == '0') {
585
    taxon_page_tabs_hidden_add('synonymy');
586
  }
587

    
588
  // -------------------------------------------- //
589

    
590
  if (variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR) && isset($_REQUEST['acceptedFor'])) {
591
    $render_array['accepted_for'] = markup_to_render_array(cdm_accepted_for($_REQUEST['acceptedFor']), $weight++);
592
  }
593

    
594
  // --- PAGE PART: DESCRIPTION --- //
595
  if (!taxon_page_tabs_hidden_check('description') && ($page_part == 'description' || $page_part == 'all')) {
596

    
597
    $merged_tree = merged_taxon_feature_tree($taxon);
598

    
599

    
600
    $render_array['general'] = compose_cdm_taxon_page_profile($taxon, $merged_tree, $media, !$synonymy_as_tab);
601
    $render_array['general']['#weight'] = $weight++;
602
    $render_array['general']['#prefix'] = '<div id="general" class="page-part">';
603
    $render_array['general']['#suffix'] = '</div>';
604
  }
605

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

    
639
  // --- PAGE PART: SYNONYMY --- //
640
  if (!taxon_page_tabs_hidden_check('synonymy') && (($page_part == 'synonymy' || $page_part == 'all') && $synonymy_as_tab)) {
641
    $synonymy_html = '<div id="synonymy" class="page-part">';
642
    if ($page_part == 'all') {
643
      $synonymy_html .= '<h2>' . t(cdm_taxonpage_tab_label('Synonymy')) . '</h2>';
644
    }
645
    $addAcceptedTaxon = variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE);
646

    
647
    $synonymy_html .= theme('cdm_taxon_page_synonymy', array('taxon' => $taxon, 'addAcceptedTaxon' => $addAcceptedTaxon));
648

    
649
    $synonymy_html .= '</div>';
650
    $render_array['synonymy'] = markup_to_render_array($synonymy_html, $weight++);
651

    
652
  }
653

    
654
  // --- PAGE PART: SPECIMENS --- //
655
  if (!taxon_page_tabs_hidden_check('specimens') && ($specimensOrObservationsCount > 0 && ($page_part == 'specimens' || $page_part == 'all'))) {
656
    $render_array['specimens'] = array(
657
        '#prefix' => '<div id="specimens" class="page-part">' . ($page_part == 'all' ? '<h2>' . t(cdm_taxonpage_tab_label('Specimens')) . '</h2>' : ''),
658
        'content' => cdm_dataportal_taxon_page_specimens($taxon), // returns render array
659
        '#suffix' => '</div>',
660
    );
661
  }
662

    
663
  // --- PAGE PART: KEYS --- //
664
  if(!taxon_page_tabs_hidden_check('keys')){
665
    if ($identificationKeyCount == 1 && $page_part == 'keys'){
666
      drupal_goto(path_to_key($polytomousKeysPager->records[0]->class, $polytomousKeysPager->records[0]->uuid));
667
    }
668
    else if ($identificationKeyCount > 0 && ($page_part == 'keys' || $page_part == 'all')) {
669
      $keys_html = '<div id="keys" class="page-part">';
670
      if ($page_part == 'all') {
671
        $keys_html .= '<h2>' . t(cdm_taxonpage_tab_label('Keys')) . '</h2>';
672
      }
673
      $keys_html .= theme('cdm_block_IdentificationKeys', array('taxonUuid' => $taxon->uuid));
674
      $keys_html .= '</div>';
675
      $render_array['keys'] = markup_to_render_array($keys_html, $weight++);
676
    }
677
  }
678

    
679
  // --- PAGE PART: EXPERTS --- //
680

    
681
  if (!taxon_page_tabs_hidden_check('experts') && ($page_part == 'experts' || $page_part == 'all')) {
682
    $render_array['experts'] = array(
683
        '#prefix' => '<div id="experts" class="page-part">' . ($page_part == 'all' ? '<h2>' . t(cdm_taxonpage_tab_label('Experts')) . '</h2>' : ''),
684
        'content' => compose_cdm_taxon_page_experts($taxon), // returns render array
685
        '#suffix' => '</div>',
686
    );
687
  }
688

    
689
  // ------------------ END OF PARTS -------------- //
690

    
691
  // adjust weights of page and toc elements according to the settings
692
  $taxontabs_weights = get_array_variable_merged(CDM_TAXONPAGE_TAB_WEIGHT, CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
693
  foreach($taxontabs_weights as $tab_key => $weight){
694
    if(isset($render_array[$tab_key])){
695
      $render_array[$tab_key]['#weight'] = $weight;
696
    }
697
  }
698

    
699

    
700
  // set up the TOC for the pages which contain all pageparts
701
  if($page_part == 'all') {
702

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

    
729
    // move profile image in page structure
730
    if(isset($render_array['general']['taxon_profile_image'])){
731
      $render_array['profile_image'] = $render_array['general']['taxon_profile_image'];
732
      $render_array['profile_image']['#weight'] = -100;
733
      unset($render_array['general']['taxon_profile_image']);
734
    }
735

    
736
    // finally add the table of contents to the render array
737
    $render_array['toc'] = array(
738
        '#theme' => 'item_list',
739
        '#items' => $toc_elements,
740
        '#title' => t('Content'),
741
        '#weight' => -101,
742
        '#suffix' => '</div>',
743
        '#prefix'=> '<div id="page-toc">'
744
    );
745
  }
746

    
747

    
748
  return $render_array;
749
}
750

    
751
/**
752
 * TODO should this function really be a compose function?
753
 *     For a compose function must there always be a theme function with the same name? (ak 8.8.2013)
754
 *
755
 * composes and returns an render array containing the components of the taxon profile tab:
756
 *  - 'taxon_profile_image'
757
 *  - 'taxon_description_feature_toc'
758
 *  - 'taxon_description_features'
759
 *
760
 *
761
 * @param object taxon
762
 * @param object $merged_tree
763
 * @param object media
764
 * @param bool $add_synonymy
765
 *
766
 * @return array
767
 *   A Drupal render array with the following elements:
768
 *     - 'taxon_profile_image'
769
 *     - 'taxon_description_feature_toc'
770
 *     - 'taxon_description_features'
771
 *
772
 * @throws Exception
773
 *
774
 * @ingroup compose
775
 */
776
function compose_cdm_taxon_page_profile($taxon, $merged_tree, $media, $add_synonymy) {
777

    
778
  $render_array = array();
779

    
780
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
781

    
782
  $hide_taxon_profile_image = FALSE;
783
  if (variable_get('image_hide_rank', '0') != '0' && isset($taxon->name->rank->uuid)) {
784
    $rankCompare = rank_compare($taxon->name->rank->uuid, variable_get('image_hide_rank', '-99'));
785
    $hide_taxon_profile_image = ($rankCompare > -1);
786
  }
787

    
788
  if ($taxon_profile_image_settings['show'] && !$hide_taxon_profile_image) {
789

    
790
    $representationPart = new stdClass();
791
    $attributes = array();
792
    if (isset($media[0])) {
793
      // due to a bug the portal/taxon/{uuid}/media service only delivers a filtered media object
794
      // which only contains the thumbnail representation even if the height and width filters are not set.
795
      // -->
796
      $preferred_media = cdm_ws_get(CDM_WS_MEDIA, $media[0]->uuid);
797
      $preferred_representations = cdm_preferred_media_representations($preferred_media, array(
798
        'image/jpg',
799
        'image/jpeg',
800
        'image/png',
801
        'image/gif',
802
      ),
803
        $taxon_profile_image_settings['maxextend'],
804
        $taxon_profile_image_settings['maxextend']
805
      );
806
      if(count($preferred_representations) > 0){
807

    
808
        $representation = array_shift($preferred_representations);
809
        $representationPart = $representation->parts[0];
810
        $attributes['alt'] = $representationPart->uri;
811

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

    
842
    if (isset($representationPart->uri)) {
843
      $profile_image = cdm_media_gallerie_image($representationPart, $taxon_profile_image_settings['maxextend'], FALSE, $attributes);
844
      // NOTE: style="width:${maxextend}px' is needed for IE8 !!!
845
      $render_array['taxon_profile_image'] = markup_to_render_array('<div id="taxonProfileImage" style="width:' . $taxon_profile_image_settings['maxextend'] . 'px">' . $profile_image . '</div>',
846
        -101);
847
    }
848
  }
849

    
850
  if($add_synonymy){
851
    $render_array['synonymy'] = markup_to_render_array(
852
      theme('cdm_taxon_page_synonymy', array('taxon' => $taxon, 'addAcceptedTaxon' => true)),
853
      -102
854
    );
855
  }
856

    
857
  $pseudo_feature_blocks = array();
858
  $pseudo_feature_block_toc_items = array();
859

    
860

    
861
  // Render the sections for each real feature
862
  $feature_block_list = make_feature_block_list($merged_tree->root->childNodes, $taxon);
863

    
864
  // Bibliography
865
  $bibliography_settings = get_bibliography_settings();
866
  if($bibliography_settings['enabled'] == 1){
867
    $bibliography_markup = FootnoteManager::renderFootnoteList('BIBLIOGRAPHY', '');
868
    if($bibliography_markup) {
869
      $feature_bibliography = make_pseudo_feature('Bibliography', 'BIBLIOGRAPHY');
870
      $bibliography_block = feature_block(t('Bibliography'), $feature_bibliography);
871
      $bibliography_item = markup_to_render_array($bibliography_markup);
872
      $bibliography_block->content[] = compose_feature_block_wrap_elements(array($bibliography_item), $feature_bibliography);
873

    
874
      $pseudo_feature_block_toc_items['Bibliography']= 'bibliography';
875
      $pseudo_feature_blocks[] = $bibliography_block;
876
    }
877
  }
878

    
879
  $render_array['taxon_description_features'] = _block_get_renderable_array(
880
    array_merge($feature_block_list, $pseudo_feature_blocks)
881
  );
882

    
883
  if($pseudo_feature_block_toc_items){
884
    foreach ($pseudo_feature_block_toc_items as $label=>$fragment){
885
      cdm_toc_list_add_item($label, $fragment);
886
    }
887
  }
888

    
889
  // create the table of content
890
  $toc = array(
891
      '#theme' => 'item_list',
892
    '#items' => cdm_toc_list(),
893
      '#title' => t('Content'),
894
    '#weight' => -100,                  // move to the top
895
      '#suffix' => '</div>',
896
      '#prefix'=> '<div id="page-toc">'
897
  );
898
  $render_array['taxon_description_feature_toc'] = $toc;
899

    
900
  return $render_array;
901
}
902

    
903
/**
904
 * composes and returns an render array for the experts associated with the given taxon
905
 *
906
 * @param object taxon
907
 *
908
 * @return array
909
 *   A Drupal render array for a table with the experts
910
 *
911
 * @ingroup compose
912
 */
913
function compose_cdm_taxon_page_experts($taxon){
914

    
915
  $render_array = array();
916
  if(!isset($taxon->uuid)){
917
    return $render_array;
918
  }
919

    
920
  $current_classification_uuid = get_current_classification_uuid();
921
  // TODO use cdm_ws_fetchall below but this failes! needs fix!
922
  $taxon_node_agent_relations = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODEAGENTRELATIONS,
923
    array(
924
      $taxon->uuid,
925
      $current_classification_uuid
926
    )
927
  );
928

    
929
  $header = array(
930
    array('data' => t('Expert')),
931
    array('data' => t('Role'))
932
  );
933
  $rows = array();
934

    
935

    
936
  foreach($taxon_node_agent_relations->records as $taxon_node_agent_relation){
937

    
938

    
939
    $expert_role_id = $taxon_node_agent_relation->agent->uuid . '-' . $taxon_node_agent_relation->type->uuid;
940
    $expert_details_container_id = 'expert_details_' . $expert_role_id;
941

    
942
    $agent_label_markup = cdm_dynabox(
943
      'expert_' . $expert_role_id,
944
      $taxon_node_agent_relation->agent->titleCache,
945
      // specifying both ends of the relationship will return only one record in the pager
946
      cdm_compose_url(CDM_WS_PORTAL_AGENT,
947
         array($taxon_node_agent_relation->agent->uuid, 'taxonNodeAgentRelations'),
948
        'taxon_uuid=' . $taxon->uuid . '&relType_uuid=' . $taxon_node_agent_relation->type->uuid),
949
      'cdm_taxon_expert',
950
      'Click for details',
951
      array('div', 'div'),
952
      array(), // attributes
953
      '#' . $expert_details_container_id // $content_element_selector
954
    );
955

    
956
    // Expert and Role
957
    $rows[] = array(
958
      'data' => array(
959
        array(
960
          'data' => $agent_label_markup,
961
          'class' => array(html_class_attribute_ref($taxon_node_agent_relation->agent))
962
        ),
963
        array(
964
          'data' => $taxon_node_agent_relation->type->representation_L10n,
965
          'class' => array(html_class_attribute_ref($taxon_node_agent_relation->type))
966
        )
967
      )
968
    );
969
    // Agent details
970
    $rows[] = array(
971
      'data' => array(
972
        array(
973
          'data' => '<!-- expert_details_container -->',
974
          'id' => $expert_details_container_id,
975
          'colspan' => 2
976
        )
977
      )
978
    );
979

    
980
  }
981

    
982

    
983
  $render_array['experts_table'] = array(
984
    '#theme' => 'table',
985
    '#header' => $header,
986
    '#rows' => $rows,
987
  );
988

    
989

    
990
  return $render_array;
991
}
992

    
993

    
994
/**
995
 * Manages the tabs to be hidden in the taxon page.
996
 *
997
 * The tabs are identified by their last menu link path element:
998
 *  - description
999
 *  - synonymy
1000
 *  - images
1001
 *  - specimens
1002
 *  - key
1003
 *
1004
 * Internally the tabs are stored in a static variable which is
1005
 * managed by drupal_static().
1006
 *
1007
 * @param string $add_tab
1008
 *   Optional parameter. The given string will be added to the array of tabs
1009
 *
1010
 * @return
1011
 *   The array of tabs
1012
 */
1013
function taxon_page_tabs_hidden_add($add_tab = NULL) {
1014
  $tabs = &drupal_static('taxon_page_tabs_hidden');
1015

    
1016
  if(!isset($tabs)){
1017
    $tabs = array();
1018
  }
1019

    
1020
  if (isset($add_tab) && !array_key_exists($add_tab, $tabs)) {
1021
    $tabs[] = $add_tab;
1022
  }
1023

    
1024
  return $tabs;
1025
}
1026

    
1027
/**
1028
 * Manages the tabs to be hidden in the taxon page.
1029
 *
1030
 * The tabs names are identified by their last menu link path element:
1031
 *  - description
1032
 *  - synonymy
1033
 *  - images
1034
 *  - specimens
1035
 *  - key
1036
 *
1037
 * Internally the tabs are stored in a static variable which is
1038
 * managed by drupal_static().
1039
 *
1040
 * @param string $tabname
1041
 *   The name of the tab to check
1042
 *
1043
 * @return boolean
1044
 *   True if the tab or section is to be hidden
1045
 */
1046
function taxon_page_tabs_hidden_check($tabname) {
1047

    
1048
  $tabs = &drupal_static('taxon_page_tabs_hidden');
1049

    
1050
  if(!isset($tabs)){
1051
    $tabs = array();
1052
  }
1053

    
1054
  return array_search($tabname, $tabs) !== FALSE;
1055
}
1056

    
1057
/**
1058
 * Implements the hook_preprocess_HOOK() for theme_menu_local_tasks()
1059
 *
1060
 *  - Removes the tabs to be hidden, @see taxon_page_tabs_hidden_add()
1061
 *  - Renames tabs according to the settings // TODO (this will replace the theme_cdm_taxonpage_tab() function !!!)
1062
 *
1063
 * @param array $variables
1064
 *   The variables array
1065
 */
1066
function cdm_dataportal_preprocess_menu_local_tasks(&$variables) {
1067

    
1068
  $hidden_tabs = taxon_page_tabs_hidden_add();
1069

    
1070
  if (is_array($variables['primary'])) {
1071
    foreach ($variables['primary'] as $key => &$element) {
1072

    
1073
      // 1. Remove the tabs to be hidden
1074
      foreach ($hidden_tabs as $tab) {
1075
        if ($element['#link']['path'] == 'cdm_dataportal/taxon/%/' . $tab) {
1076
          // remove the tab
1077
          unset($variables['primary'][$key]);
1078
        }
1079
      }
1080
    }
1081
  }
1082
}
1083

    
1084

    
1085

    
1086
/**
1087
 * Implements the hook_preprocess_HOOK() for theme_menu_local_task()
1088
 *
1089
 *
1090
 * @param array $variables
1091
 *   An associative array containing:
1092
 *     - element: A render element containing:
1093
 *          #link: A menu link array with 'title', 'href', and 'localized_options' keys.
1094
 *          #active: A boolean indicating whether the local task is active.
1095
 *
1096
 */
1097
function cdm_dataportal_preprocess_menu_local_task(&$variables) {
1098

    
1099
  $link = $variables['element']['#link'];
1100
  if (preg_match('/cdm_dataportal\/.*\/refresh$/', $link['href'])) {
1101
    $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']) . '"/>';
1102
    $link['localized_options']['html'] = TRUE;
1103

    
1104
    $variables['element']['#link'] = $link;
1105
  }
1106
}
1107

    
1108
/* =================== block composition ===================== */
1109

    
1110
/**
1111
 * Composes and returns an render array for the classification breadcrumbs of the given taxon.
1112
 *
1113
 * @param taxon
1114
 *
1115
 * @return array
1116
 *   A Drupal render array for a table with the experts
1117
 *
1118
 * @ingroup compose
1119
 */
1120
function compose_classification_breadcrumbs($taxon_uuid) {
1121

    
1122
  _add_js_taxonomic_children('#classification-breadcrumbs .taxonomic-children-button');
1123

    
1124
  $render_array = array();
1125

    
1126
  $render_array['#theme'] = 'item_list';
1127
  $render_array['#type'] = 'ul';
1128
  $render_array['#attributes'] = array(
1129
    'id' => 'classification-breadcrumbs',
1130
    'class' => 'breadcrumbs inline',
1131
  );
1132

    
1133
  $items = array();
1134

    
1135
  $parent_taxon_nodes = null;
1136
  if($taxon_uuid){
1137
    $parent_taxon_nodes = cdm_ws_taxonomy_pathFromRoot($taxon_uuid);
1138
  }
1139

    
1140
  $classifications = cdm_ws_fetch_all(CDM_WS_PORTAL_TAXONOMY);
1141
  // find current classification in list
1142
  $classification = null;
1143
  $current_classification_uuid = get_current_classification_uuid();
1144
  foreach ($classifications as $classification){
1145
    if($classification->uuid == $current_classification_uuid){
1146
      break;
1147
    }
1148
  }
1149

    
1150
  $node_name = '';
1151
  if(count($classifications) > 1 ){
1152
    // need to add the current classification as first label
1153

    
1154
    $label = $classification->titleCache;
1155
    if(strlen($label) > 20){
1156
      $label = substr($label, 0, strpos($label, ' ', 15)) . '...';
1157
    }
1158
    $node_name = font_awesome_icon_markup('fa-th-list')  . ' ' . l($label, '#', array(
1159
      'attributes' => array(
1160
        'class' => 'taxonomic-children-button classification-chooser',
1161
        'data-destination-uri' => drupal_get_destination(),
1162
        'data-cdm-align-with' => array('prev')
1163
      ),
1164
      'html' => true
1165
    ));
1166
  }
1167

    
1168
  $rank_limit_uuid = variable_get(TAXONTREE_RANKLIMIT, TAXONTREE_RANKLIMIT_DEFAULT);
1169

    
1170
  $rank_separator = '<span> '
1171
    . font_awesome_icon_markup('fa-chevron-right')
1172
    . ' </span>';
1173
  $more_children_icon = font_awesome_icon_markup('fa-sitemap fa-rotate-270');
1174
  $more_children_label = '...';
1175

    
1176
  $items[] = $node_name;
1177

    
1178
  $more_children_for = null;
1179
  if($parent_taxon_nodes){
1180
    foreach ($parent_taxon_nodes as $node) {
1181

    
1182
      $is_first_item = count($items) == 0;
1183
      $is_last_item = count($items) == count($parent_taxon_nodes);
1184
      $node_name = cdm_dataportal_shortname_of($node);
1185
      $path = path_to_taxon($node->taxonUuid);
1186

    
1187
      if($node->taxonomicChildrenCount > 0) {
1188
        $more_children_for = $node->taxonUuid;
1189
      } else {
1190
        $more_children_for = null;
1191
      }
1192

    
1193
      // 'fa-sitemap'
1194

    
1195
      $items[] =
1196
        ($is_first_item ? '' : ' ')
1197
        . $rank_separator
1198
        . l(
1199
          '<span class="' . html_class_attribute_ref($node) . '">' . $node_name . '</span>',
1200
          $path,
1201
          array(
1202
            'attributes' => array(
1203
              'class' => array('taxonomic-children-button'),
1204
              'data-cdm-taxon-uuid' => array($node->taxonUuid),
1205
              'data-cdm-classification-mode' => array('siblings'),
1206
              'data-cdm-align-with' => array('prev')
1207
            ),
1208
            'html' => true
1209
          )
1210
        );
1211
      }
1212
    }
1213

    
1214
  // add more button to the end
1215
  if(!$parent_taxon_nodes) {
1216
    // not taxon focused yet, adding button to make  the root nodes available
1217
    $items[] = '<span>'
1218
      . $more_children_icon . '&nbsp;' .
1219
      '<span class="taxonomic-children-button" data-classification-uuid="' . $current_classification_uuid
1220
      . '" data-rank-limit-uuid="' . $rank_limit_uuid . '" data-cdm-align-with="prev"> ' . $more_children_label . '<span>'
1221
      . '</span>';
1222
  } else if($more_children_for){
1223
    // last parent item has child taxon nodes
1224
    $items[] = ' <span>'
1225
      . $more_children_icon . '&nbsp;' .
1226
      '<span class="taxonomic-children-button" data-cdm-taxon-uuid="' .$more_children_for
1227
      . '" data-cdm-classification-mode="children" data-cdm-align-with="prev"> ' . $more_children_label . '</span>'
1228
      . '</span>';
1229

    
1230
  }
1231

    
1232
  $render_array['#items'] = $items;
1233

    
1234
  return $render_array;
1235
}
1236

    
1237

    
1238
/**
1239
 * @param $specimen_uuid
1240
 * @return array
1241
 *    The drupal render array for the page
1242
 *
1243
 * @ingroup compose
1244
 */
1245
function compose_cdm_specimen_page($specimen_uuid)
1246
{
1247
  drupal_set_title("Specimen Details");
1248
  $specimen = cdm_ws_get(CDM_WS_PORTAL_OCCURRENCE, array($specimen_uuid, 'specimenDerivates'));
1249

    
1250
  $render_array = array();
1251
  RenderHints::pushToRenderStack('specimen_page');
1252

    
1253
  $detail_html = render_cdm_specimen_page($specimen, true);
1254
  $render_array['specimen_html'] = array(
1255
    '#markup' => $detail_html
1256
  );
1257

    
1258
  RenderHints::popFromRenderStack();
1259
  return $render_array;
1260
}
1261

    
1262
/**
1263
 * @param $named_area_uuid
1264
 * @return array
1265
 *    The drupal render array for the page
1266
 *
1267
 * @ingroup compose
1268
 */
1269
function compose_cdm_named_area_page($named_area_uuid)
1270
{
1271

    
1272
  $named_area = cdm_ws_get(CDM_WS_PORTAL_TERM, array($named_area_uuid));
1273

    
1274
  $render_array = array();
1275
  RenderHints::pushToRenderStack('named_area_page');
1276

    
1277
  $groups = array();
1278
  @_description_list_group_add($groups, t('Name') . ':', $named_area->representation_L10n);
1279
  @_description_list_group_add($groups, t('IdInVocabulary') . ':', $named_area->idInVocabulary);
1280
  if(isset($named_area->level)) {
1281
    @_description_list_group_add($groups, t('Level') . ':', $named_area->level->representation_L10n);
1282
  }
1283

    
1284
  $name_area_details_elements = array(
1285
   // '#title' => $title,
1286
    '#theme' => 'description_list',
1287
    '#groups' => $groups,
1288
    '#attributes' => array('class' => html_class_attribute_ref($named_area)),
1289
  );
1290

    
1291
  $render_array[] = $name_area_details_elements;
1292

    
1293
  RenderHints::popFromRenderStack();
1294
  return $render_array;
1295
}
1296

    
1297
/**
1298
 * Provides the the label string for taxon page tabs.
1299
 *
1300
 * The $tabname as passed to the method will be returned if no override
1301
 * label is configured in the settings.
1302
 */
1303
function cdm_taxonpage_tab_label($tabname) {
1304
  static $taxon_tabs_labels = null;
1305
  if($taxon_tabs_labels == null){
1306
    $taxon_tabs_labels = get_array_variable_merged(CDM_TAXONPAGE_TAB_LABELS, CDM_TAXONPAGE_TAB_LABELS_DEFAULT);
1307
  }
1308
  $tabname_key = strtolower($tabname);
1309
  if(isset($taxon_tabs_labels[$tabname_key]) && $taxon_tabs_labels[$tabname_key]){
1310
    return $taxon_tabs_labels[$tabname_key];
1311
  }
1312
  return $tabname;
1313
}
(7-7/10)