Project

General

Profile

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