Project

General

Profile

Download (16 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

    
15
function theme_cdm_typedesignations($typeDesignations = array()){
16

    
17
	RenderHints::pushToRenderStack('typedesignations');
18
	_add_js_cluetip();
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
                $link_to_name_page = '?q=' . path_to_name($typeDesignation->typeName->uuid);
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, $link_to_name_page, $referenceUri);
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
			  $author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $std->citation->uuid);
64
			  $shortCitation = $author_team->titleCache;
65
				$shortCitation .= (strlen($shortCitation) > 0 ? ' ' : '' ). partialToYear($std->citation->datePublished->start);
66
				if(strlen($shortCitation) == 0){
67
					$shortCitation = theme('cdm_reference',$std->citation );
68
					$missingShortCitation = true;
69
				}
70
				$typeReference .= '&nbsp;(' . t('designated by');
71
				$typeReference .= '&nbsp;<span class="typeReference '.($missingShortCitation ? '' : 'cluetip').' no-print" title="'. htmlspecialchars('|'.theme('cdm_reference',$std->citation ).'|') .'">';
72
				$typeReference .= $shortCitation.'</span>';
73
				$typeReference .= ')';
74
				//$typeReference .= '<span class="reference only-print">(designated by '.theme('cdm_reference',$std->citation ).')</span>';
75
			}
76

    
77
			$out .= '<li class="specimenTypeDesignation">';
78
			$out .= '<span class="status">'.(($std->typeStatus->representation_L10n) ? $std->typeStatus->representation_L10n : t('Type')) .$typeReference.'</span>: '.$std->typeSpecimen->titleCache;
79
			//$out .= '<span class="status">'.(($std->typeStatus->representation_L10n) ? $std->typeStatus->representation_L10n : t('Type')) .$typeReference.'</span>: '.$std->typeSpecimen->titleCache . ' footnote: '. theme_cdm_footnote($std->typeSpecimen->collection->code, $std->typeSpecimen->collection->titleCache);
80
  
81
			$out .= theme('cdm_specimen', $std->typeSpecimen);
82
			$out .= '</li>';
83
		}
84
	}
85

    
86
	$out .= '</ul>';
87

    
88
	RenderHints::popFromRenderStack();
89
	return $out;
90
}
91

    
92

    
93
/**
94
 * FIXME this definitively has to be in another spot. just didn't know where to put it right now.
95
 * Compares the status of two SpecimenTypeDesignations
96
 * @param String $a 	a SpecimenTypeDesignations
97
 * @param String $b		another SpecimenTypeDesignations
98
 */
99
function compare_specimenTypeDesignationStatus($a, $b){
100
	/* this is the desired sort oder as of now:
101
	 * 	Holotype
102
	 * 	Isotype
103
	 * 	Lectotype
104
	 * 	Isolectotype
105
	 * 	Syntype
106
	 *
107
	 * TODO
108
	 * Basically, what we are trying to do is, we define an ordered array of TypeDesignation-states
109
	 * and use the index of this array for comparison. This array has to be filled with the cdm-
110
	 * TypeDesignation states and the order should be parameterisable inside the dataportal.
111
	 */
112
	// make that static for now
113
	$typeOrder = array('Holotype', 'Isotype', 'Lectotype', 'Isolectotype', 'Syntype');
114

    
115
	$aQuantifier = array_search($a->typeStatus->label, $typeOrder);
116
	$bQuantifier = array_search($b->typeStatus->label, $typeOrder);
117

    
118
	if ($aQuantifier == $bQuantifier) {
119
		// sort alphabetically
120
		return ($a->typeStatus->label < $b->typeStatus->label) ? -1 : 1;
121
	}
122
	return ($aQuantifier < $bQuantifier) ? -1 : 1;
123

    
124
}
125

    
126
function theme_cdm_nameRelations($nameRelationships, $skipTypes = false){
127

    
128
	// group by relationship type
129
	$relationshipGroups = array();
130
	foreach($nameRelationships as $nameRelationship){
131
		if(!array_key_exists($nameRelationship->type->uuid, $relationshipGroups)){
132
			$relationshipGroups[$nameRelationship->type->uuid] = array();
133
		}
134
		$relationshipGroups[$nameRelationship->type->uuid][] = $nameRelationship;
135
	}
136

    
137
	// generate output
138
	$out = '';
139
	foreach($relationshipGroups as $group){
140
		$type = $group[0]->type;
141

    
142
		if(is_array($skipTypes) && in_array($type->uuid, $skipTypes)){
143
			continue;
144
		}
145

    
146
		$block->module = 'cdm_dataportal';
147
		$block->subject = t(ucfirst($type->inverseRepresentation_L10n));
148
		$block->delta = generalizeString(strtolower($type->inverseRepresentation_L10n));
149

    
150
		foreach($group as $relationship){
151
			$relatedNames[] = cdm_taggedtext2html($relationship->fromName->taggedName);
152
		}
153

    
154
		$block->content .= implode('; ', $relatedNames);
155
		$out .= theme('block', $block);
156
	}
157
	return $out;
158
}
159

    
160

    
161

    
162
function theme_cdm_homotypicSynonymLine($taxon){
163
	$out = '';
164
	$out .= '<li class="synonym">'.theme('cdm_related_taxon', $taxon, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
165
	
166
	return $out;
167
}
168

    
169
function theme_cdm_heterotypicSynonymyGroup($homotypicalGroup){
170
	
171
	RenderHints::pushToRenderStack('heterotypicSynonymyGroup');
172
	$out = '';
173
	$out = '<ul class="heterotypicSynonymyGroup">';
174

    
175
	$is_first_entry = true;
176
	$typeDesignations = null;
177
	foreach($homotypicalGroup as $synonym){
178
		if($is_first_entry){
179
			RenderHints::setfootnoteListKey($synonym->uuid);
180
			$is_first_entry = false;
181
			//$typeDesignations = cdm_ws_get(CDM_WS_NAME_TYPEDESIGNATIONS, $synonym->name->uuid);
182
			$typeDesignations = cdm_ws_get(CDM_WS_PORTAL_TAXON_NAMETYPEDESIGNATIONS, $synonym->uuid);
183
			// is first list entry
184
			$out .= '<li class="firstentry synonym">'.theme('cdm_related_taxon',$synonym, UUID_HETEROTYPIC_SYNONYM_OF).'</li>';
185
		} else {
186
			$out .= '<li class="synonym">'.theme('cdm_related_taxon',$synonym, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
187
		}
188
	}
189
	if($typeDesignations){
190
		$out .= theme('cdm_typedesignations', $typeDesignations);
191
	}
192

    
193
	$out .= '</ul>';
194
    
195
	$out .= FootnoteManager::renderFootnoteList($firstSynonymUuid);
196
    
197
    RenderHints::popFromRenderStack();
198
	return $out;
199
}
200

    
201

    
202

    
203
function theme_cdm_homotypicSynonymyGroup($synonymList, $prependedSynonyms = array()){
204
	
205
	RenderHints::pushToRenderStack('homotypicSynonymyGroup');
206
	
207
	$firstSynonymUuid = isset($prependedSynonyms[0]) ? $prependedSynonyms[0]->uuid : (isset($synonymList[0]) ? $synonymList[0]->uuid : 'NULL');
208
	RenderHints::setfootnoteListKey($firstSynonymUuid);
209
	
210
	if(! is_array($synonymList) || count($synonymList) == 0){
211
		return;
212
	}
213

    
214
	$out = '<ul class="homotypicSynonyms">';
215

    
216
	if(!empty($prependedSynonyms)){
217
		foreach($prependedSynonyms as $taxon){
218
			$out .= '<li class="synonym">'.theme('cdm_related_taxon', $taxon, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
219
		}
220
	}
221

    
222
	foreach($synonymList as $synonym){
223
		$out .= '<li class="synonym">'.theme('cdm_related_taxon', $synonym, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
224
	}
225

    
226
	$typeDesignations = cdm_ws_get(CDM_WS_PORTAL_TAXON_NAMETYPEDESIGNATIONS, $synonymList[0]->uuid);
227
	if($typeDesignations){
228
		$out .= theme('cdm_typedesignations', $typeDesignations);
229
	}
230

    
231
	$out .= '</ul>';
232
	$out .= FootnoteManager::renderFootnoteList($firstSynonymUuid);
233
	
234
	RenderHints::popFromRenderStack();
235
	return $out;
236
}
237

    
238

    
239
function theme_cdm_taxonName($taxonName, $nameLink = NULL, $refenceLink = NULL){
240

    
241
  $renderTemplate = get_nameRenderTemplate(RenderHints::getRenderPath(), $nameLink, $refenceLink);
242
	$partDefinition = get_partDefinition($taxonName->class);
243

    
244
	// apply defintions to template
245
	foreach($renderTemplate as $part=>$uri){
246
		if(isset($partDefinition[$part])){
247
			$renderTemplate[$part] = $partDefinition[$part];
248
		}
249
		if(is_array($uri)){
250
			$renderTemplate[$part]['#uri'] = $uri['#uri'];
251
		}
252
	}
253

    
254
	$firstEntryIsValidNamePart = is_array($taxonName->taggedName)
255
	&& is_string($taxonName->taggedName[0]->text)
256
	&& $taxonName->taggedName[0]->text != ''
257
	&& $taxonName->taggedName[0]->type == 'name';
258
	
259
	// got to use second entry as first one, see ToDo comment below ...
260
	if($firstEntryIsValidNamePart){
261

    
262
		$taggedName = $taxonName->taggedName;
263
		
264
		$lastAuthorElementString = false;
265
		$hasNamePart_with_Authors = isset($renderTemplate['namePart']) && isset($renderTemplate['namePart']['authors']);
266
		$hasNameAuthorPart_with_Authors = isset($renderTemplate['nameAuthorPart']) && isset($renderTemplate['nameAuthorPart']['authors']);
267

    
268
		if(!($hasNamePart_with_Authors || $hasNameAuthorPart_with_Authors)){
269
			//      // find author and split off from name
270
			//      // TODO expecting to find the author as the last element
271
			//      if($taggedName[count($taggedName)- 1]->type == 'authors'){
272
			//        $authorTeam = $taggedName[count($taggedName)- 1]->text;
273
			//        unset($taggedName[count($taggedName)- 1]);
274
			//      }
275

    
276
			// remove all authors
277
			$taggedNameNew = array();
278
			foreach($taggedName as $element){
279
				if($element->type != 'authors'){
280
					$taggedNameNew[] = $element;
281
				} else {
282
					$lastAuthorElementString = $element->text;
283
				}
284
			}
285
			$taggedName = $taggedNameNew;
286

    
287
		}
288
		$name = '<span class="'.$taxonName->class.'">'.theme('cdm_taggedtext2html', $taggedName).'</span>';
289
	} else {
290
		$name = '<span class="'.$taxonName->class.'_titleCache">'.$taxonName->titleCache.'</span>';
291
	}
292

    
293
	// fill name into $renderTemplate
294
	array_setr('name', $name, $renderTemplate);
295

    
296
	//  // fill with authorTeam
297
	//  if($authorTeam){
298
	//    $authorTeamHtml = ' <span class="authorTeam">'.$authorTeam.'</span>';
299
	//    array_setr('authorTeam', $authorTeamHtml, $renderTemplate);
300
	//  }
301

    
302

    
303
	// fill with reference
304
	if(isset($renderTemplate['referencePart'])){
305

    
306
		// [Eckhard]:"Komma nach dem Taxonnamen ist grunsätzlich falsch,
307
		// Komma nach dem Autornamen ist überall dort falsch, wo ein "in" folgt."
308
		if(isset($renderTemplate['referencePart']['reference']) && $taxonName->nomenclaturalReference){
309
			$microreference = null;
310
			if(isset($renderTemplate['referencePart']['microreference'])){
311
				$microreference = $taxonName->nomenclaturalMicroReference;
312
			}
313
			$citation = cdm_ws_get(CDM_WS_NOMENCLATURAL_REFERENCE_CITATION, array($taxonName->nomenclaturalReference->uuid), "microReference=".urlencode($microreference));
314
			$citation = $citation->String;
315
			// find preceding element of the refrence
316
			$precedingKey = get_preceding_contentElementKey('reference', $renderTemplate);
317
			if(str_beginsWith($citation, ", in")){
318
				$citation = substr($citation, 2);
319
				$separator = ' ';
320
			} else if(!str_beginsWith($citation, "in") && $precedingKey == 'authors'){
321
				$separator = ', ';
322
			} else {
323
				$separator = ' ';
324
			}
325

    
326
			$referenceArray['#separator'] = $separator;
327
			$referenceArray['#html'] = '<span class="reference">'.$citation.'</span>';
328
			array_setr('reference', $referenceArray, $renderTemplate);
329
		}
330

    
331
		// if authors have been removed from the name part the last named authorteam
332
		// should be added to the reference citation, otherwise, keep the separator
333
		// out of the reference
334
		if(isset($renderTemplate['referencePart']['authors']) && $lastAuthorElementString){
335
			// if the nomenclaturalReference cintation is not included in the reference part but diplay of the microreference
336
			// is whanted append the microreference to the authorTeam
337
			if(!isset($renderTemplate['referencePart']['reference']) && isset($renderTemplate['referencePart']['microreference'])){
338
				$separator = ": ";
339
				$citation = $taxonName->nomenclaturalMicroReference;
340
			}
341
			$referenceArray['#html'] = ' <span class="reference">'.$lastAuthorElementString.$separator.$citation.'</span>';
342
			array_setr('authors', $referenceArray, $renderTemplate);
343
		}
344

    
345
	}
346

    
347
	// fill with status
348
	if(array_setr('status', true, $renderTemplate)){
349
		if(isset($taxon->name->status[0])){
350
			foreach($taxon->name->status as $status){
351
				$statusHtml .= ', '.$status->type->representation_L10n;
352
			}
353
		}
354
		array_setr('status', ' <span class="nomenclatural_status">'.$statusHtml.'</span>', $renderTemplate);
355
	}
356

    
357
	// fill with protologues etc...
358
	if(array_setr('description', true, $renderTemplate)){
359
		$descriptions = cdm_ws_get(CDM_WS_PORTAL_NAME_DESCRIPTIONS, $taxonName->uuid);
360
		foreach($descriptions as $description){
361
			if(!empty($description)){
362
				foreach($description->elements as $description_element){
363
					$descriptionHtml .= theme("cdm_media", $description_element, array('application/pdf', 'image/png', 'image/jpeg', 'image/gif', 'text/html'));
364
				}
365
			}
366
		}
367
		array_setr('description', $descriptionHtml, $renderTemplate);
368
	}
369

    
370
	// render
371
	$out = '<span ref="/name/'.$taxonName->uuid.'">';
372
	
373
	foreach($renderTemplate as $partName=>$part){
374
		$separator = '';
375
		$partHtml = '';
376
		$uri = false;
377
		if(!is_array($part)){
378
			continue;
379
		}
380
		if(isset($part['#uri']) && is_string($part['#uri'])){
381
			$uri = $part['#uri'];
382
			unset($part['#uri']);
383
		}
384
		foreach($part as $key=>$content){
385
			$html = '';
386
			if(is_array($content)){
387
				$html = $content['#html'];
388
				$separator = $content['#separator'];
389
			} else if(is_string($content)){
390
				$html = $content;
391
			}
392
			$partHtml .= '<span class="'.$key.'">'.$html.'</span>';
393
		}
394
		if($uri){
395
			$out .= $separator.'<a href="'.$uri.'" class="'.$partName.'">'.$partHtml.'</a>';
396
		} else {
397
			$out .= $separator.$partHtml;
398
		}
399
	}
400

    
401
	return $out.'</span>';
402
}
403

    
404
/**
405
 * Recursively searches the array for the $key and sets the given value
406
 * @param $key
407
 * @param $value
408
 * @param $array
409
 * @return true if the key has been found
410
 */
411
function &array_setr($key, $value, array &$array){
412
	foreach($array as $k=>&$v){
413
		if($key == $k){
414
			$v = $value;
415
			return $array;
416
		} else if(is_array($v)){
417
			$innerArray = array_setr($key, $value, $v);
418
			if($innerArray){
419
				return $array;
420
			}
421
		}
422
	}
423
	return null;
424
}
425

    
426
function &get_preceding_contentElement($contentElementKey, array &$renderTemplate){
427
	$precedingElement = null;
428
	foreach($renderTemplate as &$part){
429
		foreach($part as $key=>&$element){
430
			if($key == $contentElementKey){
431
				return $precedingElement;
432
			}
433
			$precedingElement = $element;
434
		}
435
	}
436
	return null;
437
}
438

    
439
function &get_preceding_contentElementKey($contentElementKey, array &$renderTemplate){
440
	$precedingKey = null;
441
	foreach($renderTemplate as &$part){
442
		foreach($part as $key=>&$element){
443
			if($key == $contentElementKey){
444
				return $precedingKey;
445
			}
446
			if(!str_beginsWith($key, '#')){
447
				$precedingKey = $key;
448
			}
449
		}
450
	}
451
	return null;
452
}
453

    
454

    
455

    
456

    
457

    
458

    
459

    
(4-4/8)