Project

General

Profile

Download (14.9 KB) Statistics
| Branch: | Tag: | Revision:
1 806baeb2 Andreas Kohlbecker
<?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
15
function theme_cdm_typedesignations($typeDesignations = array()){
16
17
	_add_js_cluetip();
18
	$renderPath = 'typedesignations';
19
	$out = '<ul class="typeDesignations">';
20
21
	$specimenTypeDesignations = array();
22
	foreach($typeDesignations as $typeDesignation){
23
		if($typeDesignation->class == 'SpecimenTypeDesignation'){
24
			// SpecimenTypeDesignations should be ordered. collect theme here only
25
			$specimenTypeDesignations[] = $typeDesignation;
26
		}else {
27
28
			// it's a NameTypeDesignation
29
			if($typeDesignation->notDesignated){
30
				$out .= '<li class="nameTypeDesignation"><span class="status">Type</span>: '.t('not designated'). '</li>';
31
			}else if($typeDesignation->typeName){
32
33
				$out .= '<li class="nameTypeDesignation"><span class="status">Type</span>: ';
34
35
				if($typeDesignation->typeName->nomenclaturalReference){
36
					$referenceUri = url(path_to_reference($typeDesignation->typeName->nomenclaturalReference->uuid));
37
				}
38
				$out .= theme('cdm_taxonName', $typeDesignation->typeName, null, $referenceUri, $renderPath);
39
40
				//        if($typeDesignation->typeName->class == 'ZoologicalName') {
41
				//          // appending authorTeam which has been skipped in cdm_name
42
				//          $authorTeam = cdm_taggedtext_value($typeDesignation->typeName->taggedName, 'authors');
43
				//          $authorTeamPart = l('<span class="authors">'.$authorTeam.'</span>', "/cdm_dataportal/reference/".$typeDesignation->typeName->nomenclaturalReference->uuid, array(), NULL, NULL, FALSE, TRUE);
44
				//          $out .= (str_endsWith($authorTeam, ')') ? '' : ', ').$authorTeamPart;
45
				//        } else {
46
				//          $out .= ' '.theme('cdm_reference', $typeDesignation->citation, true, $referenceStyle);
47
				//          $out .= '</li>';
48
				//        }
49
			}
50
		}
51
	}
52
53
	if(!empty($specimenTypeDesignations)){
54
		// sorting might be different for dataportals so this has to be parameterized
55
		usort($specimenTypeDesignations, "compare_specimenTypeDesignationStatus");
56
		foreach($specimenTypeDesignations as $std){
57
58
			$typeReference = '';
59
			//show citation only for Lectotype or Neotype
60
			$showCitation = isset($std->typeStatus) && ($std->typeStatus->uuid == UUID_NEOTYPE || $std->typeStatus->uuid == UUID_LECTOTYPE);
61
			if($showCitation && !empty($std->citation)){
62
				$shortCitation = $std->citation->authorTeam->titleCache;
63
				$shortCitation .= (strlen($shortCitation) > 0 ? ' ' : '' ). partialToYear($std->citation->datePublished->start);
64
				if(strlen($shortCitation) == 0){
65
					$shortCitation = theme('cdm_reference',$std->citation );
66
					$missingShortCitation = true;
67
				}
68
				$typeReference .= '&nbsp;(' . t('designated by');
69
				$typeReference .= '&nbsp;<span class="typeReference '.($missingShortCitation ? '' : 'cluetip').' no-print" title="'. htmlspecialchars('|'.theme('cdm_reference',$std->citation ).'|') .'">';
70
				$typeReference .= $shortCitation.'</span>';
71
				$typeReference .= ')';
72
				//$typeReference .= '<span class="reference only-print">(designated by '.theme('cdm_reference',$std->citation ).')</span>';
73
			}
74
75
			$out .= '<li class="specimenTypeDesignation">';
76
			$out .= '<span class="status">'.(($std->typeStatus->representation_L10n) ? $std->typeStatus->representation_L10n : t('Type')) .$typeReference.'</span>: '.$std->typeSpecimen->titleCache;
77
			$out .= theme('cdm_specimen', $std->typeSpecimen);
78
			$out .= '</li>';
79
		}
80
	}
81
82
	$out .= '</ul>';
83
84
	return $out;
85
}
86
87
88
/**
89
 * FIXME this definitively has to be in another spot. just didn't know where to put it right now.
90
 * Compares the status of two SpecimenTypeDesignations
91
 * @param String $a 	a SpecimenTypeDesignations
92
 * @param String $b		another SpecimenTypeDesignations
93
 */
94
function compare_specimenTypeDesignationStatus($a, $b){
95
	/* this is the desired sort oder as of now:
96
	 * 	Holotype
97
	 * 	Isotype
98
	 * 	Lectotype
99
	 * 	Isolectotype
100
	 * 	Syntype
101
	 *
102
	 * TODO
103
	 * Basically, what we are trying to do is, we define an ordered array of TypeDesignation-states
104
	 * and use the index of this array for comparison. This array has to be filled with the cdm-
105
	 * TypeDesignation states and the order should be parameterisable inside the dataportal.
106
	 */
107
	// make that static for now
108
	$typeOrder = array('Holotype', 'Isotype', 'Lectotype', 'Isolectotype', 'Syntype');
109
110
	$aQuantifier = array_search($a->typeStatus->label, $typeOrder);
111
	$bQuantifier = array_search($b->typeStatus->label, $typeOrder);
112
113
	if ($aQuantifier == $bQuantifier) {
114
		// sort alphabetically
115
		return ($a->typeStatus->label < $b->typeStatus->label) ? -1 : 1;
116
	}
117
	return ($aQuantifier < $bQuantifier) ? -1 : 1;
118
119
}
120
121
function theme_cdm_nameRelations($nameRelationships, $skipTypes = false){
122
123
	// group by relationship type
124
	$relationshipGroups = array();
125
	foreach($nameRelationships as $nameRelationship){
126
		if(!array_key_exists($nameRelationship->type->uuid, $relationshipGroups)){
127
			$relationshipGroups[$nameRelationship->type->uuid] = array();
128
		}
129
		$relationshipGroups[$nameRelationship->type->uuid][] = $nameRelationship;
130
	}
131
132
	// generate output
133
	$out = '';
134
	foreach($relationshipGroups as $group){
135
		$type = $group[0]->type;
136
137
		if(is_array($skipTypes) && in_array($type->uuid, $skipTypes)){
138
			continue;
139
		}
140
141
		$block->module = 'cdm_dataportal';
142
		$block->subject = t(ucfirst($type->inverseRepresentation_L10n));
143
		$block->delta = generalizeString(strtolower($type->inverseRepresentation_L10n));
144
145
		foreach($group as $relationship){
146
			$relatedNames[] = cdm_taggedtext2html($relationship->fromName->taggedName);
147
		}
148
149
		$block->content .= implode('; ', $relatedNames);
150
		$out .= theme('block', $block);
151
	}
152
	return $out;
153
}
154
155
156
157
function theme_cdm_homotypicSynonymLine($taxon){
158
	$out = '';
159
	$out .= '<li class="synonym">'.theme('cdm_related_taxon', $taxon, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
160
	return $out;
161
}
162
163
function theme_cdm_heterotypicSynonymyGroup($homotypicalGroup){
164
	$out = '';
165
	$out = '<ul class="heterotypicSynonymyGroup">';
166
167
	$is_first_entry = true;
168
	$typeDesignations = null;
169
	foreach($homotypicalGroup as $synonym){
170
		if($is_first_entry){
171
			$is_first_entry = false;
172
			//$typeDesignations = cdm_ws_get(CDM_WS_NAME_TYPEDESIGNATIONS, $synonym->name->uuid);
173
			$typeDesignations = cdm_ws_get(CDM_WS_TAXON_NAMETYPEDESIGNATIONS, $synonym->uuid);
174
			// is first list entry
175
			$out .= '<li class="firstentry synonym">'.theme('cdm_related_taxon',$synonym, UUID_HETEROTYPIC_SYNONYM_OF).'</li>';
176
		} else {
177
			$out .= '<li class="synonym">'.theme('cdm_related_taxon',$synonym, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
178
		}
179
	}
180
181
	if($typeDesignations){
182
		$out .= theme('cdm_typedesignations', $typeDesignations);
183
	}
184
185
	$out .= '</ul>';
186
187
	return $out;
188
}
189
190
191
192
function theme_cdm_homotypicSynonymyGroup($synonymList, $prependedSynonyms = array()){
193
194
	if(! is_array($synonymList) || count($synonymList) == 0){
195
		return;
196
	}
197
198
	$out = '<ul class="homotypicSynonyms">';
199
200
	if(!empty($prependedSynonyms)){
201
		foreach($prependedSynonyms as $taxon){
202
			$out .= '<li class="synonym">'.theme('cdm_related_taxon', $taxon, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
203
		}
204
	}
205
206
	foreach($synonymList as $synonym){
207
		$out .= '<li class="synonym">'.theme('cdm_related_taxon', $synonym, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
208
	}
209
210
	$typeDesignations = cdm_ws_get(CDM_WS_TAXON_NAMETYPEDESIGNATIONS, $synonymList[0]->uuid);
211
	if($typeDesignations){
212
		$out .= theme('cdm_typedesignations', $typeDesignations);
213
	}
214
215
	$out .= '</ul>';
216
	return $out;
217
}
218
219
220
function theme_cdm_taxonName($taxonName, $nameLink = NULL, $refenceLink = NULL, $renderPath = null){
221
222
223
224
	$renderTemplate = get_nameRenderTemplate($renderPath, $nameLink, $refenceLink);
225
226
	$partDefinition = get_partDefinition($taxonName->class);
227
228
	// apply defintions to template
229
	foreach($renderTemplate as $part=>$uri){
230
		if(isset($partDefinition[$part])){
231
			$renderTemplate[$part] = $partDefinition[$part];
232
		}
233
		if(is_array($uri)){
234
			$renderTemplate[$part]['#uri'] = $uri['#uri'];
235
		}
236
	}
237
238
	$firstEntryIsValidNamePart = is_array($taxonName->taggedName)
239
	&& is_string($taxonName->taggedName[1]->text)
240
	&& $taxonName->taggedName[1]->text != ''
241
	&& $taxonName->taggedName[1]->type = 'name';
242
	// got to use second entry as first one, see ToDo comment below ...
243
	if($firstEntryIsValidNamePart){
244
245
		$taggedName = $taxonName->taggedName;
246
		//TODO  due to a bug in the cdmlib the taggedName alway has a lst empty element, we will remove it:
247
		array_pop($taggedName);
248
249
		$lastAuthorElementString = false;
250
		$hasNamePart_with_Authors = isset($renderTemplate['namePart']) && isset($renderTemplate['namePart']['authors']);
251
		$hasNameAuthorPart_with_Authors = isset($renderTemplate['nameAuthorPart']) && isset($renderTemplate['nameAuthorPart']['authors']);
252
253
		if(!($hasNamePart_with_Authors || $hasNameAuthorPart_with_Authors)){
254
			//      // find author and split off from name
255
			//      // TODO expecting to find the author as the last element
256
			//      if($taggedName[count($taggedName)- 1]->type == 'authors'){
257
			//        $authorTeam = $taggedName[count($taggedName)- 1]->text;
258
			//        unset($taggedName[count($taggedName)- 1]);
259
			//      }
260
261
			// remove all authors
262
			$taggedNameNew = array();
263
			foreach($taggedName as $element){
264
				if($element->type != 'authors'){
265
					$taggedNameNew[] = $element;
266
				} else {
267
					$lastAuthorElementString = $element->text;
268
				}
269
			}
270
			$taggedName = $taggedNameNew;
271
272
		}
273
		$name = '<span class="'.$taxonName->class.'">'.theme('cdm_taggedtext2html', $taggedName).'</span>';
274
	} else {
275
		$name = '<span class="'.$taxonName->class.'_titleCache">'.$taxonName->titleCache.'</span>';
276
	}
277
278
	// fill name into $renderTemplate
279
	array_setr('name', $name, $renderTemplate);
280
281
	//  // fill with authorTeam
282
	//  if($authorTeam){
283
	//    $authorTeamHtml = ' <span class="authorTeam">'.$authorTeam.'</span>';
284
	//    array_setr('authorTeam', $authorTeamHtml, $renderTemplate);
285
	//  }
286
287
288
	// fill with reference
289
	if(isset($renderTemplate['referencePart'])){
290
291
		// [Eckhard]:"Komma nach dem Taxonnamen ist grunsätzlich falsch,
292
		// Komma nach dem Autornamen ist überall dort falsch, wo ein "in" folgt."
293
		if(isset($renderTemplate['referencePart']['reference']) && $taxonName->nomenclaturalReference){
294
			$microreference = null;
295
			if(isset($renderTemplate['referencePart']['microreference'])){
296
				$microreference = $taxonName->nomenclaturalMicroReference;
297
			}
298
			$citation = cdm_ws_get(CDM_WS_NOMENCLATURAL_REFERENCE_CITATION, array($taxonName->nomenclaturalReference->uuid, $microreference));
299
			$citation = $citation->String;
300
			// find preceding element of the refrence
301
			$precedingKey = get_preceding_contentElementKey('reference', $renderTemplate);
302
			if(str_beginsWith($citation, ", in")){
303
				$citation = substr($citation, 2);
304
				$separator = ' ';
305
			} else if(!str_beginsWith($citation, "in") && $precedingKey == 'authors'){
306
				$separator = ', ';
307
			} else {
308
				$separator = ' ';
309
			}
310
311
			$referenceArray['#separator'] = $separator;
312
			$referenceArray['#html'] = '<span class="reference">'.$citation.'</span>';
313
			array_setr('reference', $referenceArray, $renderTemplate);
314
		}
315
316
		// if authors have been removed from the name part the last named authorteam
317
		// should be added to the reference citation, otherwise, keep the separator
318
		// out of the reference
319
		if(isset($renderTemplate['referencePart']['authors']) && $lastAuthorElementString){
320
			// if the nomenclaturalReference cintation is not included in the reference part but diplay of the microreference
321
			// is whanted append the microreference to the authorTeam
322
			if(!isset($renderTemplate['referencePart']['reference']) && isset($renderTemplate['referencePart']['microreference'])){
323
				$separator = ": ";
324
				$citation = $taxonName->nomenclaturalMicroReference;
325
			}
326
			$referenceArray['#html'] = ' <span class="reference">'.$lastAuthorElementString.$separator.$citation.'</span>';
327
			array_setr('authors', $referenceArray, $renderTemplate);
328
		}
329
330
	}
331
332
	// fill with status
333
	if(array_setr('status', true, $renderTemplate)){
334
		if(isset($taxon->name->status[0])){
335
			foreach($taxon->name->status as $status){
336
				$statusHtml .= ', '.$status->type->representation_L10n;
337
			}
338
		}
339
		array_setr('status', ' <span class="nomenclatural_status">'.$statusHtml.'</span>', $renderTemplate);
340
	}
341
342
	// fill with protologues etc...
343
	if(array_setr('description', true, $renderTemplate)){
344
		$descriptions = cdm_ws_get(CDM_WS_NAME_DESCRIPTIONS, $taxonName->uuid);
345
		foreach($descriptions as $description){
346
			if(!empty($description)){
347
				foreach($description->elements as $description_element){
348
					$descriptionHtml .= theme("cdm_media", $description_element, array('application/pdf', 'image/png', 'image/jpeg', 'image/gif', 'text/html'));
349
				}
350
			}
351
		}
352
		array_setr('description', $descriptionHtml, $renderTemplate);
353
	}
354
355
	// render
356
	$out = '<span ref="/name/'.$taxonName->uuid.'">';
357
	foreach($renderTemplate as $partName=>$part){
358
		$separator = '';
359
		$partHtml = '';
360
		$uri = false;
361
		if(!is_array($part)){
362
			continue;
363
		}
364
		if(isset($part['#uri']) && is_string($part['#uri'])){
365
			$uri = $part['#uri'];
366
			unset($part['#uri']);
367
		}
368
		foreach($part as $key=>$content){
369
			$html = '';
370
			if(is_array($content)){
371
				$html = $content['#html'];
372
				$separator = $content['#separator'];
373
			} else if(is_string($content)){
374
				$html = $content;
375
			}
376
			$partHtml .= '<span class="'.$key.'">'.$html.'</span>';
377
		}
378
		if($uri){
379
			$out .= $separator.'<a href="'.$uri.'" class="'.$partName.'">'.$partHtml.'</a>';
380
		} else {
381
			$out .= $separator.$partHtml;
382
		}
383
	}
384
385
	return $out.'</span>';
386
}
387
388
/**
389
 * Recursively searches the array for the $key and sets the given value
390
 * @param $key
391
 * @param $value
392
 * @param $array
393
 * @return true if the key has been found
394
 */
395
function &array_setr($key, $value, array &$array){
396
	foreach($array as $k=>&$v){
397
		if($key == $k){
398
			$v = $value;
399
			return $array;
400
		} else if(is_array($v)){
401
			$innerArray = array_setr($key, $value, $v);
402
			if($innerArray){
403
				return $array;
404
			}
405
		}
406
	}
407
	return null;
408
}
409
410
function &get_preceding_contentElement($contentElementKey, array &$renderTemplate){
411
	$precedingElement = null;
412
	foreach($renderTemplate as &$part){
413
		foreach($part as $key=>&$element){
414
			if($key == $contentElementKey){
415
				return $precedingElement;
416
			}
417
			$precedingElement = $element;
418
		}
419
	}
420
	return null;
421
}
422
423
function &get_preceding_contentElementKey($contentElementKey, array &$renderTemplate){
424
	$precedingKey = null;
425
	foreach($renderTemplate as &$part){
426
		foreach($part as $key=>&$element){
427
			if($key == $contentElementKey){
428
				return $precedingKey;
429
			}
430
			if(!str_beginsWith($key, '#')){
431
				$precedingKey = $key;
432
			}
433
		}
434
	}
435
	return null;
436
}
437
438
439
440
441
442
443