Project

General

Profile

Download (13.3 KB) Statistics
| Branch: | Tag: | Revision:
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
  $specimen_type_designations = array();
80
  $separator = ',';
81
  foreach ($typeDesignations as $typeDesignation) {
82
    if ($typeDesignation->class == 'SpecimenTypeDesignation') {
83
      // SpecimenTypeDesignations should be ordered. Collect theme here only.
84
      $specimen_type_designations[] = $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($specimen_type_designations)) {
113
    // Sorting might be different for dataportals so this has to be
114
    // parameterized.
115
    usort($specimen_type_designations, "compare_specimenTypeDesignationStatus");
116
    foreach ($specimen_type_designations as $type_designation) {
117
      $typeReference = '';
118

    
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
          $year = timePeriodToString($type_designation->citation->datePublished, true, 'YYYY');
126
          $authorteam_str = $author_team->titleCache . ($year ? ' ' : '') . $year;
127
          if($authorteam_str == $type_designation->citation->titleCache){
128
            $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
        }
135

    
136
        $footnote_key_markup = '';
137
        if($citation_footnote_str) {
138
          // footnotes should be rendered in the parent element so we
139
          // are relying on the FootnoteListKey set there
140
          $_fkey2 = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), $citation_footnote_str);
141
          $footnote_key_markup = theme('cdm_footnote_key', array(
142
            'footnoteKey' => $_fkey2,
143
            'separator' => $separator,
144
            'highlightable' => TRUE,
145
            'separator_off' => TRUE,
146
           ));
147

    
148
        }
149

    
150
        $typeReference .= '&nbsp;(' . t('designated by') . '&nbsp;<span class="typeReference">'. $authorteam_str . '</span>';
151
        if (!empty($type_designation->citationMicroReference)) {
152
          $typeReference .= ': ' . trim($type_designation->citationMicroReference);
153
        }
154
        $typeReference .= $footnote_key_markup . ')';
155

    
156
      }
157

    
158
      $derivedUnitFacadeInstance = null;
159

    
160
      $out .= '<li class="specimenTypeDesignation">';
161
      $out .= '<span class="status">'
162
        . ((isset($type_designation->typeStatus->representation_L10n)) ? $type_designation->typeStatus->representation_L10n : t('Type'))
163
        . $typeReference
164
        . '</span>';
165

    
166

    
167
      if (isset($type_designation->typeSpecimen)) {
168
        $derivedUnitFacadeInstance = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, $type_designation->typeSpecimen->uuid);
169
      }
170
      if ( isset($derivedUnitFacadeInstance ) ){
171
        $out .= ': ' . $derivedUnitFacadeInstance->titleCache; // . ': ' . theme('cdm_specimen', array('specimenTypeDesignation' => $derivedUnitFacadeInstance));
172
      }
173

    
174
      // Footnotes for collection acronyms.
175
      // footnotes should be rendered in the parent element so we
176
      // are relying on the FootnoteListKey set there
177
      $_fkey = FootnoteManager::addNewFootnote(
178
          RenderHints::getFootnoteListKey(),
179
          (isset($derivedUnitFacadeInstance->collection->titleCache) ? $derivedUnitFacadeInstance->collection->titleCache : FALSE)
180
        );
181
      $out .= theme('cdm_footnote_key', array('footnoteKey' => $_fkey, 'separator' => $separator));
182
      $out .= '</li>';
183

    
184
    }
185
  }
186

    
187
  $out .= '</ul>';
188

    
189
  RenderHints::popFromRenderStack();
190

    
191
  return $out;
192
}
193

    
194
/**
195
 * FIXME this definitively has to be in another spot.
196
 * just didn't know where to put it right now.
197
 * Compares the status of two SpecimenTypeDesignations
198
 *
199
 * @param string $a
200
 *   A SpecimenTypeDesignations.
201
 * @param string $b
202
 *   SpecimenTypeDesignations.
203
 */
204
function compare_specimenTypeDesignationStatus($a, $b) {
205
  /*
206
  This is the desired sort order as of now: Holotype Isotype Lectotype
207
  Isolectotype Syntype.
208
  TODO Basically, what we are trying to do is, we define
209
  an ordered array of TypeDesignation-states and use the index of this array
210
  for comparison. This array has to be filled with the cdm- TypeDesignation
211
  states and the order should be parameterisable inside the dataportal.
212
  */
213
  // Make that static for now.
214
  $typeOrder = array(
215
    'Holotype',
216
    'Isotype',
217
    'Lectotype',
218
    'Isolectotype',
219
    'Syntype',
220
  );
221

    
222
  $aQuantifier = FALSE;
223
  $bQuantifier = FALSE;
224
  if (isset($a->typeStatus->label) && isset($b->typeStatus->label)) {
225
    $aQuantifier = array_search($a->typeStatus->label, $typeOrder);
226
    $bQuantifier = array_search($b->typeStatus->label, $typeOrder);
227
  }
228
  if ($aQuantifier == $bQuantifier) {
229
    // Sort alphabetically.
230
    return (isset($a->typeStatus->label) && isset($b->typeStatus->label) && $a->typeStatus->label < $b->typeStatus->label) ? -1 : 1;
231
  }
232
  return ($aQuantifier < $bQuantifier) ? -1 : 1;
233
}
234

    
235
/**
236
 * @todo Please document this function.
237
 * @see http://drupal.org/node/1354
238
 */
239
function theme_cdm_homotypicSynonymLine($variables) {
240
  $taxon = $variables['taxon'];
241
  $out = '';
242
  $out .= '<li class="synonym">' . cdm_related_taxon($taxon, UUID_HOMOTYPIC_SYNONYM_OF) . '</li>';
243

    
244
  return $out;
245
}
246

    
247
/**
248
 * @todo Please document this function.
249
 * @see http://drupal.org/node/1354
250
 */
251
function theme_cdm_heterotypicSynonymyGroup($variables) {
252
  $homotypicalGroup = $variables['homotypicalGroup'];
253
  RenderHints::pushToRenderStack('heterotypicSynonymyGroup');
254

    
255
  $out = '';
256
  $out = '<div class="heterotypic-synonymy-group"><ul class="heterotypicSynonymyGroup">';
257
  $footnoteListKey = (isset($homotypicalGroup[0]) ? $homotypicalGroup[0]->uuid : 'NULL');
258
  RenderHints::setFootnoteListKey($footnoteListKey);
259

    
260
  $is_first_entry = TRUE;
261
  $typeDesignations = NULL;
262
  foreach ($homotypicalGroup as $synonym) {
263
    if ($is_first_entry) {
264
      $is_first_entry = FALSE;
265
      $typeDesignations = cdm_ws_get(CDM_WS_PORTAL_NAME_TYPEDESIGNATIONS, $synonym->name->uuid);
266
      // Is first list entry.
267
      $out .= '<li class="firstentry synonym">' . cdm_related_taxon($synonym, UUID_HETEROTYPIC_SYNONYM_OF) . '</li>';
268
    }
269
    else {
270
      $out .= '<li class="synonym">' . cdm_related_taxon($synonym, UUID_HOMOTYPIC_SYNONYM_OF) . '</li>';
271
    }
272
  }
273

    
274
  if ($typeDesignations) {
275
    $out .= theme('cdm_typedesignations', array('typeDesignations' => $typeDesignations));
276
  }
277
  $out .= '</ul>';
278

    
279
  // ------- footnotes ------- //
280
  $out .= '<ul class="footnotes">';
281
  $out .= theme('cdm_annotation_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey(), 'enclosingTag' => 'li'));
282
  $out .= theme('cdm_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey(), 'enclosingTag' => 'li'));
283
  $out .= '</ul>';
284

    
285
  $out .= '</div>';
286

    
287
  RenderHints::popFromRenderStack();
288
  return $out;
289
}
290

    
291
/**
292
 * Renders the homotypic synonymy group for the accepted taxon in the synonymy.
293
 *
294
 * Foonotes of the accepted taxon will also be rendered here in the
295
 * homotypic synonymy group even if the synonymList or prependedSynonyms are
296
 * empty. Therefore  the homotypic group and accepted taxon share the  same
297
 * footnote key.
298
 *
299
 * @param $variables
300
 *   an associative array:
301
 *   - synonymList: the list of cdm Synonym entities
302
 *   - accepted_taxon_uuid: the uuid of the accepted taxon
303
 *   - prependedSynonyms: further synonyms which should be prepended
304
 *      before the actual list of synonyms
305
 */
306
function theme_cdm_homotypicSynonymyGroup($variables) {
307
  $synonymList = $variables['synonymList'];
308
  $accepted_taxon_name_uuid = $variables['accepted_taxon_name_uuid'];
309
  $prependedSynonyms = $variables['prependedSynonyms'];
310

    
311
  RenderHints::pushToRenderStack('homotypicSynonymyGroup');
312

    
313
  $homonym_typeDesignations = NULL;
314

    
315
  // TODO improve typeDesignations retrieval: wouldn't it be suffcient to retrieve all typeDesignations
316
  // only from the accepted taxon?
317
  $accepted_typeDesignations = cdm_ws_get(CDM_WS_PORTAL_NAME_TYPEDESIGNATIONS, $accepted_taxon_name_uuid);
318

    
319
  $out = '<div class="homotypic-synonymy-group">';
320

    
321
  if (isset ($accepted_typeDesignations) || is_array($prependedSynonyms) || is_array($synonymList)) {
322
    $out .= '<ul class="homotypicSynonyms">';
323
  if (!empty($prependedSynonyms)) {
324
    foreach ($prependedSynonyms as $taxon) {
325
      $out .= '<li class="synonym">' . cdm_related_taxon($taxon, UUID_HOMOTYPIC_SYNONYM_OF) . '</li>';
326
    }
327
  }
328

    
329
  $homonym_typeDesignations = NULL;
330
  if (isset($synonymList[0])) {
331
    foreach ($synonymList as $synonym) {
332
      $out .= '<li class="synonym">' . cdm_related_taxon($synonym, UUID_HOMOTYPIC_SYNONYM_OF) . '</li>';
333
    }
334
    $homonym_typeDesignations = cdm_ws_get(CDM_WS_PORTAL_NAME_TYPEDESIGNATIONS, $synonymList[0]->name->uuid);
335
  }
336

    
337
  // type designations
338
  if ($accepted_typeDesignations) {
339
    $type_designations = filter_cdm_entity_list($homonym_typeDesignations, $accepted_typeDesignations);
340
  }
341
  else {
342
    $type_designations = $homonym_typeDesignations;
343
  }
344

    
345
  if ($type_designations) {
346
    $out .= theme('cdm_typedesignations', array('typeDesignations' => $type_designations));
347
  }
348

    
349
  }
350

    
351
  $out .= '</ul>';
352

    
353
  // ------- footnotes ------- //
354

    
355
  // all foonotes of the homotypic group and also of the accepted taxon are
356
  // rendered here, both should have the same footnote key
357
  $out .= '<ul class="footnotes">';
358
  $out .= theme('cdm_annotation_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey(), 'enclosingTag' => 'li'));
359
  $out .= theme('cdm_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey(), 'enclosingTag' => 'li'));
360
  $out .= '</ul>';
361

    
362
  $out .= '</div>';
363

    
364

    
365
  RenderHints::popFromRenderStack();
366
  return $out;
367
}
(4-4/9)