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