Project

General

Profile

Download (8.78 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
 * Manages the tab to be hidden in the taxon page.
207
 *
208
 * The tabs are identified by their last menu link path element:
209
 *  - description
210
 *  - synonymy
211
 *  - images
212
 *  - specimens
213
 *  - key
214
 *
215
 * Internally the tabs are stored in a static variable which is
216
 * managed by drupal_static().
217
 *
218
 * @param string $add_tab
219
 *   Optinal parameter. The given string will be added to the array of tabs
220
 *
221
 * @return
222
 *   The array of tabs
223
 */
224
function taxon_page_tabs_hidden($add_tab = NULL) {
225
  $tabs = &drupal_static(__FUNCTION__);
226

    
227
  if(!isset($tabs)){
228
    $tabs = array();
229
  }
230

    
231
  if (isset($add_tab) && !array_key_exists($add_tab, $tabs)) {
232
    $tabs[] = $add_tab;
233
  }
234

    
235
  return $tabs;
236
}
237

    
238
/**
239
 * Implements the hook_preprocess_HOOK() for theme_menu_local_tasks()
240
 *
241
 *  - Removes the tabs to be hidden, @see taxon_page_tabs_hidden()
242
 *  - Renames tabs according to the settings // TODO (this will replace the theme_cdm_taxonpage_tab() function !!!)
243
 *
244
 * @param array $variables
245
 *   The variables array
246
 */
247
function cdm_dataportal_preprocess_menu_local_tasks(&$variables) {
248

    
249
  $hidden_tabs = taxon_page_tabs_hidden();
250

    
251
  if (is_array($variables['primary'])) {
252
    foreach ($variables['primary'] as $key => &$element) {
253
      foreach ($hidden_tabs as $tab) {
254
        if ($element['#link']['path'] == 'cdm_dataportal/taxon/%/' . $tab) {
255
          // remove the tab
256
          unset($variables['primary'][$key]);
257
        }
258
      }
259
    }
260
  }
261
}
(6-6/7)