Project

General

Profile

Download (16.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
		
24
		if($typeDesignation->class == 'SpecimenTypeDesignation'){
25
			// SpecimenTypeDesignations should be ordered. collect theme here only
26
			
27
			
28
			$specimenTypeDesignations[] = $typeDesignation;
29
		}else {
30

    
31
			// it's a NameTypeDesignation
32
			if($typeDesignation->notDesignated){
33
				$out .= '<li class="nameTypeDesignation"><span class="status">Type</span>: '.t('not designated'). '</li>';
34
			}else if($typeDesignation->typeName){
35
                $link_to_name_page = '?q=' . path_to_name($typeDesignation->typeName->uuid);
36
				$out .= '<li class="nameTypeDesignation"><span class="status">Type</span>: ';
37

    
38
				if($typeDesignation->typeName->nomenclaturalReference){
39
					$referenceUri = url(path_to_reference($typeDesignation->typeName->nomenclaturalReference->uuid));
40
				}
41
				$out .= theme('cdm_taxonName', $typeDesignation->typeName, $link_to_name_page, $referenceUri);
42
			}
43
		}
44
	}
45

    
46
	if(!empty($specimenTypeDesignations)){
47
		// sorting might be different for dataportals so this has to be parameterized
48
		usort($specimenTypeDesignations, "compare_specimenTypeDesignationStatus");
49
		foreach($specimenTypeDesignations as $std){
50

    
51
			$typeReference = '';
52
			//show citation only for Lectotype or Neotype
53
			$showCitation = isset($std->typeStatus) && ($std->typeStatus->uuid == UUID_NEOTYPE || $std->typeStatus->uuid == UUID_LECTOTYPE);
54
			if($showCitation && !empty($std->citation)){
55
				//$shortCitation = $std->citation->authorTeam->titleCache;
56

    
57
			     $author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $std->citation->uuid);
58
			     $shortCitation = $author_team->titleCache;
59

    
60
				$shortCitation .= (strlen($shortCitation) > 0 ? ' ' : '' ). partialToYear($std->citation->datePublished->start);
61
				if(strlen($shortCitation) == 0){
62
					$shortCitation = theme('cdm_reference', $std->citation);
63
					$missingShortCitation = true;
64
				}
65
				
66
				$typeReference .= '&nbsp;(' . t('designated by');
67
				$typeReference .= '&nbsp;<span class="typeReference '.($missingShortCitation ? '' : 'cluetip').' no-print" title="'. htmlspecialchars('|'.theme('cdm_reference',$std->citation ).'|') .'">';
68
				$typeReference .= $shortCitation.'</span>';
69
				$typeReference .= ':'. $std->citationMicroReference .')';
70

    
71
			  $_fkey2 = FootnoteManager::addNewFootnote(RenderHints::getRenderPath() . '-lectotypes', $std->citation->titleCache);
72
				$typeReference .= theme('cdm_footnote_key', $_fkey2); 
73
     	}
74

    
75
     	$derivedUnitFacadeInstance = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, $std->typeSpecimen->uuid);
76
			
77
			$out .= '<li class="specimenTypeDesignation">';
78
			$out .= '<span class="status">'.(($std->typeStatus->representation_L10n) ? $std->typeStatus->representation_L10n : t('Type')) .$typeReference.'</span>: '.$derivedUnitFacadeInstance->titleCache;
79
			$out .= theme('cdm_specimen', $derivedUnitFacadeInstance);
80

    
81
			//footnotes for synonymy acronyms 
82
			$_fkey = FootnoteManager::addNewFootnote(RenderHints::getRenderPath() . '-acronyms', $derivedUnitFacadeInstance->collection->titleCache);
83
            $out .= theme('cdm_footnote_key', $_fkey);  
84
			$out .= '</li>';
85
			
86
			if (!empty($std->citation)){
87
				$render_footnote_lectotypes = true;
88
			 //$out .= theme('cdm_footnotes', RenderHints::getRenderPath() . '-lectotypes');
89
			}
90
		}
91
	}
92

    
93
	$out .= '</ul>';
94
	//render the footnotes at the end of the page
95
     if ($render_footnote_lectotypes){
96
       $out .= theme('cdm_footnotes', RenderHints::getRenderPath() . '-lectotypes');
97
      }
98
    $out .= theme('cdm_footnotes', RenderHints::getRenderPath() . '-acronyms');
99
  
100
	RenderHints::popFromRenderStack();
101
	return $out;
102
}
103

    
104

    
105
/**
106
 * FIXME this definitively has to be in another spot. just didn't know where to put it right now.
107
 * Compares the status of two SpecimenTypeDesignations
108
 * @param String $a 	a SpecimenTypeDesignations
109
 * @param String $b		another SpecimenTypeDesignations
110
 */
111
function compare_specimenTypeDesignationStatus($a, $b){
112
	/* this is the desired sort oder as of now:
113
	 * 	Holotype
114
	 * 	Isotype
115
	 * 	Lectotype
116
	 * 	Isolectotype
117
	 * 	Syntype
118
	 *
119
	 * TODO
120
	 * Basically, what we are trying to do is, we define an ordered array of TypeDesignation-states
121
	 * and use the index of this array for comparison. This array has to be filled with the cdm-
122
	 * TypeDesignation states and the order should be parameterisable inside the dataportal.
123
	 */
124
	// make that static for now
125
	$typeOrder = array('Holotype', 'Isotype', 'Lectotype', 'Isolectotype', 'Syntype');
126

    
127
	$aQuantifier = array_search($a->typeStatus->label, $typeOrder);
128
	$bQuantifier = array_search($b->typeStatus->label, $typeOrder);
129

    
130
	if ($aQuantifier == $bQuantifier) {
131
		// sort alphabetically
132
		return ($a->typeStatus->label < $b->typeStatus->label) ? -1 : 1;
133
	}
134
	return ($aQuantifier < $bQuantifier) ? -1 : 1;
135

    
136
}
137

    
138
function theme_cdm_nameRelationships($nameRelationships, $skipTypes = false){
139

    
140
    if(!$nameRelationships){
141
        return;
142
    }
143
    
144
	RenderHints::pushToRenderStack('nameRelationships');
145
    $footnoteListKey = 'nameRelationships';
146
    RenderHints::setFootnoteListKey($footnoteListKey);
147
    
148
	// group by relationship type
149
	$relationshipGroups = array();
150
	foreach($nameRelationships as $nameRelationship){
151
		if(!array_key_exists($nameRelationship->type->uuid, $relationshipGroups)){
152
			$relationshipGroups[$nameRelationship->type->uuid] = array();
153
		}
154
		$relationshipGroups[$nameRelationship->type->uuid][] = $nameRelationship;
155
	}
156

    
157
	// generate output
158
	$out = '';
159
	foreach($relationshipGroups as $group){
160
		$type = $group[0]->type;
161

    
162
		if(is_array($skipTypes) && in_array($type->uuid, $skipTypes)){
163
			continue;
164
		}
165

    
166
		$block->module = 'cdm_dataportal';
167
		$block->subject = t(ucfirst($type->inverseRepresentation_L10n));
168
		$block->delta = generalizeString(strtolower($type->inverseRepresentation_L10n));
169

    
170
		foreach($group as $relationship){
171
			$relatedNames[] = cdm_taggedtext2html($relationship->fromName->taggedName);
172
		}
173

    
174
		$block->content .= implode('; ', $relatedNames);
175
		$out .= theme('block', $block);
176
	}
177
	$out .= theme('cdm_footnotes', $footnoteListKey, 'div');
178
	
179
	RenderHints::popFromRenderStack();
180
	return $out;
181
}
182

    
183

    
184

    
185
function theme_cdm_homotypicSynonymLine($taxon){
186
	$out = '';
187
	$out .= '<li class="synonym">'.theme('cdm_related_taxon', $taxon, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
188
	
189
	return $out;
190
}
191

    
192
function theme_cdm_heterotypicSynonymyGroup($homotypicalGroup){
193
	
194
	RenderHints::pushToRenderStack('heterotypicSynonymyGroup');
195
	
196
	$out = '';
197
	$out = '<ul class="heterotypicSynonymyGroup">';
198
    $footnoteListKey = ( isset($homotypicalGroup[0]) ? $homotypicalGroup[0]->uuid : 'NULL');
199
	RenderHints::setFootnoteListKey($footnoteListKey);
200
    
201
	$is_first_entry = true;
202
	$typeDesignations = null;
203
	foreach($homotypicalGroup as $synonym){
204
		if($is_first_entry){
205
			$is_first_entry = false;
206
			$typeDesignations = cdm_ws_get(CDM_WS_NAME_TYPEDESIGNATIONS, $synonym->name->uuid);
207
			// is first list entry
208
			$out .= '<li class="firstentry synonym">'.theme('cdm_related_taxon',$synonym, UUID_HETEROTYPIC_SYNONYM_OF).'</li>';
209
		} else {
210
			$out .= '<li class="synonym">'.theme('cdm_related_taxon',$synonym, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
211
		}
212
	}
213
	if($typeDesignations){
214
		$out .= theme('cdm_typedesignations', $typeDesignations);
215
	}
216

    
217
	$out .= theme('cdm_annotation_footnotes', $footnoteListKey, 'li');
218
	$out .= '</ul>';
219
    
220
    
221
    RenderHints::popFromRenderStack();
222
	return $out;
223
}
224

    
225

    
226

    
227
function theme_cdm_homotypicSynonymyGroup($synonymList, $prependedSynonyms = array()){
228
	
229
	RenderHints::pushToRenderStack('homotypicSynonymyGroup');
230
	
231
	$footnoteListKey = isset($prependedSynonyms[0]) ? $prependedSynonyms[0]->uuid : (isset($synonymList[0]) ? $synonymList[0]->uuid : 'NULL');
232
	RenderHints::setFootnoteListKey($footnoteListKey);
233
	
234
	if(! is_array($synonymList) || count($synonymList) == 0){
235
		return;
236
	}
237

    
238
	$out = '<ul class="homotypicSynonyms">';
239

    
240
	if(!empty($prependedSynonyms)){
241
		foreach($prependedSynonyms as $taxon){
242
			$out .= '<li class="synonym">'.theme('cdm_related_taxon', $taxon, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
243
		}
244
	}
245

    
246
	foreach($synonymList as $synonym){
247
		$out .= '<li class="synonym">'.theme('cdm_related_taxon', $synonym, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
248
	}
249

    
250
	$typeDesignations = cdm_ws_get(CDM_WS_NAME_TYPEDESIGNATIONS, $synonymList[0]->name->uuid);
251
	if($typeDesignations){
252
		$out .= theme('cdm_typedesignations', $typeDesignations);
253
	}
254

    
255
	$out .= theme('cdm_annotation_footnotes', $footnoteListKey, 'li');
256
	$out .= '</ul>';
257
	
258
	RenderHints::popFromRenderStack();
259
	return $out;
260
}
261

    
262

    
263
function theme_cdm_taxonName($taxonName, $nameLink = NULL, $refenceLink = NULL, $showAnnotations = true){
264

    
265
  $renderTemplate = get_nameRenderTemplate(RenderHints::getRenderPath(), $nameLink, $refenceLink);
266
	$partDefinition = get_partDefinition($taxonName->class);
267

    
268
	// apply defintions to template
269
	foreach($renderTemplate as $part=>$uri){
270
		if(isset($partDefinition[$part])){
271
			$renderTemplate[$part] = $partDefinition[$part];
272
		}
273
		if(is_array($uri)){
274
			$renderTemplate[$part]['#uri'] = $uri['#uri'];
275
		}
276
	}
277

    
278
	$firstEntryIsValidNamePart = is_array($taxonName->taggedName)
279
	&& is_string($taxonName->taggedName[0]->text)
280
	&& $taxonName->taggedName[0]->text != ''
281
	&& $taxonName->taggedName[0]->type == 'name';
282
	
283
	// got to use second entry as first one, see ToDo comment below ...
284
	if($firstEntryIsValidNamePart){
285

    
286
		$taggedName = $taxonName->taggedName;
287
		
288
		$lastAuthorElementString = false;
289
		$hasNamePart_with_Authors = isset($renderTemplate['namePart']) && isset($renderTemplate['namePart']['authors']);
290
		$hasNameAuthorPart_with_Authors = isset($renderTemplate['nameAuthorPart']) && isset($renderTemplate['nameAuthorPart']['authors']);
291

    
292
		if(!($hasNamePart_with_Authors || $hasNameAuthorPart_with_Authors)){
293
			//      // find author and split off from name
294
			//      // TODO expecting to find the author as the last element
295
			//      if($taggedName[count($taggedName)- 1]->type == 'authors'){
296
			//        $authorTeam = $taggedName[count($taggedName)- 1]->text;
297
			//        unset($taggedName[count($taggedName)- 1]);
298
			//      }
299

    
300
			// remove all authors
301
			$taggedNameNew = array();
302
			foreach($taggedName as $element){
303
				if($element->type != 'authors'){
304
					$taggedNameNew[] = $element;
305
				} else {
306
					$lastAuthorElementString = $element->text;
307
				}
308
			}
309
			$taggedName = $taggedNameNew;
310

    
311
		}
312
		$name = '<span class="'.$taxonName->class.'">'.theme('cdm_taggedtext2html', $taggedName).'</span>';
313
	} else {
314
		$name = '<span class="'.$taxonName->class.'_titleCache">'.$taxonName->titleCache.'</span>';
315
	}
316

    
317
	// fill name into $renderTemplate
318
	array_setr('name', $name, $renderTemplate);
319

    
320
	//  // fill with authorTeam
321
	//  if($authorTeam){
322
	//    $authorTeamHtml = ' <span class="authorTeam">'.$authorTeam.'</span>';
323
	//    array_setr('authorTeam', $authorTeamHtml, $renderTemplate);
324
	//  }
325

    
326

    
327
	// fill with reference
328
	if(isset($renderTemplate['referencePart'])){
329

    
330
		// [Eckhard]:"Komma nach dem Taxonnamen ist grunsätzlich falsch,
331
		// Komma nach dem Autornamen ist überall dort falsch, wo ein "in" folgt."
332
		if(isset($renderTemplate['referencePart']['reference']) && $taxonName->nomenclaturalReference){
333
			$microreference = null;
334
			if(isset($renderTemplate['referencePart']['microreference'])){
335
				$microreference = $taxonName->nomenclaturalMicroReference;
336
			}
337
			$citation = cdm_ws_get(CDM_WS_NOMENCLATURAL_REFERENCE_CITATION, array($taxonName->nomenclaturalReference->uuid), "microReference=".urlencode($microreference));
338
			$citation = $citation->String;
339
			// find preceding element of the refrence
340
			$precedingKey = get_preceding_contentElementKey('reference', $renderTemplate);
341
			if(str_beginsWith($citation, ", in")){
342
				$citation = substr($citation, 2);
343
				$separator = ' ';
344
			} else if(!str_beginsWith($citation, "in") && $precedingKey == 'authors'){
345
				$separator = ', ';
346
			} else {
347
				$separator = ' ';
348
			}
349

    
350
			$referenceArray['#separator'] = $separator;
351
			$referenceArray['#html'] = '<span class="reference">'.$citation.'</span>';
352
			array_setr('reference', $referenceArray, $renderTemplate);
353
		}
354

    
355
		// if authors have been removed from the name part the last named authorteam
356
		// should be added to the reference citation, otherwise, keep the separator
357
		// out of the reference
358
		if(isset($renderTemplate['referencePart']['authors']) && $lastAuthorElementString){
359
			// if the nomenclaturalReference cintation is not included in the reference part but diplay of the microreference
360
			// is whanted append the microreference to the authorTeam
361
			if(!isset($renderTemplate['referencePart']['reference']) && isset($renderTemplate['referencePart']['microreference'])){
362
				$separator = ": ";
363
				$citation = $taxonName->nomenclaturalMicroReference;
364
			}
365
			$referenceArray['#html'] = ' <span class="reference">'.$lastAuthorElementString.$separator.$citation.'</span>';
366
			array_setr('authors', $referenceArray, $renderTemplate);
367
		}
368

    
369
	}
370

    
371
	// fill with status
372
	if(array_setr('status', true, $renderTemplate)){
373
		if(isset($taxon->name->status[0])){
374
			foreach($taxon->name->status as $status){
375
				$statusHtml .= ', '.$status->type->representation_L10n;
376
			}
377
		}
378
		array_setr('status', ' <span class="nomenclatural_status">'.$statusHtml.'</span>', $renderTemplate);
379
	}
380

    
381
	// fill with protologues etc...
382
	if(array_setr('description', true, $renderTemplate)){
383
		$descriptions = cdm_ws_get(CDM_WS_PORTAL_NAME_DESCRIPTIONS, $taxonName->uuid);
384
		foreach($descriptions as $description){
385
			if(!empty($description)){
386
				foreach($description->elements as $description_element){
387
				  $second_citation = '';
388
					if ($description_element->multilanguageText_L10n->text){
389
					  $second_citation = '[& ' . $description_element->multilanguageText_L10n->text . '].';
390
					}
391
					$descriptionHtml .= $second_citation;
392
					$descriptionHtml .= theme("cdm_media", $description_element, array('application/pdf', 'image/png', 'image/jpeg', 'image/gif', 'text/html'));
393
				}
394
			}
395
		}
396
		array_setr('description', $descriptionHtml, $renderTemplate);
397
	}
398

    
399
	// render
400
	$out = '<span ref="/name/'.$taxonName->uuid.'">';
401
	
402
	foreach($renderTemplate as $partName=>$part){
403
		$separator = '';
404
		$partHtml = '';
405
		$uri = false;
406
		if(!is_array($part)){
407
			continue;
408
		}
409
		if(isset($part['#uri']) && is_string($part['#uri'])){
410
			$uri = $part['#uri'];
411
			unset($part['#uri']);
412
		}
413
		foreach($part as $key=>$content){
414
			$html = '';
415
			if(is_array($content)){
416
				$html = $content['#html'];
417
				$separator = $content['#separator'];
418
			} else if(is_string($content)){
419
				$html = $content;
420
			}
421
			$partHtml .= '<span class="'.$key.'">'.$html.'</span>';
422
		}
423
		if($uri){
424
			$out .= $separator.'<a href="'.$uri.'" class="'.$partName.'">'.$partHtml.'</a>';
425
		} else {
426
			$out .= $separator.$partHtml;
427
		}
428
	}
429
    $out .= '</span>';
430
    
431
	$out .= theme('cdm_annotations_as_footnotekeys', $taxonName);
432
	
433
	return $out;
434
}
435

    
436
/**
437
 * Recursively searches the array for the $key and sets the given value
438
 * @param $key
439
 * @param $value
440
 * @param $array
441
 * @return true if the key has been found
442
 */
443
function &array_setr($key, $value, array &$array){
444
	foreach($array as $k=>&$v){
445
		if($key == $k){
446
			$v = $value;
447
			return $array;
448
		} else if(is_array($v)){
449
			$innerArray = array_setr($key, $value, $v);
450
			if($innerArray){
451
				return $array;
452
			}
453
		}
454
	}
455
	return null;
456
}
457

    
458
function &get_preceding_contentElement($contentElementKey, array &$renderTemplate){
459
	$precedingElement = null;
460
	foreach($renderTemplate as &$part){
461
		foreach($part as $key=>&$element){
462
			if($key == $contentElementKey){
463
				return $precedingElement;
464
			}
465
			$precedingElement = $element;
466
		}
467
	}
468
	return null;
469
}
470

    
471
function &get_preceding_contentElementKey($contentElementKey, array &$renderTemplate){
472
	$precedingKey = null;
473
	foreach($renderTemplate as &$part){
474
		foreach($part as $key=>&$element){
475
			if($key == $contentElementKey){
476
				return $precedingKey;
477
			}
478
			if(!str_beginsWith($key, '#')){
479
				$precedingKey = $key;
480
			}
481
		}
482
	}
483
	return null;
484
}
485

    
486

    
487

    
488

    
489

    
490

    
491

    
(4-4/8)