Project

General

Profile

Download (23.2 KB) Statistics
| Branch: | Tag: | Revision:
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 paramaters
90
  if (count($specimensOrObservations) > 0) {
91
    $occurrence_query = cdm_ws_get(CDM_WS_GEOSERVICE_OCCURRENCEMAP, $taxon->uuid,  $by_associatedtaxon_query);
92

    
93
    if( isset($occurrence_query->String) ) {
94
      $occurrence_query = $occurrence_query->String;
95
      $legend_format_query = null;
96
      $distribution_query = NULL;
97

    
98
      $render_array['map'] = compose_map($occurrence_query, $distribution_query, $legend_format_query);
99
    }
100
  }
101

    
102
  // --- generate the specimen list as table
103
  $specimen_table = array(
104
      '#theme' => 'table',
105
      '#weight' => 2,
106
      // prefix attributes and rows with '#' to let it pass to the theme function,
107
      // otherwise it is handled as child render array
108
      '#attributes' => array('class' => 'specimens'),
109
      '#rows' => array(),
110
  );
111

    
112
  if ($specimensOrObservations) {
113

    
114
    foreach ($specimensOrObservations as $specimenOrObservation) {
115

    
116
      $mediaList = array();
117
      if (is_array($specimenOrObservation->_fieldObjectMedia)) {
118
        $mediaList = array_merge($mediaList, $specimenOrObservation->_fieldObjectMedia);
119
      }
120
      if (is_array($specimenOrObservation->_derivedUnitMedia)) {
121
        $mediaList = array_merge($mediaList, $specimenOrObservation->_derivedUnitMedia);
122
      }
123

    
124
      // typelabel will contain the typeStatus
125
      $type_label = '';
126
      $typeDesignationPager = cdm_ws_get(CDM_WS_OCCURRENCE . '/$0/specimenTypeDesignations', $specimenOrObservation->uuid);
127
      if (isset($typeDesignationPager)) {
128
        $type_status = array();
129
        foreach ($typeDesignationPager->records as $typeDesignation) {
130
          if (isset($typeDesignation->typeStatus->representation_L10n)){
131
            $type_status[] = $typeDesignation->typeStatus->representation_L10n;
132
          }
133
        }
134
        $type_label = implode(', ', $type_status);
135
        if($type_label){
136
          $type_label .= ': ' ;
137
        }
138
      }
139

    
140
      // --- Specimen entry as dynamic label:
141
      //     -> Dynabox for the specimenOrObservation
142
      $gallery_name = $specimenOrObservation->uuid;
143

    
144
      $derived_unit_ws_request = cdm_compose_url(CDM_WS_OCCURRENCE, array( $specimenOrObservation->uuid));
145
      $label_html = cdm_dynabox(
146
          $specimenOrObservation->uuid,
147
          $type_label . $specimenOrObservation->titleCache,
148
          $derived_unit_ws_request,
149
          'cdm_specimenOrObservation', // the theme or compose function to use
150
          'Click for details',
151
          array('div','div'),
152
          array(),
153
          'function(){ jQuery(\'#media_gallery_' . $gallery_name . '\').hide(); }', // open_callback
154
          'function(){ jQuery(\'#media_gallery_' . $gallery_name . '\').show(); }' // close_callback
155
      );
156

    
157
      // --- Render associated media.
158
      $gallery_html = '';
159
      if (count($mediaList) > 0) {
160
        $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
161
        $captionElements = array(
162
            '#uri' => t('open media'),
163
        );
164

    
165
        $gallery_html = theme('cdm_media_gallerie', array(
166
            'mediaList' => $mediaList,
167
            'galleryName' => $gallery_name,
168
            'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
169
            'cols' => $gallery_settings['cdm_dataportal_media_cols'],
170
            'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
171
            'captionElements' => $captionElements,
172
            'mediaLinkType' => 'LIGHTBOX',
173
            'alternativeMediaUri' => NULL,
174
            'galleryLinkUri' => NULL,
175
        ));
176
      }
177

    
178
      $specimen_table['#rows'][] = array(
179
          // An array of table rows. Every row is an array of cells, or an associative array
180
          'data' => array(
181
              // Each cell can be either a string or an associative array
182
              $label_html . $gallery_html
183
          ),
184
          'class' =>  array(
185
              'descriptionElement',
186
              'descriptionElement_IndividualsAssociation'
187
          ),
188
      );
189
    }
190
  }
191

    
192
  $render_array['specimen_list'] = $specimen_table;
193
  $render_array['pager'] = markup_to_render_array(
194
      theme('cdm_pager', array(
195
          'pager' => $pager,
196
          'path' => $_REQUEST['q'],
197
          'parameters' => $_REQUEST,
198
      )),
199
      10 // weight
200
  );
201

    
202
  RenderHints::popFromRenderStack();
203
  return $render_array;
204
}
205

    
206

    
207
/**
208
 * Composes a taxon page which can consist of multiple parts like
209
 * 'General', 'Synonymy', 'Images', 'Keys'. These parts can be displayed
210
 * as tabs or as sections of a single page.
211
 *
212
 * It is headed by the name of the accepted taxon without author and reference.
213
 *
214
 * @param $taxon
215
 *   The CDM Taxon Instance to compose the page for.
216
 * @param $page_part
217
 *   Name of the part to display, valid values are:
218
 *    - 'description' -  for the general part
219
 *    - 'images'
220
 *    - 'synonymy'
221
 *    - 'keys'
222
 *    - 'all'
223
 *
224
 * @return array
225
 *   A drupal render array
226
 *
227
 * @ingroup compose
228
 */
229
function compose_cdm_taxon_page($taxon, $page_part = 'description') {
230

    
231
  global $theme;
232

    
233
  // we better cache here since drupal_get_query_parameters has no internal static cache variable
234
  $http_request_params = drupal_get_query_parameters();
235

    
236
  // add all mandatory js sources
237
  _add_js_footnotes();
238

    
239

    
240
  $render_array = array();
241
  $weight = 0; // the weight for the render array elements
242

    
243
  $tabsToDisplay = variable_get('cdm_taxonpage_tabs_visibility', unserialize(TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT));
244

    
245
  $page_part = variable_get('cdm_dataportal_taxonpage_tabs', 1) ? $page_part : 'all';
246

    
247
  $media = _load_media_for_taxon($taxon);
248

    
249

    
250
  if (!isset($media[0]) || ($tabsToDisplay["Images"] == '0')) {
251
    taxon_page_tabs_hidden('images');
252
  }
253

    
254
  // --- GET specimensOrObservations --- //
255
  $specimensOrObservations = cdm_ws_get(CDM_WS_TAXON, array( $taxon->uuid, 'specimensOrObservations'));
256

    
257
  $specimensOrObservationsCount = is_array($specimensOrObservations) ? count($specimensOrObservations) : 0;
258
  if ($specimensOrObservationsCount == 0 || ($tabsToDisplay["Specimens"] == '0')) {
259
    taxon_page_tabs_hidden('specimens');
260
  }
261

    
262
  // --- GET polytomousKeys --- //
263
  $polytomousKeysPager = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, NULL, "findByTaxonomicScope=$taxon->uuid");
264
  $identificationKeyCount = 0;
265
  if ($polytomousKeysPager) {
266
    $identificationKeyCount += $polytomousKeysPager->count;
267
  }
268
  if ($identificationKeyCount == 0 || ($tabsToDisplay["Keys"] == '0')) {
269
    taxon_page_tabs_hidden('keys');
270
  }
271

    
272
  if ($tabsToDisplay["Synonymy"] == '0') {
273
    taxon_page_tabs_hidden('synonymy');
274
  }
275

    
276
  // -------------------------------------------- //
277

    
278
  $render_array['back_to_search'] = markup_to_render_array(theme('cdm_back_to_search_result_button'), -103);
279

    
280
  if (variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR) && isset($_REQUEST['acceptedFor'])) {
281
    $render_array['accepted_for'] = markup_to_render_array(theme('cdm_acceptedFor', array('acceptedFor' => $_REQUEST['acceptedFor'])), $weight++);
282
  }
283

    
284
  // --- PAGE PART: DESCRIPTION --- //
285
  if ($page_part == 'description' || $page_part == 'all') {
286

    
287
    // 1. fetch descriptions_by_featuretree but exclude the distribution feature
288
    $merged_tree = cdm_ws_descriptions_by_featuretree(get_profile_featureTree(), $taxon->uuid, array(UUID_DISTRIBUTION));
289

    
290

    
291
    // 2. find the distribution feature node
292
    $distribution_node =& cdm_feature_tree_find_node($merged_tree->root->childNodes, UUID_DISTRIBUTION);
293

    
294
    if ( $distribution_node) {
295
      // 3. get the distributionInfoDTO
296
      $query_parameters = cdm_distribution_filter_query();
297
      $query_parameters['part'] = array('mapUriParams');
298
      if(variable_get('distribution_sort', 'NO_SORT') != 'NO_SORT'){
299
        $query_parameters['part'][] = 'tree';
300
      } else {
301
        $query_parameters['part'][] = 'elements';
302
      }
303
      $query_parameters['omitLevels'] = array(UUID_NAMEDAREALEVEL_TDWGLEVEL_2);
304
      $customStatusColorsJson = variable_get(DISTRIBUTION_STATUS_COLORS, null);
305
      if($customStatusColorsJson){
306
        $query_parameters['statusColors'] = $customStatusColorsJson;
307
      }
308

    
309
      $distribution_info_dto = cdm_ws_get(CDM_WS_PORTAL_DESCRIPTION_DISTRIBUTION_INFO_FOR, $taxon->uuid, queryString($query_parameters));
310
      // 4. get distribution TextData is there are any
311
      $distribution_text_data = cdm_ws_fetch_all(CDM_WS_DESCRIPTIONELEMENT_BY_TAXON,
312
        array(
313
            'taxon' => $taxon->uuid,
314
            'type'=>'TextData',
315
            'features' => UUID_DISTRIBUTION
316
          )
317
      );
318

    
319
      // 5. put all disitribution data into the distribution feature node
320
      if($distribution_text_data //if text data exists
321
      || ($distribution_info_dto && isset($distribution_info_dto->tree) && $distribution_info_dto->tree->rootElement->numberOfChildren>0) // OR if tree element has distribution elements
322
      || ($distribution_info_dto && !empty($distribution_info_dto->elements))) {  // OR if DTO has distribution elements
323
        $distribution_node->descriptionElements = array('#type' => 'DTO');
324
        if($distribution_text_data){
325
          $distribution_node->descriptionElements['TextData'] = $distribution_text_data;
326
        }
327
        if($distribution_info_dto){
328
          $distribution_node->descriptionElements['DistributionInfoDTO'] = $distribution_info_dto;
329
        }
330
      }
331
    }
332

    
333
    $render_array['general'] = compose_cdm_taxon_page_profile($taxon, $merged_tree, $media);
334
    $render_array['general']['#weight'] = $weight++;
335
    $render_array['general']['#prefix'] = '<div id="general" class="page-part">';
336
    $render_array['general']['#suffix'] = '</div>';
337
  }
338

    
339
  // --- PAGE PART: IMAGES --- //
340
  if (array_search('images', taxon_page_tabs_hidden()) === FALSE && ($page_part == 'images' || $page_part == 'all')) {
341
    $images_html = '<div id="images" class="page-part">';
342
    if ($page_part == 'all') {
343
      $images_html .= '<h2>' . t('Images') . '</h2>';
344
    }
345
    // Get the image gallery as configured by the admin.
346
    $taxon_image_gallery = call_user_func_array('taxon_image_gallery_' . variable_get('image_gallery_viewer', 'default'), array(
347
        $taxon,
348
        $media,
349
    ));
350
    $images_html .= $taxon_image_gallery;
351
    $images_html .= '</div>';
352
    $render_array['images'] = markup_to_render_array($images_html, $weight++);
353
  }
354

    
355
  // --- PAGE PART: SYNONYMY --- //
356
  if (($page_part == 'synonymy' || $page_part == 'all')) {
357
    $synonymy_html = '<div id="synonymy" class="page-part">';
358
    if ($page_part == 'all') {
359
      $synonymy_html .= '<h2>' . t('Synonymy') . '</h2>';
360
    }
361
    $addAcceptedTaxon = variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE);
362
    $synonymy_html .= theme('cdm_taxon_page_synonymy', array('taxon' => $taxon, 'addAcceptedTaxon' => $addAcceptedTaxon));
363

    
364
    $synonymy_html .= '</div>';
365
    $render_array['synonymy'] = markup_to_render_array($synonymy_html, $weight++);
366

    
367
  }
368

    
369
  // --- PAGE PART: SPECIMENS --- //
370
  if ($specimensOrObservationsCount > 0 && ($page_part == 'specimens' || $page_part == 'all')) {
371
    $render_array['specimens'] = array(
372
        '#prefix' => '<div id="specimens" class="page-part">' . ($page_part == 'all' ? '<h2>' . t('Specimens') . '</h2>' : ''),
373
        'content' => cdm_dataportal_taxon_page_specimens($taxon), // returns render array
374
        '#suffix' => '</div>',
375
    );
376
  }
377

    
378
  // --- PAGE PART: KEYS --- //
379
  if ($identificationKeyCount == 1 && $page_part == 'keys'){
380
    drupal_goto(path_to_key($polytomousKeysPager->records[0]->class, $polytomousKeysPager->records[0]->uuid));
381
  }
382
  else if ($identificationKeyCount > 0 && ($page_part == 'keys' || $page_part == 'all')) {
383
    $keys_html = '<div id="keys" class="page-part">';
384
    if ($page_part == 'all') {
385
      $keys_html .= '<h2>' . t('Keys') . '</h2>';
386
    }
387
    $keys_html .= theme('cdm_block_IdentificationKeys', array('taxonUuid' => $taxon->uuid));
388
    $keys_html .= '</div>';
389
    $render_array['keys'] = markup_to_render_array($keys_html, $weight++);
390
  }
391

    
392

    
393
  // adjust weights of page and toc elements according to the settings
394
  $taxontabs_weights = get_array_variable_merged('cdm_taxonpage_tabs_weight', CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
395
  foreach($taxontabs_weights as $tab_key => $weight){
396
    if(isset($render_array[$tab_key])){
397
      $render_array[$tab_key]['#weight'] = $weight;
398
    }
399
  }
400

    
401

    
402
  // set up the TOC for the pages which contain all pageparts
403
  if($page_part == 'all') {
404

    
405
    asort($taxontabs_weights);
406
    foreach(array_keys($taxontabs_weights) as $tab_key){
407
      if(isset($render_array[$tab_key])){
408
        if($tab_key != 'general'){
409
          // add entry for page part
410
          $toc_elements[] = array(
411
              'data' => l(t(ucfirst($tab_key)), $_GET['q'], array('fragment' => $tab_key, 'query' => $http_request_params)),
412
              'class' => array('page-part-toc-item-' . $tab_key)
413
          );
414
        } else {
415
          // add content of profile part instead
416
          if(isset($render_array['general'])) {
417
            // in case all tabs are shown at once the feature tocs
418
            // should be integrated into the tabs toc as sub list
419
            // and the profile image should be on top of the page
420
            if(isset($render_array['general']['taxon_description_feature_toc'])){;
421
            foreach ($render_array['general']['taxon_description_feature_toc']['#items'] as $profile_toc_item){
422
              $toc_elements[] = $profile_toc_item;
423
            }
424
            unset($render_array['general']['taxon_description_feature_toc']);
425
            }
426
          }
427
        }
428
      }
429
    }
430

    
431
    // move profile image in page structure
432
    if(isset($render_array['general']['taxon_profile_image'])){
433
      $render_array['profile_image'] = $render_array['general']['taxon_profile_image'];
434
      $render_array['profile_image']['#weight'] = -100;
435
      unset($render_array['general']['taxon_profile_image']);
436
    }
437

    
438
    // finally add the table of contents to the render array
439
    $render_array['toc'] = array(
440
        '#theme' => 'item_list',
441
        '#items' => $toc_elements,
442
        '#title' => t('Content'),
443
        '#weight' => -101,
444
        '#suffix' => '</div>',
445
        '#prefix'=> '<div id="page-toc">'
446
    );
447
  }
448

    
449

    
450
  return $render_array;
451
}
452

    
453

    
454
/**
455
 * TODO should this function really be a compose funtion?
456
 *     For a compose function must there alway be a theme function with the same name? (ak 8.8.2013)
457
 *
458
 * composes and returns an render array containing the components of the taxon profile tab:
459
 *  - 'taxon_profile_image'
460
 *  - 'taxon_description_feature_toc'
461
 *  - 'taxon_description_features'
462
 *
463
 *
464
 * @param array $variables
465
 *   An associative array containing:
466
 *   - taxon
467
 *   - mergedTrees
468
 *   - media
469
 *
470
 * @return array
471
 *   A Drupal reder array with the following elements:
472
 *     - 'taxon_profile_image'
473
 *     - 'taxon_description_feature_toc'
474
 *     - 'taxon_description_features'
475
 *
476
 * @ingroup compose
477
 */
478
function compose_cdm_taxon_page_profile($taxon, $merged_tree, $media) {
479

    
480
  $render_array = array();
481

    
482
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
483

    
484
  $hide_taxon_profile_image = FALSE;
485
  if (variable_get('image_hide_rank', '0') != '0' && isset($taxon->name->rank->uuid)) {
486
    $rankCompare = rank_compare($taxon->name->rank->uuid, variable_get('image_hide_rank', '-99'));
487
    $hide_taxon_profile_image = ($rankCompare > -1);
488
  }
489

    
490
  if ($taxon_profile_image_settings['show'] && !$hide_taxon_profile_image) {
491

    
492
    $representationPart = new stdClass();
493
    $attributes = array();
494
    if (isset($media[0]->representations[0]->parts[0])) {
495
      $representationPart = $media[0]->representations[0]->parts[0];
496
      $attributes['alt'] = $representationPart->uri;
497

    
498
      if(!empty($taxon_profile_image_settings['media_uri_query'])){
499
        $representationPart->uri = $representationPart->uri
500
        . (strpos($representationPart->uri, '?') !== FALSE ? '&' : '?')
501
        . $taxon_profile_image_settings['media_uri_query'];
502
      }
503
    }
504
    else {
505
      // show placeholder image instead
506
      if(!empty($taxon_profile_image_settings['custom_placeholder_image_on']) && !empty($taxon_profile_image_settings['custom_placeholder_image_fid'])){
507
        // use the user provided image
508
        $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
509
        $url = file_create_url($profile_image_file->uri);
510
        $image_info = image_get_info($profile_image_file->uri);
511
        $representationPart->width = $image_info['width'];
512
        $representationPart->height = $image_info['height'];
513
        $representationPart->uri = $url;
514
      } else {
515
        // use the hard coded default
516
        $representationPart->width = 184;
517
        $representationPart->height = 144;
518
        $representationPart->uri = base_path() .  drupal_get_path('module', 'cdm_dataportal') . '/images/no_picture.png';
519
      }
520
      $attributes['alt'] = "no image available";
521
    }
522

    
523
    $profile_image = theme('cdm_media_gallerie_image', array(
524
        'mediaRepresentationPart' => $representationPart,
525
        'maxExtend' => $taxon_profile_image_settings['maxextend'],
526
        'addPassePartout' => FALSE,
527
        'attributes' => $attributes,
528
    ));
529
    // NOTE: style="width:${maxextend}px' is needed for IE8 !!!
530
    $render_array['taxon_profile_image'] = markup_to_render_array('<div id="taxonProfileImage" style="width:' . $taxon_profile_image_settings['maxextend'] . 'px">' . $profile_image. '</div>', -101);
531
  }
532

    
533
  $toc = array(
534
      '#theme' => 'item_list',
535
      '#items' => cdm_feature_node_toc_items($merged_tree->root->childNodes),
536
      '#title' => t('Content'),
537
      '#weight' => -100,
538
      '#suffix' => '</div>',
539
      '#prefix'=> '<div id="page-toc">'
540
  );
541
  $render_array['taxon_description_feature_toc'] = $toc; //markup_to_render_array($toc_html);
542

    
543
  // Render the sections for each feature
544
  $render_array['taxon_description_features'] = markup_to_render_array(
545
      theme(
546
          'cdm_feature_nodes',
547
          array('mergedFeatureNodes' => $merged_tree->root->childNodes, 'taxon' => $taxon)
548
      )
549
  );
550

    
551
  return $render_array;
552
}
553

    
554

    
555
/**
556
 * Manages the tab to be hidden in the taxon page.
557
 *
558
 * The tabs are identified by their last menu link path element:
559
 *  - description
560
 *  - synonymy
561
 *  - images
562
 *  - specimens
563
 *  - key
564
 *
565
 * Internally the tabs are stored in a static variable which is
566
 * managed by drupal_static().
567
 *
568
 * @param string $add_tab
569
 *   Optinal parameter. The given string will be added to the array of tabs
570
 *
571
 * @return
572
 *   The array of tabs
573
 */
574
function taxon_page_tabs_hidden($add_tab = NULL) {
575
  $tabs = &drupal_static(__FUNCTION__);
576

    
577
  if(!isset($tabs)){
578
    $tabs = array();
579
  }
580

    
581
  if (isset($add_tab) && !array_key_exists($add_tab, $tabs)) {
582
    $tabs[] = $add_tab;
583
  }
584

    
585
  return $tabs;
586
}
587

    
588
/**
589
 * Implements the hook_preprocess_HOOK() for theme_menu_local_tasks()
590
 *
591
 *  - Removes the tabs to be hidden, @see taxon_page_tabs_hidden()
592
 *  - Renames tabs according to the settings // TODO (this will replace the theme_cdm_taxonpage_tab() function !!!)
593
 *
594
 * @param array $variables
595
 *   The variables array
596
 */
597
function cdm_dataportal_preprocess_menu_local_tasks(&$variables) {
598

    
599
  $hidden_tabs = taxon_page_tabs_hidden();
600

    
601
  if (is_array($variables['primary'])) {
602
    foreach ($variables['primary'] as $key => &$element) {
603

    
604
      // 1. Remove the tabs to be hidden
605
      foreach ($hidden_tabs as $tab) {
606
        if ($element['#link']['path'] == 'cdm_dataportal/taxon/%/' . $tab) {
607
          // remove the tab
608
          unset($variables['primary'][$key]);
609
        }
610
      }
611
    }
612
  }
613
}
614

    
615

    
616

    
617
/**
618
 * Implements the hook_preprocess_HOOK() for theme_menu_local_task()
619
 *
620
 *
621
 * @param array $variables
622
 *   An associative array containing:
623
 *     - element: A render element containing:
624
 *          #link: A menu link array with 'title', 'href', and 'localized_options' keys.
625
 *          #active: A boolean indicating whether the local task is active.
626
 *
627
 */
628
function cdm_dataportal_preprocess_menu_local_task(&$variables) {
629

    
630
  $link = $variables['element']['#link'];
631
  if (preg_match('/cdm_dataportal\/.*\/refresh$/', $link['href'])) {
632
    $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']) . '"/>';
633
    $link['localized_options']['html'] = TRUE;
634

    
635
    $variables['element']['#link'] = $link;
636
  }
637
}
(6-6/7)