Project

General

Profile

Download (17.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

    
64
			     $author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $std->citation->uuid);
65
			     $shortCitation = $author_team->titleCache;
66

    
67
				$shortCitation .= (strlen($shortCitation) > 0 ? ' ' : '' ). partialToYear($std->citation->datePublished->start);
68
				if(strlen($shortCitation) == 0){
69
					$shortCitation = theme('cdm_reference', $std->citation);
70
					$missingShortCitation = true;
71
				}
72
				
73
				$typeReference .= '&nbsp;(' . t('designated by');
74
				$typeReference .= '&nbsp;<span class="typeReference '.($missingShortCitation ? '' : 'cluetip').' no-print" title="'. htmlspecialchars('|'.theme('cdm_reference',$std->citation ).'|') .'">';
75
				$typeReference .= $shortCitation.'</span>';
76
				$typeReference .= ':'. $std->citationMicroReference .')';
77

    
78
			    $_fkey2 = FootnoteManager::addNewFootnote(RenderHints::getRenderPath() . '-lectotypes', $std->citation->titleCache);
79
				$typeReference .= theme('cdm_footnote_key', $_fkey2); 
80
        //$citation = cdm_ws_get(CDM_WS_NOMENCLATURAL_REFERENCE_CITATION, array($taxonName->nomenclaturalReference->uuid), "microReference=".urlencode($microreference));
81
        //$citation = $citation->String;
82
				
83

    
84
				//$typeReference .= '<span class="reference only-print">(designated by '.theme('cdm_reference',$std->citation ).')</span>';
85
			}
86

    
87
			
88
			$out .= '<li class="specimenTypeDesignation">';
89
			$out .= '<span class="status">'.(($std->typeStatus->representation_L10n) ? $std->typeStatus->representation_L10n : t('Type')) .$typeReference.'</span>: '.$std->typeSpecimen->titleCache;
90
			$out .= theme('cdm_specimen', $std->typeSpecimen);
91

    
92
			//footnotes for synonymy acronyms 
93
			$_fkey = FootnoteManager::addNewFootnote(RenderHints::getRenderPath() . '-acronyms', $std->typeSpecimen->collection->titleCache);
94
            $out .= theme('cdm_footnote_key', $_fkey);  
95
			$out .= '</li>';
96
			
97
			if (!empty($std->citation)){
98
				$render_footnote_lectotypes = true;
99
			 //$out .= theme('cdm_footnotes', RenderHints::getRenderPath() . '-lectotypes');
100
			}
101
		}
102
	}
103

    
104
	$out .= '</ul>';
105
	//render the footnotes at the end of the page
106
     if ($render_footnote_lectotypes){
107
       $out .= theme('cdm_footnotes', RenderHints::getRenderPath() . '-lectotypes');
108
      }
109
    $out .= theme('cdm_footnotes', RenderHints::getRenderPath() . '-acronyms');
110
  
111
	RenderHints::popFromRenderStack();
112
	return $out;
113
}
114

    
115

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

    
138
	$aQuantifier = array_search($a->typeStatus->label, $typeOrder);
139
	$bQuantifier = array_search($b->typeStatus->label, $typeOrder);
140

    
141
	if ($aQuantifier == $bQuantifier) {
142
		// sort alphabetically
143
		return ($a->typeStatus->label < $b->typeStatus->label) ? -1 : 1;
144
	}
145
	return ($aQuantifier < $bQuantifier) ? -1 : 1;
146

    
147
}
148

    
149
function theme_cdm_nameRelationships($nameRelationships, $skipTypes = false){
150

    
151
    if(!$nameRelationships){
152
        return;
153
    }
154
    
155
	RenderHints::pushToRenderStack('nameRelationships');
156
    $footnoteListKey = 'nameRelationships';
157
    RenderHints::setFootnoteListKey($footnoteListKey);
158
    
159
	// group by relationship type
160
	$relationshipGroups = array();
161
	foreach($nameRelationships as $nameRelationship){
162
		if(!array_key_exists($nameRelationship->type->uuid, $relationshipGroups)){
163
			$relationshipGroups[$nameRelationship->type->uuid] = array();
164
		}
165
		$relationshipGroups[$nameRelationship->type->uuid][] = $nameRelationship;
166
	}
167

    
168
	// generate output
169
	$out = '';
170
	foreach($relationshipGroups as $group){
171
		$type = $group[0]->type;
172

    
173
		if(is_array($skipTypes) && in_array($type->uuid, $skipTypes)){
174
			continue;
175
		}
176

    
177
		$block->module = 'cdm_dataportal';
178
		$block->subject = t(ucfirst($type->inverseRepresentation_L10n));
179
		$block->delta = generalizeString(strtolower($type->inverseRepresentation_L10n));
180

    
181
		foreach($group as $relationship){
182
			$relatedNames[] = cdm_taggedtext2html($relationship->fromName->taggedName);
183
		}
184

    
185
		$block->content .= implode('; ', $relatedNames);
186
		$out .= theme('block', $block);
187
	}
188
	$out .= theme('cdm_footnotes', $footnoteListKey, 'div');
189
	
190
	RenderHints::popFromRenderStack();
191
	return $out;
192
}
193

    
194

    
195

    
196
function theme_cdm_homotypicSynonymLine($taxon){
197
	$out = '';
198
	$out .= '<li class="synonym">'.theme('cdm_related_taxon', $taxon, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
199
	
200
	return $out;
201
}
202

    
203
function theme_cdm_heterotypicSynonymyGroup($homotypicalGroup){
204
	
205
	RenderHints::pushToRenderStack('heterotypicSynonymyGroup');
206
	
207
	$out = '';
208
	$out = '<ul class="heterotypicSynonymyGroup">';
209
    $footnoteListKey = ( isset($homotypicalGroup[0]) ? $homotypicalGroup[0]->uuid : 'NULL');
210
	RenderHints::setFootnoteListKey($footnoteListKey);
211
    
212
	$is_first_entry = true;
213
	$typeDesignations = null;
214
	foreach($homotypicalGroup as $synonym){
215
		if($is_first_entry){
216
			$is_first_entry = false;
217
			//$typeDesignations = cdm_ws_get(CDM_WS_NAME_TYPEDESIGNATIONS, $synonym->name->uuid);
218
			$typeDesignations = cdm_ws_get(CDM_WS_PORTAL_TAXON_NAMETYPEDESIGNATIONS, $synonym->uuid);
219
			// is first list entry
220
			$out .= '<li class="firstentry synonym">'.theme('cdm_related_taxon',$synonym, UUID_HETEROTYPIC_SYNONYM_OF).'</li>';
221
		} else {
222
			$out .= '<li class="synonym">'.theme('cdm_related_taxon',$synonym, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
223
		}
224
	}
225
	if($typeDesignations){
226
		$out .= theme('cdm_typedesignations', $typeDesignations);
227
	}
228

    
229
	$out .= theme('cdm_annotation_footnotes', $footnoteListKey, 'li');
230
	$out .= '</ul>';
231
    
232
    
233
    RenderHints::popFromRenderStack();
234
	return $out;
235
}
236

    
237

    
238

    
239
function theme_cdm_homotypicSynonymyGroup($synonymList, $prependedSynonyms = array()){
240
	
241
	RenderHints::pushToRenderStack('homotypicSynonymyGroup');
242
	
243
	$footnoteListKey = isset($prependedSynonyms[0]) ? $prependedSynonyms[0]->uuid : (isset($synonymList[0]) ? $synonymList[0]->uuid : 'NULL');
244
	RenderHints::setFootnoteListKey($footnoteListKey);
245
	
246
	if(! is_array($synonymList) || count($synonymList) == 0){
247
		return;
248
	}
249

    
250
	$out = '<ul class="homotypicSynonyms">';
251

    
252
	if(!empty($prependedSynonyms)){
253
		foreach($prependedSynonyms as $taxon){
254
			$out .= '<li class="synonym">'.theme('cdm_related_taxon', $taxon, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
255
		}
256
	}
257

    
258
	foreach($synonymList as $synonym){
259
		$out .= '<li class="synonym">'.theme('cdm_related_taxon', $synonym, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
260
	}
261

    
262
	$typeDesignations = cdm_ws_get(CDM_WS_PORTAL_TAXON_NAMETYPEDESIGNATIONS, $synonymList[0]->uuid);
263
	if($typeDesignations){
264
		$out .= theme('cdm_typedesignations', $typeDesignations);
265
	}
266

    
267
	$out .= theme('cdm_annotation_footnotes', $footnoteListKey, 'li');
268
	$out .= '</ul>';
269
	
270
	RenderHints::popFromRenderStack();
271
	return $out;
272
}
273

    
274

    
275
function theme_cdm_taxonName($taxonName, $nameLink = NULL, $refenceLink = NULL, $showAnnotations = true){
276

    
277
  $renderTemplate = get_nameRenderTemplate(RenderHints::getRenderPath(), $nameLink, $refenceLink);
278
	$partDefinition = get_partDefinition($taxonName->class);
279

    
280
	// apply defintions to template
281
	foreach($renderTemplate as $part=>$uri){
282
		if(isset($partDefinition[$part])){
283
			$renderTemplate[$part] = $partDefinition[$part];
284
		}
285
		if(is_array($uri)){
286
			$renderTemplate[$part]['#uri'] = $uri['#uri'];
287
		}
288
	}
289

    
290
	$firstEntryIsValidNamePart = is_array($taxonName->taggedName)
291
	&& is_string($taxonName->taggedName[0]->text)
292
	&& $taxonName->taggedName[0]->text != ''
293
	&& $taxonName->taggedName[0]->type == 'name';
294
	
295
	// got to use second entry as first one, see ToDo comment below ...
296
	if($firstEntryIsValidNamePart){
297

    
298
		$taggedName = $taxonName->taggedName;
299
		
300
		$lastAuthorElementString = false;
301
		$hasNamePart_with_Authors = isset($renderTemplate['namePart']) && isset($renderTemplate['namePart']['authors']);
302
		$hasNameAuthorPart_with_Authors = isset($renderTemplate['nameAuthorPart']) && isset($renderTemplate['nameAuthorPart']['authors']);
303

    
304
		if(!($hasNamePart_with_Authors || $hasNameAuthorPart_with_Authors)){
305
			//      // find author and split off from name
306
			//      // TODO expecting to find the author as the last element
307
			//      if($taggedName[count($taggedName)- 1]->type == 'authors'){
308
			//        $authorTeam = $taggedName[count($taggedName)- 1]->text;
309
			//        unset($taggedName[count($taggedName)- 1]);
310
			//      }
311

    
312
			// remove all authors
313
			$taggedNameNew = array();
314
			foreach($taggedName as $element){
315
				if($element->type != 'authors'){
316
					$taggedNameNew[] = $element;
317
				} else {
318
					$lastAuthorElementString = $element->text;
319
				}
320
			}
321
			$taggedName = $taggedNameNew;
322

    
323
		}
324
		$name = '<span class="'.$taxonName->class.'">'.theme('cdm_taggedtext2html', $taggedName).'</span>';
325
	} else {
326
		$name = '<span class="'.$taxonName->class.'_titleCache">'.$taxonName->titleCache.'</span>';
327
	}
328

    
329
	// fill name into $renderTemplate
330
	array_setr('name', $name, $renderTemplate);
331

    
332
	//  // fill with authorTeam
333
	//  if($authorTeam){
334
	//    $authorTeamHtml = ' <span class="authorTeam">'.$authorTeam.'</span>';
335
	//    array_setr('authorTeam', $authorTeamHtml, $renderTemplate);
336
	//  }
337

    
338

    
339
	// fill with reference
340
	if(isset($renderTemplate['referencePart'])){
341

    
342
		// [Eckhard]:"Komma nach dem Taxonnamen ist grunsätzlich falsch,
343
		// Komma nach dem Autornamen ist überall dort falsch, wo ein "in" folgt."
344
		if(isset($renderTemplate['referencePart']['reference']) && $taxonName->nomenclaturalReference){
345
			$microreference = null;
346
			if(isset($renderTemplate['referencePart']['microreference'])){
347
				$microreference = $taxonName->nomenclaturalMicroReference;
348
			}
349
			$citation = cdm_ws_get(CDM_WS_NOMENCLATURAL_REFERENCE_CITATION, array($taxonName->nomenclaturalReference->uuid), "microReference=".urlencode($microreference));
350
			$citation = $citation->String;
351
			// find preceding element of the refrence
352
			$precedingKey = get_preceding_contentElementKey('reference', $renderTemplate);
353
			if(str_beginsWith($citation, ", in")){
354
				$citation = substr($citation, 2);
355
				$separator = ' ';
356
			} else if(!str_beginsWith($citation, "in") && $precedingKey == 'authors'){
357
				$separator = ', ';
358
			} else {
359
				$separator = ' ';
360
			}
361

    
362
			$referenceArray['#separator'] = $separator;
363
			$referenceArray['#html'] = '<span class="reference">'.$citation.'</span>';
364
			array_setr('reference', $referenceArray, $renderTemplate);
365
		}
366

    
367
		// if authors have been removed from the name part the last named authorteam
368
		// should be added to the reference citation, otherwise, keep the separator
369
		// out of the reference
370
		if(isset($renderTemplate['referencePart']['authors']) && $lastAuthorElementString){
371
			// if the nomenclaturalReference cintation is not included in the reference part but diplay of the microreference
372
			// is whanted append the microreference to the authorTeam
373
			if(!isset($renderTemplate['referencePart']['reference']) && isset($renderTemplate['referencePart']['microreference'])){
374
				$separator = ": ";
375
				$citation = $taxonName->nomenclaturalMicroReference;
376
			}
377
			$referenceArray['#html'] = ' <span class="reference">'.$lastAuthorElementString.$separator.$citation.'</span>';
378
			array_setr('authors', $referenceArray, $renderTemplate);
379
		}
380

    
381
	}
382

    
383
	// fill with status
384
	if(array_setr('status', true, $renderTemplate)){
385
		if(isset($taxon->name->status[0])){
386
			foreach($taxon->name->status as $status){
387
				$statusHtml .= ', '.$status->type->representation_L10n;
388
			}
389
		}
390
		array_setr('status', ' <span class="nomenclatural_status">'.$statusHtml.'</span>', $renderTemplate);
391
	}
392

    
393
	// fill with protologues etc...
394
	if(array_setr('description', true, $renderTemplate)){
395
		$descriptions = cdm_ws_get(CDM_WS_PORTAL_NAME_DESCRIPTIONS, $taxonName->uuid);
396
		foreach($descriptions as $description){
397
			if(!empty($description)){
398
				foreach($description->elements as $description_element){
399
				  $second_citation = '';
400
					if ($description_element->multilanguageText_L10n->text){
401
					  $second_citation = '[& ' . $description_element->multilanguageText_L10n->text . '].';
402
					}
403
					$descriptionHtml .= $second_citation;
404
					$descriptionHtml .= theme("cdm_media", $description_element, array('application/pdf', 'image/png', 'image/jpeg', 'image/gif', 'text/html'));
405
				}
406
			}
407
		}
408
		array_setr('description', $descriptionHtml, $renderTemplate);
409
	}
410

    
411
	// render
412
	$out = '<span ref="/name/'.$taxonName->uuid.'">';
413
	
414
	foreach($renderTemplate as $partName=>$part){
415
		$separator = '';
416
		$partHtml = '';
417
		$uri = false;
418
		if(!is_array($part)){
419
			continue;
420
		}
421
		if(isset($part['#uri']) && is_string($part['#uri'])){
422
			$uri = $part['#uri'];
423
			unset($part['#uri']);
424
		}
425
		foreach($part as $key=>$content){
426
			$html = '';
427
			if(is_array($content)){
428
				$html = $content['#html'];
429
				$separator = $content['#separator'];
430
			} else if(is_string($content)){
431
				$html = $content;
432
			}
433
			$partHtml .= '<span class="'.$key.'">'.$html.'</span>';
434
		}
435
		if($uri){
436
			$out .= $separator.'<a href="'.$uri.'" class="'.$partName.'">'.$partHtml.'</a>';
437
		} else {
438
			$out .= $separator.$partHtml;
439
		}
440
	}
441
    $out .= '</span>';
442
    
443
	$out .= theme('cdm_annotations_as_footnotekeys', $taxonName);
444
	
445
	return $out;
446
}
447

    
448
/**
449
 * Recursively searches the array for the $key and sets the given value
450
 * @param $key
451
 * @param $value
452
 * @param $array
453
 * @return true if the key has been found
454
 */
455
function &array_setr($key, $value, array &$array){
456
	foreach($array as $k=>&$v){
457
		if($key == $k){
458
			$v = $value;
459
			return $array;
460
		} else if(is_array($v)){
461
			$innerArray = array_setr($key, $value, $v);
462
			if($innerArray){
463
				return $array;
464
			}
465
		}
466
	}
467
	return null;
468
}
469

    
470
function &get_preceding_contentElement($contentElementKey, array &$renderTemplate){
471
	$precedingElement = null;
472
	foreach($renderTemplate as &$part){
473
		foreach($part as $key=>&$element){
474
			if($key == $contentElementKey){
475
				return $precedingElement;
476
			}
477
			$precedingElement = $element;
478
		}
479
	}
480
	return null;
481
}
482

    
483
function &get_preceding_contentElementKey($contentElementKey, array &$renderTemplate){
484
	$precedingKey = null;
485
	foreach($renderTemplate as &$part){
486
		foreach($part as $key=>&$element){
487
			if($key == $contentElementKey){
488
				return $precedingKey;
489
			}
490
			if(!str_beginsWith($key, '#')){
491
				$precedingKey = $key;
492
			}
493
		}
494
	}
495
	return null;
496
}
497

    
498

    
499

    
500

    
501

    
502

    
503

    
(4-4/8)