Project

General

Profile

Download (18.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
 * 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 lectotype_citation_layout($typeDesignation_citation){
20
	$res = '';
21
	if ($typeDesignation_citation){
22
		//$type = $typeDesignation_citation->type;
23
		$year = substr($typeDesignation_citation->datePublished->start, 0, 4);
24
		$page = $typeDesignation_citation->page;
25
		$author = $typeDesignation_citation->authorTeam->titleCache;
26
		$res .= ' (designated by ';
27
		$res .= $author;
28
		$res .= ($year ? ' '.$year : '');
29
		$res .= ($year && $page ? ': '. $page : '');
30
		//$res .= ')';
31
		//$res .= ($type ? ': ' . $type : '');
32
	}
33
	return $res;
34
}
35

    
36
function theme_cdm_typedesignations($typeDesignations = array()){
37

    
38
	RenderHints::pushToRenderStack('typedesignations');
39
	//_add_js_cluetip();
40
	$out = '<ul class="typeDesignations">';
41
  $typeDesignation_footnotes = false;
42
	$specimenTypeDesignations = array();
43
	foreach($typeDesignations as $typeDesignation){
44
		if($typeDesignation->class == 'SpecimenTypeDesignation'){
45
			// SpecimenTypeDesignations should be ordered. collect theme here only
46
			$specimenTypeDesignations[] = $typeDesignation;
47
		}else {
48
			// it's a NameTypeDesignation
49
			if($typeDesignation->notDesignated){
50
				$out .= '<li class="nameTypeDesignation"><span class="status">Lectotype</span> '.t('not designated'). '</li>';
51
			}else if($typeDesignation->typeName){
52
				$link_to_name_page = '?q=' . path_to_name($typeDesignation->typeName->uuid);
53
				$out .= '<li class="nameTypeDesignation"><span class="status">Lectotype</span> ';
54

    
55
			if($typeDesignation->citation){
56
          $out .= lectotype_citation_layout($typeDesignation->citation);
57
          //footnotes
58
          $fkey_typeDesignation = FootnoteManager::addNewFootnote(RenderHints::getRenderPath() . '-typeDesignations-' . $typeDesignation->uuid, $typeDesignation->citation->titleCache);
59
          $out .= theme('cdm_footnote_key', $fkey_typeDesignation) . '): ';          
60
          $typeDesignation_footnotes = true;
61
        }
62
				
63
				if($typeDesignation->typeName->nomenclaturalReference){
64
					$referenceUri = url(path_to_reference($typeDesignation->typeName->nomenclaturalReference->uuid));
65
				}
66
				$out .= theme('cdm_taxonName', $typeDesignation->typeName, $link_to_name_page, $referenceUri);
67
				
68
			}
69
		}
70
	}
71

    
72
	if(!empty($specimenTypeDesignations)){
73
		// sorting might be different for dataportals so this has to be parameterized
74
		usort($specimenTypeDesignations, "compare_specimenTypeDesignationStatus");
75
		foreach($specimenTypeDesignations as $std){
76

    
77
			$typeReference = '';
78
			//show citation only for Lectotype or Neotype
79
			$showCitation = isset($std->typeStatus) && ($std->typeStatus->uuid == UUID_NEOTYPE || $std->typeStatus->uuid == UUID_LECTOTYPE);
80
			if($showCitation && !empty($std->citation)){
81
				//$shortCitation = $std->citation->authorTeam->titleCache;
82

    
83
				$author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $std->citation->uuid);
84
				$shortCitation = $author_team->titleCache;
85

    
86
				$shortCitation .= (strlen($shortCitation) > 0 ? ' ' : '' ). partialToYear($std->citation->datePublished->start);
87
				if(strlen($shortCitation) == 0){
88
					$shortCitation = theme('cdm_reference', $std->citation);
89
					$missingShortCitation = true;
90
				}
91

    
92
				$typeReference .= '&nbsp;(' . t('designated by');
93
				$typeReference .= '&nbsp;<span class="typeReference '.($missingShortCitation ? '' : 'cluetip').' no-print" title="'. htmlspecialchars('|'.theme('cdm_reference',$std->citation ).'|') .'">';
94
				$typeReference .= $shortCitation.'</span>';
95
				$typeReference .= ':'. $std->citationMicroReference .')';
96

    
97
				$_fkey2 = FootnoteManager::addNewFootnote(RenderHints::getRenderPath() . '-lectotypes', $std->citation->titleCache);
98
				$typeReference .= theme('cdm_footnote_key', $_fkey2);
99
			}
100

    
101
			$derivedUnitFacadeInstance = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, $std->typeSpecimen->uuid);
102
				
103
			$out .= '<li class="specimenTypeDesignation">';
104
			$out .= '<span class="status">'.(($std->typeStatus->representation_L10n) ? $std->typeStatus->representation_L10n : t('Type')) .$typeReference.'</span>: '.$derivedUnitFacadeInstance->titleCache;
105
			$out .= theme('cdm_specimen', $derivedUnitFacadeInstance);
106

    
107
			//footnotes for synonymy acronyms
108
			$_fkey = FootnoteManager::addNewFootnote(RenderHints::getRenderPath() . '-acronyms', $derivedUnitFacadeInstance->collection->titleCache);
109
			$out .= theme('cdm_footnote_key', $_fkey);
110
			$out .= '</li>';
111
				
112
			if (!empty($std->citation)){
113
				$render_footnote_lectotypes = true;
114
			 //$out .= theme('cdm_footnotes', RenderHints::getRenderPath() . '-lectotypes');
115
			}
116
		}
117
	}
118

    
119
	$out .= '</ul>';
120
	//render the footnotes at the end of the page
121
	if ($render_footnote_lectotypes){
122
		$out .= theme('cdm_footnotes', RenderHints::getRenderPath() . '-lectotypes');
123
	}
124
	$out .= theme('cdm_footnotes', RenderHints::getRenderPath() . '-acronyms');
125
	if ($typeDesignation_footnotes){
126
	  $out .= theme('cdm_footnotes', RenderHints::getRenderPath() . '-typeDesignations-' . $typeDesignation->uuid);  
127
	}
128
	RenderHints::popFromRenderStack();
129
	return $out;
130
}
131

    
132

    
133
/**
134
 * FIXME this definitively has to be in another spot. just didn't know where to put it right now.
135
 * Compares the status of two SpecimenTypeDesignations
136
 * @param String $a 	a SpecimenTypeDesignations
137
 * @param String $b		another SpecimenTypeDesignations
138
 */
139
function compare_specimenTypeDesignationStatus($a, $b){
140
	/* this is the desired sort oder as of now:
141
	 * 	Holotype
142
	 * 	Isotype
143
	 * 	Lectotype
144
	 * 	Isolectotype
145
	 * 	Syntype
146
	 *
147
	 * TODO
148
	 * Basically, what we are trying to do is, we define an ordered array of TypeDesignation-states
149
	 * and use the index of this array for comparison. This array has to be filled with the cdm-
150
	 * TypeDesignation states and the order should be parameterisable inside the dataportal.
151
	 */
152
	// make that static for now
153
	$typeOrder = array('Holotype', 'Isotype', 'Lectotype', 'Isolectotype', 'Syntype');
154

    
155
	$aQuantifier = array_search($a->typeStatus->label, $typeOrder);
156
	$bQuantifier = array_search($b->typeStatus->label, $typeOrder);
157

    
158
	if ($aQuantifier == $bQuantifier) {
159
		// sort alphabetically
160
		return ($a->typeStatus->label < $b->typeStatus->label) ? -1 : 1;
161
	}
162
	return ($aQuantifier < $bQuantifier) ? -1 : 1;
163

    
164
}
165

    
166
function theme_cdm_nameRelationships($nameRelationships, $skipTypes = false){
167

    
168
	if(!$nameRelationships){
169
		return;
170
	}
171

    
172
	RenderHints::pushToRenderStack('nameRelationships');
173
	$footnoteListKey = 'nameRelationships';
174
	RenderHints::setFootnoteListKey($footnoteListKey);
175

    
176
	// group by relationship type
177
	$relationshipGroups = array();
178
	foreach($nameRelationships as $nameRelationship){
179
		if(!array_key_exists($nameRelationship->type->uuid, $relationshipGroups)){
180
			$relationshipGroups[$nameRelationship->type->uuid] = array();
181
		}
182
		$relationshipGroups[$nameRelationship->type->uuid][] = $nameRelationship;
183
	}
184

    
185
	// generate output
186
	$out = '';
187
	foreach($relationshipGroups as $group){
188
		$type = $group[0]->type;
189

    
190
		if(is_array($skipTypes) && in_array($type->uuid, $skipTypes)){
191
			continue;
192
		}
193

    
194
		$block->module = 'cdm_dataportal';
195
		$block->subject = t(ucfirst($type->inverseRepresentation_L10n));
196
		$block->delta = generalizeString(strtolower($type->inverseRepresentation_L10n));
197

    
198
		foreach($group as $relationship){
199
			$relatedNames[] = cdm_taggedtext2html($relationship->fromName->taggedName);
200
		}
201

    
202
		$block->content .= implode('; ', $relatedNames);
203
		$out .= theme('block', $block);
204
	}
205
	$out .= theme('cdm_footnotes', $footnoteListKey, 'div');
206

    
207
	RenderHints::popFromRenderStack();
208
	return $out;
209
}
210

    
211

    
212

    
213
function theme_cdm_homotypicSynonymLine($taxon){
214
	$out = '';
215
	$out .= '<li class="synonym">'.theme('cdm_related_taxon', $taxon, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
216

    
217
	return $out;
218
}
219

    
220
function theme_cdm_heterotypicSynonymyGroup($homotypicalGroup){
221

    
222
	RenderHints::pushToRenderStack('heterotypicSynonymyGroup');
223

    
224
	$out = '';
225
	$out = '<ul class="heterotypicSynonymyGroup">';
226
	$footnoteListKey = ( isset($homotypicalGroup[0]) ? $homotypicalGroup[0]->uuid : 'NULL');
227
	RenderHints::setFootnoteListKey($footnoteListKey);
228

    
229
	$is_first_entry = true;
230
	$typeDesignations = null;
231
	foreach($homotypicalGroup as $synonym){
232
		if($is_first_entry){
233
			$is_first_entry = false;
234
			$typeDesignations = cdm_ws_get(CDM_WS_NAME_TYPEDESIGNATIONS, $synonym->name->uuid);
235
			// is first list entry
236
			$out .= '<li class="firstentry synonym">'.theme('cdm_related_taxon',$synonym, UUID_HETEROTYPIC_SYNONYM_OF).'</li>';
237
		} else {
238
			$out .= '<li class="synonym">'.theme('cdm_related_taxon',$synonym, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
239
		}
240
	}
241
	$test =  theme('cdm_annotation_footnotes', $footnoteListKey, 'li');
242
	//tuypedesignations footnotes
243
	if($typeDesignations){
244
		$out .= theme('cdm_typedesignations', $typeDesignations);
245
		
246
	}
247
	//annotation footnotes
248
	//$annotation_key = ( isset($homotypicalGroup[0]) ? $homotypicalGroup[0]->uuid : 'NULL');
249
	//$fkey_annotations = FootnoteManager::addNewFootnote(RenderHints::getRenderPath() . '-annotations-' . $annotation_key, $annotation_key);
250
	//$out .= theme('cdm_footnotes', RenderHints::getRenderPath() . '-annotations-' . $annotation_key);  
251
	$out .= theme('cdm_annotation_footnotes', $footnoteListKey, 'li');  
252
	$out .= '</ul>';
253

    
254

    
255
	RenderHints::popFromRenderStack();
256
	return $out;
257
}
258

    
259

    
260

    
261
function theme_cdm_homotypicSynonymyGroup($synonymList, $prependedSynonyms = array()){
262

    
263
	RenderHints::pushToRenderStack('homotypicSynonymyGroup');
264

    
265
	$footnoteListKey = isset($prependedSynonyms[0]) ? $prependedSynonyms[0]->uuid : (isset($synonymList[0]) ? $synonymList[0]->uuid : 'NULL');
266
	RenderHints::setFootnoteListKey($footnoteListKey);
267

    
268
	if(! is_array($synonymList) || count($synonymList) == 0){
269
		return;
270
	}
271

    
272
	$out = '<ul class="homotypicSynonyms">';
273

    
274
	if(!empty($prependedSynonyms)){
275
		foreach($prependedSynonyms as $taxon){
276
			$out .= '<li class="synonym">'.theme('cdm_related_taxon', $taxon, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
277
		}
278
	}
279

    
280
	foreach($synonymList as $synonym){
281
		$out .= '<li class="synonym">'.theme('cdm_related_taxon', $synonym, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
282
	}
283

    
284
	$typeDesignations = cdm_ws_get(CDM_WS_NAME_TYPEDESIGNATIONS, $synonymList[0]->name->uuid);
285
	if($typeDesignations){
286
		$out .= theme('cdm_typedesignations', $typeDesignations);
287
	}
288

    
289
	$out .= theme('cdm_annotation_footnotes', $footnoteListKey, 'li');
290
	$out .= '</ul>';
291

    
292
	RenderHints::popFromRenderStack();
293
	return $out;
294
}
295

    
296

    
297
function theme_cdm_taxonName($taxonName, $nameLink = NULL, $refenceLink = NULL, $showAnnotations = true){
298

    
299
	$renderTemplate = get_nameRenderTemplate(RenderHints::getRenderPath(), $nameLink, $refenceLink);
300
	$partDefinition = get_partDefinition($taxonName->class);
301

    
302
	// apply defintions to template
303
	foreach($renderTemplate as $part=>$uri){
304
		if(isset($partDefinition[$part])){
305
			$renderTemplate[$part] = $partDefinition[$part];
306
		}
307
		if(is_array($uri)){
308
			$renderTemplate[$part]['#uri'] = $uri['#uri'];
309
		}
310
	}
311

    
312
	$firstEntryIsValidNamePart = is_array($taxonName->taggedName)
313
	&& is_string($taxonName->taggedName[0]->text)
314
	&& $taxonName->taggedName[0]->text != ''
315
	&& $taxonName->taggedName[0]->type == 'name';
316

    
317
	// got to use second entry as first one, see ToDo comment below ...
318
	if($firstEntryIsValidNamePart){
319

    
320
		$taggedName = $taxonName->taggedName;
321

    
322
		$lastAuthorElementString = false;
323
		$hasNamePart_with_Authors = isset($renderTemplate['namePart']) && isset($renderTemplate['namePart']['authors']);
324
		$hasNameAuthorPart_with_Authors = isset($renderTemplate['nameAuthorPart']) && isset($renderTemplate['nameAuthorPart']['authors']);
325

    
326
		if(!($hasNamePart_with_Authors || $hasNameAuthorPart_with_Authors)){
327
			//      // find author and split off from name
328
			//      // TODO expecting to find the author as the last element
329
			//      if($taggedName[count($taggedName)- 1]->type == 'authors'){
330
			//        $authorTeam = $taggedName[count($taggedName)- 1]->text;
331
			//        unset($taggedName[count($taggedName)- 1]);
332
			//      }
333

    
334
			// remove all authors
335
			$taggedNameNew = array();
336
			foreach($taggedName as $element){
337
				if($element->type != 'authors'){
338
					$taggedNameNew[] = $element;
339
				} else {
340
					$lastAuthorElementString = $element->text;
341
				}
342
			}
343
			$taggedName = $taggedNameNew;
344

    
345
		}
346
		$name = '<span class="'.$taxonName->class.'">'.theme('cdm_taggedtext2html', $taggedName).'</span>';
347
	} else {
348
		$name = '<span class="'.$taxonName->class.'_titleCache">'.$taxonName->titleCache.'</span>';
349
	}
350

    
351
	// fill name into $renderTemplate
352
	array_setr('name', $name, $renderTemplate);
353

    
354
	//  // fill with authorTeam
355
	//  if($authorTeam){
356
	//    $authorTeamHtml = ' <span class="authorTeam">'.$authorTeam.'</span>';
357
	//    array_setr('authorTeam', $authorTeamHtml, $renderTemplate);
358
	//  }
359

    
360

    
361
	// fill with reference
362
	if(isset($renderTemplate['referencePart'])){
363

    
364
		// [Eckhard]:"Komma nach dem Taxonnamen ist grunsätzlich falsch,
365
		// Komma nach dem Autornamen ist überall dort falsch, wo ein "in" folgt."
366
		if(isset($renderTemplate['referencePart']['reference']) && $taxonName->nomenclaturalReference){
367
			$microreference = null;
368
			if(isset($renderTemplate['referencePart']['microreference'])){
369
				$microreference = $taxonName->nomenclaturalMicroReference;
370
			}
371
			$citation = cdm_ws_get(CDM_WS_NOMENCLATURAL_REFERENCE_CITATION, array($taxonName->nomenclaturalReference->uuid), "microReference=".urlencode($microreference));
372
			$citation = $citation->String;
373
			// find preceding element of the refrence
374
			$precedingKey = get_preceding_contentElementKey('reference', $renderTemplate);
375
			if(str_beginsWith($citation, ", in")){
376
				$citation = substr($citation, 2);
377
				$separator = ' ';
378
			} else if(!str_beginsWith($citation, "in") && $precedingKey == 'authors'){
379
				$separator = ', ';
380
			} else {
381
				$separator = ' ';
382
			}
383

    
384
			$referenceArray['#separator'] = $separator;
385
			$referenceArray['#html'] = '<span class="reference">'.$citation.'</span>';
386
			array_setr('reference', $referenceArray, $renderTemplate);
387
		}
388

    
389
		// if authors have been removed from the name part the last named authorteam
390
		// should be added to the reference citation, otherwise, keep the separator
391
		// out of the reference
392
		if(isset($renderTemplate['referencePart']['authors']) && $lastAuthorElementString){
393
			// if the nomenclaturalReference cintation is not included in the reference part but diplay of the microreference
394
			// is whanted append the microreference to the authorTeam
395
			if(!isset($renderTemplate['referencePart']['reference']) && isset($renderTemplate['referencePart']['microreference'])){
396
				$separator = ": ";
397
				$citation = $taxonName->nomenclaturalMicroReference;
398
			}
399
			$referenceArray['#html'] = ' <span class="reference">'.$lastAuthorElementString.$separator.$citation.'</span>';
400
			array_setr('authors', $referenceArray, $renderTemplate);
401
		}
402

    
403
	}
404

    
405
	// fill with status
406
	if(array_setr('status', true, $renderTemplate)){
407
		if(isset($taxon->name->status[0])){
408
			foreach($taxon->name->status as $status){
409
				$statusHtml .= ', '.$status->type->representation_L10n;
410
			}
411
		}
412
		array_setr('status', ' <span class="nomenclatural_status">'.$statusHtml.'</span>', $renderTemplate);
413
	}
414

    
415
	// fill with protologues etc...
416
	if(array_setr('description', true, $renderTemplate)){
417
		$descriptions = cdm_ws_get(CDM_WS_PORTAL_NAME_DESCRIPTIONS, $taxonName->uuid);
418
		foreach($descriptions as $description){
419
			if(!empty($description)){
420
				foreach($description->elements as $description_element){
421
					$second_citation = '';
422
					if ($description_element->multilanguageText_L10n->text){
423
						$second_citation = '[& ' . $description_element->multilanguageText_L10n->text . '].';
424
					}
425
					$descriptionHtml .= $second_citation;
426
					$descriptionHtml .= theme("cdm_media", $description_element, array('application/pdf', 'image/png', 'image/jpeg', 'image/gif', 'text/html'));
427
				}
428
			}
429
		}
430
		array_setr('description', $descriptionHtml, $renderTemplate);
431
	}
432

    
433
	// render
434
	$out = '<span ref="/name/'.$taxonName->uuid.'">';
435

    
436
	foreach($renderTemplate as $partName=>$part){
437
		$separator = '';
438
		$partHtml = '';
439
		$uri = false;
440
		if(!is_array($part)){
441
			continue;
442
		}
443
		if(isset($part['#uri']) && is_string($part['#uri'])){
444
			$uri = $part['#uri'];
445
			unset($part['#uri']);
446
		}
447
		foreach($part as $key=>$content){
448
			$html = '';
449
			if(is_array($content)){
450
				$html = $content['#html'];
451
				$separator = $content['#separator'];
452
			} else if(is_string($content)){
453
				$html = $content;
454
			}
455
			$partHtml .= '<span class="'.$key.'">'.$html.'</span>';
456
		}
457
		if($uri){
458
			$out .= $separator.'<a href="'.$uri.'" class="'.$partName.'">'.$partHtml.'</a>';
459
		} else {
460
			$out .= $separator.$partHtml;
461
		}
462
	}
463
	$out .= '</span>';
464

    
465
	$out .= theme('cdm_annotations_as_footnotekeys', $taxonName);
466
	return $out;
467
}
468

    
469
/**
470
 * Recursively searches the array for the $key and sets the given value
471
 * @param $key
472
 * @param $value
473
 * @param $array
474
 * @return true if the key has been found
475
 */
476
function &array_setr($key, $value, array &$array){
477
	foreach($array as $k=>&$v){
478
		if($key == $k){
479
			$v = $value;
480
			return $array;
481
		} else if(is_array($v)){
482
			$innerArray = array_setr($key, $value, $v);
483
			if($innerArray){
484
				return $array;
485
			}
486
		}
487
	}
488
	return null;
489
}
490

    
491
function &get_preceding_contentElement($contentElementKey, array &$renderTemplate){
492
	$precedingElement = null;
493
	foreach($renderTemplate as &$part){
494
		foreach($part as $key=>&$element){
495
			if($key == $contentElementKey){
496
				return $precedingElement;
497
			}
498
			$precedingElement = $element;
499
		}
500
	}
501
	return null;
502
}
503

    
504
function &get_preceding_contentElementKey($contentElementKey, array &$renderTemplate){
505
	$precedingKey = null;
506
	foreach($renderTemplate as &$part){
507
		foreach($part as $key=>&$element){
508
			if($key == $contentElementKey){
509
				return $precedingKey;
510
			}
511
			if(!str_beginsWith($key, '#')){
512
				$precedingKey = $key;
513
			}
514
		}
515
	}
516
	return null;
517
}
518

    
519

    
520

    
521

    
522

    
523

    
524

    
(4-4/8)