Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

cdm-dataportal / modules / cdm_dataportal / theme / cdm_dataportal.name.theme @ f41c2b5e

History | View | Annotate | Download (12.9 KB)

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
  $link_to_specimen_page = $variables['link_to_specimen_page'];
74

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

    
79
  $out = '<' . $enclosing_tag .' class="typeDesignations">';
80
  $typeDesignation_footnotes = FALSE;
81
  $is_lectotype = FALSE;
82
  $specimen_type_designations = array();
83
  $separator = ',';
84

    
85
  foreach ($type_designations as $type_designation) {
86
    if ($type_designation->class == 'SpecimenTypeDesignation') {
87
      // --> SpecimenTypeDesignations should be ordered. Collect theme here only.
88
      $specimen_type_designations[] = $type_designation;
89
    }
90
    else {
91
      // --> NameTypeDesignations
92
      // It is a lectotype?
93
      if (isset($type_designation->typeStatus->uuid) && $type_designation->typeStatus->uuid == UUID_NTD_LECTOTYPE) {
94
        $is_lectotype = TRUE;
95
      }
96
      if ($type_designation->notDesignated) {
97
        $out .= '<'. $element_tag .' class="' . html_class_attribute_ref($type_designation) . '"><span class="type-status">' . ($is_lectotype ? 'Lectotype' : 'Type') . '</span>: ' . t('not designated') . '</'. $element_tag .'>';
98
      }
99
      elseif ($type_designation->typeName) {
100
        $link_to_name_page = url(path_to_name($type_designation->typeName->uuid));
101
        $out .= '<'. $element_tag .' class="' . html_class_attribute_ref($type_designation) . '"><span class="type-status">' . ($is_lectotype ? 'Lectotype' : 'Type') . '</span>';
102

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

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

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

    
123
      if (!empty($type_designation->citation)) {
124

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

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

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

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

    
157
        }
158

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

    
165
      }
166

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

    
172

    
173
      $derivedUnitFacadeInstance = null;
174
      if (isset($type_designation->typeSpecimen)) {
175
        $derivedUnitFacadeInstance = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, $type_designation->typeSpecimen->uuid);
176
      }
177

    
178
      if (isset($derivedUnitFacadeInstance->titleCache)) {
179
        $specimen_markup = $derivedUnitFacadeInstance->titleCache;
180
        if($link_to_specimen_page && isset($derivedUnitFacadeInstance->specimenLabel) && $derivedUnitFacadeInstance->specimenLabel){
181
          $specimen_markup = str_replace($derivedUnitFacadeInstance->specimenLabel, l($derivedUnitFacadeInstance->specimenLabel, path_to_specimen($type_designation->typeSpecimen->uuid)), $specimen_markup);
182
        }
183
        $out .= ': <span class="' . html_class_attribute_ref($type_designation->typeSpecimen) . '">'
184
           . $specimen_markup
185
           . '</span>'; // . ': ' . theme('cdm_specimen', array('specimenTypeDesignation' => $derivedUnitFacadeInstance));
186
        if(isset($derivedUnitFacadeInstance->preferredStableUri)){
187
          $out .= ' ' . l($derivedUnitFacadeInstance->preferredStableUri, $derivedUnitFacadeInstance->preferredStableUri, array('absolute' => true));
188
        }
189
      }
190

    
191
      // Footnotes for collection acronyms.
192
      // footnotes should be rendered in the parent element so we
193
      // are relying on the FootnoteListKey set there
194
      $_fkey = FootnoteManager::addNewFootnote(
195
        RenderHints::getFootnoteListKey(),
196
        (isset($derivedUnitFacadeInstance->collection->titleCache) ? $derivedUnitFacadeInstance->collection->titleCache : FALSE)
197
      );
198
      $out .= theme('cdm_footnote_key', array('footnoteKey' => $_fkey, 'separator' => $separator));
199
      $out .= '</'. $element_tag .'>';
200

    
201
    }
202
  }
203

    
204
  $out .= '</' . $enclosing_tag .'>';
205

    
206
  RenderHints::popFromRenderStack();
207

    
208
  return $out;
209
}
210

    
211

    
212
/**
213
 * @todo Please document this function.
214
 * @see http://drupal.org/node/1354
215
 */
216
function theme_cdm_homotypicSynonymLine($variables) {
217
  $taxon = $variables['taxon'];
218
  $out = '';
219
  $out .= '<li class="synonym">' . cdm_related_taxon($taxon, UUID_HOMOTYPIC_SYNONYM_OF) . '</li>';
220

    
221
  return $out;
222
}
223

    
224
/**
225
 * @todo Please document this function.
226
 * @see http://drupal.org/node/1354
227
 */
228
function theme_cdm_heterotypicSynonymyGroup($variables) {
229
  $homotypical_group = $variables['homotypicalGroup'];
230
  RenderHints::pushToRenderStack('heterotypicSynonymyGroup');
231

    
232
  $out = '';
233
  $out = '<div class="heterotypic-synonymy-group"><ul class="heterotypicSynonymyGroup">';
234
  $footnoteListKey = (isset($homotypical_group[0]) ? $homotypical_group[0]->uuid : 'NULL');
235
  RenderHints::setFootnoteListKey($footnoteListKey);
236

    
237
  $type_designations= type_designations_for_synonymy_group($homotypical_group);
238

    
239
  $is_first_entry = TRUE;
240
  foreach ($homotypical_group as $synonym) {
241
    if ($is_first_entry) {
242
      $is_first_entry = FALSE;
243
      // Is first list entry.
244
      $out .= '<li class="firstentry synonym">' . cdm_related_taxon($synonym, UUID_HETEROTYPIC_SYNONYM_OF) . '</li>';
245
    }
246
    else {
247
      $out .= '<li class="synonym">' . cdm_related_taxon($synonym, UUID_HOMOTYPIC_SYNONYM_OF) . '</li>';
248
    }
249
  }
250

    
251
  if (count($type_designations) > 0) {
252
    $out .= theme('cdm_typedesignations', array('typeDesignations' => $type_designations));
253
  }
254
  $out .= '</ul>';
255

    
256
  // ------- footnotes ------- //
257
  $out .= '<ul class="footnotes">';
258
  $out .= theme('cdm_annotation_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey(), 'enclosingTag' => 'li'));
259
  $out .= theme('cdm_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey(), 'enclosingTag' => 'li'));
260
  $out .= '</ul>';
261

    
262
  $out .= '</div>';
263

    
264
  RenderHints::popFromRenderStack();
265
  return $out;
266
}
267

    
268
/**
269
 * Renders the homotypic synonymy group for the accepted taxon in the synonymy.
270
 *
271
 * Foonotes of the accepted taxon will also be rendered here in the
272
 * homotypic synonymy group even if the synonymList or prependedSynonyms are
273
 * empty. Therefore  the homotypic group and accepted taxon share the  same
274
 * footnote key.
275
 *
276
 * @param $variables
277
 *   an associative array:
278
 *   - synonymList: the list of cdm Synonym entities
279
 *   - accepted_taxon_uuid: the uuid of the accepted taxon
280
 *   - prependedSynonyms: further synonyms which should be prepended
281
 *      before the actual list of synonyms
282
 */
283
function theme_cdm_homotypicSynonymyGroup($variables) {
284
  $synonymList = $variables['synonymList'];
285
  $accepted_taxon_name_uuid = $variables['accepted_taxon_name_uuid'];
286
  $prependedSynonyms = $variables['prependedSynonyms'];
287

    
288
  RenderHints::pushToRenderStack('homotypicSynonymyGroup');
289

    
290
  $type_designations_in_group = NULL;
291

    
292
  $out = '<div class="homotypic-synonymy-group">';
293

    
294
  $type_designations = type_designations_for_synonymy_group($synonymList, $accepted_taxon_name_uuid);
295

    
296
  if (count($type_designations) > 0 || is_array($prependedSynonyms) || is_array($synonymList)) {
297
    $out .= '<ul class="homotypicSynonyms">';
298
  if (!empty($prependedSynonyms)) {
299
    foreach ($prependedSynonyms as $taxon) {
300
      $out .= '<li class="synonym">' . cdm_related_taxon($taxon, UUID_HOMOTYPIC_SYNONYM_OF) . '</li>';
301
    }
302
  }
303

    
304

    
305
  if (isset($synonymList[0])) {
306
    foreach ($synonymList as $synonym) {
307
      $out .= '<li class="synonym">' . cdm_related_taxon($synonym, UUID_HOMOTYPIC_SYNONYM_OF) . '</li>';
308
    }
309
  }
310

    
311
  if (count($type_designations) > 0) {
312
    $out .= theme('cdm_typedesignations', array('typeDesignations' => $type_designations));
313
  }
314

    
315
  }
316

    
317
  $out .= '</ul>';
318

    
319
  // ------- footnotes ------- //
320

    
321
  // all foonotes of the homotypic group and also of the accepted taxon are
322
  // rendered here, both should have the same footnote key
323
  $out .= '<ul class="footnotes">';
324
  $out .= theme('cdm_annotation_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey(), 'enclosingTag' => 'li'));
325
  $out .= theme('cdm_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey(), 'enclosingTag' => 'li'));
326
  $out .= '</ul>';
327

    
328
  $out .= '</div>';
329

    
330

    
331
  RenderHints::popFromRenderStack();
332
  return $out;
333
}
Add picture from clipboard (Maximum size: 40 MB)