Project

General

Profile

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