Project

General

Profile

Download (45.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
    $cdm_dataportal_list_view = false;
53
    $ws_string = 'specimensOrObservation';
54
    if ($cdm_dataportal_list_view){
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
            'fieldObjectMedia',
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
        $occurrence_queryDto = cdm_ws_get(CDM_WS_GEOSERVICE_OCCURRENCEMAP, $taxon->uuid,  $by_associatedtaxon_query);
102
        //the information about the points are already available
103
        $points = array();
104
        foreach ($specimensOrObservations as &$occurrence) {
105
            if ($occurrence != null) {
106
                $points[] = $occurrence->uuid;
107
            }
108
        }
109

    
110
        $parameterFieldUnitUuids = 'fieldUnitUuidList=' . urlencode(implode(',', $points));
111
     //   $occurrence_queryDto = cdm_ws_get(CDM_WS_GEOSERVICE_OCCURRENCEMAP, $taxon->uuid,  $by_associatedtaxon_query);
112

    
113
       $occurrence_queryDto = cdm_ws_get(CDM_WS_GEOSERVICE_OCCURRENCEMAP_FOR_FIELDUNITS, null, $parameterFieldUnitUuids);
114

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

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

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

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

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

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

    
152
        $render_array['derivate_hierarchy_table'] = compose_specimen_table($field_unit_uuids);
153

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

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

    
190
        $render_array['specimen_list'] = $specimen_table;
191
      //  $render_array['specimen_list'] = $specimen_array;
192

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

    
206
        if ($specimensOrObservations) {
207

    
208
            foreach ($specimensOrObservations as $specimenOrObservation) {
209

    
210
                $mediaList = array();
211
                if (is_array($specimenOrObservation->listOfMedia)) {
212
                    $mediaList = array_merge($mediaList, $specimenOrObservation->listOfMedia);
213
                }
214
               if (is_array($specimenOrObservation->_derivedUnitMedia)) {
215
                    $mediaList = array_merge($mediaList, $specimenOrObservation->_derivedUnitMedia);
216
                }
217

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

    
234
                // --- Specimen entry as dynamic label:
235
                //     -> Dynabox for the specimenOrObservation
236
                $gallery_name = $specimenOrObservation->uuid;
237

    
238
                $derived_unit_ws_request = cdm_compose_url(CDM_WS_OCCURRENCE,  array( $specimenOrObservation->taxonRelatedDerivedUnits[0], 'occurrencesDTO') );
239
                // --- Render associated media.
240
                $gallery_html = '';
241
                if (count($mediaList) > 0) {
242
                    $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
243
                    $captionElements = array(
244
                        '#uri' => t('open media'),
245
                    );
246

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

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

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

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

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

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

    
364
  $rowcount = 0;
365
  $rows = array();
366

    
367
  foreach ($field_unit_uuids as $field_unit_uuid) {
368

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

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

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

    
464
  //add toggle functionality to derivate hierarchy table
465
  drupal_add_js_rowToggle("#" . $tableId);
466

    
467
  return $derivateHierarchyTable;
468
}
469

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

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

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

    
526
  // we better cache here since drupal_get_query_parameters has no internal static cache variable
527
  $http_request_params = drupal_get_query_parameters();
528

    
529
  // add all mandatory js sources
530
  _add_js_footnotes();
531

    
532

    
533
  $render_array = array();
534
  $weight = 0; // the weight for the render array elements
535

    
536
  $tabsToDisplay = variable_get('cdm_taxonpage_tabs_visibility', unserialize(TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT));
537

    
538
  $page_part = variable_get('cdm_dataportal_taxonpage_tabs', 1) ? $page_part : 'all';
539

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

    
549
  $media = _load_media_for_taxon($taxon);
550

    
551

    
552
  if (!isset($media[0]) || ($tabsToDisplay["Images"] == '0')) {
553
    taxon_page_tabs_hidden('images');
554
  }
555

    
556
  // --- GET specimensOrObservations --- //
557
  $specimensOrObservations = cdm_ws_get(CDM_WS_TAXON, array( $taxon->uuid, 'specimensOrObservationsCount'));
558

    
559
  $specimensOrObservationsCount = $specimensOrObservations != null ? $specimensOrObservations->result : 0;
560
  if ($specimensOrObservationsCount == 0 || ($tabsToDisplay["Specimens"] == '0')) {
561
    taxon_page_tabs_hidden('specimens');
562
  }
563

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

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

    
587
  if (!isset($tabsToDisplay["Synonymy"]) || $tabsToDisplay["Synonymy"] == '0') {
588
    taxon_page_tabs_hidden('synonymy');
589
  }
590

    
591
  // -------------------------------------------- //
592

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

    
597
  // --- PAGE PART: DESCRIPTION --- //
598
  if ($page_part == 'description' || $page_part == 'all') {
599

    
600
    $merged_tree = merged_taxon_feature_tree($taxon);
601

    
602

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

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

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

    
650
    $synonymy_html .= theme('cdm_taxon_page_synonymy', array('taxon' => $taxon, 'addAcceptedTaxon' => $addAcceptedTaxon));
651

    
652
    $synonymy_html .= '</div>';
653
    $render_array['synonymy'] = markup_to_render_array($synonymy_html, $weight++);
654

    
655
  }
656

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

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

    
680
  // --- PAGE PART: EXPERTS --- //
681

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

    
690
  // ------------------ END OF PARTS -------------- //
691

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

    
700

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

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

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

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

    
748

    
749
  return $render_array;
750
}
751

    
752
/**
753
 * TODO should this function really be a compose function?
754
 *     For a compose function must there always be a theme function with the same name? (ak 8.8.2013)
755
 *
756
 * composes and returns an render array containing the components of the taxon profile tab:
757
 *  - 'taxon_profile_image'
758
 *  - 'taxon_description_feature_toc'
759
 *  - 'taxon_description_features'
760
 *
761
 *
762
 * @param taxon
763
 * @param mergedTrees
764
 * @param media
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
 * @ingroup compose
773
 */
774
function compose_cdm_taxon_page_profile($taxon, $merged_tree, $media, $add_synonymy) {
775

    
776
  $render_array = array();
777

    
778
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
779

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

    
786
  if ($taxon_profile_image_settings['show'] && !$hide_taxon_profile_image) {
787

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

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

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

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

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

    
855
  $pseudo_feature_blocks = array();
856
  $pseudo_feature_block_toc_items = array();
857

    
858

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

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

    
870
    if(!empty($bibliography_block->content)){
871
      $pseudo_feature_block_toc_items['Bibliography']= 'bibliography';
872
      $pseudo_feature_blocks[] = $bibliography_block;
873
    }
874
  }
875

    
876
  $render_array['taxon_description_features'] = _block_get_renderable_array(
877
    array_merge($feature_block_list, $pseudo_feature_blocks)
878
  );
879

    
880
  if($pseudo_feature_block_toc_items){
881
    foreach ($pseudo_feature_block_toc_items as $label=>$fragment){
882
      cdm_toc_list_add_item($label, $fragment);
883
    }
884
  }
885

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

    
897
  return $render_array;
898
}
899

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

    
912
  $render_array = array();
913
  if(!isset($taxon->uuid)){
914
    return $render_array;
915
  }
916

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

    
926
  $header = array(
927
    array('data' => t('Expert')),
928
    array('data' => t('Role'))
929
  );
930
  $rows = array();
931

    
932

    
933
  foreach($taxon_node_agent_relations->records as $taxon_node_agent_relation){
934

    
935

    
936
    $expert_role_id = $taxon_node_agent_relation->agent->uuid . '-' . $taxon_node_agent_relation->type->uuid;
937
    $expert_details_container_id = 'expert_details_' . $expert_role_id;
938

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

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

    
977
  }
978

    
979

    
980
  $render_array['experts_table'] = array(
981
    '#theme' => 'table',
982
    '#header' => $header,
983
    '#rows' => $rows,
984
  );
985

    
986

    
987
  return $render_array;
988
}
989

    
990

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

    
1013
  if(!isset($tabs)){
1014
    $tabs = array();
1015
  }
1016

    
1017
  if (isset($add_tab) && !array_key_exists($add_tab, $tabs)) {
1018
    $tabs[] = $add_tab;
1019
  }
1020

    
1021
  return $tabs;
1022
}
1023

    
1024
/**
1025
 * Implements the hook_preprocess_HOOK() for theme_menu_local_tasks()
1026
 *
1027
 *  - Removes the tabs to be hidden, @see taxon_page_tabs_hidden()
1028
 *  - Renames tabs according to the settings // TODO (this will replace the theme_cdm_taxonpage_tab() function !!!)
1029
 *
1030
 * @param array $variables
1031
 *   The variables array
1032
 */
1033
function cdm_dataportal_preprocess_menu_local_tasks(&$variables) {
1034

    
1035
  $hidden_tabs = taxon_page_tabs_hidden();
1036

    
1037
  if (is_array($variables['primary'])) {
1038
    foreach ($variables['primary'] as $key => &$element) {
1039

    
1040
      // 1. Remove the tabs to be hidden
1041
      foreach ($hidden_tabs as $tab) {
1042
        if ($element['#link']['path'] == 'cdm_dataportal/taxon/%/' . $tab) {
1043
          // remove the tab
1044
          unset($variables['primary'][$key]);
1045
        }
1046
      }
1047
    }
1048
  }
1049
}
1050

    
1051

    
1052

    
1053
/**
1054
 * Implements the hook_preprocess_HOOK() for theme_menu_local_task()
1055
 *
1056
 *
1057
 * @param array $variables
1058
 *   An associative array containing:
1059
 *     - element: A render element containing:
1060
 *          #link: A menu link array with 'title', 'href', and 'localized_options' keys.
1061
 *          #active: A boolean indicating whether the local task is active.
1062
 *
1063
 */
1064
function cdm_dataportal_preprocess_menu_local_task(&$variables) {
1065

    
1066
  $link = $variables['element']['#link'];
1067
  if (preg_match('/cdm_dataportal\/.*\/refresh$/', $link['href'])) {
1068
    $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']) . '"/>';
1069
    $link['localized_options']['html'] = TRUE;
1070

    
1071
    $variables['element']['#link'] = $link;
1072
  }
1073
}
1074

    
1075
/* =================== block composition ===================== */
1076

    
1077
/**
1078
 * Composes and returns an render array for the classification breadcrumbs of the given taxon.
1079
 *
1080
 * @param taxon
1081
 *
1082
 * @return array
1083
 *   A Drupal render array for a table with the experts
1084
 *
1085
 * @ingroup compose
1086
 */
1087
function compose_classification_breadcrumbs($taxon_uuid) {
1088

    
1089
  _add_js_taxonomic_children('#classification-breadcrumbs .taxonomic-children-button');
1090

    
1091
  $render_array = array();
1092

    
1093
  $render_array['#theme'] = 'item_list';
1094
  $render_array['#type'] = 'ul';
1095
  $render_array['#attributes'] = array(
1096
    'id' => 'classification-breadcrumbs',
1097
    'class' => 'breadcrumbs inline',
1098
  );
1099

    
1100
  $items = array();
1101

    
1102
  $parent_taxon_nodes = null;
1103
  if($taxon_uuid){
1104
    $parent_taxon_nodes = cdm_ws_taxonomy_pathFromRoot($taxon_uuid);
1105
  }
1106

    
1107
  $classifications = cdm_ws_fetch_all(CDM_WS_PORTAL_TAXONOMY);
1108
  // find current classification in list
1109
  $classification = null;
1110
  $current_classification_uuid = get_current_classification_uuid();
1111
  foreach ($classifications as $classification){
1112
    if($classification->uuid == $current_classification_uuid){
1113
      break;
1114
    }
1115
  }
1116

    
1117
  $node_name = '';
1118
  if(count($classifications) > 1 ){
1119
    // need to add the current classification as first label
1120

    
1121
    $label = $classification->titleCache;
1122
    if(strlen($label) > 20){
1123
      $label = substr($label, 0, strpos($label, ' ', 15)) . '...';
1124
    }
1125
    $node_name = font_awesome_icon_markup('fa-th-list')  . ' ' . l($label, '#', array(
1126
      'attributes' => array(
1127
        'class' => 'taxonomic-children-button classification-chooser',
1128
        'data-destination-uri' => drupal_get_destination(),
1129
        'data-cdm-align-with' => array('prev')
1130
      ),
1131
      'html' => true
1132
    ));
1133
  }
1134

    
1135
  $rank_limit_uuid = variable_get(TAXONTREE_RANKLIMIT, TAXONTREE_RANKLIMIT_DEFAULT);
1136

    
1137
  $rank_separator = '<span> '
1138
    . font_awesome_icon_markup('fa-chevron-right')
1139
    . ' </span>';
1140
  $more_children_icon = font_awesome_icon_markup('fa-sitemap fa-rotate-270');
1141
  $more_children_label = '...';
1142

    
1143
  $items[] = $node_name;
1144

    
1145
  $more_children_for = null;
1146
  if($parent_taxon_nodes){
1147
    foreach ($parent_taxon_nodes as $node) {
1148

    
1149
      $is_first_item = count($items) == 0;
1150
      $is_last_item = count($items) == count($parent_taxon_nodes);
1151
      $node_name = cdm_dataportal_shortname_of($node);
1152
      $path = path_to_taxon($node->taxonUuid);
1153

    
1154
      if($node->taxonomicChildrenCount > 0) {
1155
        $more_children_for = $node->taxonUuid;
1156
      } else {
1157
        $more_children_for = null;
1158
      }
1159

    
1160
      // 'fa-sitemap'
1161

    
1162
      $items[] =
1163
        ($is_first_item ? '' : ' ')
1164
        . $rank_separator
1165
        . l(
1166
          '<span class="' . html_class_attribute_ref($node) . '">' . $node_name . '</span>',
1167
          $path,
1168
          array(
1169
            'attributes' => array(
1170
              'class' => array('taxonomic-children-button'),
1171
              'data-cdm-taxon-uuid' => array($node->taxonUuid),
1172
              'data-cdm-classification-mode' => array('siblings'),
1173
              'data-cdm-align-with' => array('prev')
1174
            ),
1175
            'html' => true
1176
          )
1177
        );
1178
      }
1179
    }
1180

    
1181
  // add more button to the end
1182
  if(!$parent_taxon_nodes) {
1183
    // not taxon focused yet, adding button to make  the root nodes available
1184
    $items[] = '<span>'
1185
      . $more_children_icon . '&nbsp;' .
1186
      '<span class="taxonomic-children-button" data-classification-uuid="' . $current_classification_uuid
1187
      . '" data-rank-limit-uuid="' . $rank_limit_uuid . '" data-cdm-align-with="prev"> ' . $more_children_label . '<span>'
1188
      . '</span>';
1189
  } else if($more_children_for){
1190
    // last parent item has child taxon nodes
1191
    $items[] = ' <span>'
1192
      . $more_children_icon . '&nbsp;' .
1193
      '<span class="taxonomic-children-button" data-cdm-taxon-uuid="' .$more_children_for
1194
      . '" data-cdm-classification-mode="children" data-cdm-align-with="prev"> ' . $more_children_label . '</span>'
1195
      . '</span>';
1196

    
1197
  }
1198

    
1199
  $render_array['#items'] = $items;
1200

    
1201
  return $render_array;
1202
}
1203

    
1204

    
1205
/**
1206
 * @param $specimen_uuid
1207
 * @return array
1208
 *    The drupal render array for the page
1209
 *
1210
 * @ingroup compose
1211
 */
1212
function compose_cdm_specimen_page($specimen_uuid)
1213
{
1214
  drupal_set_title("Specimen Details");
1215
  $specimen = cdm_ws_get(CDM_WS_PORTAL_OCCURRENCE, array($specimen_uuid, 'specimenDerivates'));
1216

    
1217
  $render_array = array();
1218
  RenderHints::pushToRenderStack('specimen_page');
1219

    
1220
  $detail_html = render_cdm_specimen_page($specimen, true);
1221
  $render_array['specimen_html'] = array(
1222
    '#markup' => $detail_html
1223
  );
1224

    
1225
  RenderHints::popFromRenderStack();
1226
  return $render_array;
1227
}
1228

    
1229
/**
1230
 * @param $named_area_uuid
1231
 * @return array
1232
 *    The drupal render array for the page
1233
 *
1234
 * @ingroup compose
1235
 */
1236
function compose_cdm_named_area_page($named_area_uuid)
1237
{
1238

    
1239
  $named_area = cdm_ws_get(CDM_WS_PORTAL_TERM, array($named_area_uuid));
1240

    
1241
  $render_array = array();
1242
  RenderHints::pushToRenderStack('named_area_page');
1243

    
1244
  $groups = array();
1245
  @_description_list_group_add($groups, t('Name') . ':', $named_area->representation_L10n);
1246
  @_description_list_group_add($groups, t('IdInVocabulary') . ':', $named_area->idInVocabulary);
1247
  if(isset($named_area->level)) {
1248
    @_description_list_group_add($groups, t('Level') . ':', $named_area->level->representation_L10n);
1249
  }
1250

    
1251
  $name_area_details_elements = array(
1252
   // '#title' => $title,
1253
    '#theme' => 'description_list',
1254
    '#groups' => $groups,
1255
    '#attributes' => array('class' => html_class_attribute_ref($named_area)),
1256
  );
1257

    
1258
  $render_array[] = $name_area_details_elements;
1259

    
1260
  RenderHints::popFromRenderStack();
1261
  return $render_array;
1262
}
1263

    
1264
/**
1265
 * Provides the the label string for taxon page tabs.
1266
 *
1267
 * The $tabname as passed to the method will be returned if no override
1268
 * label is configured in the settings.
1269
 */
1270
function cdm_taxonpage_tab_label($tabname) {
1271
  static $taxon_tabs_labels = null;
1272
  if($taxon_tabs_labels == null){
1273
    $taxon_tabs_labels = get_array_variable_merged(CDM_TAXONPAGE_TAB_LABELS, CDM_TAXONPAGE_TAB_LABELS_DEFAULT);
1274
  }
1275
  $tabname_key = strtolower($tabname);
1276
  if(isset($taxon_tabs_labels[$tabname_key]) && $taxon_tabs_labels[$tabname_key]){
1277
    return $taxon_tabs_labels[$tabname_key];
1278
  }
1279
  return $tabname;
1280
}
(7-7/10)