Project

General

Profile

Download (22.7 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
          'function(){ jQuery(\'#media_gallery_' . $gallery_name . '\').hide(); }', // open_callback
153
          'function(){ jQuery(\'#media_gallery_' . $gallery_name . '\').show(); }' // close_callback
154
      );
155

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

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

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

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

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

    
205

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

    
230
  global $theme;
231

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

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

    
238

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

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

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

    
246
  $media = _load_media_for_taxon($taxon);
247

    
248

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

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

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

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

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

    
275
  // -------------------------------------------- //
276

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

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

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

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

    
289

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

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

    
304
      $distribution_info_dto = cdm_ws_get(CDM_WS_PORTAL_DESCRIPTION_DISTRIBUTION_INFO_FOR, $taxon->uuid, queryString($query_parameters));
305
      // 4. get distribution TextData is there are any
306
      $distribution_text_data = cdm_ws_fetch_all(CDM_WS_DESCRIPTIONELEMENT_BY_TAXON,
307
        array(
308
            'taxon' => $taxon->uuid,
309
            'type'=>'TextData',
310
            'features' => UUID_DISTRIBUTION
311
          )
312
      );
313

    
314
      // 5. put all disitribution data into the distribution feature node
315
      if($distribution_text_data || $distribution_info_dto) {
316
        $distribution_node->descriptionElements = array('#type' => 'DTO');
317
        if($distribution_text_data){
318
          $distribution_node->descriptionElements['TextData'] = $distribution_text_data;
319
        }
320
        if($distribution_info_dto){
321
          $distribution_node->descriptionElements['DistributionInfoDTO'] = $distribution_info_dto;
322
        }
323
      }
324
    }
325

    
326
    $render_array['general'] = compose_cdm_taxon_page_profile($taxon, $merged_tree, $media);
327
    $render_array['general']['#weight'] = $weight++;
328
    $render_array['general']['#prefix'] = '<div id="general" class="page-part">';
329
    $render_array['general']['#suffix'] = '</div>';
330
  }
331

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

    
348
  // --- PAGE PART: SYNONYMY --- //
349
  if (($page_part == 'synonymy' || $page_part == 'all')) {
350
    $synonymy_html = '<div id="synonymy" class="page-part">';
351
    if ($page_part == 'all') {
352
      $synonymy_html .= '<h2>' . t('Synonymy') . '</h2>';
353
    }
354
    $addAcceptedTaxon = variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE);
355
    $synonymy_html .= theme('cdm_taxon_page_synonymy', array('taxon' => $taxon, 'addAcceptedTaxon' => $addAcceptedTaxon));
356

    
357
    $synonymy_html .= '</div>';
358
    $render_array['synonymy'] = markup_to_render_array($synonymy_html, $weight++);
359

    
360
  }
361

    
362
  // --- PAGE PART: SPECIMENS --- //
363
  if ($specimensOrObservationsCount > 0 && ($page_part == 'specimens' || $page_part == 'all')) {
364
    $render_array['specimens'] = array(
365
        '#prefix' => '<div id="specimens" class="page-part">' . ($page_part == 'all' ? '<h2>' . t('Specimens') . '</h2>' : ''),
366
        'content' => cdm_dataportal_taxon_page_specimens($taxon), // returns render array
367
        '#suffix' => '</div>',
368
    );
369
  }
370

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

    
385

    
386
  // adjust weights of page and toc elements according to the settings
387
  $taxontabs_weights = get_array_variable_merged('cdm_taxonpage_tabs_weight', CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
388
  foreach($taxontabs_weights as $tab_key => $weight){
389
    if(isset($render_array[$tab_key])){
390
      $render_array[$tab_key]['#weight'] = $weight;
391
    }
392
  }
393

    
394

    
395
  // set up the TOC for the pages wich contain all pageparts
396
  if($page_part == 'all') {
397

    
398
    asort($taxontabs_weights);
399
    foreach(array_keys($taxontabs_weights) as $tab_key){
400
      if(isset($render_array[$tab_key])){
401
        if($tab_key != 'general'){
402
          $toc_elements[] = l(t(ucfirst($tab_key)), $_GET['q'], array('fragment' => $tab_key, 'query' => $http_request_params));
403
        } else {
404
          // add content of profile part instead
405
          if(isset($render_array['general'])) {
406
            // in case all tabs are shown at once the feature tocs
407
            // should be integrated into the tabs toc as sub list
408
            // and the profile image should be on top of the page
409
            if(isset($render_array['general']['taxon_description_feature_toc'])){;
410
            foreach ($render_array['general']['taxon_description_feature_toc']['#items'] as $profile_toc_item){
411
              $toc_elements[] = $profile_toc_item;
412
            }
413
            unset($render_array['general']['taxon_description_feature_toc']);
414
            }
415
          }
416
        }
417
      }
418
    }
419

    
420
    // move profile image in page structure
421
    if(isset($render_array['general']['taxon_profile_image'])){
422
      $render_array['profile_image'] = $render_array['general']['taxon_profile_image'];
423
      $render_array['profile_image']['#weight'] = -100;
424
      unset($render_array['general']['taxon_profile_image']);
425
    }
426

    
427
    // finally add the table of contents to the render array
428
    $render_array['toc'] = array(
429
        '#theme' => 'item_list',
430
        '#items' => $toc_elements,
431
        '#title' => t('Content'),
432
        '#weight' => -101,
433
        '#suffix' => '</div>',
434
        '#prefix'=> '<div id="featureTOC">' // reusing id featureTOC even if this is semantically not correct
435
    );
436
  }
437

    
438

    
439
  return $render_array;
440
}
441

    
442

    
443
/**
444
 * TODO should this function really be a compose funtion?
445
 *     For a compose function must there alway be a theme function with the same name? (ak 8.8.2013)
446
 *
447
 * composes and returns an render array containing the components of the taxon profile tab:
448
 *  - 'taxon_profile_image'
449
 *  - 'taxon_description_feature_toc'
450
 *  - 'taxon_description_features'
451
 *
452
 *
453
 * @param array $variables
454
 *   An associative array containing:
455
 *   - taxon
456
 *   - mergedTrees
457
 *   - media
458
 *
459
 * @return array
460
 *   A Drupal reder array with the following elements:
461
 *     - 'taxon_profile_image'
462
 *     - 'taxon_description_feature_toc'
463
 *     - 'taxon_description_features'
464
 *
465
 * @ingroup compose
466
 */
467
function compose_cdm_taxon_page_profile($taxon, $merged_tree, $media) {
468

    
469
  $render_array = array();
470

    
471
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
472

    
473
  $hide_taxon_profile_image = FALSE;
474
  if (variable_get('image_hide_rank', '0') != '0' && isset($taxon->name->rank->uuid)) {
475
    $rankCompare = rank_compare($taxon->name->rank->uuid, variable_get('image_hide_rank', '-99'));
476
    $hide_taxon_profile_image = ($rankCompare > -1);
477
  }
478

    
479
  if ($taxon_profile_image_settings['show'] && !$hide_taxon_profile_image) {
480

    
481
    $representationPart = new stdClass();
482
    $attributes = array();
483
    if (isset($media[0]->representations[0]->parts[0])) {
484
      $representationPart = $media[0]->representations[0]->parts[0];
485
      $attributes['alt'] = $representationPart->uri;
486

    
487
      if(!empty($taxon_profile_image_settings['media_uri_query'])){
488
        $representationPart->uri = $representationPart->uri
489
        . (strpos($representationPart->uri, '?') !== FALSE ? '&' : '?')
490
        . $taxon_profile_image_settings['media_uri_query'];
491
      }
492
    }
493
    else {
494
      // show placeholder image instead
495
      if(!empty($taxon_profile_image_settings['custom_placeholder_image_on']) && !empty($taxon_profile_image_settings['custom_placeholder_image_fid'])){
496
        // use the user provided image
497
        $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
498
        $url = file_create_url($profile_image_file->uri);
499
        $image_info = image_get_info($profile_image_file->uri);
500
        $representationPart->width = $image_info['width'];
501
        $representationPart->height = $image_info['height'];
502
        $representationPart->uri = $url;
503
      } else {
504
        // use the hard coded default
505
        $representationPart->width = 184;
506
        $representationPart->height = 144;
507
        $representationPart->uri = base_path() .  drupal_get_path('module', 'cdm_dataportal') . '/images/no_picture.png';
508
      }
509
      $attributes['alt'] = "no image available";
510
    }
511

    
512
    $profile_image = theme('cdm_media_gallerie_image', array(
513
        'mediaRepresentationPart' => $representationPart,
514
        'maxExtend' => $taxon_profile_image_settings['maxextend'],
515
        'addPassePartout' => FALSE,
516
        'attributes' => $attributes,
517
    ));
518
    // NOTE: style="width:${maxextend}px' is needed for IE8 !!!
519
    $render_array['taxon_profile_image'] = markup_to_render_array('<div id="taxonProfileImage" style="width:' . $taxon_profile_image_settings['maxextend'] . 'px">' . $profile_image. '</div>', -101);
520
  }
521

    
522
  $toc = array(
523
      '#theme' => 'item_list',
524
      '#items' => cdm_feature_node_toc_items($merged_tree->root->childNodes),
525
      '#title' => t('Content'),
526
      '#weight' => -100,
527
      '#suffix' => '</div>',
528
      '#prefix'=> '<div id="featureTOC">' // reusing id featureTOC even if this is semantically not correct
529
  );
530
  $render_array['taxon_description_feature_toc'] = $toc; //markup_to_render_array($toc_html);
531

    
532
  // Render the sections for each feature
533
  $render_array['taxon_description_features'] = markup_to_render_array(
534
      theme(
535
          'cdm_feature_nodes',
536
          array('mergedFeatureNodes' => $merged_tree->root->childNodes, 'taxon' => $taxon)
537
      )
538
  );
539

    
540
  return $render_array;
541
}
542

    
543

    
544
/**
545
 * Manages the tab to be hidden in the taxon page.
546
 *
547
 * The tabs are identified by their last menu link path element:
548
 *  - description
549
 *  - synonymy
550
 *  - images
551
 *  - specimens
552
 *  - key
553
 *
554
 * Internally the tabs are stored in a static variable which is
555
 * managed by drupal_static().
556
 *
557
 * @param string $add_tab
558
 *   Optinal parameter. The given string will be added to the array of tabs
559
 *
560
 * @return
561
 *   The array of tabs
562
 */
563
function taxon_page_tabs_hidden($add_tab = NULL) {
564
  $tabs = &drupal_static(__FUNCTION__);
565

    
566
  if(!isset($tabs)){
567
    $tabs = array();
568
  }
569

    
570
  if (isset($add_tab) && !array_key_exists($add_tab, $tabs)) {
571
    $tabs[] = $add_tab;
572
  }
573

    
574
  return $tabs;
575
}
576

    
577
/**
578
 * Implements the hook_preprocess_HOOK() for theme_menu_local_tasks()
579
 *
580
 *  - Removes the tabs to be hidden, @see taxon_page_tabs_hidden()
581
 *  - Renames tabs according to the settings // TODO (this will replace the theme_cdm_taxonpage_tab() function !!!)
582
 *
583
 * @param array $variables
584
 *   The variables array
585
 */
586
function cdm_dataportal_preprocess_menu_local_tasks(&$variables) {
587

    
588
  $hidden_tabs = taxon_page_tabs_hidden();
589

    
590
  if (is_array($variables['primary'])) {
591
    foreach ($variables['primary'] as $key => &$element) {
592

    
593
      // 1. Remove the tabs to be hidden
594
      foreach ($hidden_tabs as $tab) {
595
        if ($element['#link']['path'] == 'cdm_dataportal/taxon/%/' . $tab) {
596
          // remove the tab
597
          unset($variables['primary'][$key]);
598
        }
599
      }
600
    }
601
  }
602
}
603

    
604

    
605

    
606
/**
607
 * Implements the hook_preprocess_HOOK() for theme_menu_local_task()
608
 *
609
 *
610
 * @param array $variables
611
 *   An associative array containing:
612
 *     - element: A render element containing:
613
 *          #link: A menu link array with 'title', 'href', and 'localized_options' keys.
614
 *          #active: A boolean indicating whether the local task is active.
615
 *
616
 */
617
function cdm_dataportal_preprocess_menu_local_task(&$variables) {
618

    
619
  $link = $variables['element']['#link'];
620
  if (preg_match('/cdm_dataportal\/.*\/refresh$/', $link['href'])) {
621
    $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']) . '"/>';
622
    $link['localized_options']['html'] = TRUE;
623

    
624
    $variables['element']['#link'] = $link;
625
  }
626
}
(6-6/7)