Project

General

Profile

Download (9.08 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 = http_build_query(array(
43
      'relationshipsInvers' => implode(',', $relationship_choice['invers']),
44
      'relationships' => implode(',', $relationship_choice['direct']),
45
      'pageSize' => null // all hits in one page
46
      )
47
    );
48

    
49
  $pager = cdm_ws_get(CDM_WS_OCCURRENCE_BY_ASSOCIATEDTAXON,
50
      null,
51
      $by_associatedtaxon_query . '&taxonUuid=' . $taxon->uuid
52
  );
53

    
54
  $specimensOrObservations = array();
55
  if(isset($pager->records[0])){
56
    $specimensOrObservations =  $pager->records;
57
  }
58

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

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

    
85
  // --- get map service HTTP query paramaters
86
  if (count($specimensOrObservations) > 0) {
87
    $occurrenceQuery = cdm_ws_get(CDM_WS_GEOSERVICE_OCCURRENCEMAP, $taxon->uuid,  $by_associatedtaxon_query);
88

    
89
    if( isset($occurrenceQuery->String) ) {
90
      $occurrenceQuery = $occurrenceQuery->String;
91

    
92
      $legendFormatQueryStr = null;
93
      if (variable_get('cdm_dataportal_map_openlayers', 1)) {
94
        $map_html = get_openlayers_map(variable_get('cdm_dataportal_geoservice_display_width', 680), variable_get('cdm_dataportal_geoservice_bounding_box', FALSE), $occurrenceQuery, NULL,
95
            $legendFormatQueryStr, variable_get('cdm_dataportal_geoservice_map_caption', ''));
96
      }
97
      else {
98
        // get_image_map($width, $occurrenceQuery = FALSE, $distributionQuery = FALSE, $legendFormatQuery = FALSE, $map_caption = FALSE )
99
        $map_html = get_image_map(variable_get('cdm_dataportal_geoservice_display_width', 680), variable_get('cdm_dataportal_geoservice_bounding_box', FALSE), $occurrenceQuery, NULL,
100
            $legendFormatQueryStr, variable_get('cdm_dataportal_geoservice_map_caption', ''));
101
      }
102
      $render_array['map'] = markup_to_render_array($map_html, 0);
103
    }
104
  }
105

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

    
116
  if ($specimensOrObservations) {
117

    
118
    foreach ($specimensOrObservations as $specimenOrObservation) {
119

    
120
      $mediaList = array();
121
      if (is_array($specimenOrObservation->_fieldObjectMedia)) {
122
        $mediaList = array_merge($mediaList, $specimenOrObservation->_fieldObjectMedia);
123
      }
124
      if (is_array($specimenOrObservation->_derivedUnitMedia)) {
125
        $mediaList = array_merge($mediaList, $specimenOrObservation->_derivedUnitMedia);
126
      }
127

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

    
144
      // --- Specimen entry as dynamic label:
145
      //     -> Dynabox for the specimenOrObservation
146
      $gallery_name = $specimenOrObservation->uuid;
147

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

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

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

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

    
195
  $render_array['specimen_list'] = $specimen_table;
196

    
197
  RenderHints::popFromRenderStack();
198
  return $render_array;
199
}
200

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

    
223
  if(!isset($tabs)){
224
    $tabs = array();
225
  }
226

    
227
  if (isset($add_tab) && !array_key_exists($add_tab, $tabs)) {
228
    $tabs[] = $add_tab;
229
  }
230

    
231
  return $tabs;
232
}
233

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

    
245
  $hidden_tabs = taxon_page_tabs_hidden();
246

    
247
  if (is_array($variables['primary'])) {
248
    foreach ($variables['primary'] as $key => &$element) {
249
      foreach ($hidden_tabs as $tab) {
250
        if ($element['#link']['path'] == 'cdm_dataportal/taxon/%/' . $tab) {
251
          // remove the tab
252
          unset($variables['primary'][$key]);
253
        }
254
      }
255
    }
256
  }
257
}
(3-3/4)