Project

General

Profile

Download (42.9 KB) Statistics
| Branch: | Tag: | Revision:
1 c70b93c3 Andreas Kohlbecker
<?php
2 f19f47fa Andreas Kohlbecker
/**
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 c70b93c3 Andreas Kohlbecker
 * @see http://www.mozilla.org/MPL/MPL-1.1.html
14
 *
15
 * @author
16 f19f47fa Andreas Kohlbecker
 *   - 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 c70b93c3 Andreas Kohlbecker
 */
33 f19f47fa Andreas Kohlbecker
function cdm_dataportal_taxon_page_specimens($taxon) {
34
35 1ce9afb7 Patric Plitzner
    $render_array = array();
36
    RenderHints::pushToRenderStack('taxon_page_specimens');
37 30f78c59 Andreas Kohlbecker
38 b8afc4bb Patric Plitzner
    $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
    $pager = cdm_ws_get(CDM_WS_OCCURRENCE_BY_ASSOCIATEDTAXON,
54
        null,
55
        $by_associatedtaxon_query . '&taxonUuid=' . $taxon->uuid
56
    );
57
58
    $specimensOrObservations = array();
59
    if(isset($pager->records[0])){
60
        $specimensOrObservations =  $pager->records;
61
    }
62
63
    // order occurrences by date but types should be on top of the list
64
    $type_specimens = array();
65
    $other_occurrences = array();
66
    foreach ($specimensOrObservations as &$occurrence) {
67
        $typeDesignationsPager = cdm_ws_get(CDM_WS_OCCURRENCE . '/$0/specimenTypeDesignations', $occurrence->uuid);
68
        if (isset($typeDesignationsPager->count) && $typeDesignationsPager->count > 0) {
69
            $type_specimens[] = $occurrence;
70
        } else {
71
            $other_occurrences[] = $occurrence;
72
        }
73
    }
74
    $specimensOrObservations = array_merge($type_specimens, $other_occurrences);
75
76
    // Collect media (fieldObjectMedia, derivedUnitMedia) and add as a custom field
77
    // $occurrence->_fieldObjectMedia
78
    foreach ($specimensOrObservations as &$occurrence) {
79
        $occurrence->_fieldObjectMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array(
80
            $occurrence->uuid,
81
            'fieldObjectMedia',
82
        ));
83
        $occurrence->_derivedUnitMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array(
84
            $occurrence->uuid,
85
            'derivedUnitMedia',
86
        ));
87
    }
88
89 b5c89485 Patric Plitzner
    // --- get map service HTTP query parameters
90 b8afc4bb Patric Plitzner
    if (count($specimensOrObservations) > 0) {
91 62cd8253 Patric Plitzner
        $occurrence_queryDto = cdm_ws_get(CDM_WS_GEOSERVICE_OCCURRENCEMAP, $taxon->uuid,  $by_associatedtaxon_query);
92 b8afc4bb Patric Plitzner
93 e0613197 Andreas Kohlbecker
      $map_visibility = variable_get(SPECIMEN_MAP_VISIBILITY, SPECIMEN_MAP_VISIBILITY_DEFAULT);
94
      if($map_visibility == 'always' ||
95
        variable_get(SPECIMEN_MAP_VISIBILITY, SPECIMEN_MAP_VISIBILITY_DEFAULT) == 'automatic' &&
96 378bc1ce Andreas Kohlbecker
          (isset($occurrence_queryDto->fieldUnitPoints[0]) || isset($occurrence_queryDto->derivedUnitPoints[0]))
97
        )
98
      {
99
        $occurrence_query = $occurrence_queryDto->occurrenceQuery;
100
        $legend_format_query = null;
101
        $distribution_query = NULL;
102 db725031 Andreas Kohlbecker
        $map_render_array = compose_map('specimens', $occurrence_query, $distribution_query, $legend_format_query, array());
103 378bc1ce Andreas Kohlbecker
      }
104 b8afc4bb Patric Plitzner
    }
105 db725031 Andreas Kohlbecker
106
    // -------------------------------------------------------
107
    $render_array['map'] = $map_render_array;
108
109 1ce9afb7 Patric Plitzner
    if(variable_get('cdm_dataportal_compressed_specimen_derivate_table')){
110
111
        //COMPRESSED SPECIMEN DERIVATE TABLE
112 4cb163f8 Patric Plitzner
        $associatedFieldUnitsQuery_parameters = array();
113
        if (isset($_REQUEST['pager']) && is_array($_REQUEST['pager'])) {
114
            $associatedFieldUnitsQuery_parameters = array_merge($associatedFieldUnitsQuery_parameters, $_REQUEST['pager']);
115
        }
116
117
        $by_associatedtaxon_query = http_build_query($associatedFieldUnitsQuery_parameters);
118 09f028e2 Andreas Kohlbecker
        $pager_field_units = cdm_ws_get(CDM_WS_PORTAL_TAXON,
119 2e82a602 Patrick Plitzner
            array($taxon->uuid, 'associatedFieldUnits'),
120
            $by_associatedtaxon_query . '&pageSize=' . variable_get('cdm_dataportal_compressed_specimen_derivate_table_page_size')
121
        );
122 1e87f89f Andreas Kohlbecker
123 09f028e2 Andreas Kohlbecker
        if (isset($pager_field_units->records[0])) {
124
          $field_unit_uuids = array();
125
          foreach ($pager_field_units->records as $field_unit) {
126
            $field_unit_uuids[] = $field_unit->uuid;
127
          }
128
        }
129
130 67f32f09 Andreas Kohlbecker
        $render_array['derivate_hierarchy_table'] = compose_specimen_table($field_unit_uuids);
131 f19f47fa Andreas Kohlbecker
132 1e87f89f Andreas Kohlbecker
        $render_array['pager'] = markup_to_render_array(
133
            theme('cdm_pager', array(
134
                'pager' => $pager_field_units,
135
                'path' => $_REQUEST['q'],
136
                'parameters' => $_REQUEST
137
            )),
138
            10 // weight
139
        );
140 f19f47fa Andreas Kohlbecker
    }
141 1ce9afb7 Patric Plitzner
    else{
142
        //BOTTOM-UP-SPECIMEN-TABLE
143
        // --- generate the specimen list as table
144
        $specimen_table = array(
145
            '#theme' => 'table',
146
            '#weight' => 2,
147 1e87f89f Andreas Kohlbecker
            // prefix attributes and rows with '#' to let it pass toF the theme function,
148 1ce9afb7 Patric Plitzner
            // otherwise it is handled as child render array
149
            '#attributes' => array('class' => 'specimens'),
150
            '#rows' => array(),
151
        );
152 f19f47fa Andreas Kohlbecker
153 1ce9afb7 Patric Plitzner
        if ($specimensOrObservations) {
154
155
            foreach ($specimensOrObservations as $specimenOrObservation) {
156
157
                $mediaList = array();
158
                if (is_array($specimenOrObservation->_fieldObjectMedia)) {
159
                    $mediaList = array_merge($mediaList, $specimenOrObservation->_fieldObjectMedia);
160
                }
161
                if (is_array($specimenOrObservation->_derivedUnitMedia)) {
162
                    $mediaList = array_merge($mediaList, $specimenOrObservation->_derivedUnitMedia);
163
                }
164
165
                // typelabel will contain the typeStatus
166
                $type_label = '';
167
                $typeDesignationPager = cdm_ws_get(CDM_WS_OCCURRENCE . '/$0/specimenTypeDesignations', $specimenOrObservation->uuid);
168 0e533708 Patric Plitzner
                if (isset($typeDesignationPager) and isset($typeDesignationPager->records)) {
169 1ce9afb7 Patric Plitzner
                    $type_status = array();
170
                    foreach ($typeDesignationPager->records as $typeDesignation) {
171
                        if (isset($typeDesignation->typeStatus->representation_L10n)){
172
                            $type_status[] = $typeDesignation->typeStatus->representation_L10n;
173
                        }
174
                    }
175
                    $type_label = implode(', ', $type_status);
176
                    if($type_label){
177
                        $type_label .= ': ' ;
178
                    }
179
                }
180
181
                // --- Specimen entry as dynamic label:
182
                //     -> Dynabox for the specimenOrObservation
183
                $gallery_name = $specimenOrObservation->uuid;
184
185
                $derived_unit_ws_request = cdm_compose_url(CDM_WS_OCCURRENCE, array( $specimenOrObservation->uuid));
186
                $label_html = cdm_dynabox(
187 cea412e7 Andreas Kohlbecker
                  $specimenOrObservation->uuid,
188
                  $type_label . $specimenOrObservation->titleCache,
189
                  $derived_unit_ws_request,
190 bd814ea2 Andreas Kohlbecker
                  'cdm_specimen_or_observation',
191 cea412e7 Andreas Kohlbecker
                  'Click for details',
192
                  array('div', 'div'),
193
                  array(),
194
                  null, // $content_element_selector
195
                  'function(){ jQuery(\'#media_gallery_' . $gallery_name . '\').hide(); }', // open_callback
196
                  'function(){ jQuery(\'#media_gallery_' . $gallery_name . '\').show(); }' // close_callback
197 1ce9afb7 Patric Plitzner
                );
198
199
                // --- Render associated media.
200
                $gallery_html = '';
201
                if (count($mediaList) > 0) {
202
                    $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
203
                    $captionElements = array(
204
                        '#uri' => t('open media'),
205
                    );
206
207 a9815578 Andreas Kohlbecker
                    $gallery_html = compose_cdm_media_gallerie(array(
208 1ce9afb7 Patric Plitzner
                        'mediaList' => $mediaList,
209
                        'galleryName' => $gallery_name,
210
                        'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
211
                        'cols' => $gallery_settings['cdm_dataportal_media_cols'],
212
                        'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
213
                        'captionElements' => $captionElements,
214
                        'mediaLinkType' => 'LIGHTBOX',
215
                        'alternativeMediaUri' => NULL,
216
                        'galleryLinkUri' => NULL,
217
                    ));
218
                }
219
220
                $specimen_table['#rows'][] = array(
221
                    // An array of table rows. Every row is an array of cells, or an associative array
222
                    'data' => array(
223
                        // Each cell can be either a string or an associative array
224
                        $label_html . $gallery_html
225
                    ),
226
                    'class' =>  array(
227
                        'descriptionElement',
228
                        'descriptionElement_IndividualsAssociation'
229
                    ),
230
                );
231
            }
232
        }
233 f19f47fa Andreas Kohlbecker
234 1ce9afb7 Patric Plitzner
        $render_array['specimen_list'] = $specimen_table;
235
        $render_array['pager'] = markup_to_render_array(
236
            theme('cdm_pager', array(
237
                'pager' => $pager,
238
                'path' => $_REQUEST['q'],
239
                'parameters' => $_REQUEST,
240
            )),
241
            10 // weight
242
        );
243
    }
244
    RenderHints::popFromRenderStack();
245
    return $render_array;
246 3f259ca3 Andreas Kohlbecker
}
247 1e87f89f Andreas Kohlbecker
248
/**
249 67f32f09 Andreas Kohlbecker
 * Creates the drupal render array for the table showing all derivated which are
250
 * derive from a common gathering event.
251 1e87f89f Andreas Kohlbecker
 *
252
 * @param $field_unit_uuids array
253
 *  An array of uuids for cdm FieldUnit entities.
254
 *
255
 * @return array
256
 *  A drupal render array for a table
257
 *
258
 * @ingroup compose
259
 */
260 67f32f09 Andreas Kohlbecker
function compose_specimen_table($field_unit_uuids)
261 1e87f89f Andreas Kohlbecker
{
262
// get icon images
263
  $expand_icon = font_awesome_icon_markup(
264
    'fa-plus-square-o',
265
    array(
266
      'alt' => 'Show details',
267
      'class' => array('expand_icon')
268
    )
269
  );
270
  $collapse_icon = font_awesome_icon_markup(
271
    'fa-minus-square-o',
272
    array(
273
      'alt' => 'Show details',
274
      'class' => array('collapse_icon')
275
    )
276
  );
277
  $detail_image_icon = '<img title="Detail Image" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/detail_image_derivate-16x16-32.png' . '"/>';
278
  $checked_box_icon = '<img src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/step_done.gif' . '"/>';
279
  $sequence_icon = '<img title="Molecular Data" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/sequence_derivate-16x16-32.png' . '"/>';
280
  $character_data_icon = '<img title="Character Data" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/character_data_derivate-16x16-32.png' . '"/>';
281
282
  $rowcount = 0;
283
  $rows = array();
284
285
  foreach ($field_unit_uuids as $field_unit_uuid) {
286
287
    //get derivate hierarchy for the FieldUnit
288
    $derivateHierarchy = cdm_ws_get(CDM_WS_PORTAL_OCCURRENCE, array($field_unit_uuid, 'derivateHierarchy'));
289
    if ($derivateHierarchy) {
290
      //summary row
291
      $rows[] = array(
292
        'data' => array(
293
          array(
294
            'data' => $expand_icon . $collapse_icon,
295
            'class' => array('summary_row_cell', 'summary_row_icon', 'expand_column')
296
          ),
297
          array(
298
            'data' => $derivateHierarchy->country,
299
            'class' => array('summary_row_cell')
300
          ),
301
          array(
302
            'data' => $derivateHierarchy->date,
303
            'class' => array('summary_row_cell')
304
          ),
305
          array(
306
            'data' => $derivateHierarchy->collection,
307
            'class' => array('summary_row_cell')
308
          ),
309
          array(
310
            'data' => $derivateHierarchy->herbarium,
311
            'class' => array('summary_row_cell')
312
          ),
313
          array(
314
            'data' => $derivateHierarchy->hasType ? $checked_box_icon : "",
315
            'class' => array('summary_row_cell', 'summary_row_icon')
316
          ),
317
          array(
318
            'data' => $derivateHierarchy->hasSpecimenScan ? $checked_box_icon : "",
319
            'class' => array('summary_row_cell', 'summary_row_icon')
320
          ),
321
          array(
322
            'data' => ($derivateHierarchy->hasDna ? $sequence_icon : "") . " "
323
              . ($derivateHierarchy->hasDetailImage ? $detail_image_icon : "") . " "
324
              . ($derivateHierarchy->hasCharacterData ? $character_data_icon : ""),
325
            'class' => array('summary_row_cell', 'summary_row_icon')
326
          )
327
        ),
328
        'id' => ('derivate_summary' . $rowcount), // summary row id
329
        'class' => array('summary_row'),
330
      );
331
332
      //assemble field unit details
333
      $detail_html = "";
334
      // - citation
335
      if ($derivateHierarchy->citation) {
336
        $detail_html .= create_label("Citation") . $derivateHierarchy->citation . "<br>";
337
      }
338
      //assemble specimen details
339 d68a30b0 Andreas Kohlbecker
      if ($derivateHierarchy->derivates) {
340
        foreach ($derivateHierarchy->derivates as $preservedSpecimenDTO) {
341 1e87f89f Andreas Kohlbecker
          $detail_html .= "<br>";
342
          $detail_html .= render_cdm_specimen_page($preservedSpecimenDTO);
343
        }
344
      }
345
      $detail_html .= "<br>";
346
      //detail row resp. one BIG detail cell
347
      $rows[] = array(
348
        'data' => array(
349
          array(
350
            'data' => "", //empty first column
351
            'class' => array('expand_column')
352
          ),
353
          array(
354
            'data' => $detail_html,
355
            'colspan' => 7,
356
          ),
357
        ),
358
        'id' => ('derivate_details' . $rowcount),//details row ID
359
        'class' => array('detail_row'),
360
      );
361
      $rowcount++;
362
    }
363
  }
364
365
  $tableId = "derivate_hierarchy_table";
366
  $derivateHierarchyTable = array(
367
    "#theme" => "table",
368
    "#weight" => 2,
369
    "#header" => array(
370
      array(
371
        'data' => "",
372
        'class' => array('expand_column')
373
      ),
374
      "Country", "Date", "Collector + collecting number", "Herbaria", "Type", "Scan", "Derivatives"),
375
    "#rows" => $rows,
376
    "#attributes" => array(
377
      "id" => $tableId,
378
      "border" => 2
379
    )
380
  );
381
382
  //add toggle functionality to derivate hierarchy table
383
  drupal_add_js_rowToggle("#" . $tableId);
384
385
  return $derivateHierarchyTable;
386
}
387
388 65a4de51 Patrick Plitzner
function create_html_link($link, $openInExternalWindow=false){
389 7d8ef9fa Patric Plitzner
    $html = "";
390 65a4de51 Patrick Plitzner
    if($link->uri && $link->uri!=""){
391
        $html .= '<a  href="' . $link->uri . '"';
392
        if($openInExternalWindow){
393
            $html .= ' target="_blank"';
394
        }
395
        $html .= '>' . $link->linkText . '</a>';
396 7d8ef9fa Patric Plitzner
    }
397
    else{
398
        $html .= $link->linkText;
399
    }
400
    return $html;
401
}
402
403
/**
404 65a4de51 Patrick Plitzner
 * Creates HTML links from the given link list concatenated by default by a comma.
405 7d8ef9fa Patric Plitzner
 * @param $linkList the list with Link objects having "uri" and "linkText" as members
406
 * @return string the assembled HTML string containing the links
407
 */
408 65a4de51 Patrick Plitzner
function create_html_links($linkList, $openInExternalWindow=false, $separator=", ")
409 7d8ef9fa Patric Plitzner
{
410
    $html = "";
411
    if ($linkList) {
412
        foreach ($linkList as $link) {
413 65a4de51 Patrick Plitzner
            $html .= create_html_link($link, $openInExternalWindow).$separator;
414 7d8ef9fa Patric Plitzner
        }
415 65a4de51 Patrick Plitzner
        $html = rtrim($html, $separator);
416 7d8ef9fa Patric Plitzner
    }
417
    return $html;
418
}
419
420 00a8e4b6 Andreas Kohlbecker
/**
421
 * Composes a taxon page which can consist of multiple parts like
422
 * 'General', 'Synonymy', 'Images', 'Keys'. These parts can be displayed
423
 * as tabs or as sections of a single page.
424
 *
425
 * It is headed by the name of the accepted taxon without author and reference.
426
 *
427
 * @param $taxon
428
 *   The CDM Taxon Instance to compose the page for.
429
 * @param $page_part
430
 *   Name of the part to display, valid values are:
431
 *    - 'description' -  for the general part
432
 *    - 'images'
433
 *    - 'synonymy'
434
 *    - 'keys'
435
 *    - 'all'
436
 *
437
 * @return array
438
 *   A drupal render array
439
 *
440
 * @ingroup compose
441
 */
442
function compose_cdm_taxon_page($taxon, $page_part = 'description') {
443
444 0ae57522 Patric Plitzner
  // we better cache here since drupal_get_query_parameters has no internal static cache variable
445
  $http_request_params = drupal_get_query_parameters();
446 00a8e4b6 Andreas Kohlbecker
447 0ae57522 Patric Plitzner
  // add all mandatory js sources
448
  _add_js_footnotes();
449 00a8e4b6 Andreas Kohlbecker
450
451 0ae57522 Patric Plitzner
  $render_array = array();
452
  $weight = 0; // the weight for the render array elements
453 00a8e4b6 Andreas Kohlbecker
454 0ae57522 Patric Plitzner
  $tabsToDisplay = variable_get('cdm_taxonpage_tabs_visibility', unserialize(TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT));
455 00a8e4b6 Andreas Kohlbecker
456 0ae57522 Patric Plitzner
  $page_part = variable_get('cdm_dataportal_taxonpage_tabs', 1) ? $page_part : 'all';
457 00a8e4b6 Andreas Kohlbecker
458 22383f95 Andreas Kohlbecker
  $synonymy_as_tab = variable_get(CDM_SYNONYMY_AS_TAB, CDM_SYNONYMY_AS_TAB_DEFAULT) === 1;
459
  if(!$synonymy_as_tab){
460
    unset($tabsToDisplay["Synonymy"]);
461 3e6dfbb3 Andreas Kohlbecker
    // the synonymy is located in the general part in this case
462
    if($page_part == 'synonymy'){
463
      $page_part = 'description';
464
    }
465 22383f95 Andreas Kohlbecker
  }
466
467 0ae57522 Patric Plitzner
  $media = _load_media_for_taxon($taxon);
468 00a8e4b6 Andreas Kohlbecker
469
470 0ae57522 Patric Plitzner
  if (!isset($media[0]) || ($tabsToDisplay["Images"] == '0')) {
471 48a6d7e8 Andreas Kohlbecker
    taxon_page_tabs_hidden_add('images');
472 0ae57522 Patric Plitzner
  }
473 00a8e4b6 Andreas Kohlbecker
474 0ae57522 Patric Plitzner
  // --- GET specimensOrObservations --- //
475
  $specimensOrObservations = cdm_ws_get(CDM_WS_TAXON, array( $taxon->uuid, 'specimensOrObservations'));
476 00a8e4b6 Andreas Kohlbecker
477 0ae57522 Patric Plitzner
  $specimensOrObservationsCount = is_array($specimensOrObservations) ? count($specimensOrObservations) : 0;
478
  if ($specimensOrObservationsCount == 0 || ($tabsToDisplay["Specimens"] == '0')) {
479 48a6d7e8 Andreas Kohlbecker
    taxon_page_tabs_hidden_add('specimens');
480 0ae57522 Patric Plitzner
  }
481 00a8e4b6 Andreas Kohlbecker
482 0ae57522 Patric Plitzner
  // --- GET polytomousKeys --- //
483
  $polytomousKeysPager = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, NULL, "findByTaxonomicScope=$taxon->uuid");
484
  $identificationKeyCount = 0;
485
  if ($polytomousKeysPager) {
486
    $identificationKeyCount += $polytomousKeysPager->count;
487
  }
488
  if ($identificationKeyCount == 0 || ($tabsToDisplay["Keys"] == '0')) {
489 48a6d7e8 Andreas Kohlbecker
    taxon_page_tabs_hidden_add('keys');
490 0ae57522 Patric Plitzner
  }
491 092744e1 Andreas Kohlbecker
492 22383f95 Andreas Kohlbecker
  // --- GET TaxonNodeAgentRelations --- //
493
  $current_classification_uuid = get_current_classification_uuid();
494
  $taxon_node_agent_relations_pager = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODEAGENTRELATIONS,
495
      array(
496
          $taxon->uuid,
497
          $current_classification_uuid,
498
      ),
499
      "pageSize=1&pageIndex=0"// we are only interested into the count so we are fetching only one item, o is not possible!
500
  );
501
  if (!$taxon_node_agent_relations_pager || $taxon_node_agent_relations_pager->count == 0){
502 48a6d7e8 Andreas Kohlbecker
      taxon_page_tabs_hidden_add('experts');
503 22383f95 Andreas Kohlbecker
  }
504 7663cd0b Andreas Kohlbecker
505 22383f95 Andreas Kohlbecker
  if (!isset($tabsToDisplay["Synonymy"]) || $tabsToDisplay["Synonymy"] == '0') {
506 48a6d7e8 Andreas Kohlbecker
    taxon_page_tabs_hidden_add('synonymy');
507 0ae57522 Patric Plitzner
  }
508 00a8e4b6 Andreas Kohlbecker
509 0ae57522 Patric Plitzner
  // -------------------------------------------- //
510 00a8e4b6 Andreas Kohlbecker
511 0ae57522 Patric Plitzner
  if (variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR) && isset($_REQUEST['acceptedFor'])) {
512 7272d19c Andreas Kohlbecker
    $render_array['accepted_for'] = markup_to_render_array(cdm_accepted_for($_REQUEST['acceptedFor']), $weight++);
513 0ae57522 Patric Plitzner
  }
514 00a8e4b6 Andreas Kohlbecker
515 0ae57522 Patric Plitzner
  // --- PAGE PART: DESCRIPTION --- //
516 48a6d7e8 Andreas Kohlbecker
  if (!taxon_page_tabs_hidden_check('description') && ($page_part == 'description' || $page_part == 'all')) {
517 00a8e4b6 Andreas Kohlbecker
518 0ae57522 Patric Plitzner
    $merged_tree = merged_taxon_feature_tree($taxon);
519 00a8e4b6 Andreas Kohlbecker
520 7d8ef9fa Patric Plitzner
521 22383f95 Andreas Kohlbecker
    $render_array['general'] = compose_cdm_taxon_page_profile($taxon, $merged_tree, $media, !$synonymy_as_tab);
522 0ae57522 Patric Plitzner
    $render_array['general']['#weight'] = $weight++;
523
    $render_array['general']['#prefix'] = '<div id="general" class="page-part">';
524
    $render_array['general']['#suffix'] = '</div>';
525
  }
526 7d8ef9fa Patric Plitzner
527 0ae57522 Patric Plitzner
  // --- PAGE PART: IMAGES --- //
528 48a6d7e8 Andreas Kohlbecker
  if (!taxon_page_tabs_hidden_check('images') && ($page_part == 'images' || $page_part == 'all')) {
529 0ae57522 Patric Plitzner
    $images_html = '<div id="images" class="page-part">';
530
    if ($page_part == 'all') {
531 4feeabc7 Andreas Kohlbecker
      $images_html .= '<h2>' . t(cdm_taxonpage_tab_label('Images')) . '</h2>';
532 7d8ef9fa Patric Plitzner
    }
533 0ae57522 Patric Plitzner
    // Get the image gallery as configured by the admin.
534 8f4eb9ce Andreas Kohlbecker
    $default_image_gallery = 'default';
535
    $configured_image_gallery_viewer = variable_get('image_gallery_viewer', 'default');
536 4feeabc7 Andreas Kohlbecker
    $taxon_image_gallery = '<div class="error">No image gallery viewer configured</div>';
537 8f4eb9ce Andreas Kohlbecker
    if($configured_image_gallery_viewer == $default_image_gallery || $configured_image_gallery_viewer == 'fsi'){
538
      // the fsi_gallery requires a flash plugin, in case the client browser is not supporting
539
      // flash we also need to provide an the default gallery as alternative
540
      $taxon_image_gallery = '<div id="default-gallery-viewer">' .
541
        call_user_func_array('taxon_image_gallery_' . $default_image_gallery, array(
542
          $taxon,
543
          $media,
544
        ))
545
        . '</div>';
546
    }
547
    if($configured_image_gallery_viewer == 'fsi'){
548
      $taxon_image_gallery .= '<div id="'. $configured_image_gallery_viewer .'-gallery-viewer">' .
549
        call_user_func_array('taxon_image_gallery_' . $configured_image_gallery_viewer, array(
550
          $taxon,
551
          $media,
552
        ))
553
       . '</div>';
554
    }
555 0ae57522 Patric Plitzner
    $images_html .= $taxon_image_gallery;
556
    $images_html .= '</div>';
557
    $render_array['images'] = markup_to_render_array($images_html, $weight++);
558
  }
559 7d8ef9fa Patric Plitzner
560 0ae57522 Patric Plitzner
  // --- PAGE PART: SYNONYMY --- //
561 48a6d7e8 Andreas Kohlbecker
  if (!taxon_page_tabs_hidden_check('synonymy') && (($page_part == 'synonymy' || $page_part == 'all') && $synonymy_as_tab)) {
562 0ae57522 Patric Plitzner
    $synonymy_html = '<div id="synonymy" class="page-part">';
563
    if ($page_part == 'all') {
564 4feeabc7 Andreas Kohlbecker
      $synonymy_html .= '<h2>' . t(cdm_taxonpage_tab_label('Synonymy')) . '</h2>';
565 00a8e4b6 Andreas Kohlbecker
    }
566 0ae57522 Patric Plitzner
    $addAcceptedTaxon = variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE);
567 41b4bfc9 Andreas Kohlbecker
568 0ae57522 Patric Plitzner
    $synonymy_html .= theme('cdm_taxon_page_synonymy', array('taxon' => $taxon, 'addAcceptedTaxon' => $addAcceptedTaxon));
569 00a8e4b6 Andreas Kohlbecker
570 0ae57522 Patric Plitzner
    $synonymy_html .= '</div>';
571
    $render_array['synonymy'] = markup_to_render_array($synonymy_html, $weight++);
572 00a8e4b6 Andreas Kohlbecker
573 0ae57522 Patric Plitzner
  }
574 00a8e4b6 Andreas Kohlbecker
575 0ae57522 Patric Plitzner
  // --- PAGE PART: SPECIMENS --- //
576 48a6d7e8 Andreas Kohlbecker
  if (!taxon_page_tabs_hidden_check('specimens') && ($specimensOrObservationsCount > 0 && ($page_part == 'specimens' || $page_part == 'all'))) {
577 0ae57522 Patric Plitzner
    $render_array['specimens'] = array(
578 4feeabc7 Andreas Kohlbecker
        '#prefix' => '<div id="specimens" class="page-part">' . ($page_part == 'all' ? '<h2>' . t(cdm_taxonpage_tab_label('Specimens')) . '</h2>' : ''),
579 0ae57522 Patric Plitzner
        'content' => cdm_dataportal_taxon_page_specimens($taxon), // returns render array
580
        '#suffix' => '</div>',
581
    );
582
  }
583
584
  // --- PAGE PART: KEYS --- //
585 48a6d7e8 Andreas Kohlbecker
  if(!taxon_page_tabs_hidden_check('keys')){
586
    if ($identificationKeyCount == 1 && $page_part == 'keys'){
587
      drupal_goto(path_to_key($polytomousKeysPager->records[0]->class, $polytomousKeysPager->records[0]->uuid));
588
    }
589
    else if ($identificationKeyCount > 0 && ($page_part == 'keys' || $page_part == 'all')) {
590
      $keys_html = '<div id="keys" class="page-part">';
591
      if ($page_part == 'all') {
592
        $keys_html .= '<h2>' . t(cdm_taxonpage_tab_label('Keys')) . '</h2>';
593
      }
594
      $keys_html .= theme('cdm_block_IdentificationKeys', array('taxonUuid' => $taxon->uuid));
595
      $keys_html .= '</div>';
596
      $render_array['keys'] = markup_to_render_array($keys_html, $weight++);
597 0ae57522 Patric Plitzner
    }
598
  }
599
600 7663cd0b Andreas Kohlbecker
  // --- PAGE PART: EXPERTS --- //
601
602 48a6d7e8 Andreas Kohlbecker
  if (!taxon_page_tabs_hidden_check('experts') && ($page_part == 'experts' || $page_part == 'all')) {
603 7663cd0b Andreas Kohlbecker
    $render_array['experts'] = array(
604 4feeabc7 Andreas Kohlbecker
        '#prefix' => '<div id="experts" class="page-part">' . ($page_part == 'all' ? '<h2>' . t(cdm_taxonpage_tab_label('Experts')) . '</h2>' : ''),
605 7663cd0b Andreas Kohlbecker
        'content' => compose_cdm_taxon_page_experts($taxon), // returns render array
606
        '#suffix' => '</div>',
607
    );
608
  }
609
610
  // ------------------ END OF PARTS -------------- //
611 0ae57522 Patric Plitzner
612
  // adjust weights of page and toc elements according to the settings
613 4feeabc7 Andreas Kohlbecker
  $taxontabs_weights = get_array_variable_merged(CDM_TAXONPAGE_TAB_WEIGHT, CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
614 0ae57522 Patric Plitzner
  foreach($taxontabs_weights as $tab_key => $weight){
615
    if(isset($render_array[$tab_key])){
616
      $render_array[$tab_key]['#weight'] = $weight;
617
    }
618
  }
619
620
621
  // set up the TOC for the pages which contain all pageparts
622
  if($page_part == 'all') {
623
624
    asort($taxontabs_weights);
625
    foreach(array_keys($taxontabs_weights) as $tab_key){
626
      if(isset($render_array[$tab_key])){
627
        if($tab_key != 'general'){
628
          // add entry for page part
629
          $toc_elements[] = array(
630 4feeabc7 Andreas Kohlbecker
              'data' => l(t(cdm_taxonpage_tab_label(ucfirst($tab_key))), $_GET['q'], array('fragment' => $tab_key, 'query' => $http_request_params)),
631 0ae57522 Patric Plitzner
              'class' => array('page-part-toc-item-' . $tab_key)
632
          );
633
        } else {
634
          // add content of profile part instead
635
          if(isset($render_array['general'])) {
636
            // in case all tabs are shown at once the feature tocs
637
            // should be integrated into the tabs toc as sub list
638
            // and the profile image should be on top of the page
639
            if(isset($render_array['general']['taxon_description_feature_toc'])){;
640
            foreach ($render_array['general']['taxon_description_feature_toc']['#items'] as $profile_toc_item){
641
              $toc_elements[] = $profile_toc_item;
642 7d8ef9fa Patric Plitzner
            }
643 0ae57522 Patric Plitzner
            unset($render_array['general']['taxon_description_feature_toc']);
644
            }
645
          }
646 7d8ef9fa Patric Plitzner
        }
647 0ae57522 Patric Plitzner
      }
648
    }
649 7d8ef9fa Patric Plitzner
650 0ae57522 Patric Plitzner
    // move profile image in page structure
651
    if(isset($render_array['general']['taxon_profile_image'])){
652
      $render_array['profile_image'] = $render_array['general']['taxon_profile_image'];
653
      $render_array['profile_image']['#weight'] = -100;
654
      unset($render_array['general']['taxon_profile_image']);
655 7d8ef9fa Patric Plitzner
    }
656
657 0ae57522 Patric Plitzner
    // finally add the table of contents to the render array
658
    $render_array['toc'] = array(
659
        '#theme' => 'item_list',
660
        '#items' => $toc_elements,
661
        '#title' => t('Content'),
662
        '#weight' => -101,
663
        '#suffix' => '</div>',
664
        '#prefix'=> '<div id="page-toc">'
665
    );
666
  }
667
668 7d8ef9fa Patric Plitzner
669 0ae57522 Patric Plitzner
  return $render_array;
670 00a8e4b6 Andreas Kohlbecker
}
671
672 1ce9afb7 Patric Plitzner
/**
673 22f5e82d Andreas Kohlbecker
 * TODO should this function really be a compose function?
674
 *     For a compose function must there always be a theme function with the same name? (ak 8.8.2013)
675 bf97c2e8 Andreas Kohlbecker
 *
676
 * composes and returns an render array containing the components of the taxon profile tab:
677
 *  - 'taxon_profile_image'
678
 *  - 'taxon_description_feature_toc'
679
 *  - 'taxon_description_features'
680
 *
681
 *
682 8a1b451e Andreas Kohlbecker
 * @param object taxon
683
 * @param object $merged_tree
684
 * @param object media
685
 * @param bool $add_synonymy
686 bf97c2e8 Andreas Kohlbecker
 *
687
 * @return array
688 f78fda81 Andreas Kohlbecker
 *   A Drupal render array with the following elements:
689 bf97c2e8 Andreas Kohlbecker
 *     - 'taxon_profile_image'
690
 *     - 'taxon_description_feature_toc'
691
 *     - 'taxon_description_features'
692
 *
693 8a1b451e Andreas Kohlbecker
 * @throws Exception
694
 *
695 bf97c2e8 Andreas Kohlbecker
 * @ingroup compose
696
 */
697 22383f95 Andreas Kohlbecker
function compose_cdm_taxon_page_profile($taxon, $merged_tree, $media, $add_synonymy) {
698 bf97c2e8 Andreas Kohlbecker
699 0ae57522 Patric Plitzner
  $render_array = array();
700
701
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
702
703
  $hide_taxon_profile_image = FALSE;
704
  if (variable_get('image_hide_rank', '0') != '0' && isset($taxon->name->rank->uuid)) {
705
    $rankCompare = rank_compare($taxon->name->rank->uuid, variable_get('image_hide_rank', '-99'));
706
    $hide_taxon_profile_image = ($rankCompare > -1);
707
  }
708
709
  if ($taxon_profile_image_settings['show'] && !$hide_taxon_profile_image) {
710
711
    $representationPart = new stdClass();
712
    $attributes = array();
713 02faa087 Andreas Kohlbecker
    if (isset($media[0])) {
714
      // due to a bug the portal/taxon/{uuid}/media service only delivers a filtered media object
715
      // which only contains the thumbnail representation even if the height and width filters are not set.
716 673929dd Andreas Kohlbecker
      // -->
717 02faa087 Andreas Kohlbecker
      $preferred_media = cdm_ws_get(CDM_WS_MEDIA, $media[0]->uuid);
718
      $preferred_representations = cdm_preferred_media_representations($preferred_media, array(
719
        'image/jpg',
720
        'image/jpeg',
721
        'image/png',
722
        'image/gif',
723
      ),
724
        $taxon_profile_image_settings['maxextend'],
725
        $taxon_profile_image_settings['maxextend']
726
      );
727
      if(count($preferred_representations) > 0){
728
729
        $representation = array_shift($preferred_representations);
730
        $representationPart = $representation->parts[0];
731
        $attributes['alt'] = $representationPart->uri;
732
733
        if (!empty($taxon_profile_image_settings['media_uri_query'])) {
734
          $representationPart->uri = $representationPart->uri
735
            . (strpos($representationPart->uri, '?') !== FALSE ? '&' : '?')
736
            . $taxon_profile_image_settings['media_uri_query'];
737
        }
738 0ae57522 Patric Plitzner
      }
739
    }
740
    else {
741 9506fd1f Andreas Kohlbecker
      if ($taxon_profile_image_settings['custom_placeholder_enabled']) {
742 ca47ea76 Andreas Kohlbecker
        // show placeholder image instead
743
        if (!empty($taxon_profile_image_settings['custom_placeholder_image_on']) && !empty($taxon_profile_image_settings['custom_placeholder_image_fid'])) {
744
          // use the user provided image
745
          $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
746
          $url = file_create_url($profile_image_file->uri);
747
          $image_info = image_get_info($profile_image_file->uri);
748
          $representationPart->width = $image_info['width'];
749
          $representationPart->height = $image_info['height'];
750
          $representationPart->uri = $url;
751
        }
752
        else {
753
          // use the hard coded default
754
          $representationPart->width = 184;
755
          $representationPart->height = 144;
756
          $representationPart->uri = base_path() . drupal_get_path('module',
757
              'cdm_dataportal') . '/images/no_picture.png';
758
        }
759
        $attributes['alt'] = "no image available";
760 0ae57522 Patric Plitzner
      }
761
    }
762
763 ca47ea76 Andreas Kohlbecker
    if (isset($representationPart->uri)) {
764 a9815578 Andreas Kohlbecker
      $profile_image = cdm_media_gallerie_image($representationPart, $taxon_profile_image_settings['maxextend'], FALSE, $attributes);
765 ca47ea76 Andreas Kohlbecker
      // NOTE: style="width:${maxextend}px' is needed for IE8 !!!
766
      $render_array['taxon_profile_image'] = markup_to_render_array('<div id="taxonProfileImage" style="width:' . $taxon_profile_image_settings['maxextend'] . 'px">' . $profile_image . '</div>',
767
        -101);
768
    }
769 0ae57522 Patric Plitzner
  }
770
771 22383f95 Andreas Kohlbecker
  if($add_synonymy){
772
    $render_array['synonymy'] = markup_to_render_array(
773
      theme('cdm_taxon_page_synonymy', array('taxon' => $taxon, 'addAcceptedTaxon' => true)),
774
      -102
775
    );
776
  }
777
778 1b756c5f Andreas Kohlbecker
  $pseudo_feature_blocks = array();
779
  $pseudo_feature_block_toc_items = array();
780 0ae57522 Patric Plitzner
781
782 1b756c5f Andreas Kohlbecker
  // Render the sections for each real feature
783
  $feature_block_list = make_feature_block_list($merged_tree->root->childNodes, $taxon);
784
785
  // Bibliography
786 0ae57522 Patric Plitzner
  $bibliography_settings = get_bibliography_settings();
787
  if($bibliography_settings['enabled'] == 1){
788 850092a7 Andreas Kohlbecker
    $bibliography_markup = FootnoteManager::renderFootnoteList('BIBLIOGRAPHY', '');
789
    if($bibliography_markup) {
790
      $feature_bibliography = make_pseudo_feature('Bibliography', 'BIBLIOGRAPHY');
791
      $bibliography_block = feature_block(t('Bibliography'), $feature_bibliography);
792
      $bibliography_item = markup_to_render_array($bibliography_markup);
793
      $bibliography_block->content[] = compose_feature_block_wrap_elements(array($bibliography_item), $feature_bibliography);
794 0ae57522 Patric Plitzner
795 1b756c5f Andreas Kohlbecker
      $pseudo_feature_block_toc_items['Bibliography']= 'bibliography';
796
      $pseudo_feature_blocks[] = $bibliography_block;
797 0ae57522 Patric Plitzner
    }
798 1b756c5f Andreas Kohlbecker
  }
799
800
  $render_array['taxon_description_features'] = _block_get_renderable_array(
801
    array_merge($feature_block_list, $pseudo_feature_blocks)
802
  );
803 0ae57522 Patric Plitzner
804 1b756c5f Andreas Kohlbecker
  if($pseudo_feature_block_toc_items){
805
    foreach ($pseudo_feature_block_toc_items as $label=>$fragment){
806
      cdm_toc_list_add_item($label, $fragment);
807
    }
808 0ae57522 Patric Plitzner
  }
809
810
  // create the table of content
811
  $toc = array(
812
      '#theme' => 'item_list',
813
    '#items' => cdm_toc_list(),
814
      '#title' => t('Content'),
815
    '#weight' => -100,                  // move to the top
816
      '#suffix' => '</div>',
817
      '#prefix'=> '<div id="page-toc">'
818
  );
819
  $render_array['taxon_description_feature_toc'] = $toc;
820
821
  return $render_array;
822 bf97c2e8 Andreas Kohlbecker
}
823
824 f9a3d0f6 Andreas Kohlbecker
/**
825
 * composes and returns an render array for the experts associated with the given taxon
826
 *
827 8a1b451e Andreas Kohlbecker
 * @param object taxon
828 f9a3d0f6 Andreas Kohlbecker
 *
829
 * @return array
830
 *   A Drupal render array for a table with the experts
831
 *
832
 * @ingroup compose
833
 */
834 7663cd0b Andreas Kohlbecker
function compose_cdm_taxon_page_experts($taxon){
835
836
  $render_array = array();
837
  if(!isset($taxon->uuid)){
838
    return $render_array;
839
  }
840
841
  $current_classification_uuid = get_current_classification_uuid();
842
  // TODO use cdm_ws_fetchall below but this failes! needs fix!
843
  $taxon_node_agent_relations = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODEAGENTRELATIONS,
844
    array(
845
      $taxon->uuid,
846
      $current_classification_uuid
847
    )
848
  );
849
850
  $header = array(
851
    array('data' => t('Expert')),
852
    array('data' => t('Role'))
853
  );
854
  $rows = array();
855
856
857
  foreach($taxon_node_agent_relations->records as $taxon_node_agent_relation){
858
859 d9763fd3 Andreas Kohlbecker
860
    $expert_role_id = $taxon_node_agent_relation->agent->uuid . '-' . $taxon_node_agent_relation->type->uuid;
861
    $expert_details_container_id = 'expert_details_' . $expert_role_id;
862
863
    $agent_label_markup = cdm_dynabox(
864
      'expert_' . $expert_role_id,
865
      $taxon_node_agent_relation->agent->titleCache,
866
      // specifying both ends of the relationship will return only one record in the pager
867
      cdm_compose_url(CDM_WS_PORTAL_AGENT,
868
         array($taxon_node_agent_relation->agent->uuid, 'taxonNodeAgentRelations'),
869
        'taxon_uuid=' . $taxon->uuid . '&relType_uuid=' . $taxon_node_agent_relation->type->uuid),
870
      'cdm_taxon_expert',
871
      'Click for details',
872
      array('div', 'div'),
873
      array(), // attributes
874 cea412e7 Andreas Kohlbecker
      '#' . $expert_details_container_id // $content_element_selector
875 d9763fd3 Andreas Kohlbecker
    );
876
877
    // Expert and Role
878
    $rows[] = array(
879
      'data' => array(
880
        array(
881
          'data' => $agent_label_markup,
882
          'class' => array(html_class_attribute_ref($taxon_node_agent_relation->agent))
883 7663cd0b Andreas Kohlbecker
        ),
884 d9763fd3 Andreas Kohlbecker
        array(
885
          'data' => $taxon_node_agent_relation->type->representation_L10n,
886
          'class' => array(html_class_attribute_ref($taxon_node_agent_relation->type))
887
        )
888
      )
889
    );
890
    // Agent details
891
    $rows[] = array(
892
      'data' => array(
893
        array(
894
          'data' => '<!-- expert_details_container -->',
895
          'id' => $expert_details_container_id,
896
          'colspan' => 2
897
        )
898
      )
899 7663cd0b Andreas Kohlbecker
    );
900 d9763fd3 Andreas Kohlbecker
901 7663cd0b Andreas Kohlbecker
  }
902
903
904
  $render_array['experts_table'] = array(
905
    '#theme' => 'table',
906
    '#header' => $header,
907
    '#rows' => $rows,
908
  );
909
910
911
  return $render_array;
912
}
913
914 bf97c2e8 Andreas Kohlbecker
915 3f259ca3 Andreas Kohlbecker
/**
916 7663cd0b Andreas Kohlbecker
 * Manages the tabs to be hidden in the taxon page.
917 3f259ca3 Andreas Kohlbecker
 *
918
 * The tabs are identified by their last menu link path element:
919
 *  - description
920
 *  - synonymy
921
 *  - images
922
 *  - specimens
923
 *  - key
924
 *
925
 * Internally the tabs are stored in a static variable which is
926
 * managed by drupal_static().
927
 *
928
 * @param string $add_tab
929 7663cd0b Andreas Kohlbecker
 *   Optional parameter. The given string will be added to the array of tabs
930 3f259ca3 Andreas Kohlbecker
 *
931
 * @return
932
 *   The array of tabs
933
 */
934 48a6d7e8 Andreas Kohlbecker
function taxon_page_tabs_hidden_add($add_tab = NULL) {
935
  $tabs = &drupal_static('taxon_page_tabs_hidden');
936 3f259ca3 Andreas Kohlbecker
937 0ae57522 Patric Plitzner
  if(!isset($tabs)){
938
    $tabs = array();
939
  }
940 3f259ca3 Andreas Kohlbecker
941 0ae57522 Patric Plitzner
  if (isset($add_tab) && !array_key_exists($add_tab, $tabs)) {
942
    $tabs[] = $add_tab;
943
  }
944 3f259ca3 Andreas Kohlbecker
945 0ae57522 Patric Plitzner
  return $tabs;
946 3f259ca3 Andreas Kohlbecker
}
947
948 48a6d7e8 Andreas Kohlbecker
/**
949
 * Manages the tabs to be hidden in the taxon page.
950
 *
951
 * The tabs names are identified by their last menu link path element:
952
 *  - description
953
 *  - synonymy
954
 *  - images
955
 *  - specimens
956
 *  - key
957
 *
958
 * Internally the tabs are stored in a static variable which is
959
 * managed by drupal_static().
960
 *
961
 * @param string $tabname
962
 *   The name of the tab to check
963
 *
964
 * @return boolean
965
 *   True if the tab or section is to be hidden
966
 */
967
function taxon_page_tabs_hidden_check($tabname) {
968
969
  $tabs = &drupal_static('taxon_page_tabs_hidden');
970
971
  if(!isset($tabs)){
972
    $tabs = array();
973
  }
974
975
  return array_search($tabname, $tabs) !== FALSE;
976
}
977
978 3f259ca3 Andreas Kohlbecker
/**
979
 * Implements the hook_preprocess_HOOK() for theme_menu_local_tasks()
980
 *
981 48a6d7e8 Andreas Kohlbecker
 *  - Removes the tabs to be hidden, @see taxon_page_tabs_hidden_add()
982 9438ad3a Andreas Kohlbecker
 *  - Renames tabs according to the settings // TODO (this will replace the theme_cdm_taxonpage_tab() function !!!)
983 3f259ca3 Andreas Kohlbecker
 *
984
 * @param array $variables
985
 *   The variables array
986
 */
987
function cdm_dataportal_preprocess_menu_local_tasks(&$variables) {
988
989 48a6d7e8 Andreas Kohlbecker
  $hidden_tabs = taxon_page_tabs_hidden_add();
990 3f259ca3 Andreas Kohlbecker
991 0ae57522 Patric Plitzner
  if (is_array($variables['primary'])) {
992
    foreach ($variables['primary'] as $key => &$element) {
993 6f1a217c Andreas Kohlbecker
994 0ae57522 Patric Plitzner
      // 1. Remove the tabs to be hidden
995
      foreach ($hidden_tabs as $tab) {
996
        if ($element['#link']['path'] == 'cdm_dataportal/taxon/%/' . $tab) {
997
          // remove the tab
998
          unset($variables['primary'][$key]);
999 9438ad3a Andreas Kohlbecker
        }
1000 0ae57522 Patric Plitzner
      }
1001 3f259ca3 Andreas Kohlbecker
    }
1002 0ae57522 Patric Plitzner
  }
1003 6f1a217c Andreas Kohlbecker
}
1004
1005
1006
1007
/**
1008
 * Implements the hook_preprocess_HOOK() for theme_menu_local_task()
1009
 *
1010
 *
1011
 * @param array $variables
1012
 *   An associative array containing:
1013
 *     - element: A render element containing:
1014
 *          #link: A menu link array with 'title', 'href', and 'localized_options' keys.
1015
 *          #active: A boolean indicating whether the local task is active.
1016
 *
1017
 */
1018
function cdm_dataportal_preprocess_menu_local_task(&$variables) {
1019
1020 0ae57522 Patric Plitzner
  $link = $variables['element']['#link'];
1021
  if (preg_match('/cdm_dataportal\/.*\/refresh$/', $link['href'])) {
1022
    $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']) . '"/>';
1023
    $link['localized_options']['html'] = TRUE;
1024 6f1a217c Andreas Kohlbecker
1025 0ae57522 Patric Plitzner
    $variables['element']['#link'] = $link;
1026
  }
1027 f19f47fa Andreas Kohlbecker
}
1028 f9a3d0f6 Andreas Kohlbecker
1029
/* =================== block composition ===================== */
1030
1031
/**
1032 23ad16a1 Andreas Kohlbecker
 * Composes and returns an render array for the classification breadcrumbs of the given taxon.
1033 f9a3d0f6 Andreas Kohlbecker
 *
1034
 * @param taxon
1035
 *
1036
 * @return array
1037
 *   A Drupal render array for a table with the experts
1038
 *
1039
 * @ingroup compose
1040
 */
1041
function compose_classification_breadcrumbs($taxon_uuid) {
1042
1043 b0adfd32 Andreas Kohlbecker
  _add_js_taxonomic_children('#classification-breadcrumbs .taxonomic-children-button');
1044 d0d23caa Andreas Kohlbecker
1045 f9a3d0f6 Andreas Kohlbecker
  $render_array = array();
1046
1047
  $render_array['#theme'] = 'item_list';
1048
  $render_array['#type'] = 'ul';
1049
  $render_array['#attributes'] = array(
1050
    'id' => 'classification-breadcrumbs',
1051
    'class' => 'breadcrumbs inline',
1052
  );
1053
1054
  $items = array();
1055
1056 38da4e54 Andreas Kohlbecker
  $parent_taxon_nodes = null;
1057
  if($taxon_uuid){
1058
    $parent_taxon_nodes = cdm_ws_taxonomy_pathFromRoot($taxon_uuid);
1059
  }
1060 f9a3d0f6 Andreas Kohlbecker
1061 38da4e54 Andreas Kohlbecker
  $classifications = cdm_ws_fetch_all(CDM_WS_PORTAL_TAXONOMY);
1062
  // find current classification in list
1063
  $classification = null;
1064
  $current_classification_uuid = get_current_classification_uuid();
1065
  foreach ($classifications as $classification){
1066
    if($classification->uuid == $current_classification_uuid){
1067
      break;
1068 b0adfd32 Andreas Kohlbecker
    }
1069 38da4e54 Andreas Kohlbecker
  }
1070 b0adfd32 Andreas Kohlbecker
1071 38da4e54 Andreas Kohlbecker
  $node_name = '';
1072
  if(count($classifications) > 1 ){
1073
    // need to add the current classification as first label
1074 0af3ce28 Andreas Kohlbecker
1075
    $label = $classification->titleCache;
1076
    if(strlen($label) > 20){
1077
      $label = substr($label, 0, strpos($label, ' ', 15)) . '...';
1078
    }
1079
    $node_name = font_awesome_icon_markup('fa-th-list')  . ' ' . l($label, '#', array(
1080
      'attributes' => array(
1081
        'class' => 'taxonomic-children-button classification-chooser',
1082
        'data-destination-uri' => drupal_get_destination(),
1083
        'data-cdm-align-with' => array('prev')
1084
      ),
1085
      'html' => true
1086
    ));
1087 f9a3d0f6 Andreas Kohlbecker
  }
1088 b0adfd32 Andreas Kohlbecker
1089 38da4e54 Andreas Kohlbecker
  $rank_limit_uuid = variable_get(TAXONTREE_RANKLIMIT, TAXONTREE_RANKLIMIT_DEFAULT);
1090 0af3ce28 Andreas Kohlbecker
1091
  $rank_separator = '<span> '
1092 38da4e54 Andreas Kohlbecker
    . font_awesome_icon_markup('fa-chevron-right')
1093
    . ' </span>';
1094 0af3ce28 Andreas Kohlbecker
  $more_children_icon = font_awesome_icon_markup('fa-sitemap fa-rotate-270');
1095 69fb3dbb Andreas Kohlbecker
  $more_children_label = '...';
1096 38da4e54 Andreas Kohlbecker
1097 0af3ce28 Andreas Kohlbecker
  $items[] = $node_name;
1098 38da4e54 Andreas Kohlbecker
1099 0af3ce28 Andreas Kohlbecker
  $more_children_for = null;
1100 e3235962 Andreas Kohlbecker
  if($parent_taxon_nodes){
1101 0af3ce28 Andreas Kohlbecker
    foreach ($parent_taxon_nodes as $node) {
1102 38da4e54 Andreas Kohlbecker
1103
      $is_first_item = count($items) == 0;
1104 0af3ce28 Andreas Kohlbecker
      $is_last_item = count($items) == count($parent_taxon_nodes);
1105 38da4e54 Andreas Kohlbecker
      $node_name = cdm_dataportal_shortname_of($node);
1106
      $path = path_to_taxon($node->taxonUuid);
1107
1108 0af3ce28 Andreas Kohlbecker
      if($node->taxonomicChildrenCount > 0) {
1109
        $more_children_for = $node->taxonUuid;
1110
      } else {
1111
        $more_children_for = null;
1112 38da4e54 Andreas Kohlbecker
      }
1113
1114 0af3ce28 Andreas Kohlbecker
      // 'fa-sitemap'
1115
1116 38da4e54 Andreas Kohlbecker
      $items[] =
1117 0af3ce28 Andreas Kohlbecker
        ($is_first_item ? '' : ' ')
1118
        . $rank_separator
1119
        . l(
1120 4b3be949 Andreas Kohlbecker
          '<span class="' . html_class_attribute_ref($node) . '">' . $node_name . '</span>',
1121 0af3ce28 Andreas Kohlbecker
          $path,
1122
          array(
1123
            'attributes' => array(
1124
              'class' => array('taxonomic-children-button'),
1125
              'data-cdm-taxon-uuid' => array($node->taxonUuid),
1126
              'data-cdm-classification-mode' => array('siblings'),
1127
              'data-cdm-align-with' => array('prev')
1128 4b3be949 Andreas Kohlbecker
            ),
1129
            'html' => true
1130 0af3ce28 Andreas Kohlbecker
          )
1131
        );
1132
      }
1133 38da4e54 Andreas Kohlbecker
    }
1134 0af3ce28 Andreas Kohlbecker
1135
  // add more button to the end
1136
  if(!$parent_taxon_nodes) {
1137
    // not taxon focused yet, adding button to make  the root nodes available
1138 69fb3dbb Andreas Kohlbecker
    $items[] = '<span>'
1139
      . $more_children_icon . '&nbsp;' .
1140
      '<span class="taxonomic-children-button" data-classification-uuid="' . $current_classification_uuid
1141 53c705d4 Andreas Kohlbecker
      . '" data-rank-limit-uuid="' . $rank_limit_uuid . '" data-cdm-align-with="prev"> ' . $more_children_label . '<span>'
1142 69fb3dbb Andreas Kohlbecker
      . '</span>';
1143 0af3ce28 Andreas Kohlbecker
  } else if($more_children_for){
1144
    // last parent item has child taxon nodes
1145 69fb3dbb Andreas Kohlbecker
    $items[] = ' <span>'
1146
      . $more_children_icon . '&nbsp;' .
1147
      '<span class="taxonomic-children-button" data-cdm-taxon-uuid="' .$more_children_for
1148 53c705d4 Andreas Kohlbecker
      . '" data-cdm-classification-mode="children" data-cdm-align-with="prev"> ' . $more_children_label . '</span>'
1149 69fb3dbb Andreas Kohlbecker
      . '</span>';
1150 0af3ce28 Andreas Kohlbecker
1151 e3235962 Andreas Kohlbecker
  }
1152 b0adfd32 Andreas Kohlbecker
1153 30845bda Andreas Kohlbecker
  $render_array['#items'] = $items;
1154 0af3ce28 Andreas Kohlbecker
1155 30845bda Andreas Kohlbecker
  return $render_array;
1156
}
1157 0af3ce28 Andreas Kohlbecker
1158 69fb3dbb Andreas Kohlbecker
1159 30845bda Andreas Kohlbecker
/**
1160
 * @param $specimen_uuid
1161
 * @return array
1162
 *    The drupal render array for the page
1163
 *
1164
 * @ingroup compose
1165
 */
1166
function compose_cdm_specimen_page($specimen_uuid)
1167
{
1168
  drupal_set_title("Specimen Details");
1169
  $specimen = cdm_ws_get(CDM_WS_PORTAL_OCCURRENCE, array($specimen_uuid, 'specimenDerivates'));
1170
1171
  $render_array = array();
1172
  RenderHints::pushToRenderStack('specimen_page');
1173 f9a3d0f6 Andreas Kohlbecker
1174 30845bda Andreas Kohlbecker
  $detail_html = render_cdm_specimen_page($specimen, true);
1175
  $render_array['specimen_html'] = array(
1176
    '#markup' => $detail_html
1177
  );
1178
1179
  RenderHints::popFromRenderStack();
1180 f9a3d0f6 Andreas Kohlbecker
  return $render_array;
1181 30845bda Andreas Kohlbecker
}
1182 f9a3d0f6 Andreas Kohlbecker
1183 30845bda Andreas Kohlbecker
/**
1184
 * @param $named_area_uuid
1185
 * @return array
1186
 *    The drupal render array for the page
1187
 *
1188
 * @ingroup compose
1189
 */
1190
function compose_cdm_named_area_page($named_area_uuid)
1191
{
1192
1193
  $named_area = cdm_ws_get(CDM_WS_PORTAL_TERM, array($named_area_uuid));
1194
1195
  $render_array = array();
1196
  RenderHints::pushToRenderStack('named_area_page');
1197
1198
  $groups = array();
1199
  @_description_list_group_add($groups, t('Name') . ':', $named_area->representation_L10n);
1200
  @_description_list_group_add($groups, t('IdInVocabulary') . ':', $named_area->idInVocabulary);
1201
  if(isset($named_area->level)) {
1202
    @_description_list_group_add($groups, t('Level') . ':', $named_area->level->representation_L10n);
1203
  }
1204
1205
  $name_area_details_elements = array(
1206
   // '#title' => $title,
1207
    '#theme' => 'description_list',
1208
    '#groups' => $groups,
1209
    '#attributes' => array('class' => html_class_attribute_ref($named_area)),
1210
  );
1211
1212
  $render_array[] = $name_area_details_elements;
1213
1214
  RenderHints::popFromRenderStack();
1215
  return $render_array;
1216 f9a3d0f6 Andreas Kohlbecker
}
1217 4feeabc7 Andreas Kohlbecker
1218
/**
1219
 * Provides the the label string for taxon page tabs.
1220
 *
1221
 * The $tabname as passed to the method will be returned if no override
1222
 * label is configured in the settings.
1223
 */
1224
function cdm_taxonpage_tab_label($tabname) {
1225
  static $taxon_tabs_labels = null;
1226
  if($taxon_tabs_labels == null){
1227
    $taxon_tabs_labels = get_array_variable_merged(CDM_TAXONPAGE_TAB_LABELS, CDM_TAXONPAGE_TAB_LABELS_DEFAULT);
1228
  }
1229
  $tabname_key = strtolower($tabname);
1230
  if(isset($taxon_tabs_labels[$tabname_key]) && $taxon_tabs_labels[$tabname_key]){
1231
    return $taxon_tabs_labels[$tabname_key];
1232
  }
1233
  return $tabname;
1234
}