Project

General

Profile

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