Project

General

Profile

Download (15.5 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
				$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
	RenderHints::popFromRenderStack();
85
	return $out;
86
}
87

    
88

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

    
111
	$aQuantifier = array_search($a->typeStatus->label, $typeOrder);
112
	$bQuantifier = array_search($b->typeStatus->label, $typeOrder);
113

    
114
	if ($aQuantifier == $bQuantifier) {
115
		// sort alphabetically
116
		return ($a->typeStatus->label < $b->typeStatus->label) ? -1 : 1;
117
	}
118
	return ($aQuantifier < $bQuantifier) ? -1 : 1;
119

    
120
}
121

    
122
function theme_cdm_nameRelations($nameRelationships, $skipTypes = false){
123

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

    
133
	// generate output
134
	$out = '';
135
	foreach($relationshipGroups as $group){
136
		$type = $group[0]->type;
137

    
138
		if(is_array($skipTypes) && in_array($type->uuid, $skipTypes)){
139
			continue;
140
		}
141

    
142
		$block->module = 'cdm_dataportal';
143
		$block->subject = t(ucfirst($type->inverseRepresentation_L10n));
144
		$block->delta = generalizeString(strtolower($type->inverseRepresentation_L10n));
145

    
146
		foreach($group as $relationship){
147
			$relatedNames[] = cdm_taggedtext2html($relationship->fromName->taggedName);
148
		}
149

    
150
		$block->content .= implode('; ', $relatedNames);
151
		$out .= theme('block', $block);
152
	}
153
	return $out;
154
}
155

    
156

    
157

    
158
function theme_cdm_homotypicSynonymLine($taxon){
159
	$out = '';
160
	$out .= '<li class="synonym">'.theme('cdm_related_taxon', $taxon, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
161
	
162
	return $out;
163
}
164

    
165
function theme_cdm_heterotypicSynonymyGroup($homotypicalGroup){
166
	
167
	RenderHints::pushToRenderStack('heterotypicSynonymyGroup');
168
	$out = '';
169
	$out = '<ul class="heterotypicSynonymyGroup">';
170

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

    
189
	$out .= '</ul>';
190
    
191
	$out .= FootnoteManager::renderFootnoteList($firstSynonymUuid);
192
    
193
    RenderHints::popFromRenderStack();
194
	return $out;
195
}
196

    
197

    
198

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

    
210
	$out = '<ul class="homotypicSynonyms">';
211

    
212
	if(!empty($prependedSynonyms)){
213
		foreach($prependedSynonyms as $taxon){
214
			$out .= '<li class="synonym">'.theme('cdm_related_taxon', $taxon, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
215
		}
216
	}
217

    
218
	foreach($synonymList as $synonym){
219
		$out .= '<li class="synonym">'.theme('cdm_related_taxon', $synonym, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
220
	}
221

    
222
	$typeDesignations = cdm_ws_get(CDM_WS_PORTAL_TAXON_NAMETYPEDESIGNATIONS, $synonymList[0]->uuid);
223
	if($typeDesignations){
224
		$out .= theme('cdm_typedesignations', $typeDesignations);
225
	}
226

    
227
	$out .= '</ul>';
228
	$out .= FootnoteManager::renderFootnoteList($firstSynonymUuid);
229
	
230
	RenderHints::popFromRenderStack();
231
	return $out;
232
}
233

    
234

    
235
function theme_cdm_taxonName($taxonName, $nameLink = NULL, $refenceLink = NULL){
236

    
237
    $renderTemplate = get_nameRenderTemplate(RenderHints::getRenderPath(), $nameLink, $refenceLink);
238

    
239
	$partDefinition = get_partDefinition($taxonName->class);
240

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

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

    
258
		$taggedName = $taxonName->taggedName;
259

    
260
		$lastAuthorElementString = false;
261
		$hasNamePart_with_Authors = isset($renderTemplate['namePart']) && isset($renderTemplate['namePart']['authors']);
262
		$hasNameAuthorPart_with_Authors = isset($renderTemplate['nameAuthorPart']) && isset($renderTemplate['nameAuthorPart']['authors']);
263

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

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

    
283
		}
284
		$name = '<span class="'.$taxonName->class.'">'.theme('cdm_taggedtext2html', $taggedName).'</span>';
285
	} else {
286
		$name = '<span class="'.$taxonName->class.'_titleCache">'.$taxonName->titleCache.'</span>';
287
	}
288

    
289
	// fill name into $renderTemplate
290
	array_setr('name', $name, $renderTemplate);
291

    
292
	//  // fill with authorTeam
293
	//  if($authorTeam){
294
	//    $authorTeamHtml = ' <span class="authorTeam">'.$authorTeam.'</span>';
295
	//    array_setr('authorTeam', $authorTeamHtml, $renderTemplate);
296
	//  }
297

    
298

    
299
	// fill with reference
300
	if(isset($renderTemplate['referencePart'])){
301

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

    
322
			$referenceArray['#separator'] = $separator;
323
			$referenceArray['#html'] = '<span class="reference">'.$citation.'</span>';
324
			array_setr('reference', $referenceArray, $renderTemplate);
325
		}
326

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

    
341
	}
342

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

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

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

    
396
	return $out.'</span>';
397
}
398

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

    
421
function &get_preceding_contentElement($contentElementKey, array &$renderTemplate){
422
	$precedingElement = null;
423
	foreach($renderTemplate as &$part){
424
		foreach($part as $key=>&$element){
425
			if($key == $contentElementKey){
426
				return $precedingElement;
427
			}
428
			$precedingElement = $element;
429
		}
430
	}
431
	return null;
432
}
433

    
434
function &get_preceding_contentElementKey($contentElementKey, array &$renderTemplate){
435
	$precedingKey = null;
436
	foreach($renderTemplate as &$part){
437
		foreach($part as $key=>&$element){
438
			if($key == $contentElementKey){
439
				return $precedingKey;
440
			}
441
			if(!str_beginsWith($key, '#')){
442
				$precedingKey = $key;
443
			}
444
		}
445
	}
446
	return null;
447
}
448

    
449

    
450

    
451

    
452

    
453

    
454

    
(4-4/8)