1
|
<?php
|
2
|
/**
|
3
|
* @file
|
4
|
* Name theming functions.
|
5
|
*
|
6
|
* @copyright
|
7
|
* (C) 2007-2012 EDIT
|
8
|
* European Distributed Institute of Taxonomy
|
9
|
* http://www.e-taxonomy.eu
|
10
|
*
|
11
|
* The contents of this module are subject to the Mozilla
|
12
|
* Public License Version 1.1.
|
13
|
* @see http://www.mozilla.org/MPL/MPL-1.1.html
|
14
|
*/
|
15
|
|
16
|
/**
|
17
|
* Return HTML for the lectotype citation with the correct layout.
|
18
|
*
|
19
|
* This function prints the lectotype citation with the correct layout.
|
20
|
* Lectotypes are renderized in the synonymy tab of a taxon if they exist.
|
21
|
*
|
22
|
* @param mixed $typeDesignation
|
23
|
* Object containing the lectotype citation to print.
|
24
|
*
|
25
|
* @return string
|
26
|
* Valid html string.
|
27
|
*/
|
28
|
function type_designation_citation_layout($typeDesignation, $footnote_separator = ',') {
|
29
|
$res = '';
|
30
|
$citation = $typeDesignation->citation;
|
31
|
$pages = $typeDesignation->citationMicroReference;
|
32
|
if(isset($typeDesignation->typeStatus->uuid) && isset($typeDesignation->typeStatus->representation_L10n)) {
|
33
|
if ( $typeDesignation->typeStatus->uuid == UUID_NTD_ORIGINAL_DESIGNATION || $typeDesignation->typeStatus->uuid == UUID_NTD_MONOTYPY) {
|
34
|
$res = ' (' . $typeDesignation->typeStatus->representation_L10n . ')';
|
35
|
return $res;
|
36
|
}
|
37
|
}
|
38
|
|
39
|
if ($citation) {
|
40
|
// $type = $typeDesignation_citation->type;
|
41
|
$year = isset($citation->datePublished->start) ? substr($citation->datePublished->start, 0, 4) : '';
|
42
|
$author = isset($citation->authorship->titleCache) ? $citation->authorship->titleCache : '';
|
43
|
$res .= ' (designated by ';
|
44
|
$res .= $author;
|
45
|
$res .= ($year ? ' ' . $year : '');
|
46
|
$res .= ($pages ? ': ' . $pages : '');
|
47
|
// $res .= ')';
|
48
|
|
49
|
// footnotes should be rendered in the parent element so we
|
50
|
// are relying on the FootnoteListKey set there
|
51
|
$fkey_typeDesignation = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), $typeDesignation->citation->titleCache);
|
52
|
$res .= theme('cdm_footnote_key', array(
|
53
|
'footnoteKey' => $fkey_typeDesignation,
|
54
|
'separator' => $footnote_separator,
|
55
|
'highlightable' => TRUE,
|
56
|
'separator_off' => TRUE,
|
57
|
)) . ')';
|
58
|
}
|
59
|
return $res;
|
60
|
}
|
61
|
|
62
|
|
63
|
/**
|
64
|
* Renders and array of CDM TypeDesignations
|
65
|
*
|
66
|
* @param array $variables
|
67
|
* - typeDesignations: an array of cdm TypeDesignation entities to render
|
68
|
*/
|
69
|
function theme_cdm_typedesignations($variables) {
|
70
|
$typeDesignations = $variables['typeDesignations'];
|
71
|
|
72
|
// need to add element to render path since type designations
|
73
|
// need other name render template
|
74
|
RenderHints::pushToRenderStack('typedesignations');
|
75
|
|
76
|
$out = '<ul class="typeDesignations">';
|
77
|
$typeDesignation_footnotes = FALSE;
|
78
|
$is_lectotype = FALSE;
|
79
|
$specimenTypeDesignations = array();
|
80
|
$separator = ',';
|
81
|
foreach ($typeDesignations as $typeDesignation) {
|
82
|
if ($typeDesignation->class == 'SpecimenTypeDesignation') {
|
83
|
// SpecimenTypeDesignations should be ordered. Collect theme here only.
|
84
|
$specimenTypeDesignations[] = $typeDesignation;
|
85
|
}
|
86
|
// It is a lectotype?
|
87
|
else {
|
88
|
if (isset($typeDesignation->typeStatus->uuid) && $typeDesignation->typeStatus->uuid == UUID_NTD_LECTOTYPE) {
|
89
|
$is_lectotype = TRUE;
|
90
|
}
|
91
|
// It's a NameTypeDesignation.
|
92
|
if ($typeDesignation->notDesignated) {
|
93
|
$out .= '<li class="nameTypeDesignation"><span class="status">' . ($is_lectotype ? 'Lectotype' : 'Type') . '</span>: ' . t('not designated') . '</li>';
|
94
|
}
|
95
|
elseif ($typeDesignation->typeName) {
|
96
|
$link_to_name_page = url(path_to_name($typeDesignation->typeName->uuid));
|
97
|
$out .= '<li class="nameTypeDesignation"><span class="status">' . ($is_lectotype ? 'Lectotype' : 'Type') . '</span>';
|
98
|
|
99
|
if ($typeDesignation->citation) {
|
100
|
$out .= type_designation_citation_layout($typeDesignation, $separator);
|
101
|
|
102
|
}
|
103
|
$referenceUri = '';
|
104
|
if (isset($typeDesignation->typeName->nomenclaturalReference)) {
|
105
|
$referenceUri = url(path_to_reference($typeDesignation->typeName->nomenclaturalReference->uuid));
|
106
|
}
|
107
|
$out .= ': ' . render_taxon_or_name($typeDesignation->typeName, $link_to_name_page, $referenceUri, TRUE, TRUE);
|
108
|
}
|
109
|
}
|
110
|
}
|
111
|
|
112
|
if (!empty($specimenTypeDesignations)) {
|
113
|
// Sorting might be different for dataportals so this has to be
|
114
|
// parameterized.
|
115
|
usort($specimenTypeDesignations, "compare_specimenTypeDesignationStatus");
|
116
|
foreach ($specimenTypeDesignations as $std) {
|
117
|
$typeReference = '';
|
118
|
if (!empty($std->citation)) {
|
119
|
$author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $std->citation->uuid);
|
120
|
$shortCitation = $author_team->titleCache;
|
121
|
|
122
|
$shortCitation .= (strlen($shortCitation) > 0 ? ' ' : '') . partialToYear($std->citation->datePublished->start);
|
123
|
$missingShortCitation = FALSE;
|
124
|
if (strlen($shortCitation) == 0) {
|
125
|
$shortCitation = theme('cdm_reference', array('reference' => $std->citation));
|
126
|
$missingShortCitation = TRUE;
|
127
|
}
|
128
|
|
129
|
$typeReference .= ' (' . t('designated by');
|
130
|
$typeReference .= ' <span class="typeReference ' . ($missingShortCitation ? '' : 'cluetip') . ' no-print" title="' . htmlspecialchars('|' . theme('cdm_reference', array('reference' => $std->citation)) . '|') . '">';
|
131
|
$typeReference .= $shortCitation . '</span>';
|
132
|
if (!empty($std->citationMicroReference)) {
|
133
|
$typeReference .= ':' . $std->citationMicroReference;
|
134
|
}
|
135
|
$typeReference .= ')';
|
136
|
|
137
|
// footnotes should be rendered in the parent element so we
|
138
|
// are relying on the FootnoteListKey set there
|
139
|
$_fkey2 = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), $std->citation->titleCache);
|
140
|
$typeReference .= theme('cdm_footnote_key', array(
|
141
|
'footnoteKey' => $_fkey2,
|
142
|
'separator' => $separator,
|
143
|
'highlightable' => TRUE,
|
144
|
'separator_off' => TRUE,
|
145
|
));
|
146
|
}
|
147
|
|
148
|
$derivedUnitFacadeInstance = null;
|
149
|
|
150
|
$out .= '<li class="specimenTypeDesignation">';
|
151
|
$out .= '<span class="status">'
|
152
|
. ((isset($std->typeStatus->representation_L10n)) ? $std->typeStatus->representation_L10n : t('Type'))
|
153
|
. $typeReference
|
154
|
. '</span>: ';
|
155
|
|
156
|
|
157
|
if (isset($std->typeSpecimen)) {
|
158
|
$derivedUnitFacadeInstance = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, $std->typeSpecimen->uuid);
|
159
|
}
|
160
|
if ( isset($derivedUnitFacadeInstance ) ){
|
161
|
$out .= $derivedUnitFacadeInstance->titleCache; // . ': ' . theme('cdm_specimen', array('specimenTypeDesignation' => $derivedUnitFacadeInstance));
|
162
|
}
|
163
|
|
164
|
// Footnotes for collection acronyms.
|
165
|
// footnotes should be rendered in the parent element so we
|
166
|
// are relying on the FootnoteListKey set there
|
167
|
$_fkey = FootnoteManager::addNewFootnote(
|
168
|
RenderHints::getFootnoteListKey(),
|
169
|
(isset($derivedUnitFacadeInstance->collection->titleCache) ? $derivedUnitFacadeInstance->collection->titleCache : FALSE)
|
170
|
);
|
171
|
$out .= theme('cdm_footnote_key', array('footnoteKey' => $_fkey, 'separator' => $separator));
|
172
|
$out .= '</li>';
|
173
|
|
174
|
}
|
175
|
}
|
176
|
|
177
|
$out .= '</ul>';
|
178
|
|
179
|
RenderHints::popFromRenderStack();
|
180
|
|
181
|
return $out;
|
182
|
}
|
183
|
|
184
|
/**
|
185
|
* FIXME this definitively has to be in another spot.
|
186
|
* just didn't know where to put it right now.
|
187
|
* Compares the status of two SpecimenTypeDesignations
|
188
|
*
|
189
|
* @param string $a
|
190
|
* A SpecimenTypeDesignations.
|
191
|
* @param string $b
|
192
|
* SpecimenTypeDesignations.
|
193
|
*/
|
194
|
function compare_specimenTypeDesignationStatus($a, $b) {
|
195
|
/*
|
196
|
This is the desired sort order as of now: Holotype Isotype Lectotype
|
197
|
Isolectotype Syntype.
|
198
|
TODO Basically, what we are trying to do is, we define
|
199
|
an ordered array of TypeDesignation-states and use the index of this array
|
200
|
for comparison. This array has to be filled with the cdm- TypeDesignation
|
201
|
states and the order should be parameterisable inside the dataportal.
|
202
|
*/
|
203
|
// Make that static for now.
|
204
|
$typeOrder = array(
|
205
|
'Holotype',
|
206
|
'Isotype',
|
207
|
'Lectotype',
|
208
|
'Isolectotype',
|
209
|
'Syntype',
|
210
|
);
|
211
|
|
212
|
$aQuantifier = FALSE;
|
213
|
$bQuantifier = FALSE;
|
214
|
if (isset($a->typeStatus->label) && isset($b->typeStatus->label)) {
|
215
|
$aQuantifier = array_search($a->typeStatus->label, $typeOrder);
|
216
|
$bQuantifier = array_search($b->typeStatus->label, $typeOrder);
|
217
|
}
|
218
|
if ($aQuantifier == $bQuantifier) {
|
219
|
// Sort alphabetically.
|
220
|
return (isset($a->typeStatus->label) && isset($b->typeStatus->label) && $a->typeStatus->label < $b->typeStatus->label) ? -1 : 1;
|
221
|
}
|
222
|
return ($aQuantifier < $bQuantifier) ? -1 : 1;
|
223
|
}
|
224
|
|
225
|
/**
|
226
|
* @todo Please document this function.
|
227
|
* @see http://drupal.org/node/1354
|
228
|
*/
|
229
|
function theme_cdm_homotypicSynonymLine($variables) {
|
230
|
$taxon = $variables['taxon'];
|
231
|
$out = '';
|
232
|
$out .= '<li class="synonym">' . cdm_related_taxon($taxon, UUID_HOMOTYPIC_SYNONYM_OF) . '</li>';
|
233
|
|
234
|
return $out;
|
235
|
}
|
236
|
|
237
|
/**
|
238
|
* @todo Please document this function.
|
239
|
* @see http://drupal.org/node/1354
|
240
|
*/
|
241
|
function theme_cdm_heterotypicSynonymyGroup($variables) {
|
242
|
$homotypicalGroup = $variables['homotypicalGroup'];
|
243
|
RenderHints::pushToRenderStack('heterotypicSynonymyGroup');
|
244
|
|
245
|
$out = '';
|
246
|
$out = '<div class="heterotypic-synonymy-group"><ul class="heterotypicSynonymyGroup">';
|
247
|
$footnoteListKey = (isset($homotypicalGroup[0]) ? $homotypicalGroup[0]->uuid : 'NULL');
|
248
|
RenderHints::setFootnoteListKey($footnoteListKey);
|
249
|
|
250
|
$is_first_entry = TRUE;
|
251
|
$typeDesignations = NULL;
|
252
|
foreach ($homotypicalGroup as $synonym) {
|
253
|
if ($is_first_entry) {
|
254
|
$is_first_entry = FALSE;
|
255
|
$typeDesignations = cdm_ws_get(CDM_WS_PORTAL_NAME_TYPEDESIGNATIONS, $synonym->name->uuid);
|
256
|
// Is first list entry.
|
257
|
$out .= '<li class="firstentry synonym">' . cdm_related_taxon($synonym, UUID_HETEROTYPIC_SYNONYM_OF) . '</li>';
|
258
|
}
|
259
|
else {
|
260
|
$out .= '<li class="synonym">' . cdm_related_taxon($synonym, UUID_HOMOTYPIC_SYNONYM_OF) . '</li>';
|
261
|
}
|
262
|
}
|
263
|
|
264
|
if ($typeDesignations) {
|
265
|
$out .= theme('cdm_typedesignations', array('typeDesignations' => $typeDesignations));
|
266
|
}
|
267
|
$out .= '</ul>';
|
268
|
|
269
|
// ------- footnotes ------- //
|
270
|
$out .= '<ul class="footnotes">';
|
271
|
$out .= theme('cdm_annotation_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey(), 'enclosingTag' => 'li'));
|
272
|
$out .= theme('cdm_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey(), 'enclosingTag' => 'li'));
|
273
|
$out .= '</ul>';
|
274
|
|
275
|
$out .= '</div>';
|
276
|
|
277
|
RenderHints::popFromRenderStack();
|
278
|
return $out;
|
279
|
}
|
280
|
|
281
|
/**
|
282
|
* Renders the homotypic synonymy group for the accepted taxon in the synonymy.
|
283
|
*
|
284
|
* Foonotes of the accepted taxon will also be rendered here in the
|
285
|
* homotypic synonymy group even if the synonymList or prependedSynonyms are
|
286
|
* empty. Therefore the homotypic group and accepted taxon share the same
|
287
|
* footnote key.
|
288
|
*
|
289
|
* @param $variables
|
290
|
* an associative array:
|
291
|
* - synonymList: the list of cdm Synonym entities
|
292
|
* - accepted_taxon_uuid: the uuid of the accepted taxon
|
293
|
* - prependedSynonyms: further synonyms which should be prepended
|
294
|
* before the actual list of synonyms
|
295
|
*/
|
296
|
function theme_cdm_homotypicSynonymyGroup($variables) {
|
297
|
$synonymList = $variables['synonymList'];
|
298
|
$accepted_taxon_name_uuid = $variables['accepted_taxon_name_uuid'];
|
299
|
$prependedSynonyms = $variables['prependedSynonyms'];
|
300
|
|
301
|
RenderHints::pushToRenderStack('homotypicSynonymyGroup');
|
302
|
|
303
|
$homonym_typeDesignations = NULL;
|
304
|
|
305
|
// TODO improve typeDesignations retrieval: wouldn't it be suffcient to retrieve all typeDesignations
|
306
|
// only from the accepted taxon?
|
307
|
$accepted_typeDesignations = cdm_ws_get(CDM_WS_PORTAL_NAME_TYPEDESIGNATIONS, $accepted_taxon_name_uuid);
|
308
|
|
309
|
$out = '<div class="homotypic-synonymy-group">';
|
310
|
|
311
|
if (isset ($accepted_typeDesignations) || is_array($prependedSynonyms) || is_array($synonymList)) {
|
312
|
$out .= '<ul class="homotypicSynonyms">';
|
313
|
if (!empty($prependedSynonyms)) {
|
314
|
foreach ($prependedSynonyms as $taxon) {
|
315
|
$out .= '<li class="synonym">' . cdm_related_taxon($taxon, UUID_HOMOTYPIC_SYNONYM_OF) . '</li>';
|
316
|
}
|
317
|
}
|
318
|
|
319
|
$homonym_typeDesignations = NULL;
|
320
|
if (isset($synonymList[0])) {
|
321
|
foreach ($synonymList as $synonym) {
|
322
|
$out .= '<li class="synonym">' . cdm_related_taxon($synonym, UUID_HOMOTYPIC_SYNONYM_OF) . '</li>';
|
323
|
}
|
324
|
$homonym_typeDesignations = cdm_ws_get(CDM_WS_PORTAL_NAME_TYPEDESIGNATIONS, $synonymList[0]->name->uuid);
|
325
|
}
|
326
|
|
327
|
// type designations
|
328
|
if ($accepted_typeDesignations) {
|
329
|
$type_designations = filter_cdm_entity_list($homonym_typeDesignations, $accepted_typeDesignations);
|
330
|
}
|
331
|
else {
|
332
|
$type_designations = $homonym_typeDesignations;
|
333
|
}
|
334
|
|
335
|
if ($type_designations) {
|
336
|
$out .= theme('cdm_typedesignations', array('typeDesignations' => $type_designations));
|
337
|
}
|
338
|
|
339
|
}
|
340
|
|
341
|
$out .= '</ul>';
|
342
|
|
343
|
// ------- footnotes ------- //
|
344
|
|
345
|
// all foonotes of the homotypic group and also of the accepted taxon are
|
346
|
// rendered here, both should have the same footnote key
|
347
|
$out .= '<ul class="footnotes">';
|
348
|
$out .= theme('cdm_annotation_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey(), 'enclosingTag' => 'li'));
|
349
|
$out .= theme('cdm_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey(), 'enclosingTag' => 'li'));
|
350
|
$out .= '</ul>';
|
351
|
|
352
|
$out .= '</div>';
|
353
|
|
354
|
|
355
|
RenderHints::popFromRenderStack();
|
356
|
return $out;
|
357
|
}
|