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
		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
			  $author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $std->citation->uuid);
64
			  $shortCitation = $author_team->titleCache;
65
				$shortCitation .= (strlen($shortCitation) > 0 ? ' ' : '' ). partialToYear($std->citation->datePublished->start);
66
				if(strlen($shortCitation) == 0){
67
					$shortCitation = theme('cdm_reference',$std->citation );
68
					$missingShortCitation = true;
69
				}
70
				$typeReference .= '&nbsp;(' . t('designated by');
71
				$typeReference .= '&nbsp;<span class="typeReference '.($missingShortCitation ? '' : 'cluetip').' no-print" title="'. htmlspecialchars('|'.theme('cdm_reference',$std->citation ).'|') .'">';
72
				$typeReference .= $shortCitation.'</span>';
73
				$typeReference .= ')';
74
				//$typeReference .= '<span class="reference only-print">(designated by '.theme('cdm_reference',$std->citation ).')</span>';
75
			}
76

    
77
			$out .= '<li class="specimenTypeDesignation">';
78
			$out .= '<span class="status">'.(($std->typeStatus->representation_L10n) ? $std->typeStatus->representation_L10n : t('Type')) .$typeReference.'</span>: '.$std->typeSpecimen->titleCache;
79
			//$out .= '<span class="status">'.(($std->typeStatus->representation_L10n) ? $std->typeStatus->representation_L10n : t('Type')) .$typeReference.'</span>: '.$std->typeSpecimen->titleCache . ' footnote: '. theme_cdm_footnote($std->typeSpecimen->collection->code, $std->typeSpecimen->collection->titleCache);
80
  
81
			$out .= theme('cdm_specimen', $std->typeSpecimen);
82
			$out .= '</li>';
83
		}
84
	}
85

    
86
	$out .= '</ul>';
87

    
88
	RenderHints::popFromRenderStack();
89
	return $out;
90
}
91

    
92

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

    
115
	$aQuantifier = array_search($a->typeStatus->label, $typeOrder);
116
	$bQuantifier = array_search($b->typeStatus->label, $typeOrder);
117

    
118
	if ($aQuantifier == $bQuantifier) {
119
		// sort alphabetically
120
		return ($a->typeStatus->label < $b->typeStatus->label) ? -1 : 1;
121
	}
122
	return ($aQuantifier < $bQuantifier) ? -1 : 1;
123

    
124
}
125

    
126
function theme_cdm_nameRelationships($nameRelationships, $skipTypes = false){
127

    
128
    if(!$nameRelationships){
129
        return;
130
    }
131
    
132
	RenderHints::pushToRenderStack('nameRelationships');
133
    $footnoteListKey = 'nameRelationships';
134
    RenderHints::setFootnoteListKey($footnoteListKey);
135
    
136
	// group by relationship type
137
	$relationshipGroups = array();
138
	foreach($nameRelationships as $nameRelationship){
139
		if(!array_key_exists($nameRelationship->type->uuid, $relationshipGroups)){
140
			$relationshipGroups[$nameRelationship->type->uuid] = array();
141
		}
142
		$relationshipGroups[$nameRelationship->type->uuid][] = $nameRelationship;
143
	}
144

    
145
	// generate output
146
	$out = '';
147
	foreach($relationshipGroups as $group){
148
		$type = $group[0]->type;
149

    
150
		if(is_array($skipTypes) && in_array($type->uuid, $skipTypes)){
151
			continue;
152
		}
153

    
154
		$block->module = 'cdm_dataportal';
155
		$block->subject = t(ucfirst($type->inverseRepresentation_L10n));
156
		$block->delta = generalizeString(strtolower($type->inverseRepresentation_L10n));
157

    
158
		foreach($group as $relationship){
159
			$relatedNames[] = cdm_taggedtext2html($relationship->fromName->taggedName);
160
		}
161

    
162
		$block->content .= implode('; ', $relatedNames);
163
		$out .= theme('block', $block);
164
	}
165
	$out .= theme('cdm_footnotes', $footnoteListKey, 'div');
166
	
167
	RenderHints::popFromRenderStack();
168
	return $out;
169
}
170

    
171

    
172

    
173
function theme_cdm_homotypicSynonymLine($taxon){
174
	$out = '';
175
	$out .= '<li class="synonym">'.theme('cdm_related_taxon', $taxon, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
176
	
177
	return $out;
178
}
179

    
180
function theme_cdm_heterotypicSynonymyGroup($homotypicalGroup){
181
	
182
	RenderHints::pushToRenderStack('heterotypicSynonymyGroup');
183
	
184
	$out = '';
185
	$out = '<ul class="heterotypicSynonymyGroup">';
186
    $footnoteListKey = ( isset($homotypicalGroup[0]) ? $homotypicalGroup[0]->uuid : 'NULL');
187
	RenderHints::setFootnoteListKey($footnoteListKey);
188
    
189
	$is_first_entry = true;
190
	$typeDesignations = null;
191
	foreach($homotypicalGroup as $synonym){
192
		if($is_first_entry){
193
			$is_first_entry = false;
194
			//$typeDesignations = cdm_ws_get(CDM_WS_NAME_TYPEDESIGNATIONS, $synonym->name->uuid);
195
			$typeDesignations = cdm_ws_get(CDM_WS_PORTAL_TAXON_NAMETYPEDESIGNATIONS, $synonym->uuid);
196
			// is first list entry
197
			$out .= '<li class="firstentry synonym">'.theme('cdm_related_taxon',$synonym, UUID_HETEROTYPIC_SYNONYM_OF).'</li>';
198
		} else {
199
			$out .= '<li class="synonym">'.theme('cdm_related_taxon',$synonym, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
200
		}
201
	}
202
	if($typeDesignations){
203
		$out .= theme('cdm_typedesignations', $typeDesignations);
204
	}
205

    
206
	$out .= theme('cdm_footnotes', $footnoteListKey, 'li');
207
	$out .= '</ul>';
208
    
209
    
210
    RenderHints::popFromRenderStack();
211
	return $out;
212
}
213

    
214

    
215

    
216
function theme_cdm_homotypicSynonymyGroup($synonymList, $prependedSynonyms = array()){
217
	
218
	RenderHints::pushToRenderStack('homotypicSynonymyGroup');
219
	
220
	$footnoteListKey = isset($prependedSynonyms[0]) ? $prependedSynonyms[0]->uuid : (isset($synonymList[0]) ? $synonymList[0]->uuid : 'NULL');
221
	RenderHints::setFootnoteListKey($footnoteListKey);
222
	
223
	if(! is_array($synonymList) || count($synonymList) == 0){
224
		return;
225
	}
226

    
227
	$out = '<ul class="homotypicSynonyms">';
228

    
229
	if(!empty($prependedSynonyms)){
230
		foreach($prependedSynonyms as $taxon){
231
			$out .= '<li class="synonym">'.theme('cdm_related_taxon', $taxon, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
232
		}
233
	}
234

    
235
	foreach($synonymList as $synonym){
236
		$out .= '<li class="synonym">'.theme('cdm_related_taxon', $synonym, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
237
	}
238

    
239
	$typeDesignations = cdm_ws_get(CDM_WS_PORTAL_TAXON_NAMETYPEDESIGNATIONS, $synonymList[0]->uuid);
240
	if($typeDesignations){
241
		$out .= theme('cdm_typedesignations', $typeDesignations);
242
	}
243

    
244
	$out .= theme('cdm_footnotes', $footnoteListKey, 'li');
245
	$out .= '</ul>';
246
	
247
	RenderHints::popFromRenderStack();
248
	return $out;
249
}
250

    
251

    
252
function theme_cdm_taxonName($taxonName, $nameLink = NULL, $refenceLink = NULL){
253

    
254
  $renderTemplate = get_nameRenderTemplate(RenderHints::getRenderPath(), $nameLink, $refenceLink);
255
	$partDefinition = get_partDefinition($taxonName->class);
256

    
257
	// apply defintions to template
258
	foreach($renderTemplate as $part=>$uri){
259
		if(isset($partDefinition[$part])){
260
			$renderTemplate[$part] = $partDefinition[$part];
261
		}
262
		if(is_array($uri)){
263
			$renderTemplate[$part]['#uri'] = $uri['#uri'];
264
		}
265
	}
266

    
267
	$firstEntryIsValidNamePart = is_array($taxonName->taggedName)
268
	&& is_string($taxonName->taggedName[0]->text)
269
	&& $taxonName->taggedName[0]->text != ''
270
	&& $taxonName->taggedName[0]->type == 'name';
271
	
272
	// got to use second entry as first one, see ToDo comment below ...
273
	if($firstEntryIsValidNamePart){
274

    
275
		$taggedName = $taxonName->taggedName;
276
		
277
		$lastAuthorElementString = false;
278
		$hasNamePart_with_Authors = isset($renderTemplate['namePart']) && isset($renderTemplate['namePart']['authors']);
279
		$hasNameAuthorPart_with_Authors = isset($renderTemplate['nameAuthorPart']) && isset($renderTemplate['nameAuthorPart']['authors']);
280

    
281
		if(!($hasNamePart_with_Authors || $hasNameAuthorPart_with_Authors)){
282
			//      // find author and split off from name
283
			//      // TODO expecting to find the author as the last element
284
			//      if($taggedName[count($taggedName)- 1]->type == 'authors'){
285
			//        $authorTeam = $taggedName[count($taggedName)- 1]->text;
286
			//        unset($taggedName[count($taggedName)- 1]);
287
			//      }
288

    
289
			// remove all authors
290
			$taggedNameNew = array();
291
			foreach($taggedName as $element){
292
				if($element->type != 'authors'){
293
					$taggedNameNew[] = $element;
294
				} else {
295
					$lastAuthorElementString = $element->text;
296
				}
297
			}
298
			$taggedName = $taggedNameNew;
299

    
300
		}
301
		$name = '<span class="'.$taxonName->class.'">'.theme('cdm_taggedtext2html', $taggedName).'</span>';
302
	} else {
303
		$name = '<span class="'.$taxonName->class.'_titleCache">'.$taxonName->titleCache.'</span>';
304
	}
305

    
306
	// fill name into $renderTemplate
307
	array_setr('name', $name, $renderTemplate);
308

    
309
	//  // fill with authorTeam
310
	//  if($authorTeam){
311
	//    $authorTeamHtml = ' <span class="authorTeam">'.$authorTeam.'</span>';
312
	//    array_setr('authorTeam', $authorTeamHtml, $renderTemplate);
313
	//  }
314

    
315

    
316
	// fill with reference
317
	if(isset($renderTemplate['referencePart'])){
318

    
319
		// [Eckhard]:"Komma nach dem Taxonnamen ist grunsätzlich falsch,
320
		// Komma nach dem Autornamen ist überall dort falsch, wo ein "in" folgt."
321
		if(isset($renderTemplate['referencePart']['reference']) && $taxonName->nomenclaturalReference){
322
			$microreference = null;
323
			if(isset($renderTemplate['referencePart']['microreference'])){
324
				$microreference = $taxonName->nomenclaturalMicroReference;
325
			}
326
			$citation = cdm_ws_get(CDM_WS_NOMENCLATURAL_REFERENCE_CITATION, array($taxonName->nomenclaturalReference->uuid), "microReference=".urlencode($microreference));
327
			$citation = $citation->String;
328
			// find preceding element of the refrence
329
			$precedingKey = get_preceding_contentElementKey('reference', $renderTemplate);
330
			if(str_beginsWith($citation, ", in")){
331
				$citation = substr($citation, 2);
332
				$separator = ' ';
333
			} else if(!str_beginsWith($citation, "in") && $precedingKey == 'authors'){
334
				$separator = ', ';
335
			} else {
336
				$separator = ' ';
337
			}
338

    
339
			$referenceArray['#separator'] = $separator;
340
			$referenceArray['#html'] = '<span class="reference">'.$citation.'</span>';
341
			array_setr('reference', $referenceArray, $renderTemplate);
342
		}
343

    
344
		// if authors have been removed from the name part the last named authorteam
345
		// should be added to the reference citation, otherwise, keep the separator
346
		// out of the reference
347
		if(isset($renderTemplate['referencePart']['authors']) && $lastAuthorElementString){
348
			// if the nomenclaturalReference cintation is not included in the reference part but diplay of the microreference
349
			// is whanted append the microreference to the authorTeam
350
			if(!isset($renderTemplate['referencePart']['reference']) && isset($renderTemplate['referencePart']['microreference'])){
351
				$separator = ": ";
352
				$citation = $taxonName->nomenclaturalMicroReference;
353
			}
354
			$referenceArray['#html'] = ' <span class="reference">'.$lastAuthorElementString.$separator.$citation.'</span>';
355
			array_setr('authors', $referenceArray, $renderTemplate);
356
		}
357

    
358
	}
359

    
360
	// fill with status
361
	if(array_setr('status', true, $renderTemplate)){
362
		if(isset($taxon->name->status[0])){
363
			foreach($taxon->name->status as $status){
364
				$statusHtml .= ', '.$status->type->representation_L10n;
365
			}
366
		}
367
		array_setr('status', ' <span class="nomenclatural_status">'.$statusHtml.'</span>', $renderTemplate);
368
	}
369

    
370
	// fill with protologues etc...
371
	if(array_setr('description', true, $renderTemplate)){
372
		$descriptions = cdm_ws_get(CDM_WS_PORTAL_NAME_DESCRIPTIONS, $taxonName->uuid);
373
		foreach($descriptions as $description){
374
			if(!empty($description)){
375
				foreach($description->elements as $description_element){
376
					$descriptionHtml .= theme("cdm_media", $description_element, array('application/pdf', 'image/png', 'image/jpeg', 'image/gif', 'text/html'));
377
				}
378
			}
379
		}
380
		array_setr('description', $descriptionHtml, $renderTemplate);
381
	}
382

    
383
	// render
384
	$out = '<span ref="/name/'.$taxonName->uuid.'">';
385
	
386
	foreach($renderTemplate as $partName=>$part){
387
		$separator = '';
388
		$partHtml = '';
389
		$uri = false;
390
		if(!is_array($part)){
391
			continue;
392
		}
393
		if(isset($part['#uri']) && is_string($part['#uri'])){
394
			$uri = $part['#uri'];
395
			unset($part['#uri']);
396
		}
397
		foreach($part as $key=>$content){
398
			$html = '';
399
			if(is_array($content)){
400
				$html = $content['#html'];
401
				$separator = $content['#separator'];
402
			} else if(is_string($content)){
403
				$html = $content;
404
			}
405
			$partHtml .= '<span class="'.$key.'">'.$html.'</span>';
406
		}
407
		if($uri){
408
			$out .= $separator.'<a href="'.$uri.'" class="'.$partName.'">'.$partHtml.'</a>';
409
		} else {
410
			$out .= $separator.$partHtml;
411
		}
412
	}
413
    $out .= '</span>';
414
    
415
	// add annotations
416
	$out .= theme('cdm_annotation', $taxonName);
417
	
418
	return $out;
419
}
420

    
421
/**
422
 * Recursively searches the array for the $key and sets the given value
423
 * @param $key
424
 * @param $value
425
 * @param $array
426
 * @return true if the key has been found
427
 */
428
function &array_setr($key, $value, array &$array){
429
	foreach($array as $k=>&$v){
430
		if($key == $k){
431
			$v = $value;
432
			return $array;
433
		} else if(is_array($v)){
434
			$innerArray = array_setr($key, $value, $v);
435
			if($innerArray){
436
				return $array;
437
			}
438
		}
439
	}
440
	return null;
441
}
442

    
443
function &get_preceding_contentElement($contentElementKey, array &$renderTemplate){
444
	$precedingElement = null;
445
	foreach($renderTemplate as &$part){
446
		foreach($part as $key=>&$element){
447
			if($key == $contentElementKey){
448
				return $precedingElement;
449
			}
450
			$precedingElement = $element;
451
		}
452
	}
453
	return null;
454
}
455

    
456
function &get_preceding_contentElementKey($contentElementKey, array &$renderTemplate){
457
	$precedingKey = null;
458
	foreach($renderTemplate as &$part){
459
		foreach($part as $key=>&$element){
460
			if($key == $contentElementKey){
461
				return $precedingKey;
462
			}
463
			if(!str_beginsWith($key, '#')){
464
				$precedingKey = $key;
465
			}
466
		}
467
	}
468
	return null;
469
}
470

    
471

    
472

    
473

    
474

    
475

    
476

    
(4-4/8)