Project

General

Profile

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