Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

cdm-dataportal / modules / cdm_dataportal / includes / pages.inc @ 106e1cf9

History | View | Annotate | Download (46 KB)

1
<?php
2
/**
3
 * @file
4
 * Page functions.
5
 *
6
 * @copyright
7
 *   (C) 2007-2012 EDIT
8
 *   European Distributed Institute of Taxonomy
9
 *   http://www.e-taxonomy.eu
10
 *
11
 *   The contents of this module are subject to the Mozilla
12
 *   Public License Version 1.1.
13
 * @see http://www.mozilla.org/MPL/MPL-1.1.html
14
 *
15
 * @author
16
 *   - Andreas Kohlbecker <a.kohlbecker@BGBM.org>
17
 */
18

    
19

    
20
/**
21
 * Creates a render array representing the ocurrences associetad with the $taxon.
22
 *
23
 * The resulting render array contains two elements:
24
 *  - 'map': A map showing all point locations of the occurences is availabale
25
 *  - 'specimen_list': the list of occurences prepated as table for theme_table()
26
 *
27
 * @param object $taxon
28
 *   A cdm Taxon object
29
 * @return
30
 *   A render array suitable for drupal_render()
31
 *
32
 */
33
function cdm_dataportal_taxon_page_specimens($taxon) {
34

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

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

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

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

    
51
    $by_associatedtaxon_query = http_build_query($by_associatedtaxon_query_parameters);
52

    
53
    $ws_string = 'specimensOrObservation';
54
    if (variable_get('cdm_dataportal_specimen_derivate_tree')){
55
        $ws_string .= "DTOs";
56
    }else{
57
        $ws_string .= "s";
58
    }
59

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

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

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

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

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

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

    
109
    if (count($specimensOrObservations) > 0) {
110

    
111
        $occurrence_queryDto = cdm_ws_get(CDM_WS_GEOSERVICE_OCCURRENCEMAP, $taxon->uuid, $by_associatedtaxon_query);
112

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

    
124
    // -------------------------------------------------------
125

    
126

    
127

    
128
    if(variable_get('cdm_dataportal_compressed_specimen_derivate_table')){
129

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

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

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

    
148
          $render_array['derivate_hierarchy_table'] = compose_specimen_table($field_unit_uuids);
149
        }
150

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

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

    
191

    
192
        }
193

    
194
        $render_array['specimen_list'] = $specimen_table;
195

    
196

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

    
210
        if ($specimensOrObservations) {
211

    
212
            foreach ($specimensOrObservations as $specimenOrObservation) {
213

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

    
222

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

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

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

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

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

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

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

    
313
        $render_array['specimen_list'] = $specimen_table;
314
        $render_array['pager'] = markup_to_render_array(
315
            theme('cdm_pager', array(
316
                'pager' => $pager,
317
                'path' => $_REQUEST['q'],
318
                'parameters' => $_REQUEST,
319
            )),
320
            10 // weight
321
        );
322
    }
323

    
324
    RenderHints::popFromRenderStack();
325
    return $render_array;
326
}
327

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

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

    
365
  foreach ($field_unit_uuids as $field_unit_uuid) {
366

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

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

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

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

    
465
  return $derivateHierarchyTable;
466
}
467

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

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

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

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

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

    
530

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

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

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

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

    
547
  $media = _load_media_for_taxon($taxon);
548

    
549

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

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

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

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

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

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

    
589
  // -------------------------------------------- //
590

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

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

    
598
    $merged_tree = merged_taxon_feature_tree($taxon);
599

    
600

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

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

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

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

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

    
653
  }
654

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

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

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

    
682
  if (!taxon_page_tabs_hidden_check('experts') && ($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 object taxon
763
 * @param object $merged_tree
764
 * @param object media
765
 * @param bool $add_synonymy
766
 *
767
 * @return array
768
 *   A Drupal render array with the following elements:
769
 *     - 'taxon_profile_image'
770
 *     - 'taxon_description_feature_toc'
771
 *     - 'taxon_description_features'
772
 *
773
 * @throws Exception
774
 *
775
 * @ingroup compose
776
 */
777
function compose_cdm_taxon_page_profile($taxon, $merged_tree, $media, $add_synonymy) {
778

    
779
  $render_array = array();
780

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

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

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

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

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

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

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

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

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

    
861

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

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

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

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

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

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

    
901
  return $render_array;
902
}
903

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

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

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

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

    
936

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

    
939

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

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

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

    
981
  }
982

    
983

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

    
990

    
991
  return $render_array;
992
}
993

    
994

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

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

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

    
1025
  return $tabs;
1026
}
1027

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

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

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

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

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

    
1069
  $hidden_tabs = taxon_page_tabs_hidden_add();
1070

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

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

    
1085

    
1086

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

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

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

    
1109
/* =================== block composition ===================== */
1110

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

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

    
1125
  $render_array = array();
1126

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

    
1134
  $items = array();
1135

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

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

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

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

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

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

    
1177
  $items[] = $node_name;
1178

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

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

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

    
1194
      // 'fa-sitemap'
1195

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

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

    
1231
  }
1232

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

    
1235
  return $render_array;
1236
}
1237

    
1238

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

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

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

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

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

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

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

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

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

    
1292
  $render_array[] = $name_area_details_elements;
1293

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

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