Project

General

Profile

Download (15.1 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
  $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
  $name_type_designations = array();
84
  $textual_type_designations = array();
85
  $separator = ',';
86

    
87
  foreach ($type_designations as $type_designation) {
88
    switch ($type_designation->class) {
89
      case 'SpecimenTypeDesignation':
90
        $specimen_type_designations[] = $type_designation;
91
        break;
92
      case 'NameTypeDesignation':
93
        $name_type_designations[] = $type_designation;
94
        break;
95
      case 'TextualTypeDesignation':
96
        $textual_type_designations[] = $type_designation;
97
        break;
98
      default:  throw new Exception('Unknown type designation class');
99
    }
100
  }
101

    
102
  // NameTypeDesignation ..................................
103
  if(!empty($name_type_designations)){
104
    uksort($name_type_designations, "compare_type_designation_status");
105
    foreach($name_type_designations as $name_type_designation){
106
      if ($name_type_designation->notDesignated) {
107
        $out .= '<'. $element_tag .' class="' . html_class_attribute_ref($name_type_designation) . '">' .  type_designation_status_label_markup($name_type_designation)  . ': '
108
          . t('not designated') . '</'. $element_tag .'>';
109
      }
110
      elseif ($name_type_designation->typeName) {
111
        $link_to_name_page = url(path_to_name($name_type_designation->typeName->uuid));
112
        $out .= '<'. $element_tag .' class="' . html_class_attribute_ref($name_type_designation) . '">' .  type_designation_status_label_markup($name_type_designation) ;
113

    
114
        if (!empty($name_type_designation->citation)) {
115
          $out .= type_designation_citation_layout($name_type_designation, $separator); // TODO type_designation_citation_layout() needs most probably to be replaced
116

    
117
        }
118
        $referenceUri = '';
119
        if (isset($name_type_designation->typeName->nomenclaturalReference)) {
120
          $referenceUri = url(path_to_reference($name_type_designation->typeName->nomenclaturalReference->uuid));
121
        }
122
        $out .= ': ' . render_taxon_or_name($name_type_designation->typeName, $link_to_name_page, $referenceUri, TRUE, TRUE);
123
      }
124
    }
125
  } // END NameTypeDesignation
126

    
127
  // SpecimenTypeDesignation ...................................
128
  if (!empty($specimen_type_designations)) {
129
    usort($specimen_type_designations, "compare_specimen_type_designation");
130
    foreach ($specimen_type_designations as $specimen_type_designation) {
131
      $type_citation_markup = '';
132

    
133
      if (!empty($specimen_type_designation->citation)) {
134

    
135
        $citation_footnote_str = theme('cdm_reference', array('reference' => $specimen_type_designation->citation, 'doIconLink' => true));
136
        $author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $specimen_type_designation->citation->uuid);
137

    
138
        if (isset($author_team->titleCache)) {
139
          $year = @timePeriodToString($specimen_type_designation->citation->datePublished, true, 'YYYY');
140
          $authorteam_str = $author_team->titleCache . ($year ? ' ' : '') . $year;
141
          if ($authorteam_str == $specimen_type_designation->citation->titleCache) {
142
            $citation_footnote_str = '';
143
          }
144
        } else {
145
          $authorteam_str = $citation_footnote_str;
146
          // no need for a footnote in case in case it is used as replacement for missing author teams
147
          $citation_footnote_str = '';
148
        }
149

    
150
        // for being registered a typedesignation MUST HAVE a citation, so it is save to handle the
151
        // Registration output in if condition checking if the citation is present
152
        $registration_markup = render_registrations($specimen_type_designation->registrations);
153
        $citation_footnote_str .= ($citation_footnote_str ? ' ' : '') . $registration_markup;
154

    
155
        $footnote_key_markup = '';
156
        if ($citation_footnote_str) {
157
          // footnotes should be rendered in the parent element so we
158
          // are relying on the FootnoteListKey set there
159
          $_fkey2 = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), $citation_footnote_str);
160
          $footnote_key_markup = theme('cdm_footnote_key', array(
161
            'footnoteKey' => $_fkey2,
162
            'separator' => $separator,
163
            'highlightable' => TRUE,
164
            'separator_off' => TRUE,
165
          ));
166

    
167
        }
168

    
169
        $type_citation_markup .= '&nbsp;(' . t('designated by') . '&nbsp;<span class="typeReference">' . $authorteam_str . '</span>';
170
        if (!empty($specimen_type_designation->citationMicroReference)) {
171
          $type_citation_markup .= ': ' . trim($specimen_type_designation->citationMicroReference);
172
        }
173
        $type_citation_markup .= $footnote_key_markup . ')';
174

    
175
      }
176

    
177
      $out .= '<'. $element_tag .' class="' . html_class_attribute_ref($specimen_type_designation) . '">';
178
      $out .= type_designation_status_label_markup($specimen_type_designation) . $type_citation_markup;
179

    
180

    
181
      $derivedUnitFacadeInstance = null;
182
      if (isset($specimen_type_designation->typeSpecimen)) {
183
        $derivedUnitFacadeInstance = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, $specimen_type_designation->typeSpecimen->uuid);
184
      }
185

    
186
      if (!empty($derivedUnitFacadeInstance->titleCache)) {
187
        $specimen_markup = $derivedUnitFacadeInstance->titleCache;
188
        if($link_to_specimen_page && isset($derivedUnitFacadeInstance->specimenLabel) && $derivedUnitFacadeInstance->specimenLabel){
189
          $specimen_markup = str_replace($derivedUnitFacadeInstance->specimenLabel, l($derivedUnitFacadeInstance->specimenLabel, path_to_specimen($specimen_type_designation->typeSpecimen->uuid)), $specimen_markup);
190
        }
191
        $out .= ': <span class="' . html_class_attribute_ref($specimen_type_designation->typeSpecimen) . '">'
192
           . $specimen_markup
193
           . '</span>'; // . ': ' . theme('cdm_specimen', array('specimenTypeDesignation' => $derivedUnitFacadeInstance));
194
        if(!empty($derivedUnitFacadeInstance->preferredStableUri)){
195
          $out .= ' ' . l($derivedUnitFacadeInstance->preferredStableUri, $derivedUnitFacadeInstance->preferredStableUri, array('absolute' => true));
196
        }
197
      }
198

    
199

    
200
      $out .= '</'. $element_tag .'>';
201

    
202
    }
203
  } // END Specimen type designations
204

    
205
  // TextualTypeDesignation .........................
206
  if(!empty($textual_type_designations)) {
207
    foreach ($textual_type_designations as $textual_type_designation) {
208
      $encasement =  $textual_type_designation->verbatim ? '"' : '';
209
      $out .= '<' . $element_tag . ' class="' . html_class_attribute_ref($textual_type_designation) . '">' . type_designation_status_label_markup(null)
210
        . ': ' .  $encasement . $textual_type_designation->text_L10n->text . $encasement . '</' . $element_tag . '>';
211
      $annotations_and_sources = handle_annotations_and_sources(
212
        $textual_type_designation,
213
        array(
214
          'sources_as_content' => false, // as footnotes
215
          'link_to_name_used_in_source' => false,
216
          'link_to_reference' => true,
217
          'add_footnote_keys' => false,
218
          'bibliography_aware' => false),
219
      '',
220
        RenderHints::getFootnoteListKey() // passing a defined key to avoid separate annotation footnote key see https://dev.e-taxonomy.eu/redmine/issues/8543
221
        );
222
      $out .= $annotations_and_sources['foot_note_keys'];
223
        if(is_array( $annotations_and_sources['source_references'])){
224
          $citation_markup = join(', ', $annotations_and_sources['source_references']);
225
        }
226
    }
227
  }
228

    
229
  // Footnotes for citations, collection acronym?s.
230
  // footnotes should be rendered in the parent element so we
231
  // are relying on the FootnoteListKey set there
232
  $_fkey = FootnoteManager::addNewFootnote(
233
    RenderHints::getFootnoteListKey(),
234
    (isset($derivedUnitFacadeInstance->collection->titleCache) ? $derivedUnitFacadeInstance->collection->titleCache : FALSE)
235
  );
236
  $out .= theme('cdm_footnote_key', array('footnoteKey' => $_fkey, 'separator' => $separator));
237
  $out .= '</' . $enclosing_tag .'>';
238

    
239
  RenderHints::popFromRenderStack();
240

    
241
  return $out;
242
}
243

    
244
/**
245
 * Creates markup for the status of a type designation. In case the status or its representation is missing the label will be set to "Type"
246
 *
247
 * @param $type_designation
248
 * @return string
249
 */
250
function type_designation_status_label_markup($type_designation)
251
{
252
  return '<span class="type-status">'
253
    . ((isset($type_designation->typeStatus->representation_L10n)) ? $type_designation->typeStatus->representation_L10n : t('Type')) . '</span>'
254
    ;
255
}
256

    
257

    
258
/**
259
 * @todo Please document this function.
260
 * @see http://drupal.org/node/1354
261
 */
262
function theme_cdm_homotypicSynonymLine($variables) {
263
  $taxon = $variables['taxon'];
264
  $out = '';
265
  $out .= '<li class="synonym">' . cdm_related_taxon($taxon, UUID_HOMOTYPIC_SYNONYM_OF) . '</li>';
266

    
267
  return $out;
268
}
269

    
270
/**
271
 * @todo Please document this function.
272
 * @see http://drupal.org/node/1354
273
 */
274
function theme_cdm_heterotypicSynonymyGroup($variables) {
275
  $homotypical_group = $variables['homotypicalGroup'];
276
  RenderHints::pushToRenderStack('heterotypicSynonymyGroup');
277

    
278
  $out = '';
279
  $out = '<div class="heterotypic-synonymy-group"><ul class="heterotypicSynonymyGroup">';
280
  $footnoteListKey = (isset($homotypical_group[0]) ? $homotypical_group[0]->uuid : 'NULL');
281
  RenderHints::setFootnoteListKey($footnoteListKey);
282

    
283
  $type_designations= type_designations_for_synonymy_group($homotypical_group);
284

    
285
  $is_first_entry = TRUE;
286
  foreach ($homotypical_group as $synonym) {
287
    if ($is_first_entry) {
288
      $is_first_entry = FALSE;
289
      // Is first list entry.
290
      $out .= '<li class="firstentry synonym">' . cdm_related_taxon($synonym, UUID_HETEROTYPIC_SYNONYM_OF) . '</li>';
291
    }
292
    else {
293
      $out .= '<li class="synonym">' . cdm_related_taxon($synonym, UUID_HOMOTYPIC_SYNONYM_OF) . '</li>';
294
    }
295
  }
296

    
297
  if (count($type_designations) > 0) {
298
    $out .= theme('cdm_typedesignations', array('typeDesignations' => $type_designations));
299
  }
300
  $out .= '</ul>';
301

    
302
  // ------- footnotes ------- //
303
  $out .= '<ul class="footnotes">';
304
  $out .= theme('cdm_annotation_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey(), 'enclosingTag' => 'li'));
305
  $out .= theme('cdm_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey(), 'enclosingTag' => 'li'));
306
  $out .= '</ul>';
307

    
308
  $out .= '</div>';
309

    
310
  RenderHints::popFromRenderStack();
311
  return $out;
312
}
313

    
314
/**
315
 * Renders the homotypic synonymy group for the accepted taxon in the synonymy.
316
 *
317
 * Foonotes of the accepted taxon will also be rendered here in the
318
 * homotypic synonymy group even if the synonymList or prependedSynonyms are
319
 * empty. Therefore  the homotypic group and accepted taxon share the  same
320
 * footnote key.
321
 *
322
 * @param $variables
323
 *   an associative array:
324
 *   - synonymList: the list of cdm Synonym entities
325
 *   - accepted_taxon_uuid: the uuid of the accepted taxon
326
 *   - prependedSynonyms: further synonyms which should be prepended
327
 *      before the actual list of synonyms
328
 */
329
function theme_cdm_homotypicSynonymyGroup($variables) {
330
  $synonymList = $variables['synonymList'];
331
  $accepted_taxon_name_uuid = $variables['accepted_taxon_name_uuid'];
332
  $prependedSynonyms = $variables['prependedSynonyms'];
333

    
334
  RenderHints::pushToRenderStack('homotypicSynonymyGroup');
335

    
336
  $type_designations_in_group = NULL;
337

    
338
  $out = '<div class="homotypic-synonymy-group">';
339

    
340
  $type_designations = type_designations_for_synonymy_group($synonymList, $accepted_taxon_name_uuid);
341

    
342
  if (count($type_designations) > 0 || is_array($prependedSynonyms) || is_array($synonymList)) {
343
    $out .= '<ul class="homotypicSynonyms">';
344
  if (!empty($prependedSynonyms)) {
345
    foreach ($prependedSynonyms as $taxon) {
346
      $out .= '<li class="synonym">' . cdm_related_taxon($taxon, UUID_HOMOTYPIC_SYNONYM_OF) . '</li>';
347
    }
348
  }
349

    
350

    
351
  if (isset($synonymList[0])) {
352
    foreach ($synonymList as $synonym) {
353
      $out .= '<li class="synonym">' . cdm_related_taxon($synonym, UUID_HOMOTYPIC_SYNONYM_OF) . '</li>';
354
    }
355
  }
356

    
357
  if (count($type_designations) > 0) {
358
    $out .= theme('cdm_typedesignations', array('typeDesignations' => $type_designations));
359
  }
360

    
361
  }
362

    
363
  $out .= '</ul>';
364

    
365
  // ------- footnotes ------- //
366

    
367
  // all foonotes of the homotypic group and also of the accepted taxon are
368
  // rendered here, both should have the same footnote key
369
  $out .= '<ul class="footnotes">';
370
  $out .= theme('cdm_annotation_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey(), 'enclosingTag' => 'li'));
371
  $out .= theme('cdm_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey(), 'enclosingTag' => 'li'));
372
  $out .= '</ul>';
373

    
374
  $out .= '</div>';
375

    
376

    
377
  RenderHints::popFromRenderStack();
378
  return $out;
379
}
(4-4/9)