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
|
_add_js_cluetip();
|
18
|
$renderPath = 'typedesignations';
|
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, $renderPath);
|
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
|
$shortCitation .= (strlen($shortCitation) > 0 ? ' ' : '' ). partialToYear($std->citation->datePublished->start);
|
64
|
if(strlen($shortCitation) == 0){
|
65
|
$shortCitation = theme('cdm_reference',$std->citation );
|
66
|
$missingShortCitation = true;
|
67
|
}
|
68
|
$typeReference .= ' (' . t('designated by');
|
69
|
$typeReference .= ' <span class="typeReference '.($missingShortCitation ? '' : 'cluetip').' no-print" title="'. htmlspecialchars('|'.theme('cdm_reference',$std->citation ).'|') .'">';
|
70
|
$typeReference .= $shortCitation.'</span>';
|
71
|
$typeReference .= ')';
|
72
|
//$typeReference .= '<span class="reference only-print">(designated by '.theme('cdm_reference',$std->citation ).')</span>';
|
73
|
}
|
74
|
|
75
|
$out .= '<li class="specimenTypeDesignation">';
|
76
|
$out .= '<span class="status">'.(($std->typeStatus->representation_L10n) ? $std->typeStatus->representation_L10n : t('Type')) .$typeReference.'</span>: '.$std->typeSpecimen->titleCache;
|
77
|
$out .= theme('cdm_specimen', $std->typeSpecimen);
|
78
|
$out .= '</li>';
|
79
|
}
|
80
|
}
|
81
|
|
82
|
$out .= '</ul>';
|
83
|
|
84
|
return $out;
|
85
|
}
|
86
|
|
87
|
|
88
|
/**
|
89
|
* FIXME this definitively has to be in another spot. just didn't know where to put it right now.
|
90
|
* Compares the status of two SpecimenTypeDesignations
|
91
|
* @param String $a a SpecimenTypeDesignations
|
92
|
* @param String $b another SpecimenTypeDesignations
|
93
|
*/
|
94
|
function compare_specimenTypeDesignationStatus($a, $b){
|
95
|
/* this is the desired sort oder as of now:
|
96
|
* Holotype
|
97
|
* Isotype
|
98
|
* Lectotype
|
99
|
* Isolectotype
|
100
|
* Syntype
|
101
|
*
|
102
|
* TODO
|
103
|
* Basically, what we are trying to do is, we define an ordered array of TypeDesignation-states
|
104
|
* and use the index of this array for comparison. This array has to be filled with the cdm-
|
105
|
* TypeDesignation states and the order should be parameterisable inside the dataportal.
|
106
|
*/
|
107
|
// make that static for now
|
108
|
$typeOrder = array('Holotype', 'Isotype', 'Lectotype', 'Isolectotype', 'Syntype');
|
109
|
|
110
|
$aQuantifier = array_search($a->typeStatus->label, $typeOrder);
|
111
|
$bQuantifier = array_search($b->typeStatus->label, $typeOrder);
|
112
|
|
113
|
if ($aQuantifier == $bQuantifier) {
|
114
|
// sort alphabetically
|
115
|
return ($a->typeStatus->label < $b->typeStatus->label) ? -1 : 1;
|
116
|
}
|
117
|
return ($aQuantifier < $bQuantifier) ? -1 : 1;
|
118
|
|
119
|
}
|
120
|
|
121
|
function theme_cdm_nameRelations($nameRelationships, $skipTypes = false){
|
122
|
|
123
|
// group by relationship type
|
124
|
$relationshipGroups = array();
|
125
|
foreach($nameRelationships as $nameRelationship){
|
126
|
if(!array_key_exists($nameRelationship->type->uuid, $relationshipGroups)){
|
127
|
$relationshipGroups[$nameRelationship->type->uuid] = array();
|
128
|
}
|
129
|
$relationshipGroups[$nameRelationship->type->uuid][] = $nameRelationship;
|
130
|
}
|
131
|
|
132
|
// generate output
|
133
|
$out = '';
|
134
|
foreach($relationshipGroups as $group){
|
135
|
$type = $group[0]->type;
|
136
|
|
137
|
if(is_array($skipTypes) && in_array($type->uuid, $skipTypes)){
|
138
|
continue;
|
139
|
}
|
140
|
|
141
|
$block->module = 'cdm_dataportal';
|
142
|
$block->subject = t(ucfirst($type->inverseRepresentation_L10n));
|
143
|
$block->delta = generalizeString(strtolower($type->inverseRepresentation_L10n));
|
144
|
|
145
|
foreach($group as $relationship){
|
146
|
$relatedNames[] = cdm_taggedtext2html($relationship->fromName->taggedName);
|
147
|
}
|
148
|
|
149
|
$block->content .= implode('; ', $relatedNames);
|
150
|
$out .= theme('block', $block);
|
151
|
}
|
152
|
return $out;
|
153
|
}
|
154
|
|
155
|
|
156
|
|
157
|
function theme_cdm_homotypicSynonymLine($taxon){
|
158
|
$out = '';
|
159
|
$out .= '<li class="synonym">'.theme('cdm_related_taxon', $taxon, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
|
160
|
return $out;
|
161
|
}
|
162
|
|
163
|
function theme_cdm_heterotypicSynonymyGroup($homotypicalGroup){
|
164
|
$out = '';
|
165
|
$out = '<ul class="heterotypicSynonymyGroup">';
|
166
|
|
167
|
$is_first_entry = true;
|
168
|
$typeDesignations = null;
|
169
|
foreach($homotypicalGroup as $synonym){
|
170
|
if($is_first_entry){
|
171
|
$is_first_entry = false;
|
172
|
//$typeDesignations = cdm_ws_get(CDM_WS_NAME_TYPEDESIGNATIONS, $synonym->name->uuid);
|
173
|
$typeDesignations = cdm_ws_get(CDM_WS_TAXON_NAMETYPEDESIGNATIONS, $synonym->uuid);
|
174
|
// is first list entry
|
175
|
$out .= '<li class="firstentry synonym">'.theme('cdm_related_taxon',$synonym, UUID_HETEROTYPIC_SYNONYM_OF).'</li>';
|
176
|
} else {
|
177
|
$out .= '<li class="synonym">'.theme('cdm_related_taxon',$synonym, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
|
178
|
}
|
179
|
}
|
180
|
|
181
|
if($typeDesignations){
|
182
|
$out .= theme('cdm_typedesignations', $typeDesignations);
|
183
|
}
|
184
|
|
185
|
$out .= '</ul>';
|
186
|
|
187
|
return $out;
|
188
|
}
|
189
|
|
190
|
|
191
|
|
192
|
function theme_cdm_homotypicSynonymyGroup($synonymList, $prependedSynonyms = array()){
|
193
|
|
194
|
if(! is_array($synonymList) || count($synonymList) == 0){
|
195
|
return;
|
196
|
}
|
197
|
|
198
|
$out = '<ul class="homotypicSynonyms">';
|
199
|
|
200
|
if(!empty($prependedSynonyms)){
|
201
|
foreach($prependedSynonyms as $taxon){
|
202
|
$out .= '<li class="synonym">'.theme('cdm_related_taxon', $taxon, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
|
203
|
}
|
204
|
}
|
205
|
|
206
|
foreach($synonymList as $synonym){
|
207
|
$out .= '<li class="synonym">'.theme('cdm_related_taxon', $synonym, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
|
208
|
}
|
209
|
|
210
|
$typeDesignations = cdm_ws_get(CDM_WS_TAXON_NAMETYPEDESIGNATIONS, $synonymList[0]->uuid);
|
211
|
if($typeDesignations){
|
212
|
$out .= theme('cdm_typedesignations', $typeDesignations);
|
213
|
}
|
214
|
|
215
|
$out .= '</ul>';
|
216
|
return $out;
|
217
|
}
|
218
|
|
219
|
|
220
|
function theme_cdm_taxonName($taxonName, $nameLink = NULL, $refenceLink = NULL, $renderPath = null){
|
221
|
|
222
|
$renderTemplate = get_nameRenderTemplate($renderPath, $nameLink, $refenceLink);
|
223
|
|
224
|
$partDefinition = get_partDefinition($taxonName->class);
|
225
|
|
226
|
// apply defintions to template
|
227
|
foreach($renderTemplate as $part=>$uri){
|
228
|
if(isset($partDefinition[$part])){
|
229
|
$renderTemplate[$part] = $partDefinition[$part];
|
230
|
}
|
231
|
if(is_array($uri)){
|
232
|
$renderTemplate[$part]['#uri'] = $uri['#uri'];
|
233
|
}
|
234
|
}
|
235
|
|
236
|
$firstEntryIsValidNamePart = is_array($taxonName->taggedName)
|
237
|
&& is_string($taxonName->taggedName[1]->text)
|
238
|
&& $taxonName->taggedName[1]->text != ''
|
239
|
&& $taxonName->taggedName[1]->type = 'name';
|
240
|
// got to use second entry as first one, see ToDo comment below ...
|
241
|
if($firstEntryIsValidNamePart){
|
242
|
|
243
|
$taggedName = $taxonName->taggedName;
|
244
|
//TODO due to a bug in the cdmlib the taggedName alway has a lst empty element, we will remove it:
|
245
|
array_pop($taggedName);
|
246
|
|
247
|
$lastAuthorElementString = false;
|
248
|
$hasNamePart_with_Authors = isset($renderTemplate['namePart']) && isset($renderTemplate['namePart']['authors']);
|
249
|
$hasNameAuthorPart_with_Authors = isset($renderTemplate['nameAuthorPart']) && isset($renderTemplate['nameAuthorPart']['authors']);
|
250
|
|
251
|
if(!($hasNamePart_with_Authors || $hasNameAuthorPart_with_Authors)){
|
252
|
// // find author and split off from name
|
253
|
// // TODO expecting to find the author as the last element
|
254
|
// if($taggedName[count($taggedName)- 1]->type == 'authors'){
|
255
|
// $authorTeam = $taggedName[count($taggedName)- 1]->text;
|
256
|
// unset($taggedName[count($taggedName)- 1]);
|
257
|
// }
|
258
|
|
259
|
// remove all authors
|
260
|
$taggedNameNew = array();
|
261
|
foreach($taggedName as $element){
|
262
|
if($element->type != 'authors'){
|
263
|
$taggedNameNew[] = $element;
|
264
|
} else {
|
265
|
$lastAuthorElementString = $element->text;
|
266
|
}
|
267
|
}
|
268
|
$taggedName = $taggedNameNew;
|
269
|
|
270
|
}
|
271
|
$name = '<span class="'.$taxonName->class.'">'.theme('cdm_taggedtext2html', $taggedName).'</span>';
|
272
|
} else {
|
273
|
$name = '<span class="'.$taxonName->class.'_titleCache">'.$taxonName->titleCache.'</span>';
|
274
|
}
|
275
|
|
276
|
// fill name into $renderTemplate
|
277
|
array_setr('name', $name, $renderTemplate);
|
278
|
|
279
|
// // fill with authorTeam
|
280
|
// if($authorTeam){
|
281
|
// $authorTeamHtml = ' <span class="authorTeam">'.$authorTeam.'</span>';
|
282
|
// array_setr('authorTeam', $authorTeamHtml, $renderTemplate);
|
283
|
// }
|
284
|
|
285
|
|
286
|
// fill with reference
|
287
|
if(isset($renderTemplate['referencePart'])){
|
288
|
|
289
|
// [Eckhard]:"Komma nach dem Taxonnamen ist grunsätzlich falsch,
|
290
|
// Komma nach dem Autornamen ist überall dort falsch, wo ein "in" folgt."
|
291
|
if(isset($renderTemplate['referencePart']['reference']) && $taxonName->nomenclaturalReference){
|
292
|
$microreference = null;
|
293
|
if(isset($renderTemplate['referencePart']['microreference'])){
|
294
|
$microreference = $taxonName->nomenclaturalMicroReference;
|
295
|
}
|
296
|
$citation = cdm_ws_get(CDM_WS_NOMENCLATURAL_REFERENCE_CITATION, array($taxonName->nomenclaturalReference->uuid, $microreference));
|
297
|
$citation = $citation->String;
|
298
|
// find preceding element of the refrence
|
299
|
$precedingKey = get_preceding_contentElementKey('reference', $renderTemplate);
|
300
|
if(str_beginsWith($citation, ", in")){
|
301
|
$citation = substr($citation, 2);
|
302
|
$separator = ' ';
|
303
|
} else if(!str_beginsWith($citation, "in") && $precedingKey == 'authors'){
|
304
|
$separator = ', ';
|
305
|
} else {
|
306
|
$separator = ' ';
|
307
|
}
|
308
|
|
309
|
$referenceArray['#separator'] = $separator;
|
310
|
$referenceArray['#html'] = '<span class="reference">'.$citation.'</span>';
|
311
|
array_setr('reference', $referenceArray, $renderTemplate);
|
312
|
}
|
313
|
|
314
|
// if authors have been removed from the name part the last named authorteam
|
315
|
// should be added to the reference citation, otherwise, keep the separator
|
316
|
// out of the reference
|
317
|
if(isset($renderTemplate['referencePart']['authors']) && $lastAuthorElementString){
|
318
|
// if the nomenclaturalReference cintation is not included in the reference part but diplay of the microreference
|
319
|
// is whanted append the microreference to the authorTeam
|
320
|
if(!isset($renderTemplate['referencePart']['reference']) && isset($renderTemplate['referencePart']['microreference'])){
|
321
|
$separator = ": ";
|
322
|
$citation = $taxonName->nomenclaturalMicroReference;
|
323
|
}
|
324
|
$referenceArray['#html'] = ' <span class="reference">'.$lastAuthorElementString.$separator.$citation.'</span>';
|
325
|
array_setr('authors', $referenceArray, $renderTemplate);
|
326
|
}
|
327
|
|
328
|
}
|
329
|
|
330
|
// fill with status
|
331
|
if(array_setr('status', true, $renderTemplate)){
|
332
|
if(isset($taxon->name->status[0])){
|
333
|
foreach($taxon->name->status as $status){
|
334
|
$statusHtml .= ', '.$status->type->representation_L10n;
|
335
|
}
|
336
|
}
|
337
|
array_setr('status', ' <span class="nomenclatural_status">'.$statusHtml.'</span>', $renderTemplate);
|
338
|
}
|
339
|
|
340
|
// fill with protologues etc...
|
341
|
if(array_setr('description', true, $renderTemplate)){
|
342
|
$descriptions = cdm_ws_get(CDM_WS_NAME_DESCRIPTIONS, $taxonName->uuid);
|
343
|
foreach($descriptions as $description){
|
344
|
if(!empty($description)){
|
345
|
foreach($description->elements as $description_element){
|
346
|
$descriptionHtml .= theme("cdm_media", $description_element, array('application/pdf', 'image/png', 'image/jpeg', 'image/gif', 'text/html'));
|
347
|
}
|
348
|
}
|
349
|
}
|
350
|
array_setr('description', $descriptionHtml, $renderTemplate);
|
351
|
}
|
352
|
|
353
|
// render
|
354
|
$out = '<span ref="/name/'.$taxonName->uuid.'">';
|
355
|
foreach($renderTemplate as $partName=>$part){
|
356
|
$separator = '';
|
357
|
$partHtml = '';
|
358
|
$uri = false;
|
359
|
if(!is_array($part)){
|
360
|
continue;
|
361
|
}
|
362
|
if(isset($part['#uri']) && is_string($part['#uri'])){
|
363
|
$uri = $part['#uri'];
|
364
|
unset($part['#uri']);
|
365
|
}
|
366
|
foreach($part as $key=>$content){
|
367
|
$html = '';
|
368
|
if(is_array($content)){
|
369
|
$html = $content['#html'];
|
370
|
$separator = $content['#separator'];
|
371
|
} else if(is_string($content)){
|
372
|
$html = $content;
|
373
|
}
|
374
|
$partHtml .= '<span class="'.$key.'">'.$html.'</span>';
|
375
|
}
|
376
|
if($uri){
|
377
|
$out .= $separator.'<a href="'.$uri.'" class="'.$partName.'">'.$partHtml.'</a>';
|
378
|
} else {
|
379
|
$out .= $separator.$partHtml;
|
380
|
}
|
381
|
}
|
382
|
|
383
|
return $out.'</span>';
|
384
|
}
|
385
|
|
386
|
/**
|
387
|
* Recursively searches the array for the $key and sets the given value
|
388
|
* @param $key
|
389
|
* @param $value
|
390
|
* @param $array
|
391
|
* @return true if the key has been found
|
392
|
*/
|
393
|
function &array_setr($key, $value, array &$array){
|
394
|
foreach($array as $k=>&$v){
|
395
|
if($key == $k){
|
396
|
$v = $value;
|
397
|
return $array;
|
398
|
} else if(is_array($v)){
|
399
|
$innerArray = array_setr($key, $value, $v);
|
400
|
if($innerArray){
|
401
|
return $array;
|
402
|
}
|
403
|
}
|
404
|
}
|
405
|
return null;
|
406
|
}
|
407
|
|
408
|
function &get_preceding_contentElement($contentElementKey, array &$renderTemplate){
|
409
|
$precedingElement = null;
|
410
|
foreach($renderTemplate as &$part){
|
411
|
foreach($part as $key=>&$element){
|
412
|
if($key == $contentElementKey){
|
413
|
return $precedingElement;
|
414
|
}
|
415
|
$precedingElement = $element;
|
416
|
}
|
417
|
}
|
418
|
return null;
|
419
|
}
|
420
|
|
421
|
function &get_preceding_contentElementKey($contentElementKey, array &$renderTemplate){
|
422
|
$precedingKey = null;
|
423
|
foreach($renderTemplate as &$part){
|
424
|
foreach($part as $key=>&$element){
|
425
|
if($key == $contentElementKey){
|
426
|
return $precedingKey;
|
427
|
}
|
428
|
if(!str_beginsWith($key, '#')){
|
429
|
$precedingKey = $key;
|
430
|
}
|
431
|
}
|
432
|
}
|
433
|
return null;
|
434
|
}
|
435
|
|
436
|
|
437
|
|
438
|
|
439
|
|
440
|
|
441
|
|