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
|
if(variable_get('cdm_dataportal_compressed_specimen_derivate_table')){
|
103
|
|
104
|
//COMPRESSED SPECIMEN DERIVATE TABLE
|
105
|
$fieldUnits = cdm_ws_get(CDM_WS_PORTAL_TAXON, array($taxon->uuid, 'associatedFieldUnits'));
|
106
|
$detail_image_icon = '<img title="Detail Image" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/detail_image_derivate-16x16-32.png' . '"/>';
|
107
|
$checked_box_icon = '<img src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/step_done.gif' . '"/>';
|
108
|
$sequence_icon = '<img title="Molecular Data" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/sequence_derivate-16x16-32.png' . '"/>';
|
109
|
if ($fieldUnits) {
|
110
|
$rowcount = 0;
|
111
|
foreach ($fieldUnits as $fieldUnit) {
|
112
|
//get derivate hierarchy for the FieldUnit
|
113
|
$derivateHierarchy = cdm_ws_get(CDM_WS_PORTAL_OCCURRENCE, array($fieldUnit->uuid, 'derivateHierarchy'), 'taxonUuid=' . $taxon->uuid);
|
114
|
if($derivateHierarchy){
|
115
|
//summary row
|
116
|
$rows[] = array(
|
117
|
'data' => array(
|
118
|
$derivateHierarchy->country,
|
119
|
$derivateHierarchy->date,
|
120
|
$derivateHierarchy->collection,
|
121
|
$derivateHierarchy->herbarium,
|
122
|
array(
|
123
|
'data' => $derivateHierarchy->hasType? $checked_box_icon:"",
|
124
|
'class' => array('checkBoxCell')
|
125
|
),
|
126
|
array(
|
127
|
'data' => $derivateHierarchy->hasSpecimenScan? $checked_box_icon:"",
|
128
|
'class' => array('checkBoxCell')
|
129
|
),
|
130
|
($derivateHierarchy->hasDna? $sequence_icon :"") . ($derivateHierarchy->hasDetailImage?$detail_image_icon:"")
|
131
|
),
|
132
|
'id' => ('derivate_summary' . $rowcount), // summary row id
|
133
|
'class' => array('summary_row'),
|
134
|
);
|
135
|
|
136
|
//assemble detail html
|
137
|
$taxonName = $derivateHierarchy->taxonName;
|
138
|
$protologue = $derivateHierarchy->protologue;
|
139
|
$citation = $derivateHierarchy->citation;
|
140
|
$types = "";
|
141
|
if(isset($derivateHierarchy->types)){
|
142
|
foreach($derivateHierarchy->types as $typeStatus => $accessionList){
|
143
|
$types .= $typeStatus;
|
144
|
foreach($accessionList as $accessionNumber){
|
145
|
$types .= " (" . $accessionNumber . ") ";
|
146
|
}
|
147
|
}
|
148
|
}
|
149
|
$specimenScans = createLinks($derivateHierarchy->specimenScans);
|
150
|
$molecularData = createLinks($derivateHierarchy->molecularData);
|
151
|
$detailImages = createLinks($derivateHierarchy->detailImages);
|
152
|
|
153
|
$detail_html = "";
|
154
|
if($taxonName){
|
155
|
$detail_html .= "<b>Name:</b> " . $taxonName . "<br>";
|
156
|
}
|
157
|
if($protologue){
|
158
|
//$detail_html .= "<b>Protologue:</b> " . $protologue . "<br>"
|
159
|
}
|
160
|
if($citation){
|
161
|
$detail_html .= "<b>Citation:</b> " . $citation . "<br>";
|
162
|
}
|
163
|
if($types){
|
164
|
$detail_html .= "<b>Types:</b> " . $types . "<br>";
|
165
|
}
|
166
|
if($specimenScans){
|
167
|
$detail_html .= "<b>Specimen Scans:</b> " . $specimenScans . "<br>";
|
168
|
}
|
169
|
if($molecularData){
|
170
|
$detail_html .= "<b>Molecular Data:</b> " . $molecularData . "<br>";
|
171
|
}
|
172
|
if($detailImages){
|
173
|
$detail_html .= "<b>Detail Images:</b> " . $detailImages . "<br>";;
|
174
|
}
|
175
|
|
176
|
//detail row resp. one BIG detail cell
|
177
|
$rows[] = array(
|
178
|
'data' => array(
|
179
|
array(
|
180
|
'data' => $detail_html,
|
181
|
'colspan' => 8,
|
182
|
),
|
183
|
),
|
184
|
'id' => ('derivate_details' . $rowcount),//details row ID
|
185
|
'class' => array('detail_row'),
|
186
|
);
|
187
|
$rowcount++;
|
188
|
}
|
189
|
}
|
190
|
}
|
191
|
|
192
|
$tableId = "derivate_hierarchy_table";
|
193
|
$derivateHierarchyTable = array(
|
194
|
"#theme" => "table",
|
195
|
"#weight" => 2,
|
196
|
"#header" => array("Country", "Date", "Collection", "Herbaria", "Type", "Image", "Derivates"),
|
197
|
"#rows" => $rows,
|
198
|
"#attributes" => array(
|
199
|
"id" => $tableId,
|
200
|
"border" => 2
|
201
|
)
|
202
|
);
|
203
|
|
204
|
//add toggle functionality to derivate hierarchy table
|
205
|
drupal_add_js_rowToggle("#".$tableId);
|
206
|
|
207
|
$render_array['derivate_hierarchy_table'] = $derivateHierarchyTable;
|
208
|
}
|
209
|
else{
|
210
|
//BOTTOM-UP-SPECIMEN-TABLE
|
211
|
// --- generate the specimen list as table
|
212
|
$specimen_table = array(
|
213
|
'#theme' => 'table',
|
214
|
'#weight' => 2,
|
215
|
// prefix attributes and rows with '#' to let it pass to the theme function,
|
216
|
// otherwise it is handled as child render array
|
217
|
'#attributes' => array('class' => 'specimens'),
|
218
|
'#rows' => array(),
|
219
|
);
|
220
|
|
221
|
if ($specimensOrObservations) {
|
222
|
|
223
|
foreach ($specimensOrObservations as $specimenOrObservation) {
|
224
|
|
225
|
$mediaList = array();
|
226
|
if (is_array($specimenOrObservation->_fieldObjectMedia)) {
|
227
|
$mediaList = array_merge($mediaList, $specimenOrObservation->_fieldObjectMedia);
|
228
|
}
|
229
|
if (is_array($specimenOrObservation->_derivedUnitMedia)) {
|
230
|
$mediaList = array_merge($mediaList, $specimenOrObservation->_derivedUnitMedia);
|
231
|
}
|
232
|
|
233
|
// typelabel will contain the typeStatus
|
234
|
$type_label = '';
|
235
|
$typeDesignationPager = cdm_ws_get(CDM_WS_OCCURRENCE . '/$0/specimenTypeDesignations', $specimenOrObservation->uuid);
|
236
|
if (isset($typeDesignationPager)) {
|
237
|
$type_status = array();
|
238
|
foreach ($typeDesignationPager->records as $typeDesignation) {
|
239
|
if (isset($typeDesignation->typeStatus->representation_L10n)){
|
240
|
$type_status[] = $typeDesignation->typeStatus->representation_L10n;
|
241
|
}
|
242
|
}
|
243
|
$type_label = implode(', ', $type_status);
|
244
|
if($type_label){
|
245
|
$type_label .= ': ' ;
|
246
|
}
|
247
|
}
|
248
|
|
249
|
// --- Specimen entry as dynamic label:
|
250
|
// -> Dynabox for the specimenOrObservation
|
251
|
$gallery_name = $specimenOrObservation->uuid;
|
252
|
|
253
|
$derived_unit_ws_request = cdm_compose_url(CDM_WS_OCCURRENCE, array( $specimenOrObservation->uuid));
|
254
|
$label_html = cdm_dynabox(
|
255
|
$specimenOrObservation->uuid,
|
256
|
$type_label . $specimenOrObservation->titleCache,
|
257
|
$derived_unit_ws_request,
|
258
|
'cdm_specimenOrObservation', // the theme or compose function to use
|
259
|
'Click for details',
|
260
|
array('div','div'),
|
261
|
array(),
|
262
|
'function(){ jQuery(\'#media_gallery_' . $gallery_name . '\').hide(); }', // open_callback
|
263
|
'function(){ jQuery(\'#media_gallery_' . $gallery_name . '\').show(); }' // close_callback
|
264
|
);
|
265
|
|
266
|
// --- Render associated media.
|
267
|
$gallery_html = '';
|
268
|
if (count($mediaList) > 0) {
|
269
|
$gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
|
270
|
$captionElements = array(
|
271
|
'#uri' => t('open media'),
|
272
|
);
|
273
|
|
274
|
$gallery_html = theme('cdm_media_gallerie', array(
|
275
|
'mediaList' => $mediaList,
|
276
|
'galleryName' => $gallery_name,
|
277
|
'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
|
278
|
'cols' => $gallery_settings['cdm_dataportal_media_cols'],
|
279
|
'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
|
280
|
'captionElements' => $captionElements,
|
281
|
'mediaLinkType' => 'LIGHTBOX',
|
282
|
'alternativeMediaUri' => NULL,
|
283
|
'galleryLinkUri' => NULL,
|
284
|
));
|
285
|
}
|
286
|
|
287
|
$specimen_table['#rows'][] = array(
|
288
|
// An array of table rows. Every row is an array of cells, or an associative array
|
289
|
'data' => array(
|
290
|
// Each cell can be either a string or an associative array
|
291
|
$label_html . $gallery_html
|
292
|
),
|
293
|
'class' => array(
|
294
|
'descriptionElement',
|
295
|
'descriptionElement_IndividualsAssociation'
|
296
|
),
|
297
|
);
|
298
|
}
|
299
|
}
|
300
|
|
301
|
$render_array['specimen_list'] = $specimen_table;
|
302
|
$render_array['pager'] = markup_to_render_array(
|
303
|
theme('cdm_pager', array(
|
304
|
'pager' => $pager,
|
305
|
'path' => $_REQUEST['q'],
|
306
|
'parameters' => $_REQUEST,
|
307
|
)),
|
308
|
10 // weight
|
309
|
);
|
310
|
}
|
311
|
RenderHints::popFromRenderStack();
|
312
|
return $render_array;
|
313
|
}
|
314
|
|
315
|
/**
|
316
|
* Creates HTML links from the given pair list concatenated by a white space.
|
317
|
* @param $linkTextPairList the list with pairs which hold the uri as "first" and uriText as "second"
|
318
|
* @return string the assembled HTML string containing the links
|
319
|
*/
|
320
|
function createLinks($linkTextPairList)
|
321
|
{
|
322
|
$html = "";
|
323
|
if ($linkTextPairList) {
|
324
|
foreach ($linkTextPairList as $linkTextPair) {
|
325
|
if($linkTextPair->first!=""){
|
326
|
$html .= '<a href="' . $linkTextPair->first . '">' . $linkTextPair->second . "</a>";
|
327
|
}
|
328
|
else{
|
329
|
$html .= $linkTextPair->second;
|
330
|
}
|
331
|
}
|
332
|
}
|
333
|
return $html;
|
334
|
}
|
335
|
/**
|
336
|
* Composes a taxon page which can consist of multiple parts like
|
337
|
* 'General', 'Synonymy', 'Images', 'Keys'. These parts can be displayed
|
338
|
* as tabs or as sections of a single page.
|
339
|
*
|
340
|
* It is headed by the name of the accepted taxon without author and reference.
|
341
|
*
|
342
|
* @param $taxon
|
343
|
* The CDM Taxon Instance to compose the page for.
|
344
|
* @param $page_part
|
345
|
* Name of the part to display, valid values are:
|
346
|
* - 'description' - for the general part
|
347
|
* - 'images'
|
348
|
* - 'synonymy'
|
349
|
* - 'keys'
|
350
|
* - 'all'
|
351
|
*
|
352
|
* @return array
|
353
|
* A drupal render array
|
354
|
*
|
355
|
* @ingroup compose
|
356
|
*/
|
357
|
function compose_cdm_taxon_page($taxon, $page_part = 'description') {
|
358
|
|
359
|
global $theme;
|
360
|
|
361
|
// we better cache here since drupal_get_query_parameters has no internal static cache variable
|
362
|
$http_request_params = drupal_get_query_parameters();
|
363
|
|
364
|
// add all mandatory js sources
|
365
|
_add_js_footnotes();
|
366
|
|
367
|
|
368
|
$render_array = array();
|
369
|
$weight = 0; // the weight for the render array elements
|
370
|
|
371
|
$tabsToDisplay = variable_get('cdm_taxonpage_tabs_visibility', unserialize(TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT));
|
372
|
|
373
|
$page_part = variable_get('cdm_dataportal_taxonpage_tabs', 1) ? $page_part : 'all';
|
374
|
|
375
|
$media = _load_media_for_taxon($taxon);
|
376
|
|
377
|
|
378
|
if (!isset($media[0]) || ($tabsToDisplay["Images"] == '0')) {
|
379
|
taxon_page_tabs_hidden('images');
|
380
|
}
|
381
|
|
382
|
// --- GET specimensOrObservations --- //
|
383
|
$specimensOrObservations = cdm_ws_get(CDM_WS_TAXON, array( $taxon->uuid, 'specimensOrObservations'));
|
384
|
|
385
|
$specimensOrObservationsCount = is_array($specimensOrObservations) ? count($specimensOrObservations) : 0;
|
386
|
if ($specimensOrObservationsCount == 0 || ($tabsToDisplay["Specimens"] == '0')) {
|
387
|
taxon_page_tabs_hidden('specimens');
|
388
|
}
|
389
|
|
390
|
// --- GET polytomousKeys --- //
|
391
|
$polytomousKeysPager = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, NULL, "findByTaxonomicScope=$taxon->uuid");
|
392
|
$identificationKeyCount = 0;
|
393
|
if ($polytomousKeysPager) {
|
394
|
$identificationKeyCount += $polytomousKeysPager->count;
|
395
|
}
|
396
|
if ($identificationKeyCount == 0 || ($tabsToDisplay["Keys"] == '0')) {
|
397
|
taxon_page_tabs_hidden('keys');
|
398
|
}
|
399
|
|
400
|
if ($tabsToDisplay["Synonymy"] == '0') {
|
401
|
taxon_page_tabs_hidden('synonymy');
|
402
|
}
|
403
|
|
404
|
// -------------------------------------------- //
|
405
|
|
406
|
$render_array['back_to_search'] = markup_to_render_array(theme('cdm_back_to_search_result_button'), -103);
|
407
|
|
408
|
if (variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR) && isset($_REQUEST['acceptedFor'])) {
|
409
|
$render_array['accepted_for'] = markup_to_render_array(theme('cdm_acceptedFor', array('acceptedFor' => $_REQUEST['acceptedFor'])), $weight++);
|
410
|
}
|
411
|
|
412
|
// --- PAGE PART: DESCRIPTION --- //
|
413
|
if ($page_part == 'description' || $page_part == 'all') {
|
414
|
|
415
|
$merged_tree = merged_taxon_feature_tree($taxon);
|
416
|
|
417
|
|
418
|
$render_array['general'] = compose_cdm_taxon_page_profile($taxon, $merged_tree, $media);
|
419
|
$render_array['general']['#weight'] = $weight++;
|
420
|
$render_array['general']['#prefix'] = '<div id="general" class="page-part">';
|
421
|
$render_array['general']['#suffix'] = '</div>';
|
422
|
}
|
423
|
|
424
|
// --- PAGE PART: IMAGES --- //
|
425
|
if (array_search('images', taxon_page_tabs_hidden()) === FALSE && ($page_part == 'images' || $page_part == 'all')) {
|
426
|
$images_html = '<div id="images" class="page-part">';
|
427
|
if ($page_part == 'all') {
|
428
|
$images_html .= '<h2>' . t('Images') . '</h2>';
|
429
|
}
|
430
|
// Get the image gallery as configured by the admin.
|
431
|
$taxon_image_gallery = call_user_func_array('taxon_image_gallery_' . variable_get('image_gallery_viewer', 'default'), array(
|
432
|
$taxon,
|
433
|
$media,
|
434
|
));
|
435
|
$images_html .= $taxon_image_gallery;
|
436
|
$images_html .= '</div>';
|
437
|
$render_array['images'] = markup_to_render_array($images_html, $weight++);
|
438
|
}
|
439
|
|
440
|
// --- PAGE PART: SYNONYMY --- //
|
441
|
if (($page_part == 'synonymy' || $page_part == 'all')) {
|
442
|
$synonymy_html = '<div id="synonymy" class="page-part">';
|
443
|
if ($page_part == 'all') {
|
444
|
$synonymy_html .= '<h2>' . t('Synonymy') . '</h2>';
|
445
|
}
|
446
|
$addAcceptedTaxon = variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE);
|
447
|
$synonymy_html .= theme('cdm_taxon_page_synonymy', array('taxon' => $taxon, 'addAcceptedTaxon' => $addAcceptedTaxon));
|
448
|
|
449
|
$synonymy_html .= '</div>';
|
450
|
$render_array['synonymy'] = markup_to_render_array($synonymy_html, $weight++);
|
451
|
|
452
|
}
|
453
|
|
454
|
// --- PAGE PART: SPECIMENS --- //
|
455
|
if ($specimensOrObservationsCount > 0 && ($page_part == 'specimens' || $page_part == 'all')) {
|
456
|
$render_array['specimens'] = array(
|
457
|
'#prefix' => '<div id="specimens" class="page-part">' . ($page_part == 'all' ? '<h2>' . t('Specimens') . '</h2>' : ''),
|
458
|
'content' => cdm_dataportal_taxon_page_specimens($taxon), // returns render array
|
459
|
'#suffix' => '</div>',
|
460
|
);
|
461
|
}
|
462
|
|
463
|
// --- PAGE PART: KEYS --- //
|
464
|
if ($identificationKeyCount == 1 && $page_part == 'keys'){
|
465
|
drupal_goto(path_to_key($polytomousKeysPager->records[0]->class, $polytomousKeysPager->records[0]->uuid));
|
466
|
}
|
467
|
else if ($identificationKeyCount > 0 && ($page_part == 'keys' || $page_part == 'all')) {
|
468
|
$keys_html = '<div id="keys" class="page-part">';
|
469
|
if ($page_part == 'all') {
|
470
|
$keys_html .= '<h2>' . t('Keys') . '</h2>';
|
471
|
}
|
472
|
$keys_html .= theme('cdm_block_IdentificationKeys', array('taxonUuid' => $taxon->uuid));
|
473
|
$keys_html .= '</div>';
|
474
|
$render_array['keys'] = markup_to_render_array($keys_html, $weight++);
|
475
|
}
|
476
|
|
477
|
|
478
|
// adjust weights of page and toc elements according to the settings
|
479
|
$taxontabs_weights = get_array_variable_merged('cdm_taxonpage_tabs_weight', CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
|
480
|
foreach($taxontabs_weights as $tab_key => $weight){
|
481
|
if(isset($render_array[$tab_key])){
|
482
|
$render_array[$tab_key]['#weight'] = $weight;
|
483
|
}
|
484
|
}
|
485
|
|
486
|
|
487
|
// set up the TOC for the pages which contain all pageparts
|
488
|
if($page_part == 'all') {
|
489
|
|
490
|
asort($taxontabs_weights);
|
491
|
foreach(array_keys($taxontabs_weights) as $tab_key){
|
492
|
if(isset($render_array[$tab_key])){
|
493
|
if($tab_key != 'general'){
|
494
|
// add entry for page part
|
495
|
$toc_elements[] = array(
|
496
|
'data' => l(t(ucfirst($tab_key)), $_GET['q'], array('fragment' => $tab_key, 'query' => $http_request_params)),
|
497
|
'class' => array('page-part-toc-item-' . $tab_key)
|
498
|
);
|
499
|
} else {
|
500
|
// add content of profile part instead
|
501
|
if(isset($render_array['general'])) {
|
502
|
// in case all tabs are shown at once the feature tocs
|
503
|
// should be integrated into the tabs toc as sub list
|
504
|
// and the profile image should be on top of the page
|
505
|
if(isset($render_array['general']['taxon_description_feature_toc'])){;
|
506
|
foreach ($render_array['general']['taxon_description_feature_toc']['#items'] as $profile_toc_item){
|
507
|
$toc_elements[] = $profile_toc_item;
|
508
|
}
|
509
|
unset($render_array['general']['taxon_description_feature_toc']);
|
510
|
}
|
511
|
}
|
512
|
}
|
513
|
}
|
514
|
}
|
515
|
|
516
|
// move profile image in page structure
|
517
|
if(isset($render_array['general']['taxon_profile_image'])){
|
518
|
$render_array['profile_image'] = $render_array['general']['taxon_profile_image'];
|
519
|
$render_array['profile_image']['#weight'] = -100;
|
520
|
unset($render_array['general']['taxon_profile_image']);
|
521
|
}
|
522
|
|
523
|
// finally add the table of contents to the render array
|
524
|
$render_array['toc'] = array(
|
525
|
'#theme' => 'item_list',
|
526
|
'#items' => $toc_elements,
|
527
|
'#title' => t('Content'),
|
528
|
'#weight' => -101,
|
529
|
'#suffix' => '</div>',
|
530
|
'#prefix'=> '<div id="page-toc">'
|
531
|
);
|
532
|
}
|
533
|
|
534
|
|
535
|
return $render_array;
|
536
|
}
|
537
|
|
538
|
/**
|
539
|
* TODO move into description.inc or in cdm_api.module?
|
540
|
*
|
541
|
* @param $taxon
|
542
|
* @param $distribution_node
|
543
|
* @return array
|
544
|
*/
|
545
|
function merged_taxon_feature_tree($taxon) {
|
546
|
|
547
|
// 1. fetch descriptions_by_featuretree but exclude the distribution feature
|
548
|
$merged_tree = cdm_ws_descriptions_by_featuretree(get_profile_featureTree(), $taxon->uuid, array(UUID_DISTRIBUTION));
|
549
|
|
550
|
|
551
|
// 2. find the distribution feature node
|
552
|
$distribution_node =& cdm_feature_tree_find_node($merged_tree->root->childNodes, UUID_DISTRIBUTION);
|
553
|
|
554
|
if ($distribution_node) {
|
555
|
// 3. get the distributionInfoDTO
|
556
|
$query_parameters = cdm_distribution_filter_query();
|
557
|
$query_parameters['part'] = array('mapUriParams');
|
558
|
if (variable_get('distribution_sort', 'NO_SORT') != 'NO_SORT') {
|
559
|
$query_parameters['part'][] = 'tree';
|
560
|
}
|
561
|
else {
|
562
|
$query_parameters['part'][] = 'elements';
|
563
|
}
|
564
|
$query_parameters['omitLevels'] = array(UUID_NAMEDAREALEVEL_TDWGLEVEL_2);
|
565
|
$customStatusColorsJson = variable_get(DISTRIBUTION_STATUS_COLORS, NULL);
|
566
|
if ($customStatusColorsJson) {
|
567
|
$query_parameters['statusColors'] = $customStatusColorsJson;
|
568
|
}
|
569
|
|
570
|
$distribution_info_dto = cdm_ws_get(CDM_WS_PORTAL_DESCRIPTION_DISTRIBUTION_INFO_FOR, $taxon->uuid, queryString($query_parameters));
|
571
|
// 4. get distribution TextData is there are any
|
572
|
$distribution_text_data = cdm_ws_fetch_all(CDM_WS_DESCRIPTIONELEMENT_BY_TAXON,
|
573
|
array(
|
574
|
'taxon' => $taxon->uuid,
|
575
|
'type' => 'TextData',
|
576
|
'features' => UUID_DISTRIBUTION
|
577
|
)
|
578
|
);
|
579
|
|
580
|
// 5. put all distribution data into the distribution feature node
|
581
|
if ($distribution_text_data //if text data exists
|
582
|
|| ($distribution_info_dto && isset($distribution_info_dto->tree) && $distribution_info_dto->tree->rootElement->numberOfChildren > 0) // OR if tree element has distribution elements
|
583
|
|| ($distribution_info_dto && !empty($distribution_info_dto->elements))
|
584
|
) { // OR if DTO has distribution elements
|
585
|
$distribution_node->descriptionElements = array('#type' => 'DTO');
|
586
|
if ($distribution_text_data) {
|
587
|
$distribution_node->descriptionElements['TextData'] = $distribution_text_data;
|
588
|
}
|
589
|
if ($distribution_info_dto) {
|
590
|
$distribution_node->descriptionElements['DistributionInfoDTO'] = $distribution_info_dto;
|
591
|
}
|
592
|
}
|
593
|
}
|
594
|
return $merged_tree;
|
595
|
}
|
596
|
|
597
|
|
598
|
/**
|
599
|
* TODO should this function really be a compose function?
|
600
|
* For a compose function must there always be a theme function with the same name? (ak 8.8.2013)
|
601
|
*
|
602
|
* composes and returns an render array containing the components of the taxon profile tab:
|
603
|
* - 'taxon_profile_image'
|
604
|
* - 'taxon_description_feature_toc'
|
605
|
* - 'taxon_description_features'
|
606
|
*
|
607
|
*
|
608
|
* @param array $variables
|
609
|
* An associative array containing:
|
610
|
* - taxon
|
611
|
* - mergedTrees
|
612
|
* - media
|
613
|
*
|
614
|
* @return array
|
615
|
* A Drupal reder array with the following elements:
|
616
|
* - 'taxon_profile_image'
|
617
|
* - 'taxon_description_feature_toc'
|
618
|
* - 'taxon_description_features'
|
619
|
*
|
620
|
* @ingroup compose
|
621
|
*/
|
622
|
function compose_cdm_taxon_page_profile($taxon, $merged_tree, $media) {
|
623
|
|
624
|
$render_array = array();
|
625
|
|
626
|
$taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
|
627
|
|
628
|
$hide_taxon_profile_image = FALSE;
|
629
|
if (variable_get('image_hide_rank', '0') != '0' && isset($taxon->name->rank->uuid)) {
|
630
|
$rankCompare = rank_compare($taxon->name->rank->uuid, variable_get('image_hide_rank', '-99'));
|
631
|
$hide_taxon_profile_image = ($rankCompare > -1);
|
632
|
}
|
633
|
|
634
|
if ($taxon_profile_image_settings['show'] && !$hide_taxon_profile_image) {
|
635
|
|
636
|
$representationPart = new stdClass();
|
637
|
$attributes = array();
|
638
|
if (isset($media[0]->representations[0]->parts[0])) {
|
639
|
$representationPart = $media[0]->representations[0]->parts[0];
|
640
|
$attributes['alt'] = $representationPart->uri;
|
641
|
|
642
|
if(!empty($taxon_profile_image_settings['media_uri_query'])){
|
643
|
$representationPart->uri = $representationPart->uri
|
644
|
. (strpos($representationPart->uri, '?') !== FALSE ? '&' : '?')
|
645
|
. $taxon_profile_image_settings['media_uri_query'];
|
646
|
}
|
647
|
}
|
648
|
else {
|
649
|
// show placeholder image instead
|
650
|
if(!empty($taxon_profile_image_settings['custom_placeholder_image_on']) && !empty($taxon_profile_image_settings['custom_placeholder_image_fid'])){
|
651
|
// use the user provided image
|
652
|
$profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
|
653
|
$url = file_create_url($profile_image_file->uri);
|
654
|
$image_info = image_get_info($profile_image_file->uri);
|
655
|
$representationPart->width = $image_info['width'];
|
656
|
$representationPart->height = $image_info['height'];
|
657
|
$representationPart->uri = $url;
|
658
|
} else {
|
659
|
// use the hard coded default
|
660
|
$representationPart->width = 184;
|
661
|
$representationPart->height = 144;
|
662
|
$representationPart->uri = base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/no_picture.png';
|
663
|
}
|
664
|
$attributes['alt'] = "no image available";
|
665
|
}
|
666
|
|
667
|
$profile_image = theme('cdm_media_gallerie_image', array(
|
668
|
'mediaRepresentationPart' => $representationPart,
|
669
|
'maxExtend' => $taxon_profile_image_settings['maxextend'],
|
670
|
'addPassePartout' => FALSE,
|
671
|
'attributes' => $attributes,
|
672
|
));
|
673
|
// NOTE: style="width:${maxextend}px' is needed for IE8 !!!
|
674
|
$render_array['taxon_profile_image'] = markup_to_render_array('<div id="taxonProfileImage" style="width:' . $taxon_profile_image_settings['maxextend'] . 'px">' . $profile_image. '</div>', -101);
|
675
|
}
|
676
|
|
677
|
|
678
|
// Render the sections for each feature
|
679
|
$render_array['taxon_description_features'] = compose_cdm_feature_nodes($merged_tree->root->childNodes, $taxon);
|
680
|
|
681
|
$bibliography_settings = get_bibliography_settings();
|
682
|
if($bibliography_settings['enabled'] == 1){
|
683
|
$bibliography_block = feature_block(t('Bibliography'));
|
684
|
$bibliography_block->content = FootnoteManager::renderFootnoteList('BIBLIOGRAPHY', '');
|
685
|
|
686
|
if(!empty($bibliography_block->content)){
|
687
|
$render_array['taxon_description_bibliography'] = markup_to_render_array(
|
688
|
theme('block',
|
689
|
array(
|
690
|
'elements' => array(
|
691
|
'#block' => $bibliography_block,
|
692
|
'#children' => $bibliography_block->content,
|
693
|
)
|
694
|
)
|
695
|
),
|
696
|
100 // weight
|
697
|
);
|
698
|
cdm_toc_list_add_item('Bibliography', 'bibliography');
|
699
|
}
|
700
|
|
701
|
}
|
702
|
|
703
|
// create the table of content
|
704
|
$toc = array(
|
705
|
'#theme' => 'item_list',
|
706
|
'#items' => cdm_toc_list(),
|
707
|
'#title' => t('Content'),
|
708
|
'#weight' => -100, // move to the top
|
709
|
'#suffix' => '</div>',
|
710
|
'#prefix'=> '<div id="page-toc">'
|
711
|
);
|
712
|
$render_array['taxon_description_feature_toc'] = $toc;
|
713
|
|
714
|
return $render_array;
|
715
|
}
|
716
|
|
717
|
|
718
|
/**
|
719
|
* Manages the tab to be hidden in the taxon page.
|
720
|
*
|
721
|
* The tabs are identified by their last menu link path element:
|
722
|
* - description
|
723
|
* - synonymy
|
724
|
* - images
|
725
|
* - specimens
|
726
|
* - key
|
727
|
*
|
728
|
* Internally the tabs are stored in a static variable which is
|
729
|
* managed by drupal_static().
|
730
|
*
|
731
|
* @param string $add_tab
|
732
|
* Optinal parameter. The given string will be added to the array of tabs
|
733
|
*
|
734
|
* @return
|
735
|
* The array of tabs
|
736
|
*/
|
737
|
function taxon_page_tabs_hidden($add_tab = NULL) {
|
738
|
$tabs = &drupal_static(__FUNCTION__);
|
739
|
|
740
|
if(!isset($tabs)){
|
741
|
$tabs = array();
|
742
|
}
|
743
|
|
744
|
if (isset($add_tab) && !array_key_exists($add_tab, $tabs)) {
|
745
|
$tabs[] = $add_tab;
|
746
|
}
|
747
|
|
748
|
return $tabs;
|
749
|
}
|
750
|
|
751
|
/**
|
752
|
* Implements the hook_preprocess_HOOK() for theme_menu_local_tasks()
|
753
|
*
|
754
|
* - Removes the tabs to be hidden, @see taxon_page_tabs_hidden()
|
755
|
* - Renames tabs according to the settings // TODO (this will replace the theme_cdm_taxonpage_tab() function !!!)
|
756
|
*
|
757
|
* @param array $variables
|
758
|
* The variables array
|
759
|
*/
|
760
|
function cdm_dataportal_preprocess_menu_local_tasks(&$variables) {
|
761
|
|
762
|
$hidden_tabs = taxon_page_tabs_hidden();
|
763
|
|
764
|
if (is_array($variables['primary'])) {
|
765
|
foreach ($variables['primary'] as $key => &$element) {
|
766
|
|
767
|
// 1. Remove the tabs to be hidden
|
768
|
foreach ($hidden_tabs as $tab) {
|
769
|
if ($element['#link']['path'] == 'cdm_dataportal/taxon/%/' . $tab) {
|
770
|
// remove the tab
|
771
|
unset($variables['primary'][$key]);
|
772
|
}
|
773
|
}
|
774
|
}
|
775
|
}
|
776
|
}
|
777
|
|
778
|
|
779
|
|
780
|
/**
|
781
|
* Implements the hook_preprocess_HOOK() for theme_menu_local_task()
|
782
|
*
|
783
|
*
|
784
|
* @param array $variables
|
785
|
* An associative array containing:
|
786
|
* - element: A render element containing:
|
787
|
* #link: A menu link array with 'title', 'href', and 'localized_options' keys.
|
788
|
* #active: A boolean indicating whether the local task is active.
|
789
|
*
|
790
|
*/
|
791
|
function cdm_dataportal_preprocess_menu_local_task(&$variables) {
|
792
|
|
793
|
$link = $variables['element']['#link'];
|
794
|
if (preg_match('/cdm_dataportal\/.*\/refresh$/', $link['href'])) {
|
795
|
$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']) . '"/>';
|
796
|
$link['localized_options']['html'] = TRUE;
|
797
|
|
798
|
$variables['element']['#link'] = $link;
|
799
|
}
|
800
|
}
|