1
|
<?php
|
2
|
// $Id$
|
3
|
|
4
|
/**
|
5
|
* Copyright (C) 2007 EDIT
|
6
|
* European Distributed Institute of Taxonomy
|
7
|
* http://www.e-taxonomy.eu
|
8
|
*
|
9
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
10
|
* See http://www.mozilla.org/MPL/MPL-1.1.html for the full license terms.
|
11
|
*/
|
12
|
|
13
|
|
14
|
function theme_cdm_feature_nodesTOC($featureNodes){
|
15
|
|
16
|
$out .= '<ul>';
|
17
|
|
18
|
foreach($featureNodes as $node){
|
19
|
// process $descriptionElements with content only
|
20
|
if(is_array($node->descriptionElements) && count($node->descriptionElements) > 0 || count($node->children) > 0){
|
21
|
|
22
|
$featureRepresentation = isset($node->feature->representation_L10n) ? $node->feature->representation_L10n : 'Feature';
|
23
|
// HACK to implement images for taxa, should be removed
|
24
|
if($node->feature->uuid != UUID_IMAGE){
|
25
|
$out .= '<li>'.l(t(theme('cdm_feature_name', $featureRepresentation)), $_GET['q'], array("class"=>"toc"), NULL, generalizeString($featureRepresentation)).'</li>';
|
26
|
}
|
27
|
}
|
28
|
}
|
29
|
|
30
|
$out .= '</ul>';
|
31
|
return $out;
|
32
|
}
|
33
|
|
34
|
function theme_cdm_feature_name($feature_name){
|
35
|
//TODO replace by using translations ?
|
36
|
switch($feature_name){
|
37
|
default: return t(ucfirst($feature_name));
|
38
|
}
|
39
|
}
|
40
|
|
41
|
function theme_cdm_featureTrees($mergedTrees, $taxon){
|
42
|
if(!$mergedTrees){
|
43
|
return;
|
44
|
}
|
45
|
foreach($mergedTrees as &$mTree){
|
46
|
//TODO diplay title and reference in case of multiple $mergedTrees -> theme
|
47
|
$out .= theme('cdm_feature_nodes', $mTree->root->children, $taxon);
|
48
|
}
|
49
|
return $out;
|
50
|
}
|
51
|
|
52
|
|
53
|
|
54
|
function theme_cdm_featureTreeTOCs($mergedTrees){
|
55
|
|
56
|
if(!$mergedTrees){
|
57
|
return;
|
58
|
}
|
59
|
//FIXME
|
60
|
$out = '<div class="featureTOC">';
|
61
|
$out .= '<h2>' . t('Content') .'</h2>';
|
62
|
|
63
|
//TODO diplay title and reference in case of multiple $mergedTrees -> theme
|
64
|
|
65
|
foreach($mergedTrees as &$mTree){
|
66
|
$out .= theme('cdm_feature_nodesTOC', $mTree->root->children);
|
67
|
}
|
68
|
|
69
|
$out .= '</div>';
|
70
|
return $out;
|
71
|
}
|
72
|
|
73
|
|
74
|
|
75
|
function theme_cdm_feature_nodes($featureNodes, $taxon){
|
76
|
|
77
|
RenderHints::pushToRenderStack('feature_nodes');
|
78
|
$gallery_settings = getGallerySettings(CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME);
|
79
|
|
80
|
foreach($featureNodes as $node){
|
81
|
// process $descriptionElements with content only
|
82
|
if(is_array($node->descriptionElements) && count($node->descriptionElements) > 0 || count($node->children) > 0){
|
83
|
$featureRepresentation = isset($node->feature->representation_L10n) ? $node->feature->representation_L10n : 'Feature';
|
84
|
$block->module = 'cdm_dataportal';
|
85
|
|
86
|
if($node->feature->uuid != UUID_IMAGE){
|
87
|
$block->delta = generalizeString($featureRepresentation);
|
88
|
$block->subject = theme('cdm_feature_name', $featureRepresentation);
|
89
|
$block->module = "cdm_dataportal-feature";
|
90
|
$block->content = '';
|
91
|
|
92
|
// Display cdm distribution map TODO this is a HACK to a proper generic implementation?
|
93
|
if($node->feature->uuid == UUID_DISTRIBUTION){
|
94
|
$block->content .= theme('cdm_distribution_map', $taxon);
|
95
|
}
|
96
|
|
97
|
//get the text for the feature block
|
98
|
//if ($node->feature->titleCache == 'Common Name'){
|
99
|
if ($node->feature->uuid == UUID_COMMON_NAME){
|
100
|
$block->content .= theme('cdm_common_names', $node->descriptionElements);
|
101
|
/*
|
102
|
}else if($node->feature->uuid == UUID_IMAGE_SOURCES) {
|
103
|
$block->content .= theme('cdm_image_sources', $node->descriptionElements);
|
104
|
*/
|
105
|
} else {
|
106
|
$block->content .= theme('cdm_descriptionElements', $node->descriptionElements, $node->feature->uuid, $taxon->uuid);
|
107
|
}
|
108
|
|
109
|
// get media for the feature block
|
110
|
$media_list = cdm_dataportal_media_from_descriptionElements($node->descriptionElements);
|
111
|
$captionElements = array('title', 'rights');
|
112
|
//$block->content .= theme('cdm_media_gallerie', $media_list, "test", 150, 4, false, $captionElements);
|
113
|
$block->content .= theme('cdm_media_gallery', $media_list,
|
114
|
CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME.'_'.$node->feature->uuid,
|
115
|
$gallery_settings['cdm_dataportal_media_maxextend'],
|
116
|
$gallery_settings['cdm_dataportal_media_cols'],
|
117
|
$gallery_settings['cdm_dataportal_media_maxRows'],
|
118
|
$captionElements
|
119
|
);
|
120
|
|
121
|
$block->content .= theme('cdm_footnotes', $node->feature->uuid);
|
122
|
$block->content .= theme('cdm_annotation_footnotes', $node->feature->uuid);
|
123
|
|
124
|
// set anchor; FIXME put anchor in $block->subject
|
125
|
$out .= '<a name="'.$block->delta.'"></a>';
|
126
|
$out .= theme('block', $block);
|
127
|
|
128
|
}
|
129
|
}
|
130
|
// theme
|
131
|
if(count($node->children) > 0){
|
132
|
/*
|
133
|
$out .= '<div class="nested_description_elements">';
|
134
|
$out .= theme('cdm_feature_nodes', $node->children, $taxon);
|
135
|
$out .= '</div>';
|
136
|
*/
|
137
|
$text = '';
|
138
|
foreach ($node->children as $child){
|
139
|
//$out .= theme('cdm_descriptionElementTextData', $child->descriptionElements[0], false);
|
140
|
if (is_array($child->descriptionElements)){//if condition added to avoid warnings
|
141
|
foreach ($child->descriptionElements as $element) {
|
142
|
$description = str_replace("\n", "<br/>", $element->multilanguageText_L10n->text);
|
143
|
$description = str_replace($element->feature->titleCache, '<em>' . $element->feature->titleCache . '</em>', $description);
|
144
|
}
|
145
|
$text .= $description;
|
146
|
$description = '';
|
147
|
}
|
148
|
}
|
149
|
$out .= $text;
|
150
|
}
|
151
|
|
152
|
}
|
153
|
RenderHints::popFromRenderStack();
|
154
|
return $out;
|
155
|
}
|
156
|
|
157
|
function theme_FeatureTree_hierarchy($FeatureTreeUuid){
|
158
|
|
159
|
if(!is_uuid($FeatureTreeUuid)){
|
160
|
return;
|
161
|
}
|
162
|
$out = '';
|
163
|
$featureTree = cdm_ws_get(CDM_WS_FEATURETREE, array($FeatureTreeUuid));
|
164
|
if($featureTree && $featureTree->root){
|
165
|
$out = '<ul class="'.$featureTree->class.'">';
|
166
|
$out .= theme('FeatureTree_hierarchy_children', $featureTree->root);
|
167
|
$out .= '</ul>';
|
168
|
}
|
169
|
return $out;
|
170
|
}
|
171
|
|
172
|
function theme_FeatureTree_hierarchy_children($node){
|
173
|
|
174
|
$out = '';
|
175
|
if($node->children){
|
176
|
|
177
|
foreach($node->children as $childNode){
|
178
|
$out .= '<li>'.check_plain($childNode->feature->representation_L10n);
|
179
|
if($childNode->childen && count($childNode->childen) > 0){
|
180
|
$out .= '<ul>'.theme('FeatureTree_hierarchy_children', $childNode).'</ul>';
|
181
|
}
|
182
|
$out .= '</li>';
|
183
|
}
|
184
|
}
|
185
|
return $out;
|
186
|
}
|
187
|
|
188
|
|
189
|
|
190
|
|
191
|
function theme_cdm_descriptionElementArray($elementArray, $feature, $glue = '', $sortArray = false, $enclosingHtml = 'ul'){
|
192
|
$out = '<'.$enclosingHtml.' class="description" id="'.$feature->representation_L10n.'">';
|
193
|
|
194
|
if($sortArray) sort($elementArray);
|
195
|
|
196
|
$out .= join($elementArray, $glue);
|
197
|
|
198
|
$out .= '</'.$enclosingHtml.'>';
|
199
|
return $out;
|
200
|
}
|
201
|
|
202
|
|
203
|
function theme_cdm_descriptionElement_CommonTaxonName($element){
|
204
|
$out = $element->language->representation_L10n . ' (' . $element->area->titleCache . '): ' . $element->name;
|
205
|
return $out;
|
206
|
}
|
207
|
|
208
|
/**
|
209
|
* TODO: assign a new name to the function? because it is used for the citations
|
210
|
* textdata elements and not for all text data description elements
|
211
|
* @param $element The description element which contains the text information
|
212
|
* @param $asListElement A boolean which determines whether the citations should
|
213
|
* be renderer as a list or not
|
214
|
* @return unknown_type Html to be renderized in drupal
|
215
|
*/
|
216
|
function theme_cdm_descriptionElementTextData($element, $asListElement, $feature_uuid = null){
|
217
|
$description = str_replace("\n", "<br/>", $element->multilanguageText_L10n->text);
|
218
|
$sourceRefs = '';
|
219
|
$result = array();
|
220
|
$out;
|
221
|
$res_author;
|
222
|
$res_date;
|
223
|
|
224
|
if(is_array($element->sources)){
|
225
|
foreach($element->sources as $source){
|
226
|
$referenceCitation = theme('cdm_DescriptionElementSource', $source);
|
227
|
if($description && strlen($description) > 0 && $referenceCitation ){
|
228
|
$sourceRefs .= ' ('.$referenceCitation.')' ;
|
229
|
}else if ($referenceCitation){
|
230
|
$sourceRefs = $referenceCitation;
|
231
|
}
|
232
|
|
233
|
if(strlen($sourceRefs) > 0){
|
234
|
$sourceRefs = '<span class="sources">' . $sourceRefs . '</span>';
|
235
|
}
|
236
|
|
237
|
if ($source->nameUsedInSource->uuid){ //do a link to name page
|
238
|
$name_used_in_source_link_to_show = l($source->nameUsedInSource->titleCache,
|
239
|
path_to_name($source->nameUsedInSource->uuid),
|
240
|
array(), NULL, NULL, FALSE ,TRUE);
|
241
|
}else if (strlen($source->nameUsedInSource->originalNameString) > 0){ //show a text without link
|
242
|
$name_used_in_source_link_to_show = $source->nameUsedInSource->originalNameString;
|
243
|
}
|
244
|
|
245
|
if ($asListElement){
|
246
|
$out = '<li class="descriptionText">' . $name_used_in_source_link_to_show;
|
247
|
//adding ":" if necesary
|
248
|
if ($name_used_in_source_link_to_show && ($description || $sourceRefs)){
|
249
|
$out .= ': ';
|
250
|
}
|
251
|
$out .= $description . $sourceRefs . theme('cdm_annotations_as_footnotekeys', $element) . '</li>';
|
252
|
}else{
|
253
|
if ($name_used_in_source_link_to_show){
|
254
|
$name_used_in_source_link_to_show = ' (name in source: '. $name_used_in_source_link_to_show . ')';
|
255
|
}
|
256
|
$out = $description . $sourceRefs . $name_used_in_source_link_to_show;
|
257
|
}
|
258
|
}
|
259
|
}
|
260
|
//if no sources, print the description
|
261
|
if(!isset($out)) {
|
262
|
$out = $description;
|
263
|
}
|
264
|
//printing annotations footnotes
|
265
|
//$out .= theme('cdm_annotations_as_footnotekeys', $element);
|
266
|
// add annotations as footnote key
|
267
|
//$out .= theme('cdm_annotations_as_footnotekeys', $element); move above
|
268
|
return $out;
|
269
|
}
|
270
|
|
271
|
function theme_cdm_common_names($elements){
|
272
|
$text_data_out = '';
|
273
|
$common_name_out = '';
|
274
|
$separator = ',';
|
275
|
$textData_commonNames = array();
|
276
|
|
277
|
|
278
|
if (is_array($elements)){
|
279
|
foreach ($elements as $element){
|
280
|
if ($element->class == 'CommonTaxonName'){
|
281
|
//$key = '<b>' . $element->language->representation_L10n . '</b> (' . $element->area->titleCache . ')';
|
282
|
if ($element->language->representation_L10n){
|
283
|
$key = '<b>' . $element->language->representation_L10n . '</b>';
|
284
|
$key .= (strlen($element->area->titleCache)>0) ? ' (' . $element->area->titleCache . ')' : '';
|
285
|
}
|
286
|
$common_names[$key][] = $element;
|
287
|
}else if ($element->class == 'TextData'){
|
288
|
//else if ($element->class == 'TextData' && $element->feature->uuid == UUID_COMMON_NAME){
|
289
|
$textData_commonNames[] = $element;
|
290
|
}
|
291
|
}
|
292
|
}
|
293
|
//handling common names
|
294
|
|
295
|
if (count($common_names) > 0){
|
296
|
//sorting the a-array based on the area (key)
|
297
|
ksort($common_names);
|
298
|
//creating the output to be render by drupal
|
299
|
foreach ($common_names as $key => $elements){
|
300
|
$rendered_element_list = '';
|
301
|
foreach($elements as $element){
|
302
|
$sourcesFootnoteKeyList = '';
|
303
|
// adding footnotes sources
|
304
|
foreach($element->sources as $source){
|
305
|
if(_is_original_source_type($source)){
|
306
|
$_fkey = FootnoteManager::addNewFootnote(UUID_COMMON_NAME, theme('cdm_DescriptionElementSource', $source, false));
|
307
|
$sourcesFootnoteKeyList .= theme('cdm_footnote_key', $_fkey, ($sourcesFootnoteKeyList ? $separator : ''));
|
308
|
}
|
309
|
}
|
310
|
if($element->name){
|
311
|
$rendered_element_list .= (strlen($rendered_element_list) > 0 ? ', ': '') . $element->name . $sourcesFootnoteKeyList;
|
312
|
}
|
313
|
}
|
314
|
if ($key){
|
315
|
$common_name_out .= (strlen($common_name_out) > 0 ? '; ': '') . $key . ': ' . $rendered_element_list;
|
316
|
}else{
|
317
|
$common_name_out .= (strlen($common_name_out) > 0 ? '; ': '') . $rendered_element_list;
|
318
|
}
|
319
|
}
|
320
|
}
|
321
|
//handling commons names as text data
|
322
|
foreach($textData_commonNames as $text_data_element){
|
323
|
$text_data_out .= theme('cdm_descriptionElementTextData', $text_data_element, true, $text_data_element->feature->uuid);
|
324
|
}
|
325
|
|
326
|
$common_name_out = "<div class=common_names_as_common_names> $common_name_out </div>";
|
327
|
$out_array[] = $text_data_out;
|
328
|
$common_name_out_text_data = '<div class=common_names_as_text_data>' . theme('cdm_descriptionElementArray', $out_array, $element->feature) . '</div>';
|
329
|
|
330
|
return $common_name_out . $common_name_out_text_data;
|
331
|
//return $common_name_out . theme('cdm_descriptionElementArray', $out_array, $element->feature);
|
332
|
//return "<div class=common_names> $common_name_out $common_name_out_text_data";
|
333
|
}
|
334
|
|
335
|
/**
|
336
|
* Theme a list of description elements, usually of a specific feature type
|
337
|
* @param $descriptionElements
|
338
|
* @return unknown_type
|
339
|
*/
|
340
|
function theme_cdm_descriptionElements($descriptionElements, $featureUuid, $taxon_uuid){
|
341
|
$outArray = array();
|
342
|
if(variable_get('distribution_sort', 'NO_SORT') != 'NO_SORT'){
|
343
|
$glue = '';
|
344
|
$enclosingHtml = 'dl';
|
345
|
} else {
|
346
|
$glue = '';
|
347
|
$enclosingHtml = 'ul';
|
348
|
}
|
349
|
$sortOutArray = false;
|
350
|
$distributionElements = array();
|
351
|
|
352
|
RenderHints::pushToRenderStack('cdm_descriptionElements');
|
353
|
//$common_names = theme('cdm_common_names', $descriptionElements);
|
354
|
if(is_array($descriptionElements)){//avoiding warning box in drupal for flora malesiana
|
355
|
foreach($descriptionElements as $descriptionElement){
|
356
|
if($descriptionElement->feature->uuid == UUID_DISTRIBUTION){
|
357
|
if($descriptionElement->class == 'Distribution'){
|
358
|
$distributionElements[]= $descriptionElement;
|
359
|
} else if($descriptionElement->class == 'TextData'){
|
360
|
$asListElement = false;
|
361
|
$repr = theme ('cdm_descriptionElementTextData', $descriptionElement, $asListElement, $descriptionElement->feature->uuid);
|
362
|
|
363
|
if( !array_search($repr, $outArray)){
|
364
|
$outArray[] = $repr;
|
365
|
$glue = '<br/> ';
|
366
|
$sortOutArray = true;
|
367
|
$enclosingHtml = 'p';
|
368
|
}
|
369
|
}
|
370
|
}else if($descriptionElement->feature->uuid == UUID_IMAGE_SOURCES){
|
371
|
$image_sources[] = $descriptionElement;
|
372
|
}else if($descriptionElement->class == 'TextData'){
|
373
|
$asListElement = true;
|
374
|
$outArray[] = theme('cdm_descriptionElementTextData', $descriptionElement, $asListElement, $descriptionElement->feature->uuid);
|
375
|
}else if ($descriptionElement->class == 'CommonTaxonName') {
|
376
|
$outArray[] = theme('cdm_descriptionElement_CommonTaxonName', $descriptionElement);
|
377
|
}else {
|
378
|
$outArray[] = '<li>No method for rendering unknown description class: '.$descriptionElement->classType.'</li>';
|
379
|
}
|
380
|
}
|
381
|
}
|
382
|
//if feature = NAME USAGE sort the list of sources
|
383
|
//this is ONLY for FLORA MALESIANA and FLORE d'AFRIQUE CENTRALE
|
384
|
if($descriptionElement->feature->uuid == UUID_NAME_USAGE){
|
385
|
sort($outArray);
|
386
|
}
|
387
|
if($image_sources){
|
388
|
$outArray[] = theme('cdm_description_element_image_source', $image_sources, true);
|
389
|
|
390
|
}
|
391
|
if(variable_get('distribution_sort', 'NO_SORT') != 'NO_SORT'){
|
392
|
$outArray[] = theme('cdm_description_ordered_distributions', $taxon_uuid, $distributionElements);
|
393
|
}else{
|
394
|
$outArray[] = theme('cdm_descriptionElementDistribution', $distributionElements);
|
395
|
}
|
396
|
//$outArray[] = theme('cdm_descriptionElementDistribution', $distributionElements);
|
397
|
//$outArray[] = theme('cdm_description_ordered_distributions', $taxon_uuid, $distributionElements);
|
398
|
|
399
|
// take the feature of the last $descriptionElement
|
400
|
$feature = $descriptionElement->feature;
|
401
|
$out = theme('cdm_descriptionElementArray', $outArray, $feature, $glue, $sortOutArray, $enclosingHtml);
|
402
|
|
403
|
RenderHints::popFromRenderStack();
|
404
|
return $out;
|
405
|
}
|
406
|
|
407
|
function compare_image_sources($a, $b){
|
408
|
if($a->multilanguageText_L10n->text == $b->multilanguageText_L10n->text){
|
409
|
return 0;
|
410
|
}
|
411
|
return ($a->multilanguageText_L10n->text < $b->multilanguageText_L10n->text) ? -1 : 1;
|
412
|
}
|
413
|
|
414
|
/**
|
415
|
*
|
416
|
*/
|
417
|
function theme_cdm_description_element_image_source($image_sources, $asListElement) {
|
418
|
$out = '';
|
419
|
$separator = ',';
|
420
|
RenderHints::pushToRenderStack('descriptionElementImageSource');
|
421
|
RenderHints::setFootnoteListKey(UUID_IMAGE_SOURCES);
|
422
|
|
423
|
//sorting the image sources
|
424
|
usort($image_sources, "compare_image_sources");
|
425
|
//generate the footnotes
|
426
|
foreach($image_sources as $image_source){
|
427
|
$footNoteKeys = cdm_annotations_as_footnotekeys($image_source);
|
428
|
foreach($image_source->sources as $source){
|
429
|
if(_is_original_source_type($source)){
|
430
|
$fn_key = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), theme('cdm_DescriptionElementSource', $source, false));
|
431
|
cdm_add_footnote_to_array($footNoteKeys, $fn_key);// ensure uniqueness of the footnote keys
|
432
|
}
|
433
|
}
|
434
|
//sort and render footnote keys
|
435
|
$footnoteKeyListStr = '';
|
436
|
asort($footNoteKeys);
|
437
|
foreach($footNoteKeys as $footNoteKey){
|
438
|
$footnoteKeyListStr .= theme('cdm_footnote_key', $footNoteKey, ($footnoteKeyListStr ? $separator : ''));
|
439
|
}
|
440
|
//return value!
|
441
|
if ($asListElement){
|
442
|
$out .= '<p><span class="descriptionElement descriptionElement-'.$image_source->uuid.'">'.$image_source->multilanguageText_L10n->text . $footnoteKeyListStr . ' </span><p>';
|
443
|
}else{
|
444
|
$out .= '<span class="descriptionElement descriptionElement-'.$image_source->uuid.'">'.$image_source->multilanguageText_L10n->text . $footnoteKeyListStr . ' </span>';
|
445
|
}
|
446
|
}
|
447
|
|
448
|
RenderHints::popFromRenderStack();
|
449
|
return $out;
|
450
|
}
|
451
|
|
452
|
/**
|
453
|
*
|
454
|
* @param unknown_type $descriptionElements
|
455
|
* @return unknown_type
|
456
|
*/
|
457
|
function theme_cdm_descriptionElementDistribution($descriptionElements){
|
458
|
$out = '';
|
459
|
$separator = ',';
|
460
|
RenderHints::pushToRenderStack('descriptionElementDistribution');
|
461
|
RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
|
462
|
foreach($descriptionElements as $descriptionElement){
|
463
|
// annotations as footnotes
|
464
|
//$annotationFootnoteKeys = theme('cdm_annotations_as_footnotekeys', $descriptionElement);
|
465
|
$footNoteKeys = cdm_annotations_as_footnotekeys($descriptionElement);
|
466
|
// source references as footnotes
|
467
|
foreach($descriptionElement->sources as $source){
|
468
|
if(_is_original_source_type($source)){
|
469
|
$fn_key = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), theme('cdm_DescriptionElementSource', $source, false));
|
470
|
cdm_add_footnote_to_array($footNoteKeys, $fn_key);// ensure uniqueness of the footnote keys
|
471
|
}
|
472
|
}
|
473
|
// sort and render footnote keys
|
474
|
$footnoteKeyListStr = '';
|
475
|
asort($footNoteKeys);
|
476
|
foreach($footNoteKeys as $footNoteKey){
|
477
|
$footnoteKeyListStr .= theme('cdm_footnote_key', $footNoteKey, ($footnoteKeyListStr ? $separator : ''));
|
478
|
}
|
479
|
$out .= '<span class="descriptionElement descriptionElement-'.$descriptionElement->uuid.'">'.$descriptionElement->area->representation_L10n . $footnoteKeyListStr . ' </span>';
|
480
|
}
|
481
|
|
482
|
//$out = substr($out, 0, strlen($out)-strlen($separator) );
|
483
|
|
484
|
RenderHints::popFromRenderStack();
|
485
|
return $out;
|
486
|
}
|
487
|
/**
|
488
|
* Function target is to compare two different foootnotes objects.
|
489
|
* The comparation is based on the footnote key. The one which is
|
490
|
* displayed as footnote number.
|
491
|
*
|
492
|
* @param footnote object $a
|
493
|
* @param footnote object $b
|
494
|
*/
|
495
|
function footnotes_key_compare($a, $b){
|
496
|
$res = 0;
|
497
|
if ($a->keyStr < $b->keyStr){
|
498
|
$res = -1;
|
499
|
}elseif ($a->keyStr > $b->keyStr){
|
500
|
$res = 1;
|
501
|
}
|
502
|
return $res;
|
503
|
}
|
504
|
|
505
|
function theme_cdm_description_ordered_distributions($taxon_uuid, $descriptionElements){
|
506
|
//returning null if no description elements
|
507
|
if ($descriptionElements == null){
|
508
|
return '';
|
509
|
}
|
510
|
//initialization some variables
|
511
|
$out = '';
|
512
|
$separator = ',';
|
513
|
RenderHints::pushToRenderStack('descriptionElementDistribution');
|
514
|
RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
|
515
|
//getting all the taxon description for a given taxon
|
516
|
$taxonDescriptions = cdm_ws_get(CDM_WS_PORTAL_TAXON_DESCRIPTIONS, $taxon_uuid);
|
517
|
foreach ($taxonDescriptions as $description){
|
518
|
$descriptions_uuids[] = $description->uuid;
|
519
|
}
|
520
|
//getting the sortered distributions (omiting level ??)
|
521
|
$request_params = array();
|
522
|
$request_params['omitLevels'] = UUID_NAMEDAREALEVEL_TDWGLEVEL_2;
|
523
|
$ordered_areas = cdm_ws_get(CDM_WS_PORTAL_DESCRIPTION_DISTRIBUTION_TREE, join(',',$descriptions_uuids), queryString($request_params));
|
524
|
$ordered_areas = $ordered_areas->rootElement->children;
|
525
|
|
526
|
//printing the distributions
|
527
|
foreach ($ordered_areas as $element_level1){
|
528
|
//level1
|
529
|
if ($element_level1->data){
|
530
|
$out .= '<dt>' . $element_level1->data->area->representation_L10n . ':</dt> ';
|
531
|
}
|
532
|
$out .= '<dd>';
|
533
|
|
534
|
//level3
|
535
|
foreach ($element_level1->children as $element_level3){
|
536
|
if ($element_level3->data){
|
537
|
$text_l3 = $element_level3->data->area->representation_L10n;
|
538
|
}
|
539
|
$fnKeysLevel3Str = '';
|
540
|
$fnKeysLevel3 = cdm_annotations_as_footnotekeys($element_level3->data);
|
541
|
foreach($element_level3->data->sources as $source){
|
542
|
if(_is_original_source_type($source)){
|
543
|
$fn_key3 = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), theme('cdm_DescriptionElementSource', $source, false));
|
544
|
cdm_add_footnote_to_array($fnKeysLevel3, $fn_key3);
|
545
|
}
|
546
|
}
|
547
|
//level4
|
548
|
$l4_regions = array();
|
549
|
foreach ($element_level3->children as $element_level4){
|
550
|
if ($element_level4->data){
|
551
|
$text_l4 = $element_level4->data->area->representation_L10n;
|
552
|
$l4_regions[$element_level3->data->area->representation_L10n] = '';
|
553
|
$fnKeysLevel4Str = '';
|
554
|
$fnKeysLevel4 = cdm_annotations_as_footnotekeys($element_level4->data);
|
555
|
foreach($element_level4->data->sources as $source){
|
556
|
if(_is_original_source_type($source)){
|
557
|
$fn_key4 = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), theme('cdm_DescriptionElementSource', $source, false));
|
558
|
cdm_add_footnote_to_array($fnKeysLevel4, $fn_key4);
|
559
|
}
|
560
|
}
|
561
|
usort($fnKeysLevel4, "footnotes_key_compare");
|
562
|
$l4_regions[$text_l4] = $fnKeysLevel4;
|
563
|
}
|
564
|
}//level4
|
565
|
//managing level3 and level4 for generating the right output
|
566
|
usort($fnKeysLevel3, "footnotes_key_compare");
|
567
|
foreach ($fnKeysLevel3 as $key3){
|
568
|
foreach ($l4_regions as $key4 => $value4){
|
569
|
cdm_add_footnote_to_array($l4_regions[$key4], $key3);
|
570
|
}
|
571
|
}
|
572
|
if ($element_level3->numberOfChildren == 1 &&
|
573
|
$text_l3 == $element_level3->children[0]->data->area->representation_L10n){
|
574
|
//var_dump($element_level3->children[0]->data->area->representation_L10n);
|
575
|
$fnStr = '';
|
576
|
$region = array_pop($l4_regions);
|
577
|
foreach($region as $key){
|
578
|
$fnStr .= theme('cdm_footnote_key', $key, ($fnStr ? $separator : ''));
|
579
|
}
|
580
|
$out .= "$text_l3 $fnStr; ";
|
581
|
//removing whitespaces when &fnStr is empty
|
582
|
if(substr($out, -3) == ' ; '){
|
583
|
$out = substr($out, 0, -3) . '; ';
|
584
|
}
|
585
|
}else{
|
586
|
$fnKeysLevel3Str = '';
|
587
|
foreach($fnKeysLevel3 as $key){
|
588
|
$fnKeysLevel3Str .= theme('cdm_footnote_key', $key, ($fnKeysLevel3Str ? $separator : ''));
|
589
|
}
|
590
|
$text_l4_aux = '';
|
591
|
foreach ($l4_regions as $key => $value){
|
592
|
$fnKeysLevel4Str = '';
|
593
|
if (is_array($l4_regions[$key])) {
|
594
|
foreach ($l4_regions[$key] as $fnkey){//warning why?
|
595
|
$fnKeysLevel4Str .= theme('cdm_footnote_key', $fnkey, ($fnKeysLevel4Str ? $separator : ''));
|
596
|
}
|
597
|
}
|
598
|
//if ($key != $text_l3 || sizeof($l4_regions > 1)){
|
599
|
if ($key != $text_l3){
|
600
|
$text_l4_aux .= "$key $fnKeysLevel4Str, ";
|
601
|
}
|
602
|
}
|
603
|
$text_l4_aux = substr($text_l4_aux, 0, -2);
|
604
|
|
605
|
if (strlen($text_l4_aux) > 0){
|
606
|
$out .= "$text_l3 $fnKeysLevel3Str ($text_l4_aux); ";
|
607
|
}else{
|
608
|
$out .= "$text_l3 $fnKeysLevel3Str; ";
|
609
|
}
|
610
|
|
611
|
}
|
612
|
}//level3
|
613
|
$out = substr($out, 0, -2);
|
614
|
$out .= '.</dd>';
|
615
|
}//level1
|
616
|
|
617
|
RenderHints::popFromRenderStack();
|
618
|
return $out;
|
619
|
}
|
620
|
|
621
|
function theme_cdm_DescriptionElementSource($descriptionElementSource, $doLink = TRUE){
|
622
|
|
623
|
if(isset($descriptionElementSource->citation)){
|
624
|
$out = theme('cdm_reference', $descriptionElementSource->citation, $descriptionElementSource->citationMicroReference, $doLink);
|
625
|
}
|
626
|
return $out;
|
627
|
}
|
628
|
|
629
|
|
630
|
/*
|
631
|
function theme_cdm_descriptionElementDistribution($descriptionElements){
|
632
|
|
633
|
$out = '';
|
634
|
$separator = ',';
|
635
|
RenderHints::pushToRenderStack('descriptionElementDistribution');
|
636
|
RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
|
637
|
foreach($descriptionElements as $descriptionElement){
|
638
|
// annotations as footnotes
|
639
|
$annotationFootnoteKeys = theme('cdm_annotations_as_footnotekeys', $descriptionElement);
|
640
|
// source references as footnotes
|
641
|
$sourcesFootnoteKeyList = '';
|
642
|
foreach($descriptionElement->sources as $source){
|
643
|
if(_is_original_source_type($source)){
|
644
|
$_fkey = FootnoteManager::addNewFootnote(UUID_DISTRIBUTION, theme('cdm_DescriptionElementSource', $source, false));
|
645
|
$sourcesFootnoteKeyList .= theme('cdm_footnote_key', $_fkey, UUID_DISTRIBUTION, ($sourcesFootnoteKeyList ? $separator : ''));
|
646
|
}
|
647
|
}
|
648
|
if($annotationFootnoteKeys && $sourcesFootnoteKeyList){
|
649
|
$annotationFootnoteKeys .= $separator;
|
650
|
}
|
651
|
$out .= $descriptionElement->area->representation_L10n . $annotationFootnoteKeys . $sourcesFootnoteKeyList . ' ';
|
652
|
}
|
653
|
|
654
|
$out = substr($out, 0, strlen($out)-strlen($separator) );
|
655
|
|
656
|
RenderHints::popFromRenderStack();
|
657
|
return $out;
|
658
|
|
659
|
}
|
660
|
*/
|
661
|
|
662
|
|
663
|
/**
|
664
|
* TODO
|
665
|
* Quick-and-dirty solution to show distribution service to exemplar groups
|
666
|
*
|
667
|
* @param unknown_type $featureTo
|
668
|
* @return unknown
|
669
|
*/
|
670
|
function theme_cdm_distribution_map($taxon){
|
671
|
|
672
|
$server = getEDITMapServiceURI();
|
673
|
|
674
|
if(!$server){
|
675
|
//warning message
|
676
|
drupal_set_message('No \'Geoservice Access Point\' has been set so far. '
|
677
|
. 'Please configure the variable \'Geoservice Access Point\' here '
|
678
|
. l('CDM Dataportal Settings', 'admin/settings/cdm_dataportal/geo'), 'warning');
|
679
|
//message to render
|
680
|
return "<p>No geoservice specified</p>";
|
681
|
}else{
|
682
|
$fontStyles = array(0 => "plane", 1 => "italic");
|
683
|
|
684
|
$map_data_parameters = cdm_ws_get(CDM_WS_GEOSERVICE_DISTRIBUTIONMAP, $taxon->uuid);
|
685
|
$query_string = $map_data_parameters->String;
|
686
|
if(!$query_string){
|
687
|
// the $query_string is empty if there are no distribution areas defined
|
688
|
return ;
|
689
|
}
|
690
|
|
691
|
$query_string = str_replace('%3A', ":", $query_string);
|
692
|
|
693
|
$display_width = variable_get('cdm_dataportal_geoservice_display_width', false);
|
694
|
$bounding_box = variable_get('cdm_dataportal_geoservice_bounding_box', false);
|
695
|
$labels_on = variable_get('cdm_dataportal_geoservice_labels_on', 0);
|
696
|
|
697
|
$query_string .= ($display_width ? '&img=false&ms=' . $display_width: '').
|
698
|
($bounding_box ? '&bbox=' . $bounding_box : '')
|
699
|
. ($labels_on ? '&labels=' . $labels_on : '');
|
700
|
|
701
|
if(variable_get('cdm_dataportal_map_openlayers', 1)){
|
702
|
|
703
|
/* =========== display distributions using the openlayers map viewer =========== */
|
704
|
|
705
|
$legend_url_font_size = variable_get('cdm_dataportal_geoservice_legend_font_size', 10);
|
706
|
$legend_url_font_style = variable_get('cdm_dataportal_geoservice_legend_font_style', 1);
|
707
|
$legend_url_font_style = $fontStyles[$legend_url_font_style];
|
708
|
$legend_url_icon_width = variable_get('cdm_dataportal_geoservice_legend_icon_width', 35);
|
709
|
$legend_url_icon_height = variable_get('cdm_dataportal_geoservice_legend_icon_height', 15);
|
710
|
|
711
|
//$legendQueryStr = $geoserver_uri . "/GetLegendGraphic?SERVICE=WMS&VERSION=1.1.1&format=image".urlencode('/')."png&TRANSPARENT=TRUE";
|
712
|
$legendFormatQueryStr = "format=image".urlencode('/')."png&TRANSPARENT=TRUE";
|
713
|
$legendFormatQueryStr .= "&WIDTH=".$legend_url_icon_width."&HEIGHT=".$legend_url_icon_height."&";
|
714
|
$legendFormatQueryStr .="layer=topp".urlencode(':')."tdwg_level_4&LEGEND_OPTIONS=forceLabels".urlencode(':')."on;fontStyle".urlencode(':').$legend_url_font_style.";fontSize".urlencode(':').$legend_url_font_size."&SLD=".urlencode($sldLegend);
|
715
|
|
716
|
$out = get_openlayers_map(
|
717
|
$display_width,
|
718
|
null,
|
719
|
$query_string,
|
720
|
$legendFormatQueryStr,
|
721
|
variable_get('cdm_dataportal_geoservice_map_caption', '')
|
722
|
);
|
723
|
|
724
|
} else {
|
725
|
// simple image
|
726
|
$mapStaticCaption = '&mc_s=Georgia,15,blue&mc=' . variable_get('cdm_dataportal_geoservice_map_caption', '');
|
727
|
|
728
|
$query_string .= ($display_width ? '&img=true&ms=' . $display_width: '')
|
729
|
.'&img=true&legend=1&mlp=3' . $mapStaticCaption . '&recalculate=false';
|
730
|
|
731
|
$mapUri = url($server. '/areas.php?' .$map_data_parameters->String, $query_string);
|
732
|
$out .= '<img class="distribution_map" src="' . $mapUri . '" alt="Distribution Map" />';
|
733
|
}
|
734
|
/*
|
735
|
// add a simple legend
|
736
|
if(variable_get('cdm_dataportal_geoservice_legend_on', TRUE)){
|
737
|
$legenddata = array(
|
738
|
'native' => "4daf4a",
|
739
|
'native_doubtfully_native' => "377eb8",
|
740
|
'cultivated' => "984ea3",
|
741
|
'introduced' => "ff7f00",
|
742
|
'introduced adventitious' => "ffff33",
|
743
|
'introduced cultivated' => "a65628",
|
744
|
'introduced naturalized' => "f781bf"
|
745
|
);
|
746
|
|
747
|
$out .= '<div class="distribution_map_legend">';
|
748
|
foreach($legenddata as $term => $color){
|
749
|
$out .= '<img style="width: 3em; height: 1em; background-color: #'.$color.'" src="'.
|
750
|
drupal_get_path('module', 'cdm_dataportal').'/images/clear.gif" />'.t($term).' ';
|
751
|
}
|
752
|
$out .= '</div>';
|
753
|
|
754
|
}
|
755
|
*/
|
756
|
return $out;
|
757
|
}
|
758
|
}
|