Project

General

Profile

Download (37.3 KB) Statistics
| Branch: | Tag: | Revision:
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
/**
42
 * Renders the taxon profile. The taxon profile consists of description elements
43
 * which are ordered by the structure defined by specific FeatureTree. The chosen
44
 * FeatureTree is merged with the list of desctiprion elements prior to using this
45
 * method (see function cdm_ws_descriptions_by_featuretree() ).
46
 *
47
 * @param unknown_type $mergedTrees
48
 * @param unknown_type $taxon The taxon whose sprofile to show
49
 */
50
function theme_cdm_featureTrees($mergedTrees, $taxon){
51
	if(!$mergedTrees){
52
		return;
53
	}
54
	foreach($mergedTrees as &$mTree){
55
		//TODO diplay title and reference in case of multiple $mergedTrees -> theme
56
		$out .= theme('cdm_feature_nodes', $mTree->root->children, $taxon);
57
	}
58
	return $out;
59
}
60

    
61

    
62

    
63
function theme_cdm_featureTreeTOCs($mergedTrees){
64

    
65
	if(!$mergedTrees){
66
		return;
67
	}
68
	//FIXME
69
	$out = '<div class="featureTOC">';
70
	$out .= '<h2>' . t('Content') .'</h2>';
71

    
72
	//TODO diplay title and reference in case of multiple $mergedTrees -> theme
73

    
74
	foreach($mergedTrees as &$mTree){
75
		$out .= theme('cdm_feature_nodesTOC', $mTree->root->children);
76
	}
77

    
78
	$out .= '</div>';
79
	return $out;
80
}
81

    
82

    
83

    
84
function theme_cdm_feature_nodes($featureNodes, $taxon){
85

    
86
	RenderHints::pushToRenderStack('feature_nodes');
87
	$gallery_settings = getGallerySettings(CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME);
88

    
89
	foreach($featureNodes as $node){
90
		// process $descriptionElements with content only
91
		if(is_array($node->descriptionElements) && count($node->descriptionElements) > 0 || count($node->children) > 0){
92
			$featureRepresentation = isset($node->feature->representation_L10n) ? $node->feature->representation_L10n : 'Feature';
93
			$block->module = 'cdm_dataportal';
94

    
95
			if($node->feature->uuid != UUID_IMAGE){
96
				$block->delta = generalizeString($featureRepresentation);
97
				$block->subject = theme('cdm_feature_name', $featureRepresentation);
98
				$block->module = "cdm_dataportal-feature";
99
				$block->content = '';
100

    
101
				if($node->feature->uuid == UUID_DISTRIBUTION){
102

    
103
					if(variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0)){
104
						$distributionTextDataList = array();
105
						$distributionElementsList = array();
106
	          foreach($node->descriptionElements as $descriptionElement){
107
	          	if($descriptionElement->class == "TextData"){
108
	          		$distributionTextDataList[] = $descriptionElement;
109
	          	} else {
110
	          		$distributionElementsList[] = $descriptionElement;
111
	          	}
112
	          }
113
	          if(count($distributionTextDataList) > 0){
114
	          	$node->descriptionElements = $distributionElementsList;
115
	          	$block->content .= theme('cdm_descriptionElements', $distributionTextDataList, $node->feature->uuid, $taxon->uuid);
116
	          }
117
					}
118

    
119
					// Display cdm distribution map TODO this is a HACK to a proper generic implementation?
120
					$block->content .= theme('cdm_distribution_map', $taxon);
121
				}
122

    
123
				//get the text for the feature block
124
				//if ($node->feature->titleCache == 'Common Name'){
125
				if ($node->feature->uuid == UUID_COMMON_NAME){
126
					$block->content .= theme('cdm_common_names', $node->descriptionElements);
127
				/*
128
				}else if($node->feature->uuid == UUID_IMAGE_SOURCES) {
129
					$block->content .= theme('cdm_image_sources', $node->descriptionElements);
130
				*/
131
				} else {
132
					$block->content .= theme('cdm_descriptionElements', $node->descriptionElements, $node->feature->uuid, $taxon->uuid);
133
				}
134

    
135
				// get media for the feature block
136
				$media_list = cdm_dataportal_media_from_descriptionElements($node->descriptionElements);
137
				$captionElements = array('title', 'rights');
138
				//$block->content .= theme('cdm_media_gallerie', $media_list, "test", 150, 4, false, $captionElements);
139
				$block->content .= theme('cdm_media_gallery', $media_list,
140
				CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME.'_'.$node->feature->uuid,
141
				$gallery_settings['cdm_dataportal_media_maxextend'],
142
				$gallery_settings['cdm_dataportal_media_cols'],
143
				$gallery_settings['cdm_dataportal_media_maxRows'],
144
				$captionElements
145
				);
146

    
147
				$block->content .= theme('cdm_footnotes', $node->feature->uuid);
148
				$block->content .= theme('cdm_annotation_footnotes', $node->feature->uuid);
149

    
150
				// set anchor; FIXME put anchor in $block->subject
151
				$out .= '<a name="'.$block->delta.'"></a>';
152
				$out .= theme('block', $block);
153

    
154
			}
155
		}
156
		// theme
157
		if(count($node->children) > 0){
158
			//TODO support more than one level of childen http://dev.e-taxonomy.eu/trac/ticket/2393
159
			$text = '';
160
			foreach ($node->children as $child){
161
			 //$out .= theme('cdm_descriptionElementTextData', $child->descriptionElements[0], false);
162
			 if (is_array($child->descriptionElements)){//if condition added to avoid warnings
163
			 	foreach ($child->descriptionElements as $element) {
164
			 		$description = str_replace("\n", "<br/>", $element->multilanguageText_L10n->text);
165
					//TODO use localized version of feature name, the locale must match the locale of the multilanguage text (http://dev.e-taxonomy.eu/trac/ticket/2394)
166
			 		$description = str_replace($element->feature->titleCache, '<em>' . $element->feature->titleCache . '</em>', $description);
167
			 	}
168
			 	$text .= " " . $description;
169
			 	$description = '';
170
			 }
171
			}
172
			$out .= $text;
173
		}
174

    
175
	}
176
	RenderHints::popFromRenderStack();
177
	return $out;
178
}
179

    
180
function theme_FeatureTree_hierarchy($FeatureTreeUuid){
181

    
182
	if(!is_uuid($FeatureTreeUuid)){
183
		return;
184
	}
185
  $out = '';
186
	$featureTree = cdm_ws_get(CDM_WS_FEATURETREE, array($FeatureTreeUuid));
187
	if($featureTree && $featureTree->root){
188
		$out = '<ul class="'.$featureTree->class.'">';
189
		$out .= theme('FeatureTree_hierarchy_children', $featureTree->root);
190
		$out .= '</ul>';
191
	}
192
	return $out;
193
}
194

    
195
function theme_FeatureTree_hierarchy_children($node){
196

    
197
	$out = '';
198
	if($node->children){
199

    
200
		foreach($node->children as $childNode){
201
      $out .= '<li>'.check_plain($childNode->feature->representation_L10n);
202
      if($childNode->childen && count($childNode->childen) > 0){
203
      	$out .= '<ul>'.theme('FeatureTree_hierarchy_children', $childNode).'</ul>';
204
      }
205
      $out .= '</li>';
206
		}
207
	}
208
	return $out;
209
}
210

    
211

    
212

    
213

    
214
function theme_cdm_descriptionElementArray($elementArray, $feature, $glue = '', $sortArray = false, $enclosingHtml = 'ul'){
215
	$out = '<'.$enclosingHtml.' class="description" id="'.$feature->representation_L10n.'">';
216

    
217
	if($sortArray) sort($elementArray);
218

    
219
	$out .= join($elementArray, $glue);
220

    
221
	$out .= '</'.$enclosingHtml.'>';
222
	return $out;
223
}
224

    
225

    
226
function theme_cdm_descriptionElement_CommonTaxonName($element){
227
	$out = $element->language->representation_L10n . ' (' . $element->area->titleCache . '): ' . $element->name;
228
	return $out;
229
}
230

    
231

    
232
/**
233
 * TODO: assign a new name to the function? because it is used for the citations
234
 *       textdata elements and not for all text data description elements
235
 * @param $element The description element which contains the text information
236
 * @param $asListElement A boolean which determines whether the citations should
237
 *                       be renderer as a list or not
238
 * @return unknown_type Html to be renderized in drupal
239
 */
240
function theme_cdm_descriptionElementTextData($element, $asListElement, $feature_uuid = null){
241
	$description = str_replace("\n", "<br/>", $element->multilanguageText_L10n->text);
242
	$sourceRefs = '';
243
	$result = array();
244
	$out;
245
	$res_author;
246
	$res_date;
247

    
248
	if(is_array($element->sources)){
249
		foreach($element->sources as $source){
250
		  $referenceCitation = theme('cdm_DescriptionElementSource', $source);
251
      if($description && strlen($description) > 0 && $referenceCitation ){
252
        $sourceRefs .= ' ('.$referenceCitation.')' ;
253
      }else if ($referenceCitation){
254
        $sourceRefs = $referenceCitation;
255
      }
256

    
257
      if(strlen($sourceRefs) > 0){
258
        $sourceRefs = '<span class="sources">' . $sourceRefs . '</span>';
259
      }
260

    
261
      if ($source->nameUsedInSource->uuid){ //do a link to name page
262
        $name_used_in_source_link_to_show = l($source->nameUsedInSource->titleCache,
263
        path_to_name($source->nameUsedInSource->uuid),
264
        array(), NULL, NULL, FALSE ,TRUE);
265
      }else if (strlen($source->nameUsedInSource->originalNameString) > 0){ //show a text without link
266
        $name_used_in_source_link_to_show = $source->nameUsedInSource->originalNameString;
267
      }
268

    
269
      if ($asListElement){
270
        $out = '<li class="descriptionText">' . $name_used_in_source_link_to_show;
271
        //adding ":" if necesary
272
        if ($name_used_in_source_link_to_show && ($description || $sourceRefs)){
273
          $out .= ': ';
274
        }
275
        $out .= $description . $sourceRefs . theme('cdm_annotations_as_footnotekeys', $element) . '</li>';
276
      }else{
277
        if ($name_used_in_source_link_to_show){
278
          $name_used_in_source_link_to_show = ' (name in source: '. $name_used_in_source_link_to_show . ')';
279
        }
280
        $out = $description . $sourceRefs . $name_used_in_source_link_to_show;
281
      }
282
		}
283
	}
284
	//if no sources, print the description
285
	if(!isset($out)) {
286
		$out = $description;
287
	}
288
	//printing annotations footnotes
289
	//$out .= theme('cdm_annotations_as_footnotekeys', $element);
290
	// add annotations as footnote key
291
	//$out .= theme('cdm_annotations_as_footnotekeys', $element); move above
292
	return $out;
293
}
294

    
295

    
296
function theme_cdm_common_names($elements){
297
	$text_data_out = '';
298
	$common_name_out = '';
299
	$separator = ',';
300
	$textData_commonNames = array();
301

    
302

    
303
	if (is_array($elements)){
304
		foreach ($elements as $element){
305
			if ($element->class == 'CommonTaxonName'){
306
				//$key = '<b>' . $element->language->representation_L10n . '</b> (' . $element->area->titleCache . ')';
307
				if ($element->language->representation_L10n){
308
					$key = '<b>' . $element->language->representation_L10n . '</b>';
309
					$key .= (strlen($element->area->titleCache)>0) ? ' (' . $element->area->titleCache . ')' : '';
310
				}
311
				$common_names[$key][] = $element;
312
			}else if ($element->class == 'TextData'){
313
		 //else if ($element->class == 'TextData' && $element->feature->uuid == UUID_COMMON_NAME){
314
				$textData_commonNames[] = $element;
315
			}
316
		}
317
	}
318
	//handling common names
319

    
320
	if (count($common_names) > 0){
321
		//sorting the a-array based on the area (key)
322
		ksort($common_names);
323
		//creating the output to be render by drupal
324
		foreach ($common_names as $key => $elements){
325
			$rendered_element_list = '';
326
			foreach($elements as $element){
327
				$sourcesFootnoteKeyList = '';
328
				// adding footnotes sources
329
				foreach($element->sources as $source){
330
					if(_is_original_source_type($source)){
331
						$_fkey = FootnoteManager::addNewFootnote(UUID_COMMON_NAME, theme('cdm_DescriptionElementSource', $source, false));
332
						$sourcesFootnoteKeyList .= theme('cdm_footnote_key', $_fkey, ($sourcesFootnoteKeyList ? $separator : ''));
333
					}
334
				}
335
				if($element->name){
336
				  $rendered_element_list .= (strlen($rendered_element_list) > 0 ? ', ': '') . $element->name . $sourcesFootnoteKeyList;
337
			  }
338
			}
339
			if ($key){
340
			 $common_name_out .= (strlen($common_name_out) > 0 ? '; ': '') . $key . ': ' . $rendered_element_list;
341
			}else{
342
			  $common_name_out .= (strlen($common_name_out) > 0 ? '; ': '') . $rendered_element_list;
343
			}
344
		}
345
	}
346
	//handling commons names as text data
347
	foreach($textData_commonNames as $text_data_element){
348
		$text_data_out .= theme('cdm_descriptionElementTextData', $text_data_element, true, $text_data_element->feature->uuid);
349
	}
350

    
351
	$common_name_out = "<div class=common_names_as_common_names> $common_name_out </div>";
352
    $out_array[] = $text_data_out;
353
	$common_name_out_text_data = '<div class=common_names_as_text_data>' . theme('cdm_descriptionElementArray', $out_array, $element->feature) . '</div>';
354

    
355
	return $common_name_out . $common_name_out_text_data;
356
	//return $common_name_out . theme('cdm_descriptionElementArray', $out_array, $element->feature);
357
	//return "<div class=common_names> $common_name_out $common_name_out_text_data";
358
}
359

    
360
/**
361
 * Theme a list of description elements, usually of a specific feature type
362
 * @param $descriptionElements
363
 * @return unknown_type
364
 */
365
function theme_cdm_descriptionElements($descriptionElements, $featureUuid, $taxon_uuid){
366
	$outArray = array();
367
	if(variable_get('distribution_sort', 'NO_SORT')  != 'NO_SORT'){
368
		$glue = '';
369
		$enclosingHtml = 'dl';
370
	} else {
371
		$glue = '';
372
		$enclosingHtml = 'ul';
373
	}
374
	$sortOutArray = false;
375
	$distributionElements = array();
376

    
377
	RenderHints::pushToRenderStack('cdm_descriptionElements');
378
	//$common_names = theme('cdm_common_names', $descriptionElements);
379
	if(is_array($descriptionElements)){//avoiding warning box in drupal for flora malesiana
380
		foreach($descriptionElements as $descriptionElement){
381
			if($descriptionElement->feature->uuid == UUID_DISTRIBUTION){
382
				if($descriptionElement->class == 'Distribution'){
383
					$distributionElements[]= $descriptionElement;
384
				} else if($descriptionElement->class == 'TextData'){
385
					$asListElement = false;
386
					$repr = theme ('cdm_descriptionElementTextData', $descriptionElement, $asListElement, $descriptionElement->feature->uuid);
387

    
388
					if( !array_search($repr, $outArray)){
389
						$outArray[] = $repr;
390
						$glue = '<br/> ';
391
						$sortOutArray = true;
392
						$enclosingHtml = 'p';
393
					}
394
				}
395
			}else if($descriptionElement->feature->uuid == UUID_IMAGE_SOURCES){
396
				$image_sources[] = $descriptionElement;
397
			}else if($descriptionElement->class == 'TextData'){
398
				$asListElement = true;
399
				$outArray[] = theme('cdm_descriptionElementTextData', $descriptionElement, $asListElement, $descriptionElement->feature->uuid);
400
			}else if ($descriptionElement->class == 'CommonTaxonName') {
401
				$outArray[] = theme('cdm_descriptionElement_CommonTaxonName', $descriptionElement);
402
			}else {
403
				$outArray[] = '<li>No method for rendering unknown description class: '.$descriptionElement->classType.'</li>';
404
			}
405
		}
406
	}
407
	//if feature = NAME USAGE sort the list of sources
408
	//this is ONLY for FLORA MALESIANA and FLORE d'AFRIQUE CENTRALE
409
	if($descriptionElement->feature->uuid == UUID_NAME_USAGE){
410
		sort($outArray);
411
	}
412
    if($image_sources){
413
        $outArray[] = theme('cdm_description_element_image_source', $image_sources, true);
414

    
415
    }
416
	if(variable_get('distribution_sort', 'NO_SORT') != 'NO_SORT'){
417
		$outArray[] = theme('cdm_description_ordered_distributions', $taxon_uuid, $distributionElements);
418
	}else{
419
		$outArray[] = theme('cdm_descriptionElementDistribution', $distributionElements);
420
	}
421
	//$outArray[] = theme('cdm_descriptionElementDistribution', $distributionElements);
422
	//$outArray[] = theme('cdm_description_ordered_distributions', $taxon_uuid, $distributionElements);
423

    
424
	// take the feature of the last $descriptionElement
425
	$feature = $descriptionElement->feature;
426
	$out = theme('cdm_descriptionElementArray', $outArray, $feature, $glue, $sortOutArray, $enclosingHtml);
427

    
428
	RenderHints::popFromRenderStack();
429
	return $out;
430
}
431

    
432
function compare_image_sources($a, $b){
433
    if($a->multilanguageText_L10n->text == $b->multilanguageText_L10n->text){
434
    	return 0;
435
    }
436
    return ($a->multilanguageText_L10n->text < $b->multilanguageText_L10n->text) ? -1 : 1;
437
}
438

    
439
/**
440
 *
441
 */
442
function theme_cdm_description_element_image_source($image_sources, $asListElement) {
443
    $out = '';
444
    $separator = ',';
445
    RenderHints::pushToRenderStack('descriptionElementImageSource');
446
    RenderHints::setFootnoteListKey(UUID_IMAGE_SOURCES);
447

    
448
    //sorting the image sources
449
    usort($image_sources, "compare_image_sources");
450
    //generate the footnotes
451
    foreach($image_sources as $image_source){
452
        $footNoteKeys = cdm_annotations_as_footnotekeys($image_source);
453
        foreach($image_source->sources as $source){
454
            if(_is_original_source_type($source)){
455
                $fn_key = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), theme('cdm_DescriptionElementSource', $source, false));
456
                cdm_add_footnote_to_array($footNoteKeys, $fn_key);// ensure uniqueness of the footnote keys
457
            }
458
        }
459
        //sort and render footnote keys
460
        $footnoteKeyListStr = '';
461
        asort($footNoteKeys);
462
        foreach($footNoteKeys as $footNoteKey){
463
            $footnoteKeyListStr .= theme('cdm_footnote_key', $footNoteKey, ($footnoteKeyListStr ? $separator : ''));
464
        }
465
        //return value!
466
        $out .= '<span class="descriptionElement descriptionElement-'.$image_source->uuid.'">'.$image_source->multilanguageText_L10n->text . $footnoteKeyListStr . '; </span>';
467

    
468
    }
469

    
470
    RenderHints::popFromRenderStack();
471
    return $out;
472
}
473

    
474
/**
475
 *
476
 * @param unknown_type $descriptionElements
477
 * @return unknown_type
478
 */
479
function theme_cdm_descriptionElementDistribution($descriptionElements){
480
	$out = '';
481
	$separator = ',';
482
	RenderHints::pushToRenderStack('descriptionElementDistribution');
483
	RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
484
	foreach($descriptionElements as $descriptionElement){
485
		// annotations as footnotes
486
		//$annotationFootnoteKeys = theme('cdm_annotations_as_footnotekeys', $descriptionElement);
487
		$footNoteKeys = cdm_annotations_as_footnotekeys($descriptionElement);
488
		// source references as footnotes
489
		foreach($descriptionElement->sources as $source){
490
			if(_is_original_source_type($source)){
491
				$fn_key = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), theme('cdm_DescriptionElementSource', $source, false));
492
				cdm_add_footnote_to_array($footNoteKeys, $fn_key);// ensure uniqueness of the footnote keys
493
			}
494
		}
495
		// sort and render footnote keys
496
		$footnoteKeyListStr = '';
497
		asort($footNoteKeys);
498
		foreach($footNoteKeys as $footNoteKey){
499
			$footnoteKeyListStr .= theme('cdm_footnote_key', $footNoteKey, ($footnoteKeyListStr ? $separator : ''));
500
		}
501
		$out .= '<span class="descriptionElement descriptionElement-'.$descriptionElement->uuid.'">'.$descriptionElement->area->representation_L10n . $footnoteKeyListStr . ' </span>';
502
	}
503

    
504
	//$out = substr($out, 0, strlen($out)-strlen($separator) );
505

    
506
	RenderHints::popFromRenderStack();
507
	return $out;
508
}
509
/**
510
 * Function target is to compare two different foootnotes objects.
511
 * The comparation is based on the footnote key. The one which is
512
 * displayed as footnote number.
513
 *
514
 * @param footnote object $a
515
 * @param footnote object $b
516
 */
517
function footnotes_key_compare($a, $b){
518
	$res = 0;
519
	if ($a->keyStr < $b->keyStr){
520
		$res = -1;
521
	}elseif ($a->keyStr > $b->keyStr){
522
		$res = 1;
523
	}
524
	return $res;
525
}
526

    
527
function theme_cdm_description_ordered_distributions($taxon_uuid, $descriptionElements){
528
	//returning null if no description elements
529
	if ($descriptionElements == null){
530
		return '';
531
	}
532
	//initialization some variables
533
	$out = '';
534
	$separator = ',';
535
	RenderHints::pushToRenderStack('descriptionElementDistribution');
536
	RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
537
	//getting all the taxon description for a given taxon
538
	$taxonDescriptions = cdm_ws_get(CDM_WS_PORTAL_TAXON_DESCRIPTIONS, $taxon_uuid);
539
	foreach ($taxonDescriptions as $description){
540
		$descriptions_uuids[] = $description->uuid;
541
	}
542
	//getting the sortered distributions (omiting level ??)
543
	$request_params = array();
544
	$request_params['omitLevels'] = UUID_NAMEDAREALEVEL_TDWGLEVEL_2;
545
	$ordered_areas = cdm_ws_get(CDM_WS_PORTAL_DESCRIPTION_DISTRIBUTION_TREE, join(',',$descriptions_uuids), queryString($request_params));
546
	$ordered_areas = $ordered_areas->rootElement->children;
547

    
548
	//printing the distributions
549
	foreach ($ordered_areas as $element_level1){
550
		//level1
551
		if ($element_level1->data){
552
			$out .= '<dt>' . $element_level1->data->area->representation_L10n . ':</dt> ';
553
		}
554
		$out .= '<dd>';
555

    
556
		//level3
557
		foreach ($element_level1->children as $element_level3){
558
			if ($element_level3->data){
559
				$text_l3 = $element_level3->data->area->representation_L10n;
560
			}
561
			$fnKeysLevel3Str = '';
562
			$fnKeysLevel3 = cdm_annotations_as_footnotekeys($element_level3->data);
563
			foreach($element_level3->data->sources as $source){
564
				if(_is_original_source_type($source)){
565
					$fn_key3 = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), theme('cdm_DescriptionElementSource', $source, false));
566
					cdm_add_footnote_to_array($fnKeysLevel3, $fn_key3);
567
				}
568
			}
569
			//level4
570
			$l4_regions = array();
571
			foreach ($element_level3->children as $element_level4){
572
				if ($element_level4->data){
573
					$text_l4 = $element_level4->data->area->representation_L10n;
574
					$l4_regions[$element_level3->data->area->representation_L10n] = '';
575
					$fnKeysLevel4Str = '';
576
					$fnKeysLevel4 = cdm_annotations_as_footnotekeys($element_level4->data);
577
					foreach($element_level4->data->sources as $source){
578
						if(_is_original_source_type($source)){
579
							$fn_key4 = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), theme('cdm_DescriptionElementSource', $source, false));
580
							cdm_add_footnote_to_array($fnKeysLevel4, $fn_key4);
581
						}
582
					}
583
					usort($fnKeysLevel4, "footnotes_key_compare");
584
					$l4_regions[$text_l4] = $fnKeysLevel4;
585
				}
586
			}//level4
587
			//managing level3 and level4 for generating the right output
588
			usort($fnKeysLevel3, "footnotes_key_compare");
589
			foreach ($fnKeysLevel3 as $key3){
590
				foreach ($l4_regions as $key4 => $value4){
591
					cdm_add_footnote_to_array($l4_regions[$key4], $key3);
592
				}
593
			}
594
			if ($element_level3->numberOfChildren == 1 &&
595
			 $text_l3 == $element_level3->children[0]->data->area->representation_L10n){
596
				//var_dump($element_level3->children[0]->data->area->representation_L10n);
597
				$fnStr = '';
598
				$region = array_pop($l4_regions);
599
				foreach($region as $key){
600
					$fnStr .= theme('cdm_footnote_key', $key, ($fnStr ? $separator : ''));
601
				}
602
				$out .= "$text_l3 $fnStr; ";
603
	            //removing whitespaces when &fnStr is empty
604
				if(substr($out, -3) == ' ; '){
605
					$out = substr($out, 0, -3) . '; ';
606
				}
607
			}else{
608
				$fnKeysLevel3Str = '';
609
				foreach($fnKeysLevel3 as $key){
610
					$fnKeysLevel3Str .= theme('cdm_footnote_key', $key, ($fnKeysLevel3Str ? $separator : ''));
611
				}
612
				$text_l4_aux = '';
613
				foreach ($l4_regions as $key => $value){
614
					$fnKeysLevel4Str = '';
615
					if (is_array($l4_regions[$key])) {
616
						foreach ($l4_regions[$key] as $fnkey){//warning why?
617
							$fnKeysLevel4Str .= theme('cdm_footnote_key', $fnkey, ($fnKeysLevel4Str ? $separator : ''));
618
						}
619
					}
620
					//if ($key != $text_l3 || sizeof($l4_regions > 1)){
621
					if ($key != $text_l3){
622
						$text_l4_aux .= "$key $fnKeysLevel4Str, ";
623
					}
624
				}
625
				$text_l4_aux = substr($text_l4_aux, 0, -2);
626

    
627
				if (strlen($text_l4_aux) > 0){
628
					$out .= "$text_l3 $fnKeysLevel3Str ($text_l4_aux); ";
629
				}else{
630
					$out .= "$text_l3 $fnKeysLevel3Str; ";
631
				}
632

    
633
			}
634
		}//level3
635
		$out = substr($out, 0, -2);
636
		$out .= '.</dd>';
637
	}//level1
638

    
639
	RenderHints::popFromRenderStack();
640
	return $out;
641
}
642

    
643
function theme_cdm_DescriptionElementSource($descriptionElementSource, $doLink = TRUE){
644

    
645
	if(isset($descriptionElementSource->citation)){
646
		$out = theme('cdm_reference', $descriptionElementSource->citation, $descriptionElementSource->citationMicroReference, $doLink);
647
	}
648
	return $out;
649
}
650

    
651
function theme_cdm_IdentifieableSource($source, $doLink = TRUE){
652

    
653
  if(isset($source->citation)){
654
    $out = theme('cdm_reference', $source->citation, $source->citationMicroReference, $doLink);
655
  }
656
  return $out;
657
}
658

    
659

    
660

    
661

    
662

    
663
/*
664
 function theme_cdm_descriptionElementDistribution($descriptionElements){
665

    
666
 $out = '';
667
 $separator = ',';
668
 RenderHints::pushToRenderStack('descriptionElementDistribution');
669
 RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
670
 foreach($descriptionElements as $descriptionElement){
671
 // annotations as footnotes
672
 $annotationFootnoteKeys = theme('cdm_annotations_as_footnotekeys', $descriptionElement);
673
 // source references as footnotes
674
 $sourcesFootnoteKeyList = '';
675
 foreach($descriptionElement->sources as $source){
676
 if(_is_original_source_type($source)){
677
 $_fkey = FootnoteManager::addNewFootnote(UUID_DISTRIBUTION, theme('cdm_DescriptionElementSource', $source, false));
678
 $sourcesFootnoteKeyList .= theme('cdm_footnote_key', $_fkey, UUID_DISTRIBUTION, ($sourcesFootnoteKeyList ? $separator : ''));
679
 }
680
 }
681
 if($annotationFootnoteKeys && $sourcesFootnoteKeyList){
682
 $annotationFootnoteKeys .= $separator;
683
 }
684
 $out .= $descriptionElement->area->representation_L10n . $annotationFootnoteKeys . $sourcesFootnoteKeyList . ' ';
685
 }
686

    
687
 $out = substr($out, 0, strlen($out)-strlen($separator) );
688

    
689
 RenderHints::popFromRenderStack();
690
 return $out;
691

    
692
 }
693
 */
694

    
695

    
696
/**
697
 * TODO
698
 * Quick-and-dirty solution to show distribution service to exemplar groups
699
 *
700
 * @param unknown_type $featureTo
701
 * @return unknown
702
 */
703
function theme_cdm_distribution_map($taxon){
704

    
705
	$server = getEDITMapServiceURI();
706

    
707
	if(!$server){
708
		//warning message
709
		drupal_set_message('No \'Geoservice Access Point\' has been set so far. '
710
		. 'Please configure the variable \'Geoservice Access Point\' here '
711
		. l('CDM Dataportal Settings', 'admin/settings/cdm_dataportal/geo'), 'warning');
712
		//message to render
713
		return "<p>No geoservice specified</p>";
714
	}else{
715
		$fontStyles = array(0 => "plane", 1 => "italic");
716

    
717
		$map_data_parameters = cdm_ws_get(CDM_WS_GEOSERVICE_DISTRIBUTIONMAP, $taxon->uuid);
718
		$out .= "<!-- map_data_parameters:". print_r($map_data_parameters, true) . " -->";
719
		$query_string = $map_data_parameters->String;
720
		if(!$query_string){
721
			// the $query_string is empty if there are no distribution areas defined
722
			return ;
723
		}
724

    
725
		$query_string = str_replace('%3A', ":", $query_string);
726

    
727
		$display_width = variable_get('cdm_dataportal_geoservice_display_width', false);
728
		$bounding_box = variable_get('cdm_dataportal_geoservice_bounding_box', false);
729
		$labels_on = variable_get('cdm_dataportal_geoservice_labels_on', 0);
730

    
731
		$query_string .= ($display_width ? '&img=false&ms=' . $display_width: '').
732
		($bounding_box ? '&bbox=' .  $bounding_box : '')
733
		. ($labels_on ? '&labels=' .  $labels_on : '');
734

    
735
		/* ------ choose the display mode, either openlayers or static image ------ */
736

    
737
		if(variable_get('cdm_dataportal_map_openlayers', 1)){
738

    
739
			/* =========== display distributions using the openlayers map viewer =========== */
740

    
741
			$legend_url_font_size = variable_get('cdm_dataportal_geoservice_legend_font_size', 10);
742
			$legend_url_font_style = variable_get('cdm_dataportal_geoservice_legend_font_style', 1);
743
			$legend_url_font_style = $fontStyles[$legend_url_font_style];
744
			$legend_url_icon_width  = variable_get('cdm_dataportal_geoservice_legend_icon_width', 35);
745
			$legend_url_icon_height = variable_get('cdm_dataportal_geoservice_legend_icon_height', 15);
746

    
747
			//$legendQueryStr  = $geoserver_uri . "/GetLegendGraphic?SERVICE=WMS&VERSION=1.1.1&format=image".urlencode('/')."png&TRANSPARENT=TRUE";
748
			$legendFormatQueryStr  = "format=image".urlencode('/')."png&TRANSPARENT=TRUE";
749
			$legendFormatQueryStr .= "&WIDTH=".$legend_url_icon_width."&HEIGHT=".$legend_url_icon_height."&";
750
			$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);
751

    
752
			$out .= get_openlayers_map(
753
			$display_width,
754
			null,
755
			$query_string,
756
			$legendFormatQueryStr,
757
			variable_get('cdm_dataportal_geoservice_map_caption', '')
758
			);
759

    
760
		} else {
761
			// simple image
762
			$mapStaticCaption = '&mc_s=Georgia,15,blue&mc=' . variable_get('cdm_dataportal_geoservice_map_caption', '');
763

    
764
			$query_string .= ($display_width ? '&img=true&ms=' . $display_width: '')
765
			.'&img=true&legend=1&mlp=3' . $mapStaticCaption . '&recalculate=false';
766

    
767
			$mapUri = url($server. '/areas.php?' .$map_data_parameters->String, $query_string);
768
			$out .= '<img class="distribution_map" src="' . $mapUri . '" alt="Distribution Map" />';
769
		}
770
		/*
771
		 // add a simple legend
772
		 if(variable_get('cdm_dataportal_geoservice_legend_on', TRUE)){
773
		 $legenddata = array(
774
		 'native' => "4daf4a",
775
		 'native_doubtfully_native' => "377eb8",
776
		 'cultivated' => "984ea3",
777
		 'introduced' => "ff7f00",
778
		 'introduced adventitious' => "ffff33",
779
		 'introduced cultivated' => "a65628",
780
		 'introduced naturalized' => "f781bf"
781
		 );
782

    
783
		 $out .= '<div class="distribution_map_legend">';
784
		 foreach($legenddata as $term => $color){
785
		 $out .= '<img style="width: 3em; height: 1em; background-color: #'.$color.'" src="'.
786
		 drupal_get_path('module', 'cdm_dataportal').'/images/clear.gif" />'.t($term).' ';
787
		 }
788
		 $out .= '</div>';
789

    
790
		 }
791
		 */
792
		return $out;
793
	}
794
}
795

    
796
/**
797
 * Returns a list of a specific type of IdentificationKeys, the list can be restricteded by a taxon.
798
 * @param $type The simple name of the cdm class implementing the interface IIdentificationKey,
799
 *          valid values are : PolytomousKey, MediaKey, MultiAccessKey
800
 * @param $taxonUuid if given this parameter restrict the listed keys to
801
 *          those which have the taxon identified be this uuid in scope.
802
 */
803
function _list_IdentificationKeys($type, $taxonUuid = null, $pageSize = null, $pageNumber = null){
804

    
805
  if(!$type){
806
    drupal_set_message("Type parameter is missing", "error");
807
    return;
808
  }
809
  $cdm_ws_pasepath = null;
810
  switch($type){
811
    case "PolytomousKey" : $cdm_ws_pasepath = CDM_WS_POLYTOMOUSKEY; break;
812
    case "MediaKey" : $cdm_ws_pasepath = CDM_WS_MEDIAKEY; break;
813
    case "MultiAccessKey" : $cdm_ws_pasepath = CDM_WS_MULTIACCESSKEY; break;
814
  }
815

    
816
  if(!$cdm_ws_pasepath){
817
    drupal_set_message("Type parameter is not valid: ".$type, "error");
818
  }
819

    
820
  $queryParameters  = '';
821
  if(is_numeric($pageSize)){
822
  	$queryParameters  = "pageSize=".$pageSize;
823
  } else {
824
  	$queryParameters  = "pageSize=0";
825
  }
826

    
827
  if(is_numeric($pageNumber)){
828
    $queryParameters  = "pageNumber=".$pageNumber;
829
  } else {
830
    $queryParameters  = "pageNumber=0";
831
  }
832
  $queryParameters  = null;
833
  if($taxonUuid){
834
    $queryParameters = "findByTaxonomicScope=$taxonUuid";
835
  }
836
  $pager = cdm_ws_get($cdm_ws_pasepath, null, $queryParameters);
837

    
838
  if(!$pager || $pager->count == 0){
839
      return array();
840
  }
841
  return $pager->records;
842
}
843

    
844
function theme_cdm_IdentificationKey($identificationKey, $doLinkToKeyPage = true, $showIdentificationKeyTitle = true){
845

    
846
	 $parentRenderPath = RenderHints::getRenderPath();
847
	 RenderHints::pushToRenderStack("IdentificationKey");
848

    
849
	 if($showIdentificationKeyTitle){
850
		 if($doLinkToKeyPage) {
851
		   $out = l($identificationKey->titleCache, path_to_key($identificationKey->class, $identificationKey->uuid));
852
		 } else {
853
		   $out = $identificationKey->titleCache;
854
		 }
855
	 }
856
	 if(is_array($identificationKey->sources)){
857
	 	// display sources
858
	 	$i = 0;
859
	 	$out .= '<div>';
860
	 	foreach($identificationKey->sources as $source){
861
      $out .= ($i++ > 0 ? ', ' : '' ) . theme("cdm_IdentifieableSource", $source);
862
	 	}
863
	 	$out .= '</div>';
864
	 }
865
	 	// display annotations
866
   $out .= theme('cdm_annotations', cdm_ws_getAnnotationsFor($identificationKey), 'div');
867
	 RenderHints::popFromRenderStack();
868
	 return $out;
869
}
870

    
871
function theme_cdm_polytomousKey(&$polytomousKey){
872

    
873
	$keyStyle = "linkedStyle"; // TODO settings needed
874

    
875
	RenderHints::pushToRenderStack("polytomousKey");
876
  // key nodes in linked style
877
  $out = '<table class="polytomousKey polytomousKey_'.$keyStyle.'">';
878
  $out .= theme('cdm_polytomousKey_'.$keyStyle.'_subgraph', $polytomousKey->root);
879
  $out .= '</table>';
880
  RenderHints::popFromRenderStack();
881
  return $out;
882
}
883

    
884
function theme_cdm_polytomousKey_linkedStyle_subgraph(&$polytomousKeyNode){
885

    
886
  static $statementCountCharacter = '\'';
887

    
888
  $out = "";
889

    
890
  if(is_array($polytomousKeyNode->children)){
891

    
892
    $childCount = 0;
893

    
894
    // render edges of the current node
895
    foreach($polytomousKeyNode->children as &$child){
896

    
897
    	if(!isset($child->statement)){
898
    		// skip node with empty statements (see below for explanation: "Special case")
899
    		continue;
900
    	}
901

    
902
      $out .= '<tr class="childCount_' . $childCount . '">';
903

    
904
      $out .= '<td class="nodeNumber">'. uuid_anchor($polytomousKeyNode->uuid, $polytomousKeyNode->nodeNumber . str_pad("", $childCount++ , $statementCountCharacter)) . "</td>";
905

    
906
      /*
907
       * Special case:
908
       * Child nodes with empty statements but taxa as leaf are to
909
       * treated as if all those taxa where direct children of the source node.
910
       */
911
      $islinkToManyTaxa = !isset($child->children[0]->statement) && isset($child->children[0]->taxon->uuid);
912
      $islinkToTaxon = isset($child->taxon->uuid);
913
      $islinkToSubKey = isset($child->subkey->uuid);
914
      $islinkToOtherNode = isset($child->otherNode);
915
      $islinkToNode = $child->nodeNumber && !$islinkToManyTaxa && !$islinkToOtherNode; // either null or 0
916

    
917
      $out .= '<td ' . RenderHints::getHtmlElementID($child) . '  class="edge">';
918
      if(isset($polytomousKeyNode->question->label_l10n)){
919
        $out .= $polytomousKeyNode->question->label_l10n .  ": ";
920
      }
921
      $out .= $child->statement->label_l10n;
922

    
923
      // --- links to nodes taxa and subkeys
924
      $out .= '<div class="nodeLink">';
925

    
926
     // link to a PolytomousKeyNode
927
      if($islinkToNode){
928
        $out .= '<div class="nodeLinkToNode">' . l($child->nodeNumber, $_REQUEST["q"], null, null, $child->uuid) . '</div>';
929
      }
930

    
931
      // link to a PolytomousKeyNode
932
      if($islinkToOtherNode){
933
        $out .= '<div class="nodeLinkToOtherNode">' . l($child->otherNode->nodeNumber, $_REQUEST["q"], null, null, $child->otherNode->uuid) . '</div>';
934
      }
935

    
936
      // link to one or many taxa
937
      if($islinkToTaxon || $islinkToManyTaxa){
938

    
939
      	if($islinkToManyTaxa){
940
          $taxonChildren = $child->children;
941
      	} else {
942
          $taxonChildren = array($child);
943
      	}
944

    
945
      	foreach($taxonChildren as $taxonChild){
946
	      	// TODO many taxa $child->children->taxon
947
	      	$out .= '<div class="nodeLinkToTaxon">';
948
	      	if(is_object($taxonChild->modifyingText)){
949
	      		$i = 0;
950
            foreach(get_object_vars($taxonChild->modifyingText) as $language=>$languageString){
951
	      	    $out .= ($i++ > 0 ? ', ' : '') . '<span class="modifyingText">'. $languageString->text . '</span> ';
952
            }
953
	      	}
954
	      	$out .=  theme("cdm_taxonName", $taxonChild->taxon->name, path_to_taxon($taxonChild->taxon->uuid));
955
	      	$out .=  '</div>';
956
      	}
957

    
958
        // link to a subkey
959
	      if($islinkToSubKey){
960
	        $out .= '<div class="nodeLinkToSubkey">' . theme('cdm_IdentificationKey', $child->subkey) . '</div>';
961
	      }
962

    
963
      }
964

    
965
	    $out .= '</div>'; // end node link
966
      $out .= '</td>'; // end edge
967
      $out .= '</tr>';
968

    
969
    }
970

    
971
    // recurse into child nodes
972
    foreach($polytomousKeyNode->children as &$child){
973
      $out .= theme('cdm_polytomousKey_linkedStyle_subgraph', $child);
974
    }
975

    
976
  }
977
  return $out;
978
}
979

    
980
/**
981
 * Renders a list of a specific type of IdentificationKeys, the list can be restricteded by a taxon.
982
 * @param $type The simple name of the cdm class implementing the interface IIdentificationKey,
983
 *          valid values are : PolytomousKey, MediaKey, MultiAccessKey
984
 * @param $taxonUuid if given this parameter restrict the listed keys to
985
 *          those which have the taxon identified be this uuid in scope.
986
 */
987
function theme_cdm_list_IdentificationKeys($type, $taxonUuid = null, $pageSize, $pageNumber){
988

    
989
  $keyList = _list_IdentificationKeys($type, $taxonUuid);
990
  if(!$keyList || count ($keyList) == 0){
991
  	return;
992
  }
993

    
994
  RenderHints::pushToRenderStack('list_IdentificationKeys');
995
  $out = '<ul>';
996
  foreach ($keyList as $key){
997
    $out .= '<li>';
998
    $out .= theme('cdm_IdentificationKey', $key);
999
    $out .= '</li>';
1000
  }
1001
  $out .= '</ul>';
1002
  $out .= theme("cdm_annotation_footnotes", RenderHints::getRenderPath());
1003
  RenderHints::popFromRenderStack();
1004

    
1005
  return $out;
1006
}
1007

    
1008
function theme_cdm_block_IdentificationKeys($taxonUuid = null, $pageSize = null){
1009

    
1010
	static $types = array("PolytomousKey"=>"Polytomous", "MediaKey"=>"Media", "MultiAccessKey"=>"Multiaccess");
1011
  RenderHints::pushToRenderStack('block_IdentificationKeys');
1012
	$out = '';
1013
	foreach($types as $type=>$label){
1014
		$keylist = theme('cdm_list_IdentificationKeys', $type, $taxonUuid, $pageSize, $pageNumber);
1015
		if(!$keylist){
1016
			continue;
1017
		}
1018
		$out .= '<div class="'.$type.'">';
1019
		$out .= '<h3>'.t($label)."</h3>";
1020
		$out .= $keylist;
1021
		$out .= '</div>';
1022
	}
1023
  RenderHints::popFromRenderStack();
1024
	return $out;
1025
}
(2-2/8)