Project

General

Profile

Download (13.8 KB) Statistics
| Branch: | Tag: | Revision:
1 6657531f Andreas Kohlbecker
<?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 1ce9afb7 Patric Plitzner
    $author = isset($citation->authorship->titleCache) ? $citation->authorship->titleCache : '';
43 6657531f Andreas Kohlbecker
    $res .= ' (designated by ';
44
    $res .= $author;
45
    $res .= ($year ? ' ' . $year : '');
46
    $res .= ($pages ? ': ' . $pages : '');
47
    // $res .= ')';
48 15b7c460 Andreas Kohlbecker
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 6657531f Andreas Kohlbecker
    $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 9b9037f3 Andreas Kohlbecker
 * Renders and array of CDM TypeDesignations
65
 *
66
 * @param array $variables
67
 *   - typeDesignations: an array of cdm TypeDesignation entities to render
68 6657531f Andreas Kohlbecker
 */
69
function theme_cdm_typedesignations($variables) {
70 2f55de7d Andreas Kohlbecker
  $type_designations = $variables['typeDesignations'];
71 c9d996cd Andreas Kohlbecker
72 ff4f2e07 Andreas Kohlbecker
  // need to add element to render path since type designations
73
  // need other name render template
74
  RenderHints::pushToRenderStack('typedesignations');
75 15b7c460 Andreas Kohlbecker
76 6657531f Andreas Kohlbecker
  $out = '<ul class="typeDesignations">';
77
  $typeDesignation_footnotes = FALSE;
78
  $is_lectotype = FALSE;
79 c5294246 Andreas Kohlbecker
  $specimen_type_designations = array();
80 6657531f Andreas Kohlbecker
  $separator = ',';
81 2f55de7d Andreas Kohlbecker
  foreach ($type_designations as $type_designation) {
82
    if ($type_designation->class == 'SpecimenTypeDesignation') {
83 6657531f Andreas Kohlbecker
      // SpecimenTypeDesignations should be ordered. Collect theme here only.
84 2f55de7d Andreas Kohlbecker
      $specimen_type_designations[] = $type_designation;
85 6657531f Andreas Kohlbecker
    }
86
    // It is a lectotype?
87
    else {
88 2f55de7d Andreas Kohlbecker
      if (isset($type_designation->typeStatus->uuid) && $type_designation->typeStatus->uuid == UUID_NTD_LECTOTYPE) {
89 6657531f Andreas Kohlbecker
        $is_lectotype = TRUE;
90
      }
91
      // It's a NameTypeDesignation.
92 2f55de7d Andreas Kohlbecker
      if ($type_designation->notDesignated) {
93
        $out .= '<li class="' . html_class_attribute_ref($type_designation) . '"><span class="status">' . ($is_lectotype ? 'Lectotype' : 'Type') . '</span>: ' . t('not designated') . '</li>';
94 6657531f Andreas Kohlbecker
      }
95 2f55de7d Andreas Kohlbecker
      elseif ($type_designation->typeName) {
96
        $link_to_name_page = url(path_to_name($type_designation->typeName->uuid));
97
        $out .= '<li class="' . html_class_attribute_ref($type_designation) . '"><span class="status">' . ($is_lectotype ? 'Lectotype' : 'Type') . '</span>';
98 6657531f Andreas Kohlbecker
99 2f55de7d Andreas Kohlbecker
        if ($type_designation->citation) {
100
          $out .= type_designation_citation_layout($type_designation, $separator);
101 c9d996cd Andreas Kohlbecker
102 6657531f Andreas Kohlbecker
        }
103
        $referenceUri = '';
104 2f55de7d Andreas Kohlbecker
        if (isset($type_designation->typeName->nomenclaturalReference)) {
105
          $referenceUri = url(path_to_reference($type_designation->typeName->nomenclaturalReference->uuid));
106 6657531f Andreas Kohlbecker
        }
107 2f55de7d Andreas Kohlbecker
        $out .= ': ' . render_taxon_or_name($type_designation->typeName, $link_to_name_page, $referenceUri, TRUE, TRUE);
108 6657531f Andreas Kohlbecker
      }
109
    }
110
  }
111
112 c5294246 Andreas Kohlbecker
  if (!empty($specimen_type_designations)) {
113 6657531f Andreas Kohlbecker
    // Sorting might be different for dataportals so this has to be
114
    // parameterized.
115 c5294246 Andreas Kohlbecker
    usort($specimen_type_designations, "compare_specimenTypeDesignationStatus");
116
    foreach ($specimen_type_designations as $type_designation) {
117 6657531f Andreas Kohlbecker
      $typeReference = '';
118 c5294246 Andreas Kohlbecker
119
      if (!empty($type_designation->citation)) {
120
121
        $citation_footnote_str = theme('cdm_reference', array('reference' => $type_designation->citation));
122
        $author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $type_designation->citation->uuid);
123
124 eaff53f7 Andreas Kohlbecker
        if (isset($author_team->titleCache)) {
125 c7f92453 Andreas Kohlbecker
          $year = timePeriodToString($type_designation->citation->datePublished, true, 'YYYY');
126
          $authorteam_str = $author_team->titleCache . ($year ? ' ' : '') . $year;
127 eaff53f7 Andreas Kohlbecker
          if ($authorteam_str == $type_designation->citation->titleCache) {
128 c5294246 Andreas Kohlbecker
            $citation_footnote_str = '';
129
          }
130
        } else {
131
          $authorteam_str = $citation_footnote_str;
132
          // no need for a footnote in case in case it is used as replacement for missing author teams
133
          $citation_footnote_str = '';
134 6657531f Andreas Kohlbecker
        }
135
136 eaff53f7 Andreas Kohlbecker
        // to be registered a typedesignation MUS HAVE a citation, so it is save to handle the
137
        // Registration ouput in if condition checking if the citation is present
138
        $registration_markup = render_registrations($type_designation->registrations);
139
        $citation_footnote_str .= ($citation_footnote_str ? ' ' : '') . $registration_markup;
140
141 c5294246 Andreas Kohlbecker
        $footnote_key_markup = '';
142 eaff53f7 Andreas Kohlbecker
        if ($citation_footnote_str) {
143 c5294246 Andreas Kohlbecker
          // footnotes should be rendered in the parent element so we
144
          // are relying on the FootnoteListKey set there
145
          $_fkey2 = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), $citation_footnote_str);
146
          $footnote_key_markup = theme('cdm_footnote_key', array(
147
            'footnoteKey' => $_fkey2,
148
            'separator' => $separator,
149
            'highlightable' => TRUE,
150
            'separator_off' => TRUE,
151 eaff53f7 Andreas Kohlbecker
          ));
152 c5294246 Andreas Kohlbecker
153 f3ebc0ed Andreas Kohlbecker
        }
154 c5294246 Andreas Kohlbecker
155 eaff53f7 Andreas Kohlbecker
        $typeReference .= '&nbsp;(' . t('designated by') . '&nbsp;<span class="typeReference">' . $authorteam_str . '</span>';
156 c5294246 Andreas Kohlbecker
        if (!empty($type_designation->citationMicroReference)) {
157 c7f92453 Andreas Kohlbecker
          $typeReference .= ': ' . trim($type_designation->citationMicroReference);
158 c5294246 Andreas Kohlbecker
        }
159
        $typeReference .= $footnote_key_markup . ')';
160
161 6657531f Andreas Kohlbecker
      }
162
163 f3ebc0ed Andreas Kohlbecker
      $derivedUnitFacadeInstance = null;
164 6657531f Andreas Kohlbecker
165 eaff53f7 Andreas Kohlbecker
      $out .= '<li class="' . html_class_attribute_ref($type_designation) . '">';
166 f3ebc0ed Andreas Kohlbecker
      $out .= '<span class="status">'
167 c5294246 Andreas Kohlbecker
        . ((isset($type_designation->typeStatus->representation_L10n)) ? $type_designation->typeStatus->representation_L10n : t('Type'))
168 f3ebc0ed Andreas Kohlbecker
        . $typeReference
169 f880d174 Andreas Kohlbecker
        . '</span>';
170 f3ebc0ed Andreas Kohlbecker
171
172 c5294246 Andreas Kohlbecker
      if (isset($type_designation->typeSpecimen)) {
173
        $derivedUnitFacadeInstance = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, $type_designation->typeSpecimen->uuid);
174 f3ebc0ed Andreas Kohlbecker
      }
175 eaff53f7 Andreas Kohlbecker
      if (isset($derivedUnitFacadeInstance)) {
176 f880d174 Andreas Kohlbecker
        $out .= ': ' . $derivedUnitFacadeInstance->titleCache; // . ': ' . theme('cdm_specimen', array('specimenTypeDesignation' => $derivedUnitFacadeInstance));
177 f3ebc0ed Andreas Kohlbecker
      }
178 6657531f Andreas Kohlbecker
179 c9d996cd Andreas Kohlbecker
      // Footnotes for collection acronyms.
180 15b7c460 Andreas Kohlbecker
      // footnotes should be rendered in the parent element so we
181
      // are relying on the FootnoteListKey set there
182 f3ebc0ed Andreas Kohlbecker
      $_fkey = FootnoteManager::addNewFootnote(
183 eaff53f7 Andreas Kohlbecker
        RenderHints::getFootnoteListKey(),
184
        (isset($derivedUnitFacadeInstance->collection->titleCache) ? $derivedUnitFacadeInstance->collection->titleCache : FALSE)
185
      );
186 6657531f Andreas Kohlbecker
      $out .= theme('cdm_footnote_key', array('footnoteKey' => $_fkey, 'separator' => $separator));
187
      $out .= '</li>';
188
189
    }
190
  }
191
192 4c75b2d9 Andreas Kohlbecker
  $out .= '</ul>';
193 a0a32510 Andreas Kohlbecker
194 ff4f2e07 Andreas Kohlbecker
  RenderHints::popFromRenderStack();
195
196 6657531f Andreas Kohlbecker
  return $out;
197
}
198
199
/**
200
 * FIXME this definitively has to be in another spot.
201
 * just didn't know where to put it right now.
202
 * Compares the status of two SpecimenTypeDesignations
203
 *
204
 * @param string $a
205
 *   A SpecimenTypeDesignations.
206
 * @param string $b
207
 *   SpecimenTypeDesignations.
208
 */
209
function compare_specimenTypeDesignationStatus($a, $b) {
210
  /*
211
  This is the desired sort order as of now: Holotype Isotype Lectotype
212
  Isolectotype Syntype.
213
  TODO Basically, what we are trying to do is, we define
214
  an ordered array of TypeDesignation-states and use the index of this array
215
  for comparison. This array has to be filled with the cdm- TypeDesignation
216
  states and the order should be parameterisable inside the dataportal.
217
  */
218
  // Make that static for now.
219
  $typeOrder = array(
220
    'Holotype',
221
    'Isotype',
222
    'Lectotype',
223
    'Isolectotype',
224
    'Syntype',
225
  );
226
227
  $aQuantifier = FALSE;
228
  $bQuantifier = FALSE;
229
  if (isset($a->typeStatus->label) && isset($b->typeStatus->label)) {
230
    $aQuantifier = array_search($a->typeStatus->label, $typeOrder);
231
    $bQuantifier = array_search($b->typeStatus->label, $typeOrder);
232
  }
233
  if ($aQuantifier == $bQuantifier) {
234
    // Sort alphabetically.
235
    return (isset($a->typeStatus->label) && isset($b->typeStatus->label) && $a->typeStatus->label < $b->typeStatus->label) ? -1 : 1;
236
  }
237
  return ($aQuantifier < $bQuantifier) ? -1 : 1;
238
}
239
240
/**
241
 * @todo Please document this function.
242
 * @see http://drupal.org/node/1354
243
 */
244
function theme_cdm_homotypicSynonymLine($variables) {
245
  $taxon = $variables['taxon'];
246
  $out = '';
247
  $out .= '<li class="synonym">' . cdm_related_taxon($taxon, UUID_HOMOTYPIC_SYNONYM_OF) . '</li>';
248
249
  return $out;
250
}
251
252
/**
253
 * @todo Please document this function.
254
 * @see http://drupal.org/node/1354
255
 */
256
function theme_cdm_heterotypicSynonymyGroup($variables) {
257
  $homotypicalGroup = $variables['homotypicalGroup'];
258
  RenderHints::pushToRenderStack('heterotypicSynonymyGroup');
259
260
  $out = '';
261 fea89e38 Andreas Kohlbecker
  $out = '<div class="heterotypic-synonymy-group"><ul class="heterotypicSynonymyGroup">';
262 6657531f Andreas Kohlbecker
  $footnoteListKey = (isset($homotypicalGroup[0]) ? $homotypicalGroup[0]->uuid : 'NULL');
263
  RenderHints::setFootnoteListKey($footnoteListKey);
264
265
  $is_first_entry = TRUE;
266 2f55de7d Andreas Kohlbecker
  $type_designations = NULL;
267 6657531f Andreas Kohlbecker
  foreach ($homotypicalGroup as $synonym) {
268
    if ($is_first_entry) {
269
      $is_first_entry = FALSE;
270 2f55de7d Andreas Kohlbecker
      $type_designations = cdm_ws_get(CDM_WS_PORTAL_NAME_TYPEDESIGNATIONS, $synonym->name->uuid);
271 6657531f Andreas Kohlbecker
      // Is first list entry.
272
      $out .= '<li class="firstentry synonym">' . cdm_related_taxon($synonym, UUID_HETEROTYPIC_SYNONYM_OF) . '</li>';
273
    }
274
    else {
275
      $out .= '<li class="synonym">' . cdm_related_taxon($synonym, UUID_HOMOTYPIC_SYNONYM_OF) . '</li>';
276
    }
277
  }
278
279 2f55de7d Andreas Kohlbecker
  if ($type_designations) {
280
    $out .= theme('cdm_typedesignations', array('typeDesignations' => $type_designations));
281 6657531f Andreas Kohlbecker
  }
282 939d3bb4 Andreas Kohlbecker
  $out .= '</ul>';
283
284
  // ------- footnotes ------- //
285 fea89e38 Andreas Kohlbecker
  $out .= '<ul class="footnotes">';
286 15b7c460 Andreas Kohlbecker
  $out .= theme('cdm_annotation_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey(), 'enclosingTag' => 'li'));
287
  $out .= theme('cdm_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey(), 'enclosingTag' => 'li'));
288 939d3bb4 Andreas Kohlbecker
  $out .= '</ul>';
289
290 fea89e38 Andreas Kohlbecker
  $out .= '</div>';
291 6657531f Andreas Kohlbecker
292
  RenderHints::popFromRenderStack();
293
  return $out;
294
}
295
296
/**
297 15b7c460 Andreas Kohlbecker
 * Renders the homotypic synonymy group for the accepted taxon in the synonymy.
298
 *
299
 * Foonotes of the accepted taxon will also be rendered here in the
300
 * homotypic synonymy group even if the synonymList or prependedSynonyms are
301
 * empty. Therefore  the homotypic group and accepted taxon share the  same
302
 * footnote key.
303
 *
304
 * @param $variables
305
 *   an associative array:
306
 *   - synonymList: the list of cdm Synonym entities
307
 *   - accepted_taxon_uuid: the uuid of the accepted taxon
308
 *   - prependedSynonyms: further synonyms which should be prepended
309
 *      before the actual list of synonyms
310 6657531f Andreas Kohlbecker
 */
311
function theme_cdm_homotypicSynonymyGroup($variables) {
312
  $synonymList = $variables['synonymList'];
313 2b7cd6c2 Andreas Kohlbecker
  $accepted_taxon_name_uuid = $variables['accepted_taxon_name_uuid'];
314 6657531f Andreas Kohlbecker
  $prependedSynonyms = $variables['prependedSynonyms'];
315 15b7c460 Andreas Kohlbecker
316 6657531f Andreas Kohlbecker
  RenderHints::pushToRenderStack('homotypicSynonymyGroup');
317
318 15b7c460 Andreas Kohlbecker
  $homonym_typeDesignations = NULL;
319 6657531f Andreas Kohlbecker
320 ff5d6ecb Andreas Kohlbecker
  // TODO improve typeDesignations retrieval: wouldn't it be sufficient to retrieve all typeDesignations
321 15b7c460 Andreas Kohlbecker
  // only from the accepted taxon?
322 2b7cd6c2 Andreas Kohlbecker
  $accepted_typeDesignations = cdm_ws_get(CDM_WS_PORTAL_NAME_TYPEDESIGNATIONS, $accepted_taxon_name_uuid);
323 6657531f Andreas Kohlbecker
324 15b7c460 Andreas Kohlbecker
  $out = '<div class="homotypic-synonymy-group">';
325
326
  if (isset ($accepted_typeDesignations) || is_array($prependedSynonyms) || is_array($synonymList)) {
327 b5519d3a Andreas Kohlbecker
    $out .= '<ul class="homotypicSynonyms">';
328
  if (!empty($prependedSynonyms)) {
329
    foreach ($prependedSynonyms as $taxon) {
330
      $out .= '<li class="synonym">' . cdm_related_taxon($taxon, UUID_HOMOTYPIC_SYNONYM_OF) . '</li>';
331
    }
332
  }
333
334
  $homonym_typeDesignations = NULL;
335
  if (isset($synonymList[0])) {
336
    foreach ($synonymList as $synonym) {
337
      $out .= '<li class="synonym">' . cdm_related_taxon($synonym, UUID_HOMOTYPIC_SYNONYM_OF) . '</li>';
338
    }
339
    $homonym_typeDesignations = cdm_ws_get(CDM_WS_PORTAL_NAME_TYPEDESIGNATIONS, $synonymList[0]->name->uuid);
340
  }
341
342
  // type designations
343
  if ($accepted_typeDesignations) {
344
    $type_designations = filter_cdm_entity_list($homonym_typeDesignations, $accepted_typeDesignations);
345
  }
346
  else {
347
    $type_designations = $homonym_typeDesignations;
348
  }
349 2b7cd6c2 Andreas Kohlbecker
350 b5519d3a Andreas Kohlbecker
  if ($type_designations) {
351
    $out .= theme('cdm_typedesignations', array('typeDesignations' => $type_designations));
352
  }
353 6657531f Andreas Kohlbecker
354
  }
355
356 fea89e38 Andreas Kohlbecker
  $out .= '</ul>';
357
358
  // ------- footnotes ------- //
359 15b7c460 Andreas Kohlbecker
360
  // all foonotes of the homotypic group and also of the accepted taxon are
361
  // rendered here, both should have the same footnote key
362 fea89e38 Andreas Kohlbecker
  $out .= '<ul class="footnotes">';
363 15b7c460 Andreas Kohlbecker
  $out .= theme('cdm_annotation_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey(), 'enclosingTag' => 'li'));
364
  $out .= theme('cdm_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey(), 'enclosingTag' => 'li'));
365 6657531f Andreas Kohlbecker
  $out .= '</ul>';
366
367 fea89e38 Andreas Kohlbecker
  $out .= '</div>';
368
369
370 6657531f Andreas Kohlbecker
  RenderHints::popFromRenderStack();
371
  return $out;
372
}