Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

cdm-dataportal / modules / cdm_dataportal / includes / pages.inc @ 7965ef92

History | View | Annotate | Download (45.2 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
    $specimensOrObservations = cdm_ws_get(CDM_WS_TAXON, array( $taxon->uuid, 'specimensOrObservations'));
54

    
55
     // cdm_ws_get(CDM_WS_OCCURRENCE_FIELDUNIT_DTO_BY_ASSOCIATEDTAXON,
56
     // null,
57
     // $by_associatedtaxon_query . '&taxonUuid=' . $taxon->uuid
58
    // );
59

    
60
   // $specimensOrObservations = array();
61
   // if(isset($pager->records[0])){
62
    //    $specimensOrObservations =  $pager->records;
63
   // }
64

    
65
    // order occurrences by date but types should be on top of the list
66
    $type_specimens = array();
67
    $other_occurrences = array();
68
    foreach ($specimensOrObservations as $occurrence) {
69
        $typeDesignationsPager = cdm_ws_get(CDM_WS_OCCURRENCE . '/$0/specimenTypeDesignations', $occurrence->uuid);
70
        if (isset($typeDesignationsPager->count) && $typeDesignationsPager->count > 0) {
71
            $type_specimens[] = $occurrence;
72
        } else {
73
            $other_occurrences[] = $occurrence;
74
        }
75
    }
76
    $specimensOrObservations = array_merge($type_specimens, $other_occurrences);
77

    
78
    // Collect media (fieldObjectMedia, derivedUnitMedia) and add as a custom field
79
     $occurrence->_fieldObjectMedia;
80
    foreach ($specimensOrObservations as &$occurrence) {
81
        $occurrence->_fieldObjectMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array(
82
            $occurrence->uuid,
83
            'fieldObjectMedia',
84
        ));
85
        $occurrence->_derivedUnitMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array(
86
            $occurrence->uuid,
87
            'derivedUnitMedia',
88
        ));
89
    }
90

    
91
    // --- get map service HTTP query parameters
92

    
93
    if (count($specimensOrObservations) > 0) {
94
        //the information about the points are already available
95
        $points = array();
96
        foreach ($specimensOrObservations as &$occurrence) {
97
            if ($occurrence != null) {
98
                $points[] = $occurrence->uuid;
99
            }
100
        }
101

    
102
        $parameterFieldUnitUuids = 'fieldUnitUuidList=' . urlencode(implode(',', $points));
103
     //   $occurrence_queryDto = cdm_ws_get(CDM_WS_GEOSERVICE_OCCURRENCEMAP, $taxon->uuid,  $by_associatedtaxon_query);
104

    
105
       $occurrence_queryDto = cdm_ws_get(CDM_WS_GEOSERVICE_OCCURRENCEMAP_FOR_FIELDUNITS, null, $parameterFieldUnitUuids);
106

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

    
120
    // -------------------------------------------------------
121
    $render_array['map'] = $map_render_array;
122
    $cdm_dataportal_list_view = false;
123
    if(variable_get('cdm_dataportal_compressed_specimen_derivate_table')){
124

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

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

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

    
144
        $render_array['derivate_hierarchy_table'] = compose_specimen_table($field_unit_uuids);
145

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

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

    
182
        $render_array['specimen_list'] = $specimen_table;
183
      //  $render_array['specimen_list'] = $specimen_array;
184

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

    
198
        if ($specimensOrObservations) {
199

    
200
            foreach ($specimensOrObservations as $specimenOrObservation) {
201

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

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

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

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

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

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

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

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

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

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

    
356
  $rowcount = 0;
357
  $rows = array();
358

    
359
  foreach ($field_unit_uuids as $field_unit_uuid) {
360

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

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

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

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

    
459
  return $derivateHierarchyTable;
460
}
461

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

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

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

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

    
521
  // add all mandatory js sources
522
  _add_js_footnotes();
523

    
524

    
525
  $render_array = array();
526
  $weight = 0; // the weight for the render array elements
527

    
528
  $tabsToDisplay = variable_get('cdm_taxonpage_tabs_visibility', unserialize(TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT));
529

    
530
  $page_part = variable_get('cdm_dataportal_taxonpage_tabs', 1) ? $page_part : 'all';
531

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

    
541
  $media = _load_media_for_taxon($taxon);
542

    
543

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

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

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

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

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

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

    
583
  // -------------------------------------------- //
584

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

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

    
592
    $merged_tree = merged_taxon_feature_tree($taxon);
593

    
594

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

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

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

    
642
    $synonymy_html .= theme('cdm_taxon_page_synonymy', array('taxon' => $taxon, 'addAcceptedTaxon' => $addAcceptedTaxon));
643

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

    
647
  }
648

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

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

    
672
  // --- PAGE PART: EXPERTS --- //
673

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

    
682
  // ------------------ END OF PARTS -------------- //
683

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

    
692

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

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

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

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

    
740

    
741
  return $render_array;
742
}
743

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

    
768
  $render_array = array();
769

    
770
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
771

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

    
778
  if ($taxon_profile_image_settings['show'] && !$hide_taxon_profile_image) {
779

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

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

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

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

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

    
847
  $pseudo_feature_blocks = array();
848
  $pseudo_feature_block_toc_items = array();
849

    
850

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

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

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

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

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

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

    
889
  return $render_array;
890
}
891

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

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

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

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

    
924

    
925
  foreach($taxon_node_agent_relations->records as $taxon_node_agent_relation){
926

    
927

    
928
    $expert_role_id = $taxon_node_agent_relation->agent->uuid . '-' . $taxon_node_agent_relation->type->uuid;
929
    $expert_details_container_id = 'expert_details_' . $expert_role_id;
930

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

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

    
969
  }
970

    
971

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

    
978

    
979
  return $render_array;
980
}
981

    
982

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

    
1005
  if(!isset($tabs)){
1006
    $tabs = array();
1007
  }
1008

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

    
1013
  return $tabs;
1014
}
1015

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

    
1027
  $hidden_tabs = taxon_page_tabs_hidden();
1028

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

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

    
1043

    
1044

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

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

    
1063
    $variables['element']['#link'] = $link;
1064
  }
1065
}
1066

    
1067
/* =================== block composition ===================== */
1068

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

    
1081
  _add_js_taxonomic_children('#classification-breadcrumbs .taxonomic-children-button');
1082

    
1083
  $render_array = array();
1084

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

    
1092
  $items = array();
1093

    
1094
  $parent_taxon_nodes = null;
1095
  if($taxon_uuid){
1096
    $parent_taxon_nodes = cdm_ws_taxonomy_pathFromRoot($taxon_uuid);
1097
  }
1098

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

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

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

    
1127
  $rank_limit_uuid = variable_get(TAXONTREE_RANKLIMIT, TAXONTREE_RANKLIMIT_DEFAULT);
1128

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

    
1135
  $items[] = $node_name;
1136

    
1137
  $more_children_for = null;
1138
  if($parent_taxon_nodes){
1139
    foreach ($parent_taxon_nodes as $node) {
1140

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

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

    
1152
      // 'fa-sitemap'
1153

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

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

    
1189
  }
1190

    
1191
  $render_array['#items'] = $items;
1192

    
1193
  return $render_array;
1194
}
1195

    
1196

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

    
1209
  $render_array = array();
1210
  RenderHints::pushToRenderStack('specimen_page');
1211

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

    
1217
  RenderHints::popFromRenderStack();
1218
  return $render_array;
1219
}
1220

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

    
1231
  $named_area = cdm_ws_get(CDM_WS_PORTAL_TERM, array($named_area_uuid));
1232

    
1233
  $render_array = array();
1234
  RenderHints::pushToRenderStack('named_area_page');
1235

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

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

    
1250
  $render_array[] = $name_area_details_elements;
1251

    
1252
  RenderHints::popFromRenderStack();
1253
  return $render_array;
1254
}
1255

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