Project

General

Profile

Download (13.3 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
  $typeDesignations = $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
  foreach ($typeDesignations as $typeDesignation) {
82
    if ($typeDesignation->class == 'SpecimenTypeDesignation') {
83
      // SpecimenTypeDesignations should be ordered. Collect theme here only.
84 c5294246 Andreas Kohlbecker
      $specimen_type_designations[] = $typeDesignation;
85 6657531f Andreas Kohlbecker
    }
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 939d3bb4 Andreas Kohlbecker
        $link_to_name_page = url(path_to_name($typeDesignation->typeName->uuid));
97 6657531f Andreas Kohlbecker
        $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 c9d996cd Andreas Kohlbecker
102 6657531f Andreas Kohlbecker
        }
103
        $referenceUri = '';
104
        if (isset($typeDesignation->typeName->nomenclaturalReference)) {
105
          $referenceUri = url(path_to_reference($typeDesignation->typeName->nomenclaturalReference->uuid));
106
        }
107 63c3ac73 Andreas Kohlbecker
        $out .= ': ' . render_taxon_or_name($typeDesignation->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
        if(isset($author_team->titleCache)){
125
          $authorteam_str = $author_team->titleCache . partialToYear($type_designation->citation->datePublished->start);
126
          if($authorteam_str == $type_designation->citation->titleCache){
127
            $citation_footnote_str = '';
128
          }
129
        } else {
130
          $authorteam_str = $citation_footnote_str;
131
          // no need for a footnote in case in case it is used as replacement for missing author teams
132
          $citation_footnote_str = '';
133 6657531f Andreas Kohlbecker
        }
134
135 c5294246 Andreas Kohlbecker
        $footnote_key_markup = '';
136
        if($citation_footnote_str) {
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(), $citation_footnote_str);
140
          $footnote_key_markup = theme('cdm_footnote_key', array(
141
            'footnoteKey' => $_fkey2,
142
            'separator' => $separator,
143
            'highlightable' => TRUE,
144
            'separator_off' => TRUE,
145
           ));
146
147 f3ebc0ed Andreas Kohlbecker
        }
148 c5294246 Andreas Kohlbecker
149
        $typeReference .= '&nbsp;(' . t('designated by') . '&nbsp;<span class="typeReference">'. $authorteam_str . '</span>';
150
        if (!empty($type_designation->citationMicroReference)) {
151
          $typeReference .= ':' . $type_designation->citationMicroReference;
152
        }
153
        $typeReference .= $footnote_key_markup . ')';
154
155 6657531f Andreas Kohlbecker
      }
156
157 f3ebc0ed Andreas Kohlbecker
      $derivedUnitFacadeInstance = null;
158 6657531f Andreas Kohlbecker
159
      $out .= '<li class="specimenTypeDesignation">';
160 f3ebc0ed Andreas Kohlbecker
      $out .= '<span class="status">'
161 c5294246 Andreas Kohlbecker
        . ((isset($type_designation->typeStatus->representation_L10n)) ? $type_designation->typeStatus->representation_L10n : t('Type'))
162 f3ebc0ed Andreas Kohlbecker
        . $typeReference
163 f880d174 Andreas Kohlbecker
        . '</span>';
164 f3ebc0ed Andreas Kohlbecker
165
166 c5294246 Andreas Kohlbecker
      if (isset($type_designation->typeSpecimen)) {
167
        $derivedUnitFacadeInstance = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, $type_designation->typeSpecimen->uuid);
168 f3ebc0ed Andreas Kohlbecker
      }
169 234c77ab Andreas Kohlbecker
      if ( isset($derivedUnitFacadeInstance ) ){
170 f880d174 Andreas Kohlbecker
        $out .= ': ' . $derivedUnitFacadeInstance->titleCache; // . ': ' . theme('cdm_specimen', array('specimenTypeDesignation' => $derivedUnitFacadeInstance));
171 f3ebc0ed Andreas Kohlbecker
      }
172 6657531f Andreas Kohlbecker
173 c9d996cd Andreas Kohlbecker
      // Footnotes for collection acronyms.
174 15b7c460 Andreas Kohlbecker
      // footnotes should be rendered in the parent element so we
175
      // are relying on the FootnoteListKey set there
176 f3ebc0ed Andreas Kohlbecker
      $_fkey = FootnoteManager::addNewFootnote(
177 15b7c460 Andreas Kohlbecker
          RenderHints::getFootnoteListKey(),
178 f3ebc0ed Andreas Kohlbecker
          (isset($derivedUnitFacadeInstance->collection->titleCache) ? $derivedUnitFacadeInstance->collection->titleCache : FALSE)
179
        );
180 6657531f Andreas Kohlbecker
      $out .= theme('cdm_footnote_key', array('footnoteKey' => $_fkey, 'separator' => $separator));
181
      $out .= '</li>';
182
183
    }
184
  }
185
186 4c75b2d9 Andreas Kohlbecker
  $out .= '</ul>';
187 a0a32510 Andreas Kohlbecker
188 ff4f2e07 Andreas Kohlbecker
  RenderHints::popFromRenderStack();
189
190 6657531f Andreas Kohlbecker
  return $out;
191
}
192
193
/**
194
 * FIXME this definitively has to be in another spot.
195
 * just didn't know where to put it right now.
196
 * Compares the status of two SpecimenTypeDesignations
197
 *
198
 * @param string $a
199
 *   A SpecimenTypeDesignations.
200
 * @param string $b
201
 *   SpecimenTypeDesignations.
202
 */
203
function compare_specimenTypeDesignationStatus($a, $b) {
204
  /*
205
  This is the desired sort order as of now: Holotype Isotype Lectotype
206
  Isolectotype Syntype.
207
  TODO Basically, what we are trying to do is, we define
208
  an ordered array of TypeDesignation-states and use the index of this array
209
  for comparison. This array has to be filled with the cdm- TypeDesignation
210
  states and the order should be parameterisable inside the dataportal.
211
  */
212
  // Make that static for now.
213
  $typeOrder = array(
214
    'Holotype',
215
    'Isotype',
216
    'Lectotype',
217
    'Isolectotype',
218
    'Syntype',
219
  );
220
221
  $aQuantifier = FALSE;
222
  $bQuantifier = FALSE;
223
  if (isset($a->typeStatus->label) && isset($b->typeStatus->label)) {
224
    $aQuantifier = array_search($a->typeStatus->label, $typeOrder);
225
    $bQuantifier = array_search($b->typeStatus->label, $typeOrder);
226
  }
227
  if ($aQuantifier == $bQuantifier) {
228
    // Sort alphabetically.
229
    return (isset($a->typeStatus->label) && isset($b->typeStatus->label) && $a->typeStatus->label < $b->typeStatus->label) ? -1 : 1;
230
  }
231
  return ($aQuantifier < $bQuantifier) ? -1 : 1;
232
}
233
234
/**
235
 * @todo Please document this function.
236
 * @see http://drupal.org/node/1354
237
 */
238
function theme_cdm_homotypicSynonymLine($variables) {
239
  $taxon = $variables['taxon'];
240
  $out = '';
241
  $out .= '<li class="synonym">' . cdm_related_taxon($taxon, UUID_HOMOTYPIC_SYNONYM_OF) . '</li>';
242
243
  return $out;
244
}
245
246
/**
247
 * @todo Please document this function.
248
 * @see http://drupal.org/node/1354
249
 */
250
function theme_cdm_heterotypicSynonymyGroup($variables) {
251
  $homotypicalGroup = $variables['homotypicalGroup'];
252
  RenderHints::pushToRenderStack('heterotypicSynonymyGroup');
253
254
  $out = '';
255 fea89e38 Andreas Kohlbecker
  $out = '<div class="heterotypic-synonymy-group"><ul class="heterotypicSynonymyGroup">';
256 6657531f Andreas Kohlbecker
  $footnoteListKey = (isset($homotypicalGroup[0]) ? $homotypicalGroup[0]->uuid : 'NULL');
257
  RenderHints::setFootnoteListKey($footnoteListKey);
258
259
  $is_first_entry = TRUE;
260
  $typeDesignations = NULL;
261
  foreach ($homotypicalGroup as $synonym) {
262
    if ($is_first_entry) {
263
      $is_first_entry = FALSE;
264
      $typeDesignations = cdm_ws_get(CDM_WS_PORTAL_NAME_TYPEDESIGNATIONS, $synonym->name->uuid);
265
      // Is first list entry.
266
      $out .= '<li class="firstentry synonym">' . cdm_related_taxon($synonym, UUID_HETEROTYPIC_SYNONYM_OF) . '</li>';
267
    }
268
    else {
269
      $out .= '<li class="synonym">' . cdm_related_taxon($synonym, UUID_HOMOTYPIC_SYNONYM_OF) . '</li>';
270
    }
271
  }
272
273
  if ($typeDesignations) {
274
    $out .= theme('cdm_typedesignations', array('typeDesignations' => $typeDesignations));
275
  }
276 939d3bb4 Andreas Kohlbecker
  $out .= '</ul>';
277
278
  // ------- footnotes ------- //
279 fea89e38 Andreas Kohlbecker
  $out .= '<ul class="footnotes">';
280 15b7c460 Andreas Kohlbecker
  $out .= theme('cdm_annotation_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey(), 'enclosingTag' => 'li'));
281
  $out .= theme('cdm_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey(), 'enclosingTag' => 'li'));
282 939d3bb4 Andreas Kohlbecker
  $out .= '</ul>';
283
284 fea89e38 Andreas Kohlbecker
  $out .= '</div>';
285 6657531f Andreas Kohlbecker
286
  RenderHints::popFromRenderStack();
287
  return $out;
288
}
289
290
/**
291 15b7c460 Andreas Kohlbecker
 * Renders the homotypic synonymy group for the accepted taxon in the synonymy.
292
 *
293
 * Foonotes of the accepted taxon will also be rendered here in the
294
 * homotypic synonymy group even if the synonymList or prependedSynonyms are
295
 * empty. Therefore  the homotypic group and accepted taxon share the  same
296
 * footnote key.
297
 *
298
 * @param $variables
299
 *   an associative array:
300
 *   - synonymList: the list of cdm Synonym entities
301
 *   - accepted_taxon_uuid: the uuid of the accepted taxon
302
 *   - prependedSynonyms: further synonyms which should be prepended
303
 *      before the actual list of synonyms
304 6657531f Andreas Kohlbecker
 */
305
function theme_cdm_homotypicSynonymyGroup($variables) {
306
  $synonymList = $variables['synonymList'];
307 2b7cd6c2 Andreas Kohlbecker
  $accepted_taxon_name_uuid = $variables['accepted_taxon_name_uuid'];
308 6657531f Andreas Kohlbecker
  $prependedSynonyms = $variables['prependedSynonyms'];
309 15b7c460 Andreas Kohlbecker
310 6657531f Andreas Kohlbecker
  RenderHints::pushToRenderStack('homotypicSynonymyGroup');
311
312 15b7c460 Andreas Kohlbecker
  $homonym_typeDesignations = NULL;
313 6657531f Andreas Kohlbecker
314 15b7c460 Andreas Kohlbecker
  // TODO improve typeDesignations retrieval: wouldn't it be suffcient to retrieve all typeDesignations
315
  // only from the accepted taxon?
316 2b7cd6c2 Andreas Kohlbecker
  $accepted_typeDesignations = cdm_ws_get(CDM_WS_PORTAL_NAME_TYPEDESIGNATIONS, $accepted_taxon_name_uuid);
317 6657531f Andreas Kohlbecker
318 15b7c460 Andreas Kohlbecker
  $out = '<div class="homotypic-synonymy-group">';
319
320
  if (isset ($accepted_typeDesignations) || is_array($prependedSynonyms) || is_array($synonymList)) {
321 b5519d3a Andreas Kohlbecker
    $out .= '<ul class="homotypicSynonyms">';
322
  if (!empty($prependedSynonyms)) {
323
    foreach ($prependedSynonyms as $taxon) {
324
      $out .= '<li class="synonym">' . cdm_related_taxon($taxon, UUID_HOMOTYPIC_SYNONYM_OF) . '</li>';
325
    }
326
  }
327
328
  $homonym_typeDesignations = NULL;
329
  if (isset($synonymList[0])) {
330
    foreach ($synonymList as $synonym) {
331
      $out .= '<li class="synonym">' . cdm_related_taxon($synonym, UUID_HOMOTYPIC_SYNONYM_OF) . '</li>';
332
    }
333
    $homonym_typeDesignations = cdm_ws_get(CDM_WS_PORTAL_NAME_TYPEDESIGNATIONS, $synonymList[0]->name->uuid);
334
  }
335
336
  // type designations
337
  if ($accepted_typeDesignations) {
338
    $type_designations = filter_cdm_entity_list($homonym_typeDesignations, $accepted_typeDesignations);
339
  }
340
  else {
341
    $type_designations = $homonym_typeDesignations;
342
  }
343 2b7cd6c2 Andreas Kohlbecker
344 b5519d3a Andreas Kohlbecker
  if ($type_designations) {
345
    $out .= theme('cdm_typedesignations', array('typeDesignations' => $type_designations));
346
  }
347 6657531f Andreas Kohlbecker
348
  }
349
350 fea89e38 Andreas Kohlbecker
  $out .= '</ul>';
351
352
  // ------- footnotes ------- //
353 15b7c460 Andreas Kohlbecker
354
  // all foonotes of the homotypic group and also of the accepted taxon are
355
  // rendered here, both should have the same footnote key
356 fea89e38 Andreas Kohlbecker
  $out .= '<ul class="footnotes">';
357 15b7c460 Andreas Kohlbecker
  $out .= theme('cdm_annotation_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey(), 'enclosingTag' => 'li'));
358
  $out .= theme('cdm_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey(), 'enclosingTag' => 'li'));
359 6657531f Andreas Kohlbecker
  $out .= '</ul>';
360
361 fea89e38 Andreas Kohlbecker
  $out .= '</div>';
362
363
364 6657531f Andreas Kohlbecker
  RenderHints::popFromRenderStack();
365
  return $out;
366
}