Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

cdm-dataportal / modules / cdm_dataportal / includes / pages.inc @ 4feeabc7

History | View | Annotate | Download (41.8 KB)

1
<?php
2
/**
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
 * @see http://www.mozilla.org/MPL/MPL-1.1.html
14
 *
15
 * @author
16
 *   - 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
 */
33
function cdm_dataportal_taxon_page_specimens($taxon) {
34

    
35
    $render_array = array();
36
    RenderHints::pushToRenderStack('taxon_page_specimens');
37

    
38
    $relationship_choice = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
39
    $relationship_choice['direct'] = get_selection($relationship_choice['direct']);
40
    $relationship_choice['invers'] = get_selection($relationship_choice['invers']);
41

    
42
    $by_associatedtaxon_query_parameters = array(
43
        'relationshipsInvers' => implode(',', $relationship_choice['invers']),
44
        'relationships' => implode(',', $relationship_choice['direct']),
45
    );
46

    
47
    if (isset($_REQUEST['pager']) && is_array($_REQUEST['pager'])) {
48
        $by_associatedtaxon_query_parameters = array_merge($by_associatedtaxon_query_parameters, $_REQUEST['pager']);
49
    }
50

    
51
    $by_associatedtaxon_query = http_build_query($by_associatedtaxon_query_parameters);
52

    
53
    $pager = cdm_ws_get(CDM_WS_OCCURRENCE_BY_ASSOCIATEDTAXON,
54
        null,
55
        $by_associatedtaxon_query . '&taxonUuid=' . $taxon->uuid
56
    );
57

    
58
    $specimensOrObservations = array();
59
    if(isset($pager->records[0])){
60
        $specimensOrObservations =  $pager->records;
61
    }
62

    
63
    // order occurrences by date but types should be on top of the list
64
    $type_specimens = array();
65
    $other_occurrences = array();
66
    foreach ($specimensOrObservations as &$occurrence) {
67
        $typeDesignationsPager = cdm_ws_get(CDM_WS_OCCURRENCE . '/$0/specimenTypeDesignations', $occurrence->uuid);
68
        if (isset($typeDesignationsPager->count) && $typeDesignationsPager->count > 0) {
69
            $type_specimens[] = $occurrence;
70
        } else {
71
            $other_occurrences[] = $occurrence;
72
        }
73
    }
74
    $specimensOrObservations = array_merge($type_specimens, $other_occurrences);
75

    
76
    // Collect media (fieldObjectMedia, derivedUnitMedia) and add as a custom field
77
    // $occurrence->_fieldObjectMedia
78
    foreach ($specimensOrObservations as &$occurrence) {
79
        $occurrence->_fieldObjectMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array(
80
            $occurrence->uuid,
81
            'fieldObjectMedia',
82
        ));
83
        $occurrence->_derivedUnitMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array(
84
            $occurrence->uuid,
85
            'derivedUnitMedia',
86
        ));
87
    }
88

    
89
    // --- get map service HTTP query parameters
90
    if (count($specimensOrObservations) > 0) {
91
        $occurrence_queryDto = cdm_ws_get(CDM_WS_GEOSERVICE_OCCURRENCEMAP, $taxon->uuid,  $by_associatedtaxon_query);
92

    
93
      $map_visibility = variable_get(SPECIMEN_MAP_VISIBILITY, SPECIMEN_MAP_VISIBILITY_DEFAULT);
94
      if($map_visibility == 'always' ||
95
        variable_get(SPECIMEN_MAP_VISIBILITY, SPECIMEN_MAP_VISIBILITY_DEFAULT) == 'automatic' &&
96
          (isset($occurrence_queryDto->fieldUnitPoints[0]) || isset($occurrence_queryDto->derivedUnitPoints[0]))
97
        )
98
      {
99
        $occurrence_query = $occurrence_queryDto->occurrenceQuery;
100
        $legend_format_query = null;
101
        $distribution_query = NULL;
102
        $render_array['map'] = compose_map('specimens', $occurrence_query, $distribution_query, $legend_format_query, array());
103
      }
104
    }
105
    if(variable_get('cdm_dataportal_compressed_specimen_derivate_table')){
106

    
107
        //COMPRESSED SPECIMEN DERIVATE TABLE
108
        $associatedFieldUnitsQuery_parameters = array();
109
        if (isset($_REQUEST['pager']) && is_array($_REQUEST['pager'])) {
110
            $associatedFieldUnitsQuery_parameters = array_merge($associatedFieldUnitsQuery_parameters, $_REQUEST['pager']);
111
        }
112

    
113
        $by_associatedtaxon_query = http_build_query($associatedFieldUnitsQuery_parameters);
114
        $pagerFieldUnits = cdm_ws_get(CDM_WS_PORTAL_TAXON, array($taxon->uuid, 'associatedFieldUnits'), $by_associatedtaxon_query);
115
        // get icon images
116
        $expand_icon = font_awesome_icon_markup(
117
            'fa-plus-square-o',
118
            array(
119
                'alt'=>'Show details',
120
                'class' => array('expand_icon')
121
            )
122
        );
123
        $collapse_icon = font_awesome_icon_markup(
124
            'fa-minus-square-o',
125
            array(
126
                'alt'=>'Show details',
127
                'class' => array('collapse_icon')
128
            )
129
        );
130
        $detail_image_icon = '<img title="Detail Image" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/detail_image_derivate-16x16-32.png' . '"/>';
131
        $checked_box_icon = '<img src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/step_done.gif' . '"/>';
132
        $sequence_icon = '<img title="Molecular Data" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/sequence_derivate-16x16-32.png' . '"/>';
133
        $character_data_icon = '<img title="Character Data" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/character_data_derivate-16x16-32.png' . '"/>';
134
        if (isset($pagerFieldUnits->records[0])) {
135
            $rowcount = 0;
136
            foreach ($pagerFieldUnits->records as $fieldUnit) {
137
                //get derivate hierarchy for the FieldUnit
138
                $derivateHierarchy = cdm_ws_get(CDM_WS_PORTAL_OCCURRENCE, array($fieldUnit->uuid, 'derivateHierarchy'), 'taxonUuid=' . $taxon->uuid);
139
                if($derivateHierarchy){
140
                    //summary row
141
                    $rows[] = array(
142
                        'data' => array(
143
                            array(
144
                                'data' => $expand_icon . $collapse_icon,
145
                                'class' => array('summary_row_cell', 'summary_row_icon', 'expand_column')
146
                            ),
147
                            array(
148
                                'data' => $derivateHierarchy->country,
149
                                'class' => array('summary_row_cell')
150
                            ),
151
                            array(
152
                                'data' => $derivateHierarchy->date,
153
                                'class' => array('summary_row_cell')
154
                            ),
155
                            array(
156
                                'data' => $derivateHierarchy->collection,
157
                                'class' => array('summary_row_cell')
158
                            ),
159
                            array(
160
                                'data' => $derivateHierarchy->herbarium,
161
                                'class' => array('summary_row_cell')
162
                            ),
163
                            array(
164
                                'data' => $derivateHierarchy->hasType? $checked_box_icon:"",
165
                                'class' => array('summary_row_cell', 'summary_row_icon')
166
                            ),
167
                            array(
168
                                'data' => $derivateHierarchy->hasSpecimenScan? $checked_box_icon:"",
169
                                'class' => array('summary_row_cell', 'summary_row_icon')
170
                            ),
171
                            array(
172
                                'data' => ($derivateHierarchy->hasDna? $sequence_icon :"")." "
173
                                    .($derivateHierarchy->hasDetailImage?$detail_image_icon:"")." "
174
                                    .($derivateHierarchy->hasCharacterData?$character_data_icon:""),
175
                                'class' => array('summary_row_cell', 'summary_row_icon')
176
                            )
177
                        ),
178
                        'id' => ('derivate_summary' . $rowcount), // summary row id
179
                        'class' => array('summary_row'),
180
                    );
181

    
182
                    //assemble field unit details
183
                    $detail_html = "";
184
                    // - taxon name
185
                    if (variable_get('cdm_dataportal_compressed_specimen_derivate_table_show_determined_as') && $derivateHierarchy->taxonName) {
186
                        $detail_html .= create_label("Associated with") . $derivateHierarchy->taxonName . "<br>";
187
                    }
188
                    // - protologue
189
                    if ($derivateHierarchy->protologue) {
190
                        //$detail_html .= "<strong>Protologue:</strong> " . $derivateHierarchy->protologue . "<br>"
191
                    }
192
                    // - citation
193
                    if ($derivateHierarchy->citation) {
194
                        $detail_html .= create_label("Citation") . $derivateHierarchy->citation . "<br>";
195
                    }
196
                    //assemble specimen details
197
                    if($derivateHierarchy->preservedSpecimenDTOs){
198
                        foreach($derivateHierarchy->preservedSpecimenDTOs as $preservedSpecimenDTO) {
199
                            $detail_html .= "<br>";
200
                            $detail_html .= render_cdm_specimen_page($preservedSpecimenDTO);
201
                        }
202
                    }
203
                    $detail_html .= "<br>";
204
                    //detail row resp. one BIG detail cell
205
                    $rows[] = array(
206
                        'data' => array(
207
                            array(
208
                                'data' => "", //empty first column
209
                                'class' => array('expand_column')
210
                            ),
211
                            array(
212
                                'data' => $detail_html,
213
                                'colspan' => 7,
214
                            ),
215
                        ),
216
                        'id' => ('derivate_details' . $rowcount),//details row ID
217
                        'class' => array('detail_row'),
218
                    );
219
                    $rowcount++;
220
                }
221
            }
222
        }
223

    
224
        $tableId = "derivate_hierarchy_table";
225
        $derivateHierarchyTable = array(
226
            "#theme" => "table",
227
            "#weight" => 2,
228
            "#header" => array(
229
                array(
230
                    'data' => "",
231
                    'class' => array('expand_column')
232
                ),
233
                "Country", "Date", "Collector + collecting number", "Herbaria", "Type", "Scan", "Derivatives"),
234
            "#rows" => $rows,
235
            "#attributes" => array(
236
                "id" => $tableId,
237
                "border" => 2
238
            )
239
        );
240

    
241
        //add toggle functionality to derivate hierarchy table
242
        drupal_add_js_rowToggle("#".$tableId);
243

    
244
        $render_array['derivate_hierarchy_table'] = $derivateHierarchyTable;
245
        $render_array['pager'] = markup_to_render_array(
246
            theme('cdm_pager', array(
247
                'pager' => $pagerFieldUnits,
248
                'path' => $_REQUEST['q'],
249
                'parameters' => $_REQUEST
250
            )),
251
            10 // weight
252
        );
253
    }
254
    else{
255
        //BOTTOM-UP-SPECIMEN-TABLE
256
        // --- generate the specimen list as table
257
        $specimen_table = array(
258
            '#theme' => 'table',
259
            '#weight' => 2,
260
            // prefix attributes and rows with '#' to let it pass to the theme function,
261
            // otherwise it is handled as child render array
262
            '#attributes' => array('class' => 'specimens'),
263
            '#rows' => array(),
264
        );
265

    
266
        if ($specimensOrObservations) {
267

    
268
            foreach ($specimensOrObservations as $specimenOrObservation) {
269

    
270
                $mediaList = array();
271
                if (is_array($specimenOrObservation->_fieldObjectMedia)) {
272
                    $mediaList = array_merge($mediaList, $specimenOrObservation->_fieldObjectMedia);
273
                }
274
                if (is_array($specimenOrObservation->_derivedUnitMedia)) {
275
                    $mediaList = array_merge($mediaList, $specimenOrObservation->_derivedUnitMedia);
276
                }
277

    
278
                // typelabel will contain the typeStatus
279
                $type_label = '';
280
                $typeDesignationPager = cdm_ws_get(CDM_WS_OCCURRENCE . '/$0/specimenTypeDesignations', $specimenOrObservation->uuid);
281
                if (isset($typeDesignationPager) and isset($typeDesignationPager->records)) {
282
                    $type_status = array();
283
                    foreach ($typeDesignationPager->records as $typeDesignation) {
284
                        if (isset($typeDesignation->typeStatus->representation_L10n)){
285
                            $type_status[] = $typeDesignation->typeStatus->representation_L10n;
286
                        }
287
                    }
288
                    $type_label = implode(', ', $type_status);
289
                    if($type_label){
290
                        $type_label .= ': ' ;
291
                    }
292
                }
293

    
294
                // --- Specimen entry as dynamic label:
295
                //     -> Dynabox for the specimenOrObservation
296
                $gallery_name = $specimenOrObservation->uuid;
297

    
298
                $derived_unit_ws_request = cdm_compose_url(CDM_WS_OCCURRENCE, array( $specimenOrObservation->uuid));
299
                $label_html = cdm_dynabox(
300
                  $specimenOrObservation->uuid,
301
                  $type_label . $specimenOrObservation->titleCache,
302
                  $derived_unit_ws_request,
303
                  'cdm_specimenOrObservation',
304
                  'Click for details',
305
                  array('div', 'div'),
306
                  array(),
307
                  null, // $content_element_selector
308
                  'function(){ jQuery(\'#media_gallery_' . $gallery_name . '\').hide(); }', // open_callback
309
                  'function(){ jQuery(\'#media_gallery_' . $gallery_name . '\').show(); }' // close_callback
310
                );
311

    
312
                // --- Render associated media.
313
                $gallery_html = '';
314
                if (count($mediaList) > 0) {
315
                    $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
316
                    $captionElements = array(
317
                        '#uri' => t('open media'),
318
                    );
319

    
320
                    $gallery_html = theme('cdm_media_gallerie', array(
321
                        'mediaList' => $mediaList,
322
                        'galleryName' => $gallery_name,
323
                        'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
324
                        'cols' => $gallery_settings['cdm_dataportal_media_cols'],
325
                        'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
326
                        'captionElements' => $captionElements,
327
                        'mediaLinkType' => 'LIGHTBOX',
328
                        'alternativeMediaUri' => NULL,
329
                        'galleryLinkUri' => NULL,
330
                    ));
331
                }
332

    
333
                $specimen_table['#rows'][] = array(
334
                    // An array of table rows. Every row is an array of cells, or an associative array
335
                    'data' => array(
336
                        // Each cell can be either a string or an associative array
337
                        $label_html . $gallery_html
338
                    ),
339
                    'class' =>  array(
340
                        'descriptionElement',
341
                        'descriptionElement_IndividualsAssociation'
342
                    ),
343
                );
344
            }
345
        }
346

    
347
        $render_array['specimen_list'] = $specimen_table;
348
        $render_array['pager'] = markup_to_render_array(
349
            theme('cdm_pager', array(
350
                'pager' => $pager,
351
                'path' => $_REQUEST['q'],
352
                'parameters' => $_REQUEST,
353
            )),
354
            10 // weight
355
        );
356
    }
357
    RenderHints::popFromRenderStack();
358
    return $render_array;
359
}
360
 
361
function create_html_link($link, $openInExternalWindow=false){
362
    $html = "";
363
    if($link->uri && $link->uri!=""){
364
        $html .= '<a  href="' . $link->uri . '"';
365
        if($openInExternalWindow){
366
            $html .= ' target="_blank"';
367
        }
368
        $html .= '>' . $link->linkText . '</a>';
369
    }
370
    else{
371
        $html .= $link->linkText;
372
    }
373
    return $html;
374
}
375

    
376
/**
377
 * Creates HTML links from the given link list concatenated by default by a comma.
378
 * @param $linkList the list with Link objects having "uri" and "linkText" as members
379
 * @return string the assembled HTML string containing the links
380
 */
381
function create_html_links($linkList, $openInExternalWindow=false, $separator=", ")
382
{
383
    $html = "";
384
    if ($linkList) {
385
        foreach ($linkList as $link) {
386
            $html .= create_html_link($link, $openInExternalWindow).$separator;
387
        }
388
        $html = rtrim($html, $separator);
389
    }
390
    return $html;
391
}
392

    
393
/**
394
 * Composes a taxon page which can consist of multiple parts like
395
 * 'General', 'Synonymy', 'Images', 'Keys'. These parts can be displayed
396
 * as tabs or as sections of a single page.
397
 *
398
 * It is headed by the name of the accepted taxon without author and reference.
399
 *
400
 * @param $taxon
401
 *   The CDM Taxon Instance to compose the page for.
402
 * @param $page_part
403
 *   Name of the part to display, valid values are:
404
 *    - 'description' -  for the general part
405
 *    - 'images'
406
 *    - 'synonymy'
407
 *    - 'keys'
408
 *    - 'all'
409
 *
410
 * @return array
411
 *   A drupal render array
412
 *
413
 * @ingroup compose
414
 */
415
function compose_cdm_taxon_page($taxon, $page_part = 'description') {
416

    
417
  // we better cache here since drupal_get_query_parameters has no internal static cache variable
418
  $http_request_params = drupal_get_query_parameters();
419

    
420
  // add all mandatory js sources
421
  _add_js_footnotes();
422

    
423

    
424
  $render_array = array();
425
  $weight = 0; // the weight for the render array elements
426

    
427
  $tabsToDisplay = variable_get('cdm_taxonpage_tabs_visibility', unserialize(TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT));
428

    
429
  $page_part = variable_get('cdm_dataportal_taxonpage_tabs', 1) ? $page_part : 'all';
430

    
431
  $media = _load_media_for_taxon($taxon);
432

    
433

    
434
  if (!isset($media[0]) || ($tabsToDisplay["Images"] == '0')) {
435
    taxon_page_tabs_hidden('images');
436
  }
437

    
438
  // --- GET specimensOrObservations --- //
439
  $specimensOrObservations = cdm_ws_get(CDM_WS_TAXON, array( $taxon->uuid, 'specimensOrObservations'));
440

    
441
  $specimensOrObservationsCount = is_array($specimensOrObservations) ? count($specimensOrObservations) : 0;
442
  if ($specimensOrObservationsCount == 0 || ($tabsToDisplay["Specimens"] == '0')) {
443
    taxon_page_tabs_hidden('specimens');
444
  }
445

    
446
  // --- GET polytomousKeys --- //
447
  $polytomousKeysPager = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, NULL, "findByTaxonomicScope=$taxon->uuid");
448
  $identificationKeyCount = 0;
449
  if ($polytomousKeysPager) {
450
    $identificationKeyCount += $polytomousKeysPager->count;
451
  }
452
  if ($identificationKeyCount == 0 || ($tabsToDisplay["Keys"] == '0')) {
453
    taxon_page_tabs_hidden('keys');
454
  }
455

    
456
    // --- GET TaxonNodeAgentRelations --- //
457
    $current_classification_uuid = get_current_classification_uuid();
458
    $taxon_node_agent_relations_pager = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODEAGENTRELATIONS,
459
        array(
460
            $taxon->uuid,
461
            $current_classification_uuid,
462
        ),
463
        "pageSize=1&pageIndex=0"// we are only interested into the count so we are fetching only one item, o is not possible!
464
    );
465
    if (!$taxon_node_agent_relations_pager || $taxon_node_agent_relations_pager->count == 0){
466
        taxon_page_tabs_hidden('experts');
467
    }
468

    
469
    if ($tabsToDisplay["Synonymy"] == '0') {
470
    taxon_page_tabs_hidden('synonymy');
471
  }
472

    
473
  // -------------------------------------------- //
474

    
475
  if (variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR) && isset($_REQUEST['acceptedFor'])) {
476
    $render_array['accepted_for'] = markup_to_render_array(cdm_accepted_for($_REQUEST['acceptedFor']), $weight++);
477
  }
478

    
479
  // --- PAGE PART: DESCRIPTION --- //
480
  if ($page_part == 'description' || $page_part == 'all') {
481

    
482
    $merged_tree = merged_taxon_feature_tree($taxon);
483

    
484

    
485
    $render_array['general'] = compose_cdm_taxon_page_profile($taxon, $merged_tree, $media);
486
    $render_array['general']['#weight'] = $weight++;
487
    $render_array['general']['#prefix'] = '<div id="general" class="page-part">';
488
    $render_array['general']['#suffix'] = '</div>';
489
  }
490

    
491
  // --- PAGE PART: IMAGES --- //
492
  if (array_search('images', taxon_page_tabs_hidden()) === FALSE && ($page_part == 'images' || $page_part == 'all')) {
493
    $images_html = '<div id="images" class="page-part">';
494
    if ($page_part == 'all') {
495
      $images_html .= '<h2>' . t(cdm_taxonpage_tab_label('Images')) . '</h2>';
496
    }
497
    // Get the image gallery as configured by the admin.
498
    $default_image_gallery = 'default';
499
    $configured_image_gallery_viewer = variable_get('image_gallery_viewer', 'default');
500
    $taxon_image_gallery = '<div class="error">No image gallery viewer configured</div>';
501
    if($configured_image_gallery_viewer == $default_image_gallery || $configured_image_gallery_viewer == 'fsi'){
502
      // the fsi_gallery requires a flash plugin, in case the client browser is not supporting
503
      // flash we also need to provide an the default gallery as alternative
504
      $taxon_image_gallery = '<div id="default-gallery-viewer">' .
505
        call_user_func_array('taxon_image_gallery_' . $default_image_gallery, array(
506
          $taxon,
507
          $media,
508
        ))
509
        . '</div>';
510
    }
511
    if($configured_image_gallery_viewer == 'fsi'){
512
      $taxon_image_gallery .= '<div id="'. $configured_image_gallery_viewer .'-gallery-viewer">' .
513
        call_user_func_array('taxon_image_gallery_' . $configured_image_gallery_viewer, array(
514
          $taxon,
515
          $media,
516
        ))
517
       . '</div>';
518
    }
519
    $images_html .= $taxon_image_gallery;
520
    $images_html .= '</div>';
521
    $render_array['images'] = markup_to_render_array($images_html, $weight++);
522
  }
523

    
524
  // --- PAGE PART: SYNONYMY --- //
525
  if (($page_part == 'synonymy' || $page_part == 'all')) {
526
    $synonymy_html = '<div id="synonymy" class="page-part">';
527
    if ($page_part == 'all') {
528
      $synonymy_html .= '<h2>' . t(cdm_taxonpage_tab_label('Synonymy')) . '</h2>';
529
    }
530
    $addAcceptedTaxon = variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE);
531

    
532
    $synonymy_html .= theme('cdm_taxon_page_synonymy', array('taxon' => $taxon, 'addAcceptedTaxon' => $addAcceptedTaxon));
533

    
534
    $synonymy_html .= '</div>';
535
    $render_array['synonymy'] = markup_to_render_array($synonymy_html, $weight++);
536

    
537
  }
538

    
539
  // --- PAGE PART: SPECIMENS --- //
540
  if ($specimensOrObservationsCount > 0 && ($page_part == 'specimens' || $page_part == 'all')) {
541
    $render_array['specimens'] = array(
542
        '#prefix' => '<div id="specimens" class="page-part">' . ($page_part == 'all' ? '<h2>' . t(cdm_taxonpage_tab_label('Specimens')) . '</h2>' : ''),
543
        'content' => cdm_dataportal_taxon_page_specimens($taxon), // returns render array
544
        '#suffix' => '</div>',
545
    );
546
  }
547

    
548
  // --- PAGE PART: KEYS --- //
549
  if ($identificationKeyCount == 1 && $page_part == 'keys'){
550
    drupal_goto(path_to_key($polytomousKeysPager->records[0]->class, $polytomousKeysPager->records[0]->uuid));
551
  }
552
  else if ($identificationKeyCount > 0 && ($page_part == 'keys' || $page_part == 'all')) {
553
    $keys_html = '<div id="keys" class="page-part">';
554
    if ($page_part == 'all') {
555
      $keys_html .= '<h2>' . t(cdm_taxonpage_tab_label('Keys')) . '</h2>';
556
    }
557
    $keys_html .= theme('cdm_block_IdentificationKeys', array('taxonUuid' => $taxon->uuid));
558
    $keys_html .= '</div>';
559
    $render_array['keys'] = markup_to_render_array($keys_html, $weight++);
560
  }
561

    
562
  // --- PAGE PART: EXPERTS --- //
563

    
564
  if (array_search('experts', taxon_page_tabs_hidden()) === FALSE && ($page_part == 'experts' || $page_part == 'all')) {
565
    $render_array['experts'] = array(
566
        '#prefix' => '<div id="experts" class="page-part">' . ($page_part == 'all' ? '<h2>' . t(cdm_taxonpage_tab_label('Experts')) . '</h2>' : ''),
567
        'content' => compose_cdm_taxon_page_experts($taxon), // returns render array
568
        '#suffix' => '</div>',
569
    );
570
  }
571

    
572
  // ------------------ END OF PARTS -------------- //
573

    
574
  // adjust weights of page and toc elements according to the settings
575
  $taxontabs_weights = get_array_variable_merged(CDM_TAXONPAGE_TAB_WEIGHT, CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
576
  foreach($taxontabs_weights as $tab_key => $weight){
577
    if(isset($render_array[$tab_key])){
578
      $render_array[$tab_key]['#weight'] = $weight;
579
    }
580
  }
581

    
582

    
583
  // set up the TOC for the pages which contain all pageparts
584
  if($page_part == 'all') {
585

    
586
    asort($taxontabs_weights);
587
    foreach(array_keys($taxontabs_weights) as $tab_key){
588
      if(isset($render_array[$tab_key])){
589
        if($tab_key != 'general'){
590
          // add entry for page part
591
          $toc_elements[] = array(
592
              'data' => l(t(cdm_taxonpage_tab_label(ucfirst($tab_key))), $_GET['q'], array('fragment' => $tab_key, 'query' => $http_request_params)),
593
              'class' => array('page-part-toc-item-' . $tab_key)
594
          );
595
        } else {
596
          // add content of profile part instead
597
          if(isset($render_array['general'])) {
598
            // in case all tabs are shown at once the feature tocs
599
            // should be integrated into the tabs toc as sub list
600
            // and the profile image should be on top of the page
601
            if(isset($render_array['general']['taxon_description_feature_toc'])){;
602
            foreach ($render_array['general']['taxon_description_feature_toc']['#items'] as $profile_toc_item){
603
              $toc_elements[] = $profile_toc_item;
604
            }
605
            unset($render_array['general']['taxon_description_feature_toc']);
606
            }
607
          }
608
        }
609
      }
610
    }
611

    
612
    // move profile image in page structure
613
    if(isset($render_array['general']['taxon_profile_image'])){
614
      $render_array['profile_image'] = $render_array['general']['taxon_profile_image'];
615
      $render_array['profile_image']['#weight'] = -100;
616
      unset($render_array['general']['taxon_profile_image']);
617
    }
618

    
619
    // finally add the table of contents to the render array
620
    $render_array['toc'] = array(
621
        '#theme' => 'item_list',
622
        '#items' => $toc_elements,
623
        '#title' => t('Content'),
624
        '#weight' => -101,
625
        '#suffix' => '</div>',
626
        '#prefix'=> '<div id="page-toc">'
627
    );
628
  }
629

    
630

    
631
  return $render_array;
632
}
633

    
634
/**
635
 * TODO should this function really be a compose function?
636
 *     For a compose function must there always be a theme function with the same name? (ak 8.8.2013)
637
 *
638
 * composes and returns an render array containing the components of the taxon profile tab:
639
 *  - 'taxon_profile_image'
640
 *  - 'taxon_description_feature_toc'
641
 *  - 'taxon_description_features'
642
 *
643
 *
644
 * @param taxon
645
 * @param mergedTrees
646
 * @param media
647
 *
648
 * @return array
649
 *   A Drupal render array with the following elements:
650
 *     - 'taxon_profile_image'
651
 *     - 'taxon_description_feature_toc'
652
 *     - 'taxon_description_features'
653
 *
654
 * @ingroup compose
655
 */
656
function compose_cdm_taxon_page_profile($taxon, $merged_tree, $media) {
657

    
658
  $render_array = array();
659

    
660
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
661

    
662
  $hide_taxon_profile_image = FALSE;
663
  if (variable_get('image_hide_rank', '0') != '0' && isset($taxon->name->rank->uuid)) {
664
    $rankCompare = rank_compare($taxon->name->rank->uuid, variable_get('image_hide_rank', '-99'));
665
    $hide_taxon_profile_image = ($rankCompare > -1);
666
  }
667

    
668
  if ($taxon_profile_image_settings['show'] && !$hide_taxon_profile_image) {
669

    
670
    $representationPart = new stdClass();
671
    $attributes = array();
672
    if (isset($media[0]->representations[0]->parts[0])) {
673
      $representationPart = $media[0]->representations[0]->parts[0];
674
      $attributes['alt'] = $representationPart->uri;
675

    
676
      if (!empty($taxon_profile_image_settings['media_uri_query'])) {
677
        $representationPart->uri = $representationPart->uri
678
          . (strpos($representationPart->uri, '?') !== FALSE ? '&' : '?')
679
          . $taxon_profile_image_settings['media_uri_query'];
680
      }
681
    }
682
    else {
683
      if ($taxon_profile_image_settings['custom_placeholder_enabled']) {
684
        // show placeholder image instead
685
        if (!empty($taxon_profile_image_settings['custom_placeholder_image_on']) && !empty($taxon_profile_image_settings['custom_placeholder_image_fid'])) {
686
          // use the user provided image
687
          $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
688
          $url = file_create_url($profile_image_file->uri);
689
          $image_info = image_get_info($profile_image_file->uri);
690
          $representationPart->width = $image_info['width'];
691
          $representationPart->height = $image_info['height'];
692
          $representationPart->uri = $url;
693
        }
694
        else {
695
          // use the hard coded default
696
          $representationPart->width = 184;
697
          $representationPart->height = 144;
698
          $representationPart->uri = base_path() . drupal_get_path('module',
699
              'cdm_dataportal') . '/images/no_picture.png';
700
        }
701
        $attributes['alt'] = "no image available";
702
      }
703
    }
704

    
705
    if (isset($representationPart->uri)) {
706
      $profile_image = theme('cdm_media_gallerie_image', array(
707
        'mediaRepresentationPart' => $representationPart,
708
        'maxExtend' => $taxon_profile_image_settings['maxextend'],
709
        'addPassePartout' => FALSE,
710
        'attributes' => $attributes,
711
      ));
712
      // NOTE: style="width:${maxextend}px' is needed for IE8 !!!
713
      $render_array['taxon_profile_image'] = markup_to_render_array('<div id="taxonProfileImage" style="width:' . $taxon_profile_image_settings['maxextend'] . 'px">' . $profile_image . '</div>',
714
        -101);
715
    }
716
  }
717

    
718

    
719
  // Render the sections for each feature
720
  $render_array['taxon_description_features'] = compose_feature_blocks($merged_tree->root->childNodes, $taxon);
721

    
722
  $bibliography_settings = get_bibliography_settings();
723
  if($bibliography_settings['enabled'] == 1){
724
    $bibliography_block = feature_block(t('Bibliography'));
725
    $bibliography_block->content = FootnoteManager::renderFootnoteList('BIBLIOGRAPHY', '');
726

    
727
    if(!empty($bibliography_block->content)){
728
      $render_array['taxon_description_bibliography'] =  markup_to_render_array(
729
        theme('block',
730
          array(
731
            'elements' => array(
732
              '#block' => $bibliography_block,
733
              '#children' => $bibliography_block->content,
734
            )
735
          )
736
        ),
737
        100 // weight
738
      );
739
      cdm_toc_list_add_item('Bibliography', 'bibliography');
740
    }
741

    
742
  }
743

    
744
  // create the table of content
745
  $toc = array(
746
      '#theme' => 'item_list',
747
    '#items' => cdm_toc_list(),
748
      '#title' => t('Content'),
749
    '#weight' => -100,                  // move to the top
750
      '#suffix' => '</div>',
751
      '#prefix'=> '<div id="page-toc">'
752
  );
753
  $render_array['taxon_description_feature_toc'] = $toc;
754

    
755
  return $render_array;
756
}
757

    
758
/**
759
 * composes and returns an render array for the experts associated with the given taxon
760
 *
761
 * @param taxon
762
 *
763
 * @return array
764
 *   A Drupal render array for a table with the experts
765
 *
766
 * @ingroup compose
767
 */
768
function compose_cdm_taxon_page_experts($taxon){
769

    
770
  $render_array = array();
771
  if(!isset($taxon->uuid)){
772
    return $render_array;
773
  }
774

    
775
  $current_classification_uuid = get_current_classification_uuid();
776
  // TODO use cdm_ws_fetchall below but this failes! needs fix!
777
  $taxon_node_agent_relations = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODEAGENTRELATIONS,
778
    array(
779
      $taxon->uuid,
780
      $current_classification_uuid
781
    )
782
  );
783

    
784
  $header = array(
785
    array('data' => t('Expert')),
786
    array('data' => t('Role'))
787
  );
788
  $rows = array();
789

    
790

    
791
  foreach($taxon_node_agent_relations->records as $taxon_node_agent_relation){
792

    
793

    
794
    $expert_role_id = $taxon_node_agent_relation->agent->uuid . '-' . $taxon_node_agent_relation->type->uuid;
795
    $expert_details_container_id = 'expert_details_' . $expert_role_id;
796

    
797
    $agent_label_markup = cdm_dynabox(
798
      'expert_' . $expert_role_id,
799
      $taxon_node_agent_relation->agent->titleCache,
800
      // specifying both ends of the relationship will return only one record in the pager
801
      cdm_compose_url(CDM_WS_PORTAL_AGENT,
802
         array($taxon_node_agent_relation->agent->uuid, 'taxonNodeAgentRelations'),
803
        'taxon_uuid=' . $taxon->uuid . '&relType_uuid=' . $taxon_node_agent_relation->type->uuid),
804
      'cdm_taxon_expert',
805
      'Click for details',
806
      array('div', 'div'),
807
      array(), // attributes
808
      '#' . $expert_details_container_id // $content_element_selector
809
    );
810

    
811
    // Expert and Role
812
    $rows[] = array(
813
      'data' => array(
814
        array(
815
          'data' => $agent_label_markup,
816
          'class' => array(html_class_attribute_ref($taxon_node_agent_relation->agent))
817
        ),
818
        array(
819
          'data' => $taxon_node_agent_relation->type->representation_L10n,
820
          'class' => array(html_class_attribute_ref($taxon_node_agent_relation->type))
821
        )
822
      )
823
    );
824
    // Agent details
825
    $rows[] = array(
826
      'data' => array(
827
        array(
828
          'data' => '<!-- expert_details_container -->',
829
          'id' => $expert_details_container_id,
830
          'colspan' => 2
831
        )
832
      )
833
    );
834

    
835
  }
836

    
837

    
838
  $render_array['experts_table'] = array(
839
    '#theme' => 'table',
840
    '#header' => $header,
841
    '#rows' => $rows,
842
  );
843

    
844

    
845
  return $render_array;
846
}
847

    
848

    
849
/**
850
 * Manages the tabs to be hidden in the taxon page.
851
 *
852
 * The tabs are identified by their last menu link path element:
853
 *  - description
854
 *  - synonymy
855
 *  - images
856
 *  - specimens
857
 *  - key
858
 *
859
 * Internally the tabs are stored in a static variable which is
860
 * managed by drupal_static().
861
 *
862
 * @param string $add_tab
863
 *   Optional parameter. The given string will be added to the array of tabs
864
 *
865
 * @return
866
 *   The array of tabs
867
 */
868
function taxon_page_tabs_hidden($add_tab = NULL) {
869
  $tabs = &drupal_static(__FUNCTION__);
870

    
871
  if(!isset($tabs)){
872
    $tabs = array();
873
  }
874

    
875
  if (isset($add_tab) && !array_key_exists($add_tab, $tabs)) {
876
    $tabs[] = $add_tab;
877
  }
878

    
879
  return $tabs;
880
}
881

    
882
/**
883
 * Implements the hook_preprocess_HOOK() for theme_menu_local_tasks()
884
 *
885
 *  - Removes the tabs to be hidden, @see taxon_page_tabs_hidden()
886
 *  - Renames tabs according to the settings // TODO (this will replace the theme_cdm_taxonpage_tab() function !!!)
887
 *
888
 * @param array $variables
889
 *   The variables array
890
 */
891
function cdm_dataportal_preprocess_menu_local_tasks(&$variables) {
892

    
893
  $hidden_tabs = taxon_page_tabs_hidden();
894

    
895
  if (is_array($variables['primary'])) {
896
    foreach ($variables['primary'] as $key => &$element) {
897

    
898
      // 1. Remove the tabs to be hidden
899
      foreach ($hidden_tabs as $tab) {
900
        if ($element['#link']['path'] == 'cdm_dataportal/taxon/%/' . $tab) {
901
          // remove the tab
902
          unset($variables['primary'][$key]);
903
        }
904
      }
905
    }
906
  }
907
}
908

    
909

    
910

    
911
/**
912
 * Implements the hook_preprocess_HOOK() for theme_menu_local_task()
913
 *
914
 *
915
 * @param array $variables
916
 *   An associative array containing:
917
 *     - element: A render element containing:
918
 *          #link: A menu link array with 'title', 'href', and 'localized_options' keys.
919
 *          #active: A boolean indicating whether the local task is active.
920
 *
921
 */
922
function cdm_dataportal_preprocess_menu_local_task(&$variables) {
923

    
924
  $link = $variables['element']['#link'];
925
  if (preg_match('/cdm_dataportal\/.*\/refresh$/', $link['href'])) {
926
    $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']) . '"/>';
927
    $link['localized_options']['html'] = TRUE;
928

    
929
    $variables['element']['#link'] = $link;
930
  }
931
}
932

    
933
/* =================== block composition ===================== */
934

    
935
/**
936
 * Composes and returns an render array for the classification breadcrumbs of the given taxon.
937
 *
938
 * @param taxon
939
 *
940
 * @return array
941
 *   A Drupal render array for a table with the experts
942
 *
943
 * @ingroup compose
944
 */
945
function compose_classification_breadcrumbs($taxon_uuid) {
946

    
947
  _add_js_taxonomic_children('#classification-breadcrumbs .taxonomic-children-button');
948

    
949
  $render_array = array();
950

    
951
  $render_array['#theme'] = 'item_list';
952
  $render_array['#type'] = 'ul';
953
  $render_array['#attributes'] = array(
954
    'id' => 'classification-breadcrumbs',
955
    'class' => 'breadcrumbs inline',
956
  );
957

    
958
  $items = array();
959

    
960
  $parent_taxon_nodes = null;
961
  if($taxon_uuid){
962
    $parent_taxon_nodes = cdm_ws_taxonomy_pathFromRoot($taxon_uuid);
963
  }
964

    
965
  $classifications = cdm_ws_fetch_all(CDM_WS_PORTAL_TAXONOMY);
966
  // find current classification in list
967
  $classification = null;
968
  $current_classification_uuid = get_current_classification_uuid();
969
  foreach ($classifications as $classification){
970
    if($classification->uuid == $current_classification_uuid){
971
      break;
972
    }
973
  }
974

    
975
  $node_name = '';
976
  if(count($classifications) > 1 ){
977
    // need to add the current classification as first label
978

    
979
    $label = $classification->titleCache;
980
    if(strlen($label) > 20){
981
      $label = substr($label, 0, strpos($label, ' ', 15)) . '...';
982
    }
983
    $node_name = font_awesome_icon_markup('fa-th-list')  . ' ' . l($label, '#', array(
984
      'attributes' => array(
985
        'class' => 'taxonomic-children-button classification-chooser',
986
        'data-destination-uri' => drupal_get_destination(),
987
        'data-cdm-align-with' => array('prev')
988
      ),
989
      'html' => true
990
    ));
991
  }
992

    
993
  $rank_limit_uuid = variable_get(TAXONTREE_RANKLIMIT, TAXONTREE_RANKLIMIT_DEFAULT);
994

    
995
  $rank_separator = '<span> '
996
    . font_awesome_icon_markup('fa-chevron-right')
997
    . ' </span>';
998
  $more_children_icon = font_awesome_icon_markup('fa-sitemap fa-rotate-270');
999
  $more_children_label = '...';
1000

    
1001
  $items[] = $node_name;
1002

    
1003
  $more_children_for = null;
1004
  if($parent_taxon_nodes){
1005
    foreach ($parent_taxon_nodes as $node) {
1006

    
1007
      $is_first_item = count($items) == 0;
1008
      $is_last_item = count($items) == count($parent_taxon_nodes);
1009
      $node_name = cdm_dataportal_shortname_of($node);
1010
      $path = path_to_taxon($node->taxonUuid);
1011

    
1012
      if($node->taxonomicChildrenCount > 0) {
1013
        $more_children_for = $node->taxonUuid;
1014
      } else {
1015
        $more_children_for = null;
1016
      }
1017

    
1018
      // 'fa-sitemap'
1019

    
1020
      $items[] =
1021
        ($is_first_item ? '' : ' ')
1022
        . $rank_separator
1023
        . l(
1024
          '<span class="' . html_class_attribute_ref($node) . '">' . $node_name . '</span>',
1025
          $path,
1026
          array(
1027
            'attributes' => array(
1028
              'class' => array('taxonomic-children-button'),
1029
              'data-cdm-taxon-uuid' => array($node->taxonUuid),
1030
              'data-cdm-classification-mode' => array('siblings'),
1031
              'data-cdm-align-with' => array('prev')
1032
            ),
1033
            'html' => true
1034
          )
1035
        );
1036
      }
1037
    }
1038

    
1039
  // add more button to the end
1040
  if(!$parent_taxon_nodes) {
1041
    // not taxon focused yet, adding button to make  the root nodes available
1042
    $items[] = '<span>'
1043
      . $more_children_icon . '&nbsp;' .
1044
      '<span class="taxonomic-children-button" data-classification-uuid="' . $current_classification_uuid
1045
      . '" data-rank-limit-uuid="' . $rank_limit_uuid . '" data-cdm-align-with="prev"> ' . $more_children_label . '<span>'
1046
      . '</span>';
1047
  } else if($more_children_for){
1048
    // last parent item has child taxon nodes
1049
    $items[] = ' <span>'
1050
      . $more_children_icon . '&nbsp;' .
1051
      '<span class="taxonomic-children-button" data-cdm-taxon-uuid="' .$more_children_for
1052
      . '" data-cdm-classification-mode="children" data-cdm-align-with="prev"> ' . $more_children_label . '</span>'
1053
      . '</span>';
1054

    
1055
  }
1056

    
1057
  $render_array['#items'] = $items;
1058

    
1059
  return $render_array;
1060
}
1061

    
1062

    
1063
/**
1064
 * @param $specimen_uuid
1065
 * @return array
1066
 *    The drupal render array for the page
1067
 *
1068
 * @ingroup compose
1069
 */
1070
function compose_cdm_specimen_page($specimen_uuid)
1071
{
1072
  drupal_set_title("Specimen Details");
1073
  $specimen = cdm_ws_get(CDM_WS_PORTAL_OCCURRENCE, array($specimen_uuid, 'specimenDerivates'));
1074

    
1075
  $render_array = array();
1076
  RenderHints::pushToRenderStack('specimen_page');
1077

    
1078
  $detail_html = render_cdm_specimen_page($specimen, true);
1079
  $render_array['specimen_html'] = array(
1080
    '#markup' => $detail_html
1081
  );
1082

    
1083
  RenderHints::popFromRenderStack();
1084
  return $render_array;
1085
}
1086

    
1087
/**
1088
 * @param $named_area_uuid
1089
 * @return array
1090
 *    The drupal render array for the page
1091
 *
1092
 * @ingroup compose
1093
 */
1094
function compose_cdm_named_area_page($named_area_uuid)
1095
{
1096

    
1097
  $named_area = cdm_ws_get(CDM_WS_PORTAL_TERM, array($named_area_uuid));
1098

    
1099
  $render_array = array();
1100
  RenderHints::pushToRenderStack('named_area_page');
1101

    
1102
  $groups = array();
1103
  @_description_list_group_add($groups, t('Name') . ':', $named_area->representation_L10n);
1104
  @_description_list_group_add($groups, t('IdInVocabulary') . ':', $named_area->idInVocabulary);
1105
  if(isset($named_area->level)) {
1106
    @_description_list_group_add($groups, t('Level') . ':', $named_area->level->representation_L10n);
1107
  }
1108

    
1109
  $name_area_details_elements = array(
1110
   // '#title' => $title,
1111
    '#theme' => 'description_list',
1112
    '#groups' => $groups,
1113
    '#attributes' => array('class' => html_class_attribute_ref($named_area)),
1114
  );
1115

    
1116
  $render_array[] = $name_area_details_elements;
1117

    
1118
  RenderHints::popFromRenderStack();
1119
  return $render_array;
1120
}
1121

    
1122
/**
1123
 * Provides the the label string for taxon page tabs.
1124
 *
1125
 * The $tabname as passed to the method will be returned if no override
1126
 * label is configured in the settings.
1127
 */
1128
function cdm_taxonpage_tab_label($tabname) {
1129
  static $taxon_tabs_labels = null;
1130
  if($taxon_tabs_labels == null){
1131
    $taxon_tabs_labels = get_array_variable_merged(CDM_TAXONPAGE_TAB_LABELS, CDM_TAXONPAGE_TAB_LABELS_DEFAULT);
1132
  }
1133
  $tabname_key = strtolower($tabname);
1134
  if(isset($taxon_tabs_labels[$tabname_key]) && $taxon_tabs_labels[$tabname_key]){
1135
    return $taxon_tabs_labels[$tabname_key];
1136
  }
1137
  return $tabname;
1138
}
Add picture from clipboard (Maximum size: 40 MB)