Project

General

Profile

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