Project

General

Profile

Download (19.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
 * This function prints the lectotype citation with the correct layout
15
 * Lectotypes are renderized in the synonymy tab of a taxon if they exist
16
 * @param $typeDesignation_citation The lectotype citation to print
17
 * @return html valid string
18
 */
19
function type_designation_citation_layout($typeDesignation){
20

    
21
	$res = '';
22
	$citation = $typeDesignation->citation;
23
	$pages = $typeDesignation->citationMicroReference;
24
	if ($citation){
25
		//$type = $typeDesignation_citation->type;
26
		$year = substr($citation->datePublished->start, 0, 4);
27
		$author = $citation->authorTeam->titleCache;
28
		$res .= ' (designated by ';
29
		$res .= $author;
30
		$res .= ($year ? ' '.$year : '');
31
		$res .= ($pages ? ': '. $pages : '');
32
		//$res .= ')';
33
	}
34
	return $res;
35
}
36

    
37
function theme_cdm_typedesignations($typeDesignations = array()){
38
	/*
39
	 if(isset($renderTemplate['referencePart']['reference']) && $taxonName->nomenclaturalReference){
40
	 $microreference = null;
41
	 if(isset($renderTemplate['referencePart']['microreference'])){
42
	 $microreference = $taxonName->nomenclaturalMicroReference;
43
	 }
44
	 $citation = cdm_ws_get(CDM_WS_NOMENCLATURAL_REFERENCE_CITATION, array($typeDesignation->uuid), "microReference=".urlencode($microreference));
45
	 $citation = $citation->String;
46
	 */
47

    
48
	RenderHints::pushToRenderStack('typedesignations');
49
	//_add_js_cluetip();
50
	$out = '<ul class="typeDesignations">';
51
	$typeDesignation_footnotes = false;
52
	$is_lectotype = false;
53
	$specimenTypeDesignations = array();
54
	$separator = ',';
55
	foreach($typeDesignations as $typeDesignation){
56
		if($typeDesignation->class == 'SpecimenTypeDesignation'){
57
			// SpecimenTypeDesignations should be ordered. collect theme here only
58
			$specimenTypeDesignations[] = $typeDesignation;
59
		}else{ //it is a lectotype?
60
			if(strcmp($typeDesignation->typeStatus->titleCache, 'lectotype') == 0){
61
        $is_lectotype = true;
62
      } 
63
			// it's a NameTypeDesignation
64
			if($typeDesignation->notDesignated){ 
65
				$out .= '<li class="nameTypeDesignation"><span class="status">' . ($is_lectotype ? 'Lectotype' : 'Type') . '</span>: ' . t('not designated'). '</li>';
66
				//$out .= '<li class="nameTypeDesignation"><span class="status">Lectotype</span>: '.t('not designated'). '</li>';
67
			}else if($typeDesignation->typeName){
68
				$link_to_name_page = '?q=' . path_to_name($typeDesignation->typeName->uuid);
69
				$out .= '<li class="nameTypeDesignation"><span class="status">' . ($is_lectotype ? 'Lectotype' : 'Type') . '</span>';
70
				if($typeDesignation->citation){
71
					$out .= type_designation_citation_layout($typeDesignation);
72
					//footnotes
73
					//$fkey_typeDesignation = FootnoteManager::addNewFootnote(RenderHints::getRenderPath() . '-typeDesignations-' . $typeDesignation->uuid, $typeDesignation->citation->titleCache);
74
					$fkey_typeDesignation = FootnoteManager::addNewFootnote(RenderHints::getRenderPath() . '-typeDesignations', $typeDesignation->citation->titleCache);
75
					$out .= theme('cdm_footnote_key', $fkey_typeDesignation, $separator, true, true) . ')';
76
				}
77
				if($typeDesignation->typeName->nomenclaturalReference){
78
					$referenceUri = url(path_to_reference($typeDesignation->typeName->nomenclaturalReference->uuid));
79
				}
80
				$out .= ': ' . theme('cdm_taxonName', $typeDesignation->typeName, $link_to_name_page, $referenceUri, true, true);
81
			}
82
		}
83
	}
84

    
85
	if(!empty($specimenTypeDesignations)){
86
		// sorting might be different for dataportals so this has to be parameterized
87
		usort($specimenTypeDesignations, "compare_specimenTypeDesignationStatus");
88
		foreach($specimenTypeDesignations as $std){
89
			$typeReference = '';
90
			//show citation only for Lectotype or Neotype
91
			$showCitation = isset($std->typeStatus) && ($std->typeStatus->uuid == UUID_NEOTYPE || $std->typeStatus->uuid == UUID_LECTOTYPE);
92
			if($showCitation && !empty($std->citation)){
93
				//$shortCitation = $std->citation->authorTeam->titleCache;
94

    
95
				$author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $std->citation->uuid);
96
				$shortCitation = $author_team->titleCache;
97

    
98
				$shortCitation .= (strlen($shortCitation) > 0 ? ' ' : '' ). partialToYear($std->citation->datePublished->start);
99
				if(strlen($shortCitation) == 0){
100
					$shortCitation = theme('cdm_reference', $std->citation);
101
					$missingShortCitation = true;
102
				}
103

    
104
				$typeReference .= '&nbsp;(' . t('designated by');
105
				$typeReference .= '&nbsp;<span class="typeReference '.($missingShortCitation ? '' : 'cluetip').' no-print" title="'. htmlspecialchars('|'.theme('cdm_reference',$std->citation ).'|') .'">';
106
				$typeReference .= $shortCitation.'</span>';
107
				$typeReference .= ':'. $std->citationMicroReference .')';
108

    
109
				$_fkey2 = FootnoteManager::addNewFootnote(RenderHints::getRenderPath() . '-lectotypes', $std->citation->titleCache);
110
				$typeReference .= theme('cdm_footnote_key', $_fkey2, $separator, true, true);
111
			}
112

    
113
			$derivedUnitFacadeInstance = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, $std->typeSpecimen->uuid);
114

    
115
			$out .= '<li class="specimenTypeDesignation">';
116
			$out .= '<span class="status">'.(($std->typeStatus->representation_L10n) ? $std->typeStatus->representation_L10n : t('Type')) .$typeReference.'</span>: '.$derivedUnitFacadeInstance->titleCache;
117
			$out .= theme('cdm_specimen', $derivedUnitFacadeInstance);
118

    
119
			//footnotes for synonymy acronyms
120
			$_fkey = FootnoteManager::addNewFootnote(RenderHints::getRenderPath() . '-acronyms', $derivedUnitFacadeInstance->collection->titleCache);
121
			$out .= theme('cdm_footnote_key', $_fkey, $separator);
122
			$out .= '</li>';
123

    
124
			if (!empty($std->citation)){
125
				$render_footnote_lectotypes = true;
126
			 //$out .= theme('cdm_footnotes', RenderHints::getRenderPath() . '-lectotypes');
127
			}
128
		}
129
	}
130

    
131
	$out .= '</ul>';
132
	//render the footnotes at the end of the page
133
	if ($render_footnote_lectotypes){
134
		$out .= theme('cdm_footnotes', RenderHints::getRenderPath() . '-lectotypes');
135
	}
136
	$out .= theme('cdm_footnotes', RenderHints::getRenderPath() . '-acronyms', 'li');
137
	$out .= theme('cdm_footnotes', RenderHints::getRenderPath() . '-typeDesignations', 'li');
138
	//$out .= theme('cdm_footnotes', RenderHints::getRenderPath() . '-typeDesignations-' . $typeDesignation->uuid, 'li');
139

    
140
	RenderHints::popFromRenderStack();
141
	return $out;
142
}
143

    
144

    
145
/**
146
 * FIXME this definitively has to be in another spot. just didn't know where to put it right now.
147
 * Compares the status of two SpecimenTypeDesignations
148
 * @param String $a 	a SpecimenTypeDesignations
149
 * @param String $b		another SpecimenTypeDesignations
150
 */
151
function compare_specimenTypeDesignationStatus($a, $b){
152
	/* this is the desired sort oder as of now:
153
	 * 	Holotype
154
	 * 	Isotype
155
	 * 	Lectotype
156
	 * 	Isolectotype
157
	 * 	Syntype
158
	 *
159
	 * TODO
160
	 * Basically, what we are trying to do is, we define an ordered array of TypeDesignation-states
161
	 * and use the index of this array for comparison. This array has to be filled with the cdm-
162
	 * TypeDesignation states and the order should be parameterisable inside the dataportal.
163
	 */
164
	// make that static for now
165
	$typeOrder = array('Holotype', 'Isotype', 'Lectotype', 'Isolectotype', 'Syntype');
166

    
167
	$aQuantifier = array_search($a->typeStatus->label, $typeOrder);
168
	$bQuantifier = array_search($b->typeStatus->label, $typeOrder);
169

    
170
	if ($aQuantifier == $bQuantifier) {
171
		// sort alphabetically
172
		return ($a->typeStatus->label < $b->typeStatus->label) ? -1 : 1;
173
	}
174
	return ($aQuantifier < $bQuantifier) ? -1 : 1;
175

    
176
}
177

    
178
function theme_cdm_nameRelationships($nameRelationships, $skipTypes = false){
179

    
180
	if(!$nameRelationships){
181
		return;
182
	}
183

    
184
	RenderHints::pushToRenderStack('nameRelationships');
185
	$footnoteListKey = 'nameRelationships';
186
	RenderHints::setFootnoteListKey($footnoteListKey);
187

    
188
	// group by relationship type
189
	$relationshipGroups = array();
190
	foreach($nameRelationships as $nameRelationship){
191
		if(!array_key_exists($nameRelationship->type->uuid, $relationshipGroups)){
192
			$relationshipGroups[$nameRelationship->type->uuid] = array();
193
		}
194
		$relationshipGroups[$nameRelationship->type->uuid][] = $nameRelationship;
195
	}
196

    
197
	// generate output
198
	$out = '';
199
	foreach($relationshipGroups as $group){
200
		$type = $group[0]->type;
201

    
202
		if(is_array($skipTypes) && in_array($type->uuid, $skipTypes)){
203
			continue;
204
		}
205

    
206
		$block->module = 'cdm_dataportal';
207
		$block->subject = t(ucfirst($type->inverseRepresentation_L10n));
208
		$block->delta = generalizeString(strtolower($type->inverseRepresentation_L10n));
209

    
210
		foreach($group as $relationship){
211
			$relatedNames[] = cdm_taggedtext2html($relationship->fromName->taggedName);
212
		}
213

    
214
		$block->content .= implode('; ', $relatedNames);
215
		$out .= theme('block', $block);
216
	}
217
	$out .= theme('cdm_footnotes', $footnoteListKey, 'div');
218

    
219
	RenderHints::popFromRenderStack();
220
	return $out;
221
}
222

    
223

    
224

    
225
function theme_cdm_homotypicSynonymLine($taxon){
226
	$out = '';
227
	$out .= '<li class="synonym">'.theme('cdm_related_taxon', $taxon, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
228

    
229
	return $out;
230
}
231

    
232
function theme_cdm_heterotypicSynonymyGroup($homotypicalGroup){
233

    
234
	RenderHints::pushToRenderStack('heterotypicSynonymyGroup');
235

    
236
	$out = '';
237
	$out = '<ul class="heterotypicSynonymyGroup">';
238
	$footnoteListKey = ( isset($homotypicalGroup[0]) ? $homotypicalGroup[0]->uuid : 'NULL');
239
	RenderHints::setFootnoteListKey($footnoteListKey);
240

    
241
	$is_first_entry = true;
242
	$typeDesignations = null;
243
	foreach($homotypicalGroup as $synonym){
244
		if($is_first_entry){
245
			$is_first_entry = false;
246
			$typeDesignations = cdm_ws_get(CDM_WS_PORTAL_NAME_TYPEDESIGNATIONS, $synonym->name->uuid);
247
			// is first list entry
248
			$out .= '<li class="firstentry synonym">'.theme('cdm_related_taxon',$synonym, UUID_HETEROTYPIC_SYNONYM_OF).'</li>';
249
		} else {
250
			$out .= '<li class="synonym">'.theme('cdm_related_taxon',$synonym, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
251
		}
252
	}
253
	//$test =  theme('cdm_annotation_footnotes', $footnoteListKey, 'li');
254
	//tuypedesignations footnotes
255
	
256
	if($typeDesignations){
257
		$out .= theme('cdm_typedesignations', $typeDesignations);
258

    
259
	}
260
	
261
	//annotation footnotes
262
	//$annotation_key = ( isset($homotypicalGroup[0]) ? $homotypicalGroup[0]->uuid : 'NULL');
263
	//$fkey_annotations = FootnoteManager::addNewFootnote(RenderHints::getRenderPath() . '-annotations-' . $annotation_key, $annotation_key);
264
	//$out .= theme('cdm_footnotes', RenderHints::getRenderPath() . '-annotations-' . $annotation_key);
265
	$out .= theme('cdm_annotation_footnotes', $footnoteListKey, 'li');
266
	//$out .= theme('cdm_annotation_footnotes', $footnoteListKey);
267
	$out .= '</ul>';
268

    
269

    
270
	RenderHints::popFromRenderStack();
271
	return $out;
272
}
273

    
274

    
275

    
276
function theme_cdm_homotypicSynonymyGroup($synonymList, $prependedSynonyms = array()){
277

    
278
	RenderHints::pushToRenderStack('homotypicSynonymyGroup');
279

    
280
	$footnoteListKey = isset($prependedSynonyms[0]) ? $prependedSynonyms[0]->uuid : (isset($synonymList[0]) ? $synonymList[0]->uuid : 'NULL');
281
	$accepted_taxon_footnoteListKey = RenderHints::getFootnoteListKey();
282
	RenderHints::setFootnoteListKey($footnoteListKey);
283

    
284
	if(! is_array($synonymList) || count($synonymList) == 0){
285
		return;
286
	}
287

    
288
	$out = '<ul class="homotypicSynonyms">';
289

    
290
	if(!empty($prependedSynonyms)){
291
		foreach($prependedSynonyms as $taxon){
292
			$out .= '<li class="synonym">'.theme('cdm_related_taxon', $taxon, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
293
		}
294
	}
295

    
296
	foreach($synonymList as $synonym){
297
		$out .= '<li class="synonym">'.theme('cdm_related_taxon', $synonym, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
298
	}
299

    
300
	$typeDesignations = cdm_ws_get(CDM_WS_PORTAL_NAME_TYPEDESIGNATIONS, $synonymList[0]->name->uuid);
301
	if($typeDesignations){
302
		$out .= theme('cdm_typedesignations', $typeDesignations);
303
	}
304

    
305
	$out .= theme('cdm_footnotes', $accepted_taxon_footnoteListKey, 'li');
306
	$out .= theme('cdm_annotation_footnotes', $footnoteListKey, 'li');
307
	$out .= '</ul>';
308

    
309
	RenderHints::popFromRenderStack();
310
	return $out;
311
}
312

    
313

    
314
function theme_cdm_taxonName($taxonName, $nameLink = NULL, $refenceLink = NULL, $show_annotations = true, $is_type_designation = false){
315

    
316
	$renderTemplate = get_nameRenderTemplate(RenderHints::getRenderPath(), $nameLink, $refenceLink);
317
	$partDefinition = get_partDefinition($taxonName->class);
318

    
319
	// apply defintions to template
320
	foreach($renderTemplate as $part=>$uri){
321
		if(isset($partDefinition[$part])){
322
			$renderTemplate[$part] = $partDefinition[$part];
323
		}
324
		if(is_array($uri)){
325
			$renderTemplate[$part]['#uri'] = $uri['#uri'];
326
		}
327
	}
328

    
329
	$firstEntryIsValidNamePart = is_array($taxonName->taggedName)
330
	&& is_string($taxonName->taggedName[0]->text)
331
	&& $taxonName->taggedName[0]->text != ''
332
	&& $taxonName->taggedName[0]->type == 'name';
333

    
334
	// got to use second entry as first one, see ToDo comment below ...
335
	if($firstEntryIsValidNamePart){
336

    
337
		$taggedName = $taxonName->taggedName;
338

    
339
		$lastAuthorElementString = false;
340
		$hasNamePart_with_Authors = isset($renderTemplate['namePart']) && isset($renderTemplate['namePart']['authors']);
341
		$hasNameAuthorPart_with_Authors = isset($renderTemplate['nameAuthorPart']) && isset($renderTemplate['nameAuthorPart']['authors']);
342

    
343
		if(!($hasNamePart_with_Authors || $hasNameAuthorPart_with_Authors)){
344
			//      // find author and split off from name
345
			//      // TODO expecting to find the author as the last element
346
			//      if($taggedName[count($taggedName)- 1]->type == 'authors'){
347
			//        $authorTeam = $taggedName[count($taggedName)- 1]->text;
348
			//        unset($taggedName[count($taggedName)- 1]);
349
			//      }
350

    
351
			// remove all authors
352
			$taggedNameNew = array();
353
			foreach($taggedName as $element){
354
				if($element->type != 'authors'){
355
					$taggedNameNew[] = $element;
356
				} else {
357
					$lastAuthorElementString = $element->text;
358
				}
359
			}
360
			$taggedName = $taggedNameNew;
361

    
362
		}
363
		$name = '<span class="'.$taxonName->class.'">'.theme('cdm_taggedtext2html', $taggedName).'</span>';
364
	} else {
365
		$name = '<span class="'.$taxonName->class.'_titleCache">'.$taxonName->titleCache.'</span>';
366
	}
367

    
368
	// fill name into $renderTemplate
369
	array_setr('name', $name, $renderTemplate);
370

    
371
	//  // fill with authorTeam
372
	//  if($authorTeam){
373
	//    $authorTeamHtml = ' <span class="authorTeam">'.$authorTeam.'</span>';
374
	//    array_setr('authorTeam', $authorTeamHtml, $renderTemplate);
375
	//  }
376

    
377
	// fill with reference
378
	if(isset($renderTemplate['referencePart']) && !$is_type_designation){
379

    
380
		// [Eckhard]:"Komma nach dem Taxonnamen ist grunsätzlich falsch,
381
		// Komma nach dem Autornamen ist überall dort falsch, wo ein "in" folgt."
382
		if(isset($renderTemplate['referencePart']['reference']) && $taxonName->nomenclaturalReference){
383
			$microreference = null;
384
			if(isset($renderTemplate['referencePart']['microreference'])){
385
				$microreference = $taxonName->nomenclaturalMicroReference;
386
			}
387
			$citation = cdm_ws_get(CDM_WS_NOMENCLATURAL_REFERENCE_CITATION, array($taxonName->nomenclaturalReference->uuid), "microReference=".urlencode($microreference));
388
			$citation = $citation->String;
389
			// find preceding element of the refrence
390
			$precedingKey = get_preceding_contentElementKey('reference', $renderTemplate);
391
			if(str_beginsWith($citation, ", in")){
392
				$citation = substr($citation, 2);
393
				$separator = ' ';
394
			} else if(!str_beginsWith($citation, "in") && $precedingKey == 'authors'){
395
				$separator = ', ';
396
			} else {
397
				$separator = ' ';
398
			}
399

    
400
			$referenceArray['#separator'] = $separator;
401
			$referenceArray['#html'] = '<span class="reference">'.$citation.'</span>';
402
			array_setr('reference', $referenceArray, $renderTemplate);
403
		}
404

    
405
		// if authors have been removed from the name part the last named authorteam
406
		// should be added to the reference citation, otherwise, keep the separator
407
		// out of the reference
408
		if(isset($renderTemplate['referencePart']['authors']) && $lastAuthorElementString){
409
			// if the nomenclaturalReference cintation is not included in the reference part but diplay of the microreference
410
			// is whanted append the microreference to the authorTeam
411
			if(!isset($renderTemplate['referencePart']['reference']) && isset($renderTemplate['referencePart']['microreference'])){
412
				$separator = ": ";
413
				$citation = $taxonName->nomenclaturalMicroReference;
414
			}
415
			$referenceArray['#html'] = ' <span class="reference">'.$lastAuthorElementString.$separator.$citation.'</span>';
416
			array_setr('authors', $referenceArray, $renderTemplate);
417
		}
418

    
419
	}
420

    
421
	// fill with status
422
	if(array_setr('status', true, $renderTemplate)){
423
		if(isset($taxon->name->status[0])){
424
			foreach($taxon->name->status as $status){
425
				$statusHtml .= ', '.$status->type->representation_L10n;
426
			}
427
		}
428
		array_setr('status', ' <span class="nomenclatural_status">'.$statusHtml.'</span>', $renderTemplate);
429
	}
430

    
431
	// fill with protologues etc...
432
	if(array_setr('description', true, $renderTemplate)){
433
		$descriptions = cdm_ws_get(CDM_WS_PORTAL_NAME_DESCRIPTIONS, $taxonName->uuid);
434
		foreach($descriptions as $description){
435
			if(!empty($description)){
436
				foreach($description->elements as $description_element){
437
					$second_citation = '';
438
					if ($description_element->multilanguageText_L10n->text){
439
						$second_citation = '[& ' . $description_element->multilanguageText_L10n->text . '].';
440
					}
441
					$descriptionHtml .= $second_citation;
442
					$descriptionHtml .= theme("cdm_media", $description_element, array('application/pdf', 'image/png', 'image/jpeg', 'image/gif', 'text/html'));
443
				}
444
			}
445
		}
446
		array_setr('description', $descriptionHtml, $renderTemplate);
447
	}
448

    
449
	// render
450
	$out = '<span ref="/name/'.$taxonName->uuid.'">';
451

    
452
	foreach($renderTemplate as $partName=>$part){
453
		$separator = '';
454
		$partHtml = '';
455
		$uri = false;
456
		if(!is_array($part)){
457
			continue;
458
		}
459
		if(isset($part['#uri']) && is_string($part['#uri'])){
460
			$uri = $part['#uri'];
461
			unset($part['#uri']);
462
		}
463
		foreach($part as $key=>$content){
464
			$html = '';
465
			if(is_array($content)){
466
				$html = $content['#html'];
467
				$separator = $content['#separator'];
468
			} else if(is_string($content)){
469
				$html = $content;
470
			}
471
			$partHtml .= '<span class="'.$key.'">'.$html.'</span>';
472
		}
473
		if($uri){
474
			$out .= $separator.'<a href="'.$uri.'" class="'.$partName.'">'.$partHtml.'</a>';
475
		} else {
476
			$out .= $separator.$partHtml;
477
		}
478
	}
479
	$out .= '</span>';
480
	if ($show_annotations){
481
    //$out .= theme('cdm_annotations_as_footnotekeys', $taxonName);
482
	}
483
	return $out;
484
}
485

    
486
/**
487
 * Recursively searches the array for the $key and sets the given value
488
 * @param $key
489
 * @param $value
490
 * @param $array
491
 * @return true if the key has been found
492
 */
493
function &array_setr($key, $value, array &$array){
494
	foreach($array as $k=>&$v){
495
		if($key == $k){
496
			$v = $value;
497
			return $array;
498
		} else if(is_array($v)){
499
			$innerArray = array_setr($key, $value, $v);
500
			if($innerArray){
501
				return $array;
502
			}
503
		}
504
	}
505
	return null;
506
}
507

    
508
function &get_preceding_contentElement($contentElementKey, array &$renderTemplate){
509
	$precedingElement = null;
510
	foreach($renderTemplate as &$part){
511
		foreach($part as $key=>&$element){
512
			if($key == $contentElementKey){
513
				return $precedingElement;
514
			}
515
			$precedingElement = $element;
516
		}
517
	}
518
	return null;
519
}
520

    
521
function &get_preceding_contentElementKey($contentElementKey, array &$renderTemplate){
522
	$precedingKey = null;
523
	foreach($renderTemplate as &$part){
524
		foreach($part as $key=>&$element){
525
			if($key == $contentElementKey){
526
				return $precedingKey;
527
			}
528
			if(!str_beginsWith($key, '#')){
529
				$precedingKey = $key;
530
			}
531
		}
532
	}
533
	return null;
534
}
535

    
536

    
537

    
538

    
539

    
540

    
541

    
(4-4/8)