Project

General

Profile

Download (13.9 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
  $type_designations = $variables['typeDesignations'];
71
  $enclosing_tag = $variables['enclosing_tag'];
72
  $element_tag = $variables['element_tag'];
73

    
74
  // need to add element to render path since type designations
75
  // need other name render template
76
  RenderHints::pushToRenderStack('typedesignations');
77

    
78
  $out = '<' . $enclosing_tag .' class="typeDesignations">';
79
  $typeDesignation_footnotes = FALSE;
80
  $is_lectotype = FALSE;
81
  $specimen_type_designations = array();
82
  $separator = ',';
83
  foreach ($type_designations as $type_designation) {
84
    if ($type_designation->class == 'SpecimenTypeDesignation') {
85
      // SpecimenTypeDesignations should be ordered. Collect theme here only.
86
      $specimen_type_designations[] = $type_designation;
87
    }
88
    // It is a lectotype?
89
    else {
90
      if (isset($type_designation->typeStatus->uuid) && $type_designation->typeStatus->uuid == UUID_NTD_LECTOTYPE) {
91
        $is_lectotype = TRUE;
92
      }
93
      // It's a NameTypeDesignation.
94
      if ($type_designation->notDesignated) {
95
        $out .= '<'. $element_tag .' class="' . html_class_attribute_ref($type_designation) . '"><span class="status">' . ($is_lectotype ? 'Lectotype' : 'Type') . '</span>: ' . t('not designated') . '</'. $element_tag .'>';
96
      }
97
      elseif ($type_designation->typeName) {
98
        $link_to_name_page = url(path_to_name($type_designation->typeName->uuid));
99
        $out .= '<'. $element_tag .' class="' . html_class_attribute_ref($type_designation) . '"><span class="status">' . ($is_lectotype ? 'Lectotype' : 'Type') . '</span>';
100

    
101
        if ($type_designation->citation) {
102
          $out .= type_designation_citation_layout($type_designation, $separator);
103

    
104
        }
105
        $referenceUri = '';
106
        if (isset($type_designation->typeName->nomenclaturalReference)) {
107
          $referenceUri = url(path_to_reference($type_designation->typeName->nomenclaturalReference->uuid));
108
        }
109
        $out .= ': ' . render_taxon_or_name($type_designation->typeName, $link_to_name_page, $referenceUri, TRUE, TRUE);
110
      }
111
    }
112
  }
113

    
114
  if (!empty($specimen_type_designations)) {
115
    // Sorting might be different for dataportals so this has to be
116
    // parameterized.
117
    usort($specimen_type_designations, "compare_specimen_type_designation");
118
    foreach ($specimen_type_designations as $type_designation) {
119
      $typeReference = '';
120

    
121
      if (!empty($type_designation->citation)) {
122

    
123
        $citation_footnote_str = theme('cdm_reference', array('reference' => $type_designation->citation, 'doIconLink' => true));
124
        $author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $type_designation->citation->uuid);
125

    
126
        if (isset($author_team->titleCache)) {
127
          $year = timePeriodToString($type_designation->citation->datePublished, true, 'YYYY');
128
          $authorteam_str = $author_team->titleCache . ($year ? ' ' : '') . $year;
129
          if ($authorteam_str == $type_designation->citation->titleCache) {
130
            $citation_footnote_str = '';
131
          }
132
        } else {
133
          $authorteam_str = $citation_footnote_str;
134
          // no need for a footnote in case in case it is used as replacement for missing author teams
135
          $citation_footnote_str = '';
136
        }
137

    
138
        // to be registered a typedesignation MUS HAVE a citation, so it is save to handle the
139
        // Registration output in if condition checking if the citation is present
140
        $registration_markup = render_registrations($type_designation->registrations);
141
        $citation_footnote_str .= ($citation_footnote_str ? ' ' : '') . $registration_markup;
142

    
143
        $footnote_key_markup = '';
144
        if ($citation_footnote_str) {
145
          // footnotes should be rendered in the parent element so we
146
          // are relying on the FootnoteListKey set there
147
          $_fkey2 = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), $citation_footnote_str);
148
          $footnote_key_markup = theme('cdm_footnote_key', array(
149
            'footnoteKey' => $_fkey2,
150
            'separator' => $separator,
151
            'highlightable' => TRUE,
152
            'separator_off' => TRUE,
153
          ));
154

    
155
        }
156

    
157
        $typeReference .= '&nbsp;(' . t('designated by') . '&nbsp;<span class="typeReference">' . $authorteam_str . '</span>';
158
        if (!empty($type_designation->citationMicroReference)) {
159
          $typeReference .= ': ' . trim($type_designation->citationMicroReference);
160
        }
161
        $typeReference .= $footnote_key_markup . ')';
162

    
163
      }
164

    
165
      $derivedUnitFacadeInstance = null;
166

    
167
      $out .= '<'. $element_tag .' class="' . html_class_attribute_ref($type_designation) . '">';
168
      $out .= '<span class="status">'
169
        . ((isset($type_designation->typeStatus->representation_L10n)) ? $type_designation->typeStatus->representation_L10n : t('Type'))
170
        . $typeReference
171
        . '</span>';
172

    
173

    
174
      if (isset($type_designation->typeSpecimen)) {
175
        $derivedUnitFacadeInstance = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, $type_designation->typeSpecimen->uuid);
176
      }
177
      if (isset($derivedUnitFacadeInstance)) {
178
        $out .= ': ' . $derivedUnitFacadeInstance->titleCache; // . ': ' . theme('cdm_specimen', array('specimenTypeDesignation' => $derivedUnitFacadeInstance));
179
      }
180

    
181
      // Footnotes for collection acronyms.
182
      // footnotes should be rendered in the parent element so we
183
      // are relying on the FootnoteListKey set there
184
      $_fkey = FootnoteManager::addNewFootnote(
185
        RenderHints::getFootnoteListKey(),
186
        (isset($derivedUnitFacadeInstance->collection->titleCache) ? $derivedUnitFacadeInstance->collection->titleCache : FALSE)
187
      );
188
      $out .= theme('cdm_footnote_key', array('footnoteKey' => $_fkey, 'separator' => $separator));
189
      $out .= '</'. $element_tag .'>';
190

    
191
    }
192
  }
193

    
194
  $out .= '</' . $enclosing_tag .'>';
195

    
196
  RenderHints::popFromRenderStack();
197

    
198
  return $out;
199
}
200

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

    
229
  $aQuantifier = FALSE;
230
  $bQuantifier = FALSE;
231
  if (isset($a->typeStatus->label) && isset($b->typeStatus->label)) {
232
    $aQuantifier = array_search($a->typeStatus->label, $typeOrder);
233
    $bQuantifier = array_search($b->typeStatus->label, $typeOrder);
234
  }
235
  if ($aQuantifier == $bQuantifier) {
236
    // Sort alphabetically.
237
    $a_text =  isset($a->typeSpecimen->titleCache) ? preg_replace('/[\[\]\"]/', '', $a->typeSpecimen->titleCache) : '';
238
    $b_text =  isset($b->typeSpecimen->titleCache) ? preg_replace('/[\[\]\"]/', '', $b->typeSpecimen->titleCache) : '';
239
    return strcasecmp($a_text, $b_text);
240
  }
241
  return ($aQuantifier < $bQuantifier) ? -1 : 1;
242
}
243

    
244
/**
245
 * @todo Please document this function.
246
 * @see http://drupal.org/node/1354
247
 */
248
function theme_cdm_homotypicSynonymLine($variables) {
249
  $taxon = $variables['taxon'];
250
  $out = '';
251
  $out .= '<li class="synonym">' . cdm_related_taxon($taxon, UUID_HOMOTYPIC_SYNONYM_OF) . '</li>';
252

    
253
  return $out;
254
}
255

    
256
/**
257
 * @todo Please document this function.
258
 * @see http://drupal.org/node/1354
259
 */
260
function theme_cdm_heterotypicSynonymyGroup($variables) {
261
  $homotypical_group = $variables['homotypicalGroup'];
262
  RenderHints::pushToRenderStack('heterotypicSynonymyGroup');
263

    
264
  $out = '';
265
  $out = '<div class="heterotypic-synonymy-group"><ul class="heterotypicSynonymyGroup">';
266
  $footnoteListKey = (isset($homotypical_group[0]) ? $homotypical_group[0]->uuid : 'NULL');
267
  RenderHints::setFootnoteListKey($footnoteListKey);
268

    
269
  $type_designations= type_designations_for_synonymy_group($homotypical_group);
270

    
271
  $is_first_entry = TRUE;
272
  foreach ($homotypical_group as $synonym) {
273
    if ($is_first_entry) {
274
      $is_first_entry = FALSE;
275
      // Is first list entry.
276
      $out .= '<li class="firstentry synonym">' . cdm_related_taxon($synonym, UUID_HETEROTYPIC_SYNONYM_OF) . '</li>';
277
    }
278
    else {
279
      $out .= '<li class="synonym">' . cdm_related_taxon($synonym, UUID_HOMOTYPIC_SYNONYM_OF) . '</li>';
280
    }
281
  }
282

    
283
  if (count($type_designations) > 0) {
284
    $out .= theme('cdm_typedesignations', array('typeDesignations' => $type_designations));
285
  }
286
  $out .= '</ul>';
287

    
288
  // ------- footnotes ------- //
289
  $out .= '<ul class="footnotes">';
290
  $out .= theme('cdm_annotation_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey(), 'enclosingTag' => 'li'));
291
  $out .= theme('cdm_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey(), 'enclosingTag' => 'li'));
292
  $out .= '</ul>';
293

    
294
  $out .= '</div>';
295

    
296
  RenderHints::popFromRenderStack();
297
  return $out;
298
}
299

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

    
320
  RenderHints::pushToRenderStack('homotypicSynonymyGroup');
321

    
322
  $type_designations_in_group = NULL;
323

    
324
  $out = '<div class="homotypic-synonymy-group">';
325

    
326
  $type_designations = type_designations_for_synonymy_group($synonymList);
327
  $accepted_name_type_designations = cdm_ws_get(CDM_WS_PORTAL_NAME_TYPEDESIGNATIONS, $accepted_taxon_name_uuid);
328
  if($accepted_name_type_designations  && count($accepted_name_type_designations) > 0){
329
    $type_designations = array_merge($accepted_name_type_designations, $type_designations);
330
  }
331

    
332
  if (count($type_designations) > 0 || is_array($prependedSynonyms) || is_array($synonymList)) {
333
    $out .= '<ul class="homotypicSynonyms">';
334
  if (!empty($prependedSynonyms)) {
335
    foreach ($prependedSynonyms as $taxon) {
336
      $out .= '<li class="synonym">' . cdm_related_taxon($taxon, UUID_HOMOTYPIC_SYNONYM_OF) . '</li>';
337
    }
338
  }
339

    
340

    
341
  if (isset($synonymList[0])) {
342
    foreach ($synonymList as $synonym) {
343
      $out .= '<li class="synonym">' . cdm_related_taxon($synonym, UUID_HOMOTYPIC_SYNONYM_OF) . '</li>';
344
    }
345
  }
346

    
347
  if (count($type_designations) > 0) {
348
    $out .= theme('cdm_typedesignations', array('typeDesignations' => $type_designations));
349
  }
350

    
351
  }
352

    
353
  $out .= '</ul>';
354

    
355
  // ------- footnotes ------- //
356

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

    
364
  $out .= '</div>';
365

    
366

    
367
  RenderHints::popFromRenderStack();
368
  return $out;
369
}
(4-4/9)