Project

General

Profile

Download (15.4 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 object $type_designations an array of cdm TypeDesignation entities
67
 *  to render
68
 * @param string $enclosing_tag the tag element type to enclose the whole list
69
 *  of type designation with. By default this DOM element is <ul>
70
 * @param string $element_tag the tag element type to be used for each
71
 *  type designation item.
72
 * @param bool $link_to_specimen_page whether a specimen in type designation element
73
 *  should be a link or not.
74
 *
75
 * @return string The markup.
76
 *
77
 * @InGroup Render
78
 */
79
function render_type_designations($type_designations, $enclosing_tag = 'ul', $element_tag =  'li', $link_to_specimen_page = true) {
80

    
81
  // need to add element to render path since type designations
82
  // need other name render template
83
  RenderHints::pushToRenderStack('typedesignations');
84

    
85
  $out = '<' . $enclosing_tag .' class="typeDesignations">';
86
  $typeDesignation_footnotes = FALSE;
87
  $is_lectotype = FALSE;
88
  $specimen_type_designations = array();
89
  $name_type_designations = array();
90
  $textual_type_designations = array();
91
  $separator = ',';
92

    
93
  foreach ($type_designations as $type_designation) {
94
    switch ($type_designation->class) {
95
      case 'SpecimenTypeDesignation':
96
        $specimen_type_designations[] = $type_designation;
97
        break;
98
      case 'NameTypeDesignation':
99
        $name_type_designations[] = $type_designation;
100
        break;
101
      case 'TextualTypeDesignation':
102
        $textual_type_designations[] = $type_designation;
103
        break;
104
      default:  throw new Exception('Unknown type designation class: ' . $type_designation->class);
105
    }
106
  }
107

    
108
  // NameTypeDesignation ..................................
109
  if(!empty($name_type_designations)){
110
    uksort($name_type_designations, "compare_type_designation_status");
111
    foreach($name_type_designations as $name_type_designation){
112
      if ($name_type_designation->notDesignated) {
113
        $out .= '<'. $element_tag .' class="' . html_class_attribute_ref($name_type_designation) . '">' .  type_designation_status_label_markup($name_type_designation)  . ': '
114
          . t('not designated') . '</'. $element_tag .'>';
115
      }
116
      elseif (isset($name_type_designation->typeName)) {
117
        $link_to_name_page = url(path_to_name($name_type_designation->typeName->uuid));
118
        $out .= '<'. $element_tag .' class="' . html_class_attribute_ref($name_type_designation) . '">' .  type_designation_status_label_markup($name_type_designation) ;
119

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

    
123
        }
124
        $referenceUri = '';
125
        if (isset($name_type_designation->typeName->nomenclaturalReference)) {
126
          $referenceUri = url(path_to_reference($name_type_designation->typeName->nomenclaturalReference->uuid));
127
        }
128
        $out .= ': ' . render_taxon_or_name($name_type_designation->typeName, $link_to_name_page, $referenceUri, TRUE, TRUE);
129
      }
130
    }
131
  } // END NameTypeDesignation
132

    
133
  // SpecimenTypeDesignation ...................................
134
  if (!empty($specimen_type_designations)) {
135
    usort($specimen_type_designations, "compare_specimen_type_designation");
136
    foreach ($specimen_type_designations as $specimen_type_designation) {
137
      $type_citation_markup = '';
138

    
139
      if (!empty($specimen_type_designation->citation)) {
140

    
141
        $citation_footnote_str = theme('cdm_reference', array('reference' => $specimen_type_designation->citation, 'doIconLink' => true));
142
        $author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $specimen_type_designation->citation->uuid);
143

    
144
        if (!empty($author_team->titleCache)) {
145
          $year = @timePeriodToString($specimen_type_designation->citation->datePublished, true, 'YYYY');
146
          $authorteam_str = $author_team->titleCache . ($year ? ' ' : '') . $year;
147
          if ($authorteam_str == $specimen_type_designation->citation->titleCache) {
148
            $citation_footnote_str = '';
149
          }
150
        } else {
151
          $authorteam_str = $citation_footnote_str;
152
          // no need for a footnote in case in case it is used as replacement for missing author teams
153
          $citation_footnote_str = '';
154
        }
155

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

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

    
173
        }
174

    
175
        $type_citation_markup .= '&nbsp;(' . t('designated by') . '&nbsp;<span class="typeReference">' . $authorteam_str . '</span>';
176
        if (!empty($specimen_type_designation->citationMicroReference)) {
177
          $type_citation_markup .= ': ' . trim($specimen_type_designation->citationMicroReference);
178
        }
179
        $type_citation_markup .= $footnote_key_markup . ')';
180

    
181
      }
182

    
183
      $out .= '<'. $element_tag .' class="' . html_class_attribute_ref($specimen_type_designation) . '">';
184
      $out .= type_designation_status_label_markup($specimen_type_designation) . $type_citation_markup;
185

    
186

    
187
      $derivedUnitFacadeInstance = null;
188
      if (isset($specimen_type_designation->typeSpecimen)) {
189
        $derivedUnitFacadeInstance = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, $specimen_type_designation->typeSpecimen->uuid);
190
      }
191

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

    
205

    
206
      $out .= '</'. $element_tag .'>';
207

    
208
    }
209
  } // END Specimen type designations
210

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

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

    
245
  RenderHints::popFromRenderStack();
246

    
247
  return $out;
248
}
249

    
250
/**
251
 * 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"
252
 *
253
 * @param $type_designation
254
 * @return string
255
 */
256
function type_designation_status_label_markup($type_designation)
257
{
258
  return '<span class="type-status">'
259
    . ((isset($type_designation->typeStatus->representation_L10n)) ? ucfirst($type_designation->typeStatus->representation_L10n) : t('Type')) . '</span>'
260
    ;
261
}
262

    
263

    
264
/**
265
 * @todo Please document this function.
266
 * @see http://drupal.org/node/1354
267
 */
268
function theme_cdm_homotypicSynonymLine($variables) {
269
  $taxon = $variables['taxon'];
270
  $out = '';
271
  $out .= '<li class="synonym">' . cdm_related_taxon($taxon, UUID_HOMOTYPIC_SYNONYM_OF) . '</li>';
272

    
273
  return $out;
274
}
275

    
276
/**
277
 * @todo Please document this function.
278
 * @see http://drupal.org/node/1354
279
 */
280
function theme_cdm_heterotypicSynonymyGroup($variables) {
281
  $homotypical_group = $variables['homotypicalGroup'];
282
  RenderHints::pushToRenderStack('heterotypicSynonymyGroup');
283

    
284
  $out = '';
285
  $out = '<div class="heterotypic-synonymy-group"><ul class="heterotypicSynonymyGroup">';
286
  $footnoteListKey = (isset($homotypical_group[0]) ? $homotypical_group[0]->uuid : 'NULL');
287
  RenderHints::setFootnoteListKey($footnoteListKey);
288

    
289
  $type_designations= type_designations_for_synonymy_group($homotypical_group);
290

    
291
  $is_first_entry = TRUE;
292
  foreach ($homotypical_group as $synonym) {
293
    if ($is_first_entry) {
294
      $is_first_entry = FALSE;
295
      // Is first list entry.
296
      $out .= '<li class="firstentry synonym">' . cdm_related_taxon($synonym, UUID_HETEROTYPIC_SYNONYM_OF) . '</li>';
297
    }
298
    else {
299
      $out .= '<li class="synonym">' . cdm_related_taxon($synonym, UUID_HOMOTYPIC_SYNONYM_OF) . '</li>';
300
    }
301
  }
302

    
303
  if (count($type_designations) > 0) {
304
    $out .= render_type_designations($type_designations);
305
  }
306
  $out .= '</ul>';
307

    
308
  // ------- footnotes ------- //
309
  $out .= '<ul class="footnotes">';
310
  $out .= theme('cdm_annotation_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey(), 'enclosingTag' => 'li'));
311
  $out .= theme('cdm_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey(), 'enclosingTag' => 'li'));
312
  $out .= '</ul>';
313

    
314
  $out .= '</div>';
315

    
316
  RenderHints::popFromRenderStack();
317
  return $out;
318
}
319

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

    
340
  RenderHints::pushToRenderStack('homotypicSynonymyGroup');
341

    
342
  $type_designations_in_group = NULL;
343

    
344
  $out = '<div class="homotypic-synonymy-group">';
345

    
346
  $type_designations = type_designations_for_synonymy_group($synonymList, $accepted_taxon_name_uuid);
347

    
348
  if (count($type_designations) > 0 || is_array($prependedSynonyms) || is_array($synonymList)) {
349
    $out .= '<ul class="homotypicSynonyms">';
350
  if (!empty($prependedSynonyms)) {
351
    foreach ($prependedSynonyms as $taxon) {
352
      $out .= '<li class="synonym">' . cdm_related_taxon($taxon, UUID_HOMOTYPIC_SYNONYM_OF) . '</li>';
353
    }
354
  }
355

    
356

    
357
  if (isset($synonymList[0])) {
358
    foreach ($synonymList as $synonym) {
359
      $out .= '<li class="synonym">' . cdm_related_taxon($synonym, UUID_HOMOTYPIC_SYNONYM_OF) . '</li>';
360
    }
361
  }
362

    
363
  if (count($type_designations) > 0) {
364
    $out .= theme('cdm_typedesignations', array('typeDesignations' => $type_designations));
365
  }
366

    
367
  }
368

    
369
  $out .= '</ul>';
370

    
371
  // ------- footnotes ------- //
372

    
373
  // all foonotes of the homotypic group and also of the accepted taxon are
374
  // rendered here, both should have the same footnote key
375
  $out .= '<ul class="footnotes">';
376
  $out .= theme('cdm_annotation_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey(), 'enclosingTag' => 'li'));
377
  $out .= theme('cdm_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey(), 'enclosingTag' => 'li'));
378
  $out .= '</ul>';
379

    
380
  $out .= '</div>';
381

    
382

    
383
  RenderHints::popFromRenderStack();
384
  return $out;
385
}
(4-4/9)