Project

General

Profile

Download (84.2 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/**
3
 * @file
4
 * Functions for dealing with CDM entities from the package model.name
5
 *
6
 * @copyright
7
 *   (C) 2007-2015 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
 * @author
16
 *   - Andreas Kohlbecker <a.kohlbecker@BGBM.org>
17
 */
18

    
19
/**
20
 * @defgroup compose Compose functions
21
 * @{
22
 * Functions which are composing Drupal render arays
23
 *
24
 * The cdm_dataportal module needs to compose rather complex render arrays from
25
 * the data returned by the CDM REST service. The compose functions are
26
 * responsible for creating the render arrays.
27
 *
28
 * All these functions are also implementations of the compose_hook()
29
 * which is used in the proxy_content() function.
30
 * @}
31
 */
32

    
33

    
34
/**
35
 * Provides the name render template to be used within the page elements identified the the $renderPath.
36
 *
37
 * The render templates arrays contains one or more name render templates to be used within the page elements identified the the
38
 * renderPath. The renderPath is the key of the subelements whereas the value is the name render template.
39
 *
40
 * The render paths used for a cdm_dataportal page can be visualized by supplying the HTTP query parameter RENDER_PATH=1.
41
 *
42
 * It will be tried to find  the best matching default RenderTemplate by stripping the dot separated render path
43
 * element by element. If no matching template is found the DEFAULT will be used:
44
 *
45
 * - related_taxon.heterotypicSynonymyGroup.taxon_page_synonymy
46
 * - related_taxon.heterotypicSynonymyGroup.taxon_page_synonymy
47
 * - related_taxon.heterotypicSynonymyGroup.taxon_page_synonymy
48
 *
49
 * A single render template can be used for multiple render paths. In this case the according key of the render templates
50
 * array element should be the list of these render paths concatenated by ONLY a comma character without any whitespace.
51
 *
52
 * A render template is an associative array. The keys of this array are referring to the keys as defined in the part
53
 * definitions array.
54
 * @see get_partDefinition($taxonNameType) for more information
55
 *
56
 * The value of the render template element must be set to TRUE in order to let this part being rendered.
57
 * The namePart, nameAuthorPart and referencePart can also hold an associative array with a single
58
 * element: array('#uri' => TRUE). The value of the #uri element will be replaced by the according
59
 * links if the parameters $nameLink or $refenceLink are set.
60
 *
61
 * @param string $render_path
62
 *   The render path can consist of multiple dot separated elements
63
 *   @see RenderHints::getRenderPath()
64
 * @param string $nameLink
65
 *   The link path or URL to be used for name parts if a link is forseen in the template
66
 *   matching the given $renderPath.
67
 * @param string $referenceLink
68
 *   The link path ot URL to be used for nomenclatural reference parts if a link is forseen
69
 *   in the template matching the given $renderPath.
70
 * @return array
71
 *   An associative array, the render template
72
 */
73
function get_nameRenderTemplate($render_path, $nameLink = NULL, $referenceLink = NULL) {
74

    
75
  static $split_render_templates = NULL;
76

    
77
  if($split_render_templates == NULL) {
78
    $render_templates = variable_get(NameRenderConfiguration::CDM_NAME_RENDER_TEMPLATES, NameRenderConfiguration::CDM_NAME_RENDER_TEMPLATES_DEFAULT);
79
    // needs to be converted to an array
80
    $render_templates = (object_to_array($render_templates));
81

    
82
    // separate render templates which are combined with a comma
83
    $split_render_templates = array();
84
    foreach($render_templates as $key => $template){
85
      if(strpos($key, ',')){
86
        foreach(explode(',', $key) as $path){
87
          $split_render_templates[$path] = $template;
88
        }
89
      } else {
90
        $split_render_templates[$key] = $template;
91
      }
92
    }
93
  }
94

    
95
  // get the base element of the renderPath
96
  if (($separatorPos = strpos($render_path, '.')) > 0) {
97
    $renderPath_base = substr($render_path, 0, $separatorPos);
98
  } else {
99
    $renderPath_base = $render_path;
100
  }
101

    
102
  $template = NULL;
103
  // 1. try to find a template using the render path base element
104
  if(array_key_exists($renderPath_base, $split_render_templates)){
105
    $template = (array)$split_render_templates[$renderPath_base];
106
  }
107

    
108
  // 2. Find best matching default RenderTemplate
109
  // by stripping the dot separated render path element by element
110
  // if no matching template is found the DEFAULT will be used.
111
  while (!is_array($template) && strlen($render_path) > 0) {
112
    foreach ($split_render_templates as $path => $t) {
113
      if ($path == $render_path) {
114
        $template = $t;
115
        break;
116
      }
117
    }
118
    // shorten by one element
119
    $render_path = substr($render_path, strrpos($render_path, '.') + 1, strlen($render_path));
120
  }
121

    
122

    
123
  // 3. Otherwise get default RenderTemplate from theme.
124
  if (!is_array($template)) {
125
    $template = $split_render_templates['#DEFAULT'];
126
  }
127

    
128
  // --- set the link uris to the according template fields if they exist
129
  if(isset($template['nameAuthorPart']) && isset($template['nameAuthorPart']['#uri'])) {
130
    if ($nameLink) {
131
      $template['nameAuthorPart']['#uri'] = $nameLink;
132
    }
133
    else {
134
      unset($template['nameAuthorPart']['#uri']);
135
    }
136
  }
137

    
138
  if ($nameLink && isset($template['namePart']['#uri'])) {
139
    $template['namePart']['#uri'] = $nameLink;
140
  }
141
  else {
142
    unset($template['namePart']['#uri']);
143
  }
144

    
145
  if ($referenceLink && isset($template['referencePart']['#uri'])) {
146
    $template['referencePart']['#uri'] = $referenceLink;
147
  }
148
  else {
149
    unset($template['referencePart']['#uri']);
150
  }
151

    
152
  return $template;
153
}
154

    
155
/**
156
 * The part definitions define the specific parts of which a rendered taxon name plus additional information will consist.
157
 *
158
 * A full taxon name plus additional information can consist of the following elements:
159
 *
160
 *   - name: the taxon name inclugin rank nbut without author
161
 *   - authorTeam:  The authors of a reference, also used in taxon names
162
 *   - authors:  The authors of a reference, also used in taxon names
163
 *   - reference: the nomenclatural reference,
164
 *   - microreference:  Volume, page number etc.
165
 *   - status:  The nomenclatural status of a name
166
 *   - description: name descriptions like protologues etc ...
167
 *
168
 * These elements are combined in the part definitions array to from the specific parts to be rendered.
169
 * Usually the following parts are formed:
170
 *
171
 * The name "Lapsana communis L., Sp. Pl.: 811. 1753" shall be an example here:
172
 *  - namePart: the name and rank (in example: "Lapsana communis")
173
 *  - authorshipPart: the author (in example: "L.")
174
 *  - nameAuthorPart: the combination of name and author part (in example: "Lapsana communis L.").
175
 *     This is useful for zoological names where the authorshipPart belongs to the name and both should
176
 *     be combined when a link to the taxon is rendered.
177
 *  - referencePart: the nomencaltural reference (in example: "Sp. Pl. 1753")
178
 *  - microreferencePart: usually the page number (in example ": 811.")
179
 *  - statusPart: the nomenclatorical status
180
 *  - descriptionPart:
181
 *
182
 * Each set of parts is dedicated to render a specific TaxonName type, the type names are used as keys for the
183
 * specific parts part definitions:
184
 *
185
 *  - BotanicalName
186
 *  - ZoologicalName
187
 *  - #DEFAULT:  covers ViralNames and general NonViralNames
188
 *
189
 * An example:
190
 * @code
191
 * array(
192
 *    'ZoologicalName' => array(
193
 *        'namePart' => array('name' => TRUE),
194
 *        'referencePart' => array('authorTeam' => TRUE),
195
 *        'microreferencePart' => array('microreference' => TRUE),
196
 *        'statusPart' => array('status' => TRUE),
197
 *        'descriptionPart' => array('description' => TRUE),
198
 *    ),
199
 *    'BotanicalName' => array(
200
 *        'namePart' => array(
201
 *            'name' => TRUE,
202
 *            'authors' => TRUE,
203
 *        ),
204
 *        'referencePart' => array(
205
 *            'reference' => TRUE,
206
 *            'microreference' => TRUE,
207
 *        ),
208
 *        'statusPart' => array('status' => TRUE),
209
 *        'descriptionPart' => array('description' => TRUE),
210
 *    ),
211
 *  );
212
 * @endcode
213
 *
214
 * @param object $taxonNameType
215
 *    A cdm TaxonNameType entity
216
 *
217
 */
218
function get_partDefinition($taxonNameType) {
219

    
220
  static $part_definitions = null;
221
  if (!isset($part_definitions)) {
222
    $part_definitions = object_to_array(variable_get(NameRenderConfiguration::CDM_PART_DEFINITIONS, NameRenderConfiguration::CDM_PART_DEFINITIONS_DEFAULT));
223
  }
224

    
225
  $dtype = nameTypeToDTYPE($taxonNameType);
226
  if (array_key_exists($taxonNameType, $part_definitions)) {
227
    return $part_definitions[$taxonNameType];
228
  } else if (array_key_exists($dtype, $part_definitions)) {
229
    return $part_definitions[$dtype];
230
  } else {
231
    return $part_definitions['#DEFAULT']; // covers ViralNames and general NonViralNames
232
  }
233

    
234
}
235

    
236

    
237
/**
238
 * Renders the markup for a CDM TaxonName instance.
239
 *
240
 * The layout of the name representation is configured by the
241
 * part_definitions and render_templates (see get_partDefinition() and
242
 * get_nameRenderTemplate())
243
 *
244
 * @param $taxon_name_or_taxon_base
245
 *    A cdm TaxonBase or TaxonName entity
246
 * @param $name_link
247
 *    URI to the taxon, the path provided by path_to_taxon() must be processed
248
 *    by url() before passing to this method
249
 * @param $reference_link
250
 *    URI to the reference, the path provided by path_to_reference() must be
251
 *    processed by url() before passing to this method
252
 * @param bool $show_taxon_name_annotations
253
 *    Enable the display of footnotes for annotations on the taxon and name
254
 *    (default: true)
255
 * @param bool $is_type_designation
256
 *    To indicate that the supplied taxon name is a name type designation.
257
 *    (default: false)
258
 * @param array $skip_render_template_parts
259
 *    The render template elements matching these part names will bes skipped.
260
 *    This parameter should only be used in rare cases like for suppressing
261
 *    the sec reference of synonyms. Normally the configuration of the
262
 *    name appearance should only be done via the render templates themselves. (default: [])
263
 * @param bool $is_invalid
264
 *   Indicates that this taxon is invalid. In this case the name part will be shown in double quotes.
265
 *   This is useful when rendering taxon relation ships. (default: false)
266
 *
267
 * @return string
268
 *  The markup for a taxon name.
269
 */
270
function render_taxon_or_name($taxon_name_or_taxon_base, $name_link = NULL, $reference_link = NULL,
271
  $show_taxon_name_annotations = true, $is_type_designation = false, $skip_render_template_parts = [], $is_invalid = false) {
272

    
273
  $is_doubtful = false;
274
  $taxon_base = null;
275
  $nom_status_fkey = null; // FootNoteKey
276
  if($taxon_name_or_taxon_base->class == 'Taxon' || $taxon_name_or_taxon_base->class == 'Synonym'){
277
    $taxon_base = $taxon_name_or_taxon_base;
278
    if(isset($taxon_name_or_taxon_base->name)){
279
      $taxon_name = $taxon_name_or_taxon_base->name;
280
    } else {
281
      $taxon_name = cdm_ws_get(CDM_WS_TAXON . '/$0/name', array($taxon_name_or_taxon_base->uuid));
282
    }
283
    $is_doubtful = $taxon_name_or_taxon_base->doubtful;
284
    // use the TaxonBase.tagged_title so we have the secRef
285
    $tagged_title = $taxon_name_or_taxon_base->taggedTitle;
286
  } else {
287
    // assuming this is a TaxonName
288
    $taxon_name = $taxon_name_or_taxon_base;
289
    if(isset($taxon_name->taggedFullTitle)){
290
      $tagged_title = $taxon_name_or_taxon_base->taggedFullTitle;
291
    } else {
292
      $tagged_title = $taxon_name_or_taxon_base->taggedName;
293
    }
294
  }
295

    
296

    
297
  $renderTemplate = get_nameRenderTemplate(RenderHints::getRenderPath(), $name_link, $reference_link);
298
  $partDefinition = get_partDefinition($taxon_name->nameType);
299

    
300
  // Apply definitions to template.
301
  foreach ($renderTemplate as $part => $uri) {
302

    
303
    if (isset($partDefinition[$part])) {
304
      $renderTemplate[$part] = $partDefinition[$part];
305
    }
306
    if (is_array($uri) && isset($uri['#uri'])) {
307
      $renderTemplate[$part]['#uri'] = $uri['#uri'];
308
    }
309
  }
310

    
311
  foreach($skip_render_template_parts as $part){
312
    unset($renderTemplate[$part]);
313
  }
314

    
315
  $secref_tagged_text = tagged_text_extract_reference_and_detail($tagged_title);
316
  // taxon names will have the nomenclatural reference in the tagged full title:
317
  $nomref_tagged_text = tagged_text_extract_reference($tagged_title);
318
  $nom_status_tagged_text = tagged_text_extract_nomstatus($tagged_title);
319
  $appended_phrase_tagged_text = array(); // this is filled later
320

    
321
  normalize_tagged_text($tagged_title);
322

    
323
  $is_valid_tagged_title =
324
    isset($tagged_title)
325
    && is_array($tagged_title)
326
    && isset($tagged_title[0]->text)
327
    && is_string($tagged_title[0]->text)
328
    && $tagged_title[0]->text != ''
329
    && isset($tagged_title[0]->type);
330
  $lastAuthorElementString = FALSE;
331

    
332
  $name_encasement = $is_invalid ? '"' : '';
333
  $doubtful_marker = $is_doubtful ? '?&#8239;' : ''; // 	&#8239; =  NARROW NO-BREAK SPACE
334
  $doubtful_marker_markup = '';
335

    
336
  if($doubtful_marker){
337
    $doubtful_marker_markup = '<span class="doubtful">' . $doubtful_marker . '</span>';
338
    if($tagged_title[0]->text == '?' ){
339
      // remove the first tagged text element
340
      unset($tagged_title[0]);
341
    }
342
  }
343

    
344
  // split off all appendedPhrase item  from the end of the array (usually there only should  be one)
345
  while($tagged_title[count($tagged_title)-1]->type == "appendedPhrase"){
346
    $appended_phrase_tagged_text[] = array_pop($tagged_title);
347
  }
348

    
349
  // Got to use second entry as first one, see ToDo comment below ...
350
  if ($is_valid_tagged_title) {
351

    
352
    $taggedName = $tagged_title;
353
    $hasNamePart_with_Authors = isset($renderTemplate['namePart']) && isset($renderTemplate['namePart']['authors']);
354
    $hasNameAuthorPart_with_Authors = isset($renderTemplate['nameAuthorPart']) && isset($renderTemplate['nameAuthorPart']['authors']);
355

    
356

    
357
    if (!(($hasNamePart_with_Authors) || ($hasNameAuthorPart_with_Authors))) {
358
      // Find author and split off from name.
359
      // TODO expecting to find the author as the last element.
360
      /*
361
      if($taggedName[count($taggedName)- 1]->type == 'authors'){
362
        $authorTeam = $taggedName[count($taggedName)- 1]->text;
363
        unset($taggedName[count($taggedName)- 1]);
364
      }
365
      */
366

    
367
      // Remove all authors.
368
      $taggedNameNew = array();
369
      foreach ($taggedName as $element) {
370
        if ($element->type != 'authors') {
371
          $taggedNameNew[] = $element;
372
        }
373
        else {
374
          $lastAuthorElementString = $element->text;
375
        }
376
      }
377
      $taggedName = $taggedNameNew;
378
      unset($taggedNameNew);
379
    }
380
    $name = '<span class="' . $taxon_name->class . '">' . $doubtful_marker_markup . $name_encasement . cdm_tagged_text_to_markup($taggedName) . $name_encasement . '</span>';
381
  }
382
  else {
383
    // use titleCache instead
384
    $name = '<span class="' . $taxon_name->class . '_titleCache">' . $doubtful_marker_markup . $name_encasement . $taxon_name->titleCache . $name_encasement . '</span>';
385
  }
386

    
387

    
388
  if(isset($appended_phrase_tagged_text[0])){
389
    $name .= ' <span class="appended-phrase">'. cdm_tagged_text_to_markup($appended_phrase_tagged_text) . '</span>';
390
  }
391

    
392
  // Fill name into $renderTemplate.
393
  array_setr('name', $name , $renderTemplate);
394

    
395
  // Fill with authorTeam.
396
  /*
397
  if($authorTeam){
398
    $authorTeamHtml = ' <span class="authorTeam">'.$authorTeam.'</span>';
399
    array_setr('authorTeam', $authorTeamHtml, $renderTemplate);
400
  }
401
  */
402

    
403
  // Fill with reference.
404
  if (isset($renderTemplate['referencePart']) && !$is_type_designation) {
405

    
406
    $registrations = cdm_ws_get(CDM_WS_NAME, array($taxon_name->uuid, "registrations"));
407
    $registration_markup = render_registrations($registrations);
408

    
409
    // default separator
410
    $separator = '';
411

    
412
    // [Eckhard]:"Komma nach dem Taxonnamen ist grundsätzlich falsch,
413
    // Komma nach dem Autornamen ist überall dort falsch, wo ein "in" folgt."
414
    if (isset($renderTemplate['referencePart']['reference']) && isset($taxon_name->nomenclaturalSource)) {
415
      $microreference = $taxon_name->nomenclaturalSource->citationMicroReference;
416
      if(count($nomref_tagged_text) == 0 && isset($taxon_name->nomenclaturalSource->citation)){
417
        // drupal message for debugging of #9599
418
        // drupal_set_message("reference/$0/nomenclaturalCitation' must no longer be used (type: "
419
        //  . $taxon_name_or_taxon_base->class . (isset($taxon_name_or_taxon_base->type) ? " - " +$taxon_name_or_taxon_base->type : ""  . ")"), "error");
420
        $citation = cdm_ws_getNomenclaturalReference($taxon_name->nomenclaturalSource->citation->uuid, $microreference);
421
        // Find preceding element of the reference.
422
        $precedingKey = get_preceding_contentElementKey('reference', $renderTemplate);
423
        if (str_beginsWith($citation, ", in")) {
424
          $citation = substr($citation, 2);
425
          $separator = ' ';
426
        }
427
        elseif (!str_beginsWith($citation, "in") && $precedingKey == 'authors') {
428
          $separator = ', ';
429
        } else {
430
          $separator = ' ';
431
        }
432
        $referenceArray['#separator'] = $separator;
433
        $referenceArray['#html'] = '<span class="reference">' . $citation . '</span>' . $registration_markup;
434
      } else {
435
        // this is the case for taxon names
436
        $referenceArray['#html'] = cdm_tagged_text_to_markup($nomref_tagged_text);
437
      }
438

    
439
      array_setr('reference', $referenceArray, $renderTemplate);
440
    }
441

    
442
    // If authors have been removed from the name part the last named authorteam
443
    // should be added to the reference citation, otherwise, keep the separator
444
    // out of the reference.
445
    if (isset($renderTemplate['referencePart']['authors']) && $lastAuthorElementString) {
446
      // If the nomenclaturalReference citation is not included in the
447
      // reference part but display of the microreference
448
      // is wanted, append the microreference to the authorTeam.
449
      $citation = '';
450
      if (!isset($renderTemplate['referencePart']['reference']) && isset($renderTemplate['referencePart']['microreference'])) {
451
        $separator = ": ";
452
        $citation = $taxon_name->nomenclaturalMicroReference;
453
      }
454
      $referenceArray['#html'] = ' <span class="reference">' . $lastAuthorElementString . $separator . $citation . '</span>';
455
      array_setr('authors', $referenceArray, $renderTemplate);
456
    }
457
  }
458

    
459
  $is_reference_year = false;
460
  if (isset($renderTemplate['referenceYearPart']['reference.year'])) {
461
    if(isset($taxon_name->nomenclaturalSource->citation->datePublished)){
462
      $referenceArray['#html'] = ' <span class="reference">' . timePeriodToString($taxon_name->nomenclaturalSource->citation->datePublished) . '</span>';
463
      array_setr('reference.year', $referenceArray, $renderTemplate);
464
      $is_reference_year = true;
465
    }
466
  }
467

    
468
  // Fill with status.
469
  if(isset($renderTemplate['statusPart']['status'])){
470
    if (isset($nom_status_tagged_text[0])) {
471
        $tt_to_markup_options = array('html' => false);
472
        foreach ($nom_status_tagged_text as &$tt){
473
         if($tt->type == 'nomStatus'&& isset($tt->entityReference)) {
474
           $nom_status = cdm_ws_get(CDM_WS_NOMENCLATURALSTATUS, array($tt->entityReference->uuid));
475
           $nom_status_fkey = handle_nomenclatural_status_as_footnote($nom_status);
476
           $tt_to_markup_options['html'] = true;
477
         }
478
        }
479
        array_setr(
480
          'status',
481
          '<span class="nomenclatural_status">' . cdm_tagged_text_to_markup($nom_status_tagged_text, array('postSeparator'), 'span', $tt_to_markup_options) . '</span>',
482
          $renderTemplate);
483
    }
484
  }
485

    
486
  if (isset($renderTemplate['secReferencePart'])){
487
    if(isset($secref_tagged_text[1])){
488
      $post_separator_markup = $is_reference_year ? '.': '';
489
      if(isset($nom_status_tagged_text[count($nom_status_tagged_text) - 1]) && ($nom_status_tagged_text[count($nom_status_tagged_text) - 1]->type ==  'postSeparator')){
490
        $post_separator_markup = cdm_tagged_text_to_markup(array($nom_status_tagged_text[count($nom_status_tagged_text) - 1 ]));
491
      };
492
      array_setr('secReference',
493
        $post_separator_markup
494
          . ' <span class="sec_reference">'
495
          . join('', cdm_tagged_text_values($secref_tagged_text))
496
          . '</span>', $renderTemplate);
497
    }
498
  }
499

    
500
  // Fill with protologues etc...
501
  $protologue_links = [];
502
  if (array_setr('description', TRUE, $renderTemplate)) {
503
    $external_links = cdm_ws_get(CDM_WS_NAME_PROTOLOGUE_LINKS, $taxon_name->uuid);
504
    if($external_links){
505
      foreach ($external_links as $link) {
506
        if (!empty($link->uri)) {
507
          // for the link see also cdm_external_uri()
508
          $protologue_links[] = l(font_awesome_icon_markup('fa-book'), $link->uri, ['html' => true]);
509
          }
510
        }
511
      }
512

    
513
    // ---------------
514

    
515
    $additional_pub_markup = '';
516
      $descriptions = cdm_ws_get(CDM_WS_PORTAL_NAME_DESCRIPTIONS, $taxon_name->uuid);
517
      if($descriptions) {
518
        foreach ($descriptions as $description) {
519
          if (!empty($description)) {
520
            $additional_citations = [];
521
            $additional_data = [];
522
            foreach ($description->elements as $description_element) {
523
              if (isset($description_element->multilanguageText_L10n) && $description_element->multilanguageText_L10n->text) {
524
                RenderHints::setAnnotationsAndSourceConfig(synonymy_annotations_and_source_config());
525
                $annotations_and_sources = handle_annotations_and_sources($description_element);
526
                // synonymy_annotations_and_source_config() has 'sources_as_content' => FALSE, so no need to handle inline sources here
527
                $element_media = cdm_description_element_media(
528
                  $description_element,
529
                  [
530
                    'application/pdf',
531
                    'image/png',
532
                    'image/jpeg',
533
                    'image/gif',
534
                    'text/html',
535
                  ]
536
                );
537
                if (isset($description_element->feature) && $description_element->feature->uuid == UUID_ADDITIONAL_PUBLICATION) {
538
                   $additional_citations[] = ' [& ' . trim($description_element->multilanguageText_L10n->text) . $element_media . $annotations_and_sources->footNoteKeysMarkup() .']';
539
                } else {
540
                  $additional_data[] = ' [' . trim($description_element->multilanguageText_L10n->text) . $element_media . $annotations_and_sources->footNoteKeysMarkup(). ']';
541
                }
542
              }
543
            }
544
            // merge
545
            $additional_citations = array_merge($additional_citations, $additional_data);
546
            $additional_pub_markup .= join(',', $additional_citations);
547
          }
548
        }
549
      }
550
      if($additional_pub_markup){
551
        $additional_pub_markup = ' ' . $additional_pub_markup . '. '; // surround with space etc.
552
      }
553
      array_setr('description', $additional_pub_markup . join(', ', $protologue_links), $renderTemplate);
554
      array_replace_keyr('description', 'protologue', $renderTemplate); // in preparation for #9319
555
  }
556

    
557
  // Render.
558
  $out = '';
559
  if(isset($_REQUEST['RENDER_PATH'])){
560
    // developer option to show the render path with each taxon name
561
    $out .= '<span class="render-path">' . RenderHints::getRenderPath() . '</span>';
562
  }
563
  $out .= '<span class="' . html_class_attribute_ref($taxon_name_or_taxon_base)
564
    . '" data-cdm-ref="/name/' . $taxon_name->uuid . '" data-cdm-render-path="' . RenderHints::getRenderPath() .'">';
565

    
566
  foreach ($renderTemplate as $partName => $part) {
567
    $separator = '';
568
    $partHtml = '';
569
    $uri = FALSE;
570
    if (!is_array($part)) {
571
      continue;
572
    }
573
    if (isset($part['#uri']) && is_string($part['#uri'])) {
574
      $uri = $part['#uri'];
575
      unset($part['#uri']);
576
    }
577
    foreach ($part as $part => $content) {
578
      $html = '';
579
      if (is_array($content)) {
580
        $html = $content['#html'];
581
        if(isset($content['#separator'])) {
582
          $separator = $content['#separator'];
583
        }
584
      }
585
      elseif (is_string($content)) {
586
        $html = $content;
587
      }
588
      if($html){ // skip empty elements
589
        $partHtml .= '<span class="' . $part . '">' . $html . '</span>';
590
      }
591
    }
592
    if ($uri) {
593
      // cannot use l() here since the #uri already should have been processed through uri() at this point
594
      $out .= $separator . '<a href="' . $uri . '" class="' . $partName . '">' . $partHtml . '</a>';
595

    
596
    }
597
    else {
598
      $out .= $separator . $partHtml;
599
    }
600
  }
601
  $out .= '</span>';
602

    
603
  $annotations_and_sources = new AnnotationsAndSources();
604
  if($nom_status_fkey){
605
    // the nomenclatural status footnote key refers to the source citation
606
    $annotations_and_sources->addFootNoteKey($nom_status_fkey);
607
  }
608
  if ($show_taxon_name_annotations) {
609
    if($taxon_base){
610
      $annotations_and_sources = handle_annotations_and_sources($taxon_base,
611
        null, null, $annotations_and_sources);
612
    }
613
    $annotations_and_sources = handle_annotations_and_sources($taxon_name,
614
      null, null, $annotations_and_sources);
615
  }
616
  $out .= $annotations_and_sources->footNoteKeysMarkup();
617
  return $out;
618
}
619

    
620

    
621

    
622
/**
623
 * Composes information for a registration from a dto object.
624
 *
625
 * Registrations which are not yet published are suppressed.
626
 *
627
 * @param $registration_dto
628
 * @param $with_citation
629
 *   Whether to show the citation.
630
 *
631
 * @return array
632
 *    A drupal render array with the elements:
633
 *    - 'name'
634
 *    - 'name-relations'
635
 *    - 'specimen_type_designations'
636
 *    - 'name_type_designations'
637
 *    - 'citation'
638
 *    - 'registration_date_and_institute'
639
 * @ingroup compose
640
 */
641
function compose_registration_dto_full($registration_dto, $with_citation = true)
642
{
643
  $render_array = array(
644
    '#prefix' => '<div class="registration">',
645
    '#suffix' => '</div>'
646
  );
647

    
648
  if(!(isset($registration_dto->identifier) && $registration_dto->status == 'PUBLISHED')){
649
    return $render_array;
650
  }
651

    
652
  $render_array['sub_headline'] = markup_to_render_array(join(", ", registration_types($registration_dto)),-10, '<h3 class="registration_type">' . t('Event: '), '</h3>' );
653
  $render_array['nomenclatural_act'] = array(
654
    '#weight' => 0,
655
    '#prefix' => '<div class="nomenclatural_act">',
656

    
657
    '#suffix' => '</div>'
658
  );
659

    
660
  $typified_name = null;
661

    
662
  // Nomenclatural act block element
663
  $last_footnote_listkey = RenderHints::setFootnoteListKey("nomenclatural_act");
664
  // name
665
  $name_relations = null;
666
  if(isset($registration_dto->nameRef) && $registration_dto->nameRef){
667
    $name = cdm_ws_get(CDM_WS_PORTAL_NAME, $registration_dto->nameRef->uuid);
668
    cdm_load_tagged_full_title($name);
669
    $render_array['nomenclatural_act']['published_name'] = markup_to_render_array('<div class="published-name">' . render_taxon_or_name($name, url(path_to_name($name->uuid))) . '</div>', 0);
670
    $name_relations = cdm_ws_fetch_all(str_replace("$0", $registration_dto->nameRef->uuid, CDM_WS_PORTAL_NAME_NAME_RELATIONS));
671
    // need to create the name relationships later, so that the foot notes are in correct order, see section // name relations
672
  } else {
673
    // in this case the registration must have a
674
    // typified name will be rendered later
675
    $typified_name = cdm_ws_get(CDM_WS_PORTAL_NAME, $registration_dto->typifiedNameRef->uuid);
676

    
677
  }
678

    
679
  // typedesignation in detail
680
  if(is_object($registration_dto->orderedTypeDesignationWorkingSets)) {
681
    $field_unit_uuids = array();
682
    $specimen_type_designation_refs = array();
683
    $name_type_designation_refs = array();
684
    foreach ((array)$registration_dto->orderedTypeDesignationWorkingSets as $workingset_ref => $obj) {
685
      $tokens = explode("#", $workingset_ref);
686
      $types_in_fieldunit = get_object_vars($obj); // convert into associative array
687

    
688
      if ($tokens[0] == 'NameTypeDesignation') {
689
        foreach ($types_in_fieldunit as $type_status => $entity_reference_list) {
690
          if(!isset($name_type_designation_refs[$type_status])){
691
            $name_type_designation_refs[$type_status]  = $entity_reference_list;
692
          } else {
693
            $specimen_type_designation_refs[$type_status] = array_merge($specimen_type_designation_refs[$type_status], $entity_reference_list);
694
          }
695
        }
696
      } else if ($tokens[0] == 'FieldUnit'){
697
        $field_unit_uuids[] = $tokens[1];
698
        foreach ($types_in_fieldunit as $type_status => $entity_reference_list) {
699
          if(!isset($specimen_type_designation_refs[$type_status])){
700
            $specimen_type_designation_refs[$type_status] =  $entity_reference_list;
701
          } else {
702
            array_push($specimen_type_designation_refs[$type_status], $entity_reference_list);
703
          }
704
        }
705
      } else {
706
        drupal_set_message("Unimplemented type: " . $tokens[0], 'error');
707
      }
708
    }
709
    // type designations which are in this nomenclatural act.
710
    if (count($name_type_designation_refs) > 0) {
711
      $render_array['nomenclatural_act']['name_type_designations'] = compose_name_type_designations($name_type_designation_refs);
712
      $render_array['nomenclatural_act']['name_type_designations']['#prefix'] = '<p class="name_type_designations">';
713
      $render_array['nomenclatural_act']['name_type_designations']['#suffix'] = '</p>';
714
      $render_array['nomenclatural_act']['name_type_designations']['#weight'] = 20;
715
    }
716
    if (count($field_unit_uuids) > 0) {
717
      $specimen_type_designations_array = compose_specimen_type_designations($specimen_type_designation_refs, true);
718
      $render_array['nomenclatural_act']['specimen_type_designations'] = $specimen_type_designations_array['type_designations'];
719
      $render_array['map'] = $specimen_type_designations_array['map'];
720
      $render_array['map']['#weight'] = $render_array['nomenclatural_act']['#weight'] + 20;
721
    }
722
  }
723

    
724
  // name relations
725
  if($name_relations){
726
    $render_array['nomenclatural_act']['name_relations'] = compose_name_relationships_list($name_relations, $registration_dto->nameRef->uuid, null);
727
    $render_array['nomenclatural_act']['name_relations']['#weight'] = 10;
728
  }
729

    
730
  // citation
731
  if ($with_citation) {
732
    $render_array['citation'] = markup_to_render_array(
733
      "<div class=\"citation nomenclatural_act_citation" . html_class_attribute_ref(new TypedEntityReference("Reference", $registration_dto->citationUuid)) . "\">"
734
      . "<span class=\"label\">published in: </span>"
735
      . $registration_dto->bibliographicInRefCitationString
736
      . l(custom_icon_font_markup('icon-interal-link-alt-solid', array('class' => array('superscript'))), path_to_reference($registration_dto->citationUuid), array('html' => true))
737
      . "</div>",
738
      $render_array['nomenclatural_act']['#weight'] + 10 );
739
  }
740

    
741
  $render_array['nomenclatural_act']['footnotes'] = markup_to_render_array(render_footnotes(),100);
742

    
743
  // END of nomenclatural act block
744
  RenderHints::setFootnoteListKey($last_footnote_listkey );
745

    
746
  if($typified_name){
747
    $render_array['typified_name'] = markup_to_render_array('<p class="typified-name">for ' . render_taxon_or_name($typified_name, url(path_to_name($typified_name->uuid))) . '</p>', 40);
748
  }
749

    
750
  // registration date and office
751
  $registration_date_insitute_markup = render_registration_date_and_institute($registration_dto);
752
  if($registration_date_insitute_markup){
753
    $render_array['registration_date_and_institute'] = markup_to_render_array(
754
      $registration_date_insitute_markup . '</p>',
755
      100);
756
  }
757

    
758
  $render_array['page_footnotes'] = markup_to_render_array(render_footnotes(), 110);
759

    
760
  return $render_array;
761
}
762

    
763

    
764
/**
765
 * Composes a compact representation for a registrationDTO object
766
 *
767
 * Registrations which are not yet published are suppressed.
768
 *
769
 * @param $registration_dto
770
 * @param $style string
771
 *   The style of how to compose the 'identifier' and 'registration_date_and_institute' part with the summary
772
 *   - 'citation': Similar to the appearance of nomenclatural acts in print media
773
 *   - 'list-item' : style suitable for result lists etc
774
 *
775
 * @return array
776
 *    A drupal render array with the elements:
777
 *    - 'registration-metadata' when $style == 'list-item'
778
 *    - 'summary'
779
 * @ingroup compose
780
 */
781
function compose_registration_dto_compact($registration_dto, $style = 'citation', $tag_enclosing_summary = 'p')
782
{
783
  $render_array = array();
784
  $media_link_map = array();
785

    
786
  if(!(isset($registration_dto->identifier) && $registration_dto->status == 'PUBLISHED')){
787
    return $render_array;
788
  }
789

    
790
  $registration_date_institute_markup = render_registration_date_and_institute($registration_dto, 'span');
791
  $identifier_markup = render_link_to_registration($registration_dto->identifier);
792

    
793
  $tagged_text_options = array();
794
  if(isset($registration_dto->nameRef)){
795
    $tagged_text_options[] = array(
796
      'filter-type' => 'name',
797
      'prefix' => '<span class="registered_name">',
798
      'suffix' => '</span>',
799
    );
800
  } else {
801
    $tagged_text_options[] = array(
802
      'filter-type' => 'name',
803
      'prefix' => '<span class="referenced_typified_name">',
804
      'suffix' => '</span>',
805
    );
806
  }
807
  cdm_tagged_text_add_options($registration_dto->summaryTaggedText, $tagged_text_options);
808
  $tagged_text_cropped = tagged_text_crop_at($registration_dto->summaryTaggedText, 'reference', '/[dD]esignated\s+[bB]y/');
809
  $tagged_text_expanded = cdm_tagged_text_expand_entity_references($tagged_text_cropped);
810
  foreach ($tagged_text_expanded  as $tagged_text){
811
    if(isset($tagged_text->entityReference->type) && $tagged_text->entityReference->type == 'SpecimenTypeDesignation') {
812
      $mediaDTOs = cdm_ws_get('typedesignation/$0/media', array($tagged_text->entityReference->uuid));
813
      if(isset($mediaDTOs[0]->uri)){
814
        $media_url_key = '{link-' . $mediaDTOs[0]->uuid . '}';
815
        $tagged_text->text = str_replace('[icon]', '[icon]' . $media_url_key, $tagged_text->text);
816
        $media_link_map[$media_url_key] =  cdm_external_uri($mediaDTOs[0]->uri, true);
817
      }
818
    }
819
  }
820
  $registation_markup = cdm_tagged_text_to_markup($tagged_text_expanded);
821
  foreach($media_link_map as $media_url_key => $link){
822
    $registation_markup = str_replace($media_url_key, $link, $registation_markup);
823
  }
824
  if($style == 'citation') {
825
    $registation_markup = $registation_markup . ' ' . $identifier_markup . ' ' . $registration_date_institute_markup;
826
  } else {
827
    $render_array['registration-metadata'] = markup_to_render_array('<div class="registration-metadata">' . $identifier_markup . ' ' . $registration_date_institute_markup. "</div>", -10);
828
  }
829
  $render_array['summary'] = markup_to_render_array('<' . $tag_enclosing_summary . ' class="registration-summary">' . $registation_markup . '</' . $tag_enclosing_summary . '>', 0);
830

    
831
  return $render_array;
832
}
833

    
834
/**
835
 * Renders the registrationDate and institutionTitleCache of the $registration_dto as markup.
836
 *
837
 * @param $registration_dto
838
 * @return string
839
 *    The markup or an empty string
840
 */
841
function render_registration_date_and_institute($registration_dto, $enclosing_tag = 'p') {
842
  $registration_date_institute_markup = '';
843
  if ($registration_dto->registrationDate) {
844
    $date_string = format_datetime($registration_dto->registrationDate);
845
    if (isset($registration_dto->institutionTitleCache) && $registration_dto->institutionTitleCache) {
846
      $registration_date_institute_markup =
847
        t("Registration on @date in @institution", array(
848
          '@date' => $date_string,
849
          '@institution' => $registration_dto->institutionTitleCache,
850
        ));
851
    } else {
852
      $registration_date_institute_markup =
853
        t("Registration on @date", array(
854
          '@date' => $date_string
855
        ));
856
    }
857
    $registration_date_institute_markup = '<' .$enclosing_tag . ' class="registration-date-and-institute">'. $registration_date_institute_markup . '</' .$enclosing_tag . '>';
858
  }
859
  return $registration_date_institute_markup;
860
}
861

    
862

    
863
/**
864
 * @param $registrations
865
 * @return string
866
 */
867
function render_registrations($registrations)
868
{
869
  $registration_markup = '';
870
  $registration_markup_array = array();
871
  if ($registrations) {
872
    foreach ($registrations as $reg) {
873
      $registration_markup_array[] = render_registration($reg);
874
    }
875
    $registration_markup = " Registration" . (count($registration_markup_array) > 1 ? 's: ' : ': ')
876
      . join(', ', $registration_markup_array);
877
  }
878
  return $registration_markup;
879
}
880

    
881

    
882
/**
883
 * Renders a registration
884
 *
885
 * TODO replace by compose_registration_dto_compact
886
 * @param $registration
887
 */
888
function render_registration($registration){
889
  $markup = '';
890

    
891
  if(isset($registration->identifier) && $registration->status == 'PUBLISHED'){
892
    $office_class_attribute = '';
893
    if(isset($registration->institution->titleCache)){
894
      $office_class_attribute = registration_institution_class_attribute($registration);
895
    }
896
    $markup = "<span class=\"registration $office_class_attribute\">" . render_link_to_registration($registration->identifier) . ', '
897
      .  preg_replace('/^([^T]*)(.*)$/', '${1}', $registration->registrationDate)
898
      . '</span>';
899
  }
900
  return $markup;
901
}
902

    
903
/**
904
 * @param $registration
905
 * @return string
906
 */
907
function registration_institution_class_attribute($registration_dto)
908
{
909
  if(isset($registration_dto->institutionTitleCache)){
910
    $institutionTitleCache = $registration_dto->institutionTitleCache;
911
  } else {
912
    // fall back option to also support cdm entities
913
    $institutionTitleCache = @$registration_dto->institution->titleCache;
914
  }
915
  return $institutionTitleCache ? 'registration-' . strtolower(preg_replace('/[^a-zA-Z0-9]/', '-', $institutionTitleCache)) : '';
916
}
917

    
918

    
919
/**
920
 * Renders and array of CDM TypeDesignations
921
 *
922
 *  - NameTypeDesignation
923
 *  - SpecimenTypeDesignation
924
 *  - TextualTypeDesignation
925
 *
926
 * @param array $type_designations an array of cdm TypeDesignation entities
927
 *  to render
928
 * @param string $enclosing_tag the tag element type to enclose the whole list
929
 *  of type designation with. By default this DOM element is <ul>
930
 * @param string $element_tag the tag element type to be used for each
931
 *  type designation item.
932
 * @param bool $link_to_specimen_page whether a specimen in type designation element
933
 *  should be a link or not.
934
 *
935
 * @return string The markup.
936
 *
937
 * @InGroup Render
938
 */
939
function render_type_designations($type_designations, $enclosing_tag = 'ul', $element_tag =  'li', $link_to_specimen_page = true) {
940

    
941
  // need to add element to render path since type designations
942
  // need other name render template
943
  RenderHints::pushToRenderStack('typedesignations');
944

    
945
  $out = '<' . $enclosing_tag .' class="typeDesignations">';
946
  $specimen_type_designations = array();
947
  $name_type_designations = array();
948
  $textual_type_designations = array();
949
  $separator = ',';
950

    
951
  foreach ($type_designations as $type_designation) {
952
    switch ($type_designation->class) {
953
      case 'SpecimenTypeDesignation':
954
        $specimen_type_designations[] = $type_designation;
955
        break;
956
      case 'NameTypeDesignation':
957
        $name_type_designations[] = $type_designation;
958
        break;
959
      case 'TextualTypeDesignation':
960
        $textual_type_designations[] = $type_designation;
961
        break;
962
      default:  throw new Exception('Unknown type designation class: ' . $type_designation->class);
963
    }
964
  }
965

    
966
  // NameTypeDesignation ..................................
967
  if(!empty($name_type_designations)){
968
    usort($name_type_designations, "compare_type_designations_by_status");
969
    foreach($name_type_designations as $name_type_designation){
970
      if ($name_type_designation->notDesignated) {
971
        $out .= '<'. $element_tag .' class="' . html_class_attribute_ref($name_type_designation) . '">' .  type_designation_status_label_markup($name_type_designation)  . ': '
972
          . t('not designated') . '</'. $element_tag .'>';
973
      }
974
      elseif (isset($name_type_designation->typeName)) {
975
        $link_to_name_page = url(path_to_name($name_type_designation->typeName->uuid));
976
        $out .= '<'. $element_tag .' class="' . html_class_attribute_ref($name_type_designation) . '">' .  type_designation_status_label_markup($name_type_designation) ;
977

    
978
        if (!empty($name_type_designation->designationSource->citation)) {
979
          $out .= type_designation_citation_layout($name_type_designation, $separator); // TODO type_designation_citation_layout() needs most probably to be replaced
980

    
981
        }
982
        $referenceUri = '';
983
        if (isset($name_type_designation->typeName->nomenclaturalSource->citation)) {
984
          $referenceUri = url(path_to_reference($name_type_designation->typeName->nomenclaturalSource->citation->uuid));
985
        }
986
        $out .= ': ' . render_taxon_or_name($name_type_designation->typeName, $link_to_name_page, $referenceUri, TRUE, TRUE);
987
      }
988
      RenderHints::setAnnotationsAndSourceConfig(annotations_and_sources_config_typedesignations());
989
      $annotations_and_sources = handle_annotations_and_sources($name_type_designation);
990
      $out .= $annotations_and_sources->footNoteKeysMarkup();
991
    }
992
  } // END NameTypeDesignation
993

    
994
  // SpecimenTypeDesignation ...................................
995
  if (!empty($specimen_type_designations)) {
996
    usort($specimen_type_designations, "compare_specimen_type_designation");
997
    foreach ($specimen_type_designations as $specimen_type_designation) {
998
      $type_citation_markup = '';
999

    
1000
      if (!empty($specimen_type_designation->designationSource->citation)) {
1001

    
1002
        $citation_footnote_str = cdm_reference_markup($specimen_type_designation->designationSource->citation, null, false, true);
1003
        $author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $specimen_type_designation->designationSource->citation->uuid);
1004

    
1005
        if (!empty($author_team->titleCache)) {
1006
          $year = @timePeriodToString($specimen_type_designation->designationSource->citation->datePublished, true, 'YYYY');
1007
          $authorteam_str = $author_team->titleCache . ($year ? ' ' : '') . $year;
1008
          if ($authorteam_str == $specimen_type_designation->designationSource->citation->titleCache) {
1009
            $citation_footnote_str = '';
1010
          }
1011
        } else {
1012
          $authorteam_str = $citation_footnote_str;
1013
          // no need for a footnote in case in case it is used as replacement for missing author teams
1014
          $citation_footnote_str = '';
1015
        }
1016

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

    
1022
        $footnote_key_markup = '';
1023
        if ($citation_footnote_str) {
1024
          // footnotes should be rendered in the parent element so we
1025
          // are relying on the FootnoteListKey set there
1026
          $_fkey2 = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), $citation_footnote_str);
1027
          $footnote_key_markup = render_footnote_key($_fkey2, $separator, TRUE);
1028
        }
1029

    
1030
        $type_citation_markup .= '&nbsp;(' . t('designated by') . '&nbsp;<span class="typeReference">' . $authorteam_str . '</span>';
1031
        if (!empty($specimen_type_designation->designationSource->citationMicroReference)) {
1032
          $type_citation_markup .= ': ' . trim($specimen_type_designation->designationSource->citationMicroReference);
1033
        }
1034
        $type_citation_markup .= $footnote_key_markup . ')';
1035
      }
1036

    
1037
      $out .= '<'. $element_tag .' class="' . html_class_attribute_ref($specimen_type_designation) . '">';
1038
      $out .= type_designation_status_label_markup($specimen_type_designation) . $type_citation_markup;
1039

    
1040

    
1041
      $derivedUnitFacadeInstance = null;
1042
      if (isset($specimen_type_designation->typeSpecimen)) {
1043
        $derivedUnitFacadeInstance = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, $specimen_type_designation->typeSpecimen->uuid);
1044
      }
1045

    
1046
      if (!empty($derivedUnitFacadeInstance->titleCache)) {
1047
        $specimen_markup = $derivedUnitFacadeInstance->titleCache;
1048
        if($link_to_specimen_page && isset($derivedUnitFacadeInstance->specimenLabel) && $derivedUnitFacadeInstance->specimenLabel){
1049
          $specimen_markup = str_replace($derivedUnitFacadeInstance->specimenLabel, l($derivedUnitFacadeInstance->specimenLabel, path_to_specimen($specimen_type_designation->typeSpecimen->uuid)), $specimen_markup);
1050
        }
1051
        RenderHints::setAnnotationsAndSourceConfig(annotations_and_sources_config_typedesignations());
1052
        $annotations_and_sources = handle_annotations_and_sources($derivedUnitFacadeInstance);
1053
        $out .= ': <span class="' . html_class_attribute_ref($specimen_type_designation->typeSpecimen) . '">'
1054
          . $specimen_markup
1055
          . '</span>'; // . ': ' . theme('cdm_specimen', array('specimenTypeDesignation' => $derivedUnitFacadeInstance));
1056
        if(!empty($derivedUnitFacadeInstance->preferredStableUri)){
1057
          $out .= ' ' . l($derivedUnitFacadeInstance->preferredStableUri, $derivedUnitFacadeInstance->preferredStableUri, array('absolute' => true));
1058
        }
1059
        $out .= $annotations_and_sources->footNoteKeysMarkup();
1060
      }
1061
      $out .= '</'. $element_tag .'>';
1062
    }
1063
  } // END Specimen type designations
1064

    
1065
  // TextualTypeDesignation .........................
1066
  usort($textual_type_designations, 'compare_textual_type_designation');
1067
  if(!empty($textual_type_designations)) {
1068
      RenderHints::setAnnotationsAndSourceConfig([
1069
          // these settings differ from those provided by annotations_and_sources_config_typedesignations()
1070
          // TODO is this by purpose? please document the reason for the difference
1071
          'sources_as_content' => false, // as footnotes
1072
          'link_to_name_used_in_source' => false,
1073
          'link_to_reference' => true,
1074
          'add_footnote_keys' => true,
1075
          'bibliography_aware' => false
1076
        ]
1077
      );
1078
    foreach ($textual_type_designations as $textual_type_designation) {
1079
      $annotations_and_sources = handle_annotations_and_sources($textual_type_designation);
1080
      $encasement =  $textual_type_designation->verbatim ? '"' : '';
1081
      $out .= '<' . $element_tag . ' class="' . html_class_attribute_ref($textual_type_designation) . '">' . type_designation_status_label_markup(null)
1082
        . ': ' .  $encasement . trim($textual_type_designation->text_L10n->text) . $encasement .  $annotations_and_sources->footNoteKeysMarkup() .'</' . $element_tag . '>';
1083
//      if($annotations_and_sources->hasSourceReferences())){
1084
//        $citation_markup = join(', ', getSourceReferences());
1085
//      }
1086
//      $out .= $citation_markup;
1087
    }
1088
  }
1089

    
1090
  // Footnotes for citations, collection acronyms.
1091
  // footnotes should be rendered in the parent element so we
1092
  // are relying on the FootnoteListKey set there
1093
  $_fkey = FootnoteManager::addNewFootnote(
1094
    RenderHints::getFootnoteListKey(),
1095
    (isset($derivedUnitFacadeInstance->collection->titleCache) ? $derivedUnitFacadeInstance->collection->titleCache : FALSE)
1096
  );
1097
  $out .= render_footnote_key($_fkey, $separator);
1098
  $out .= '</' . $enclosing_tag .'>';
1099

    
1100
  RenderHints::popFromRenderStack();
1101

    
1102
  return $out;
1103
}
1104

    
1105
/**
1106
 * Creates markup for a list of SpecimenTypedesignationDTO
1107
 *
1108
 * @param array $specimen_typedesignation_dtos
1109
 *  The SpecimenTypedesignationDTOs to be rendered
1110
 *
1111
 * @param bool $show_type_specimen
1112
 *
1113
 * @param string $enclosing_tag
1114
 * @param string $element_tag
1115
 *
1116
 * @return string
1117
 *   The markup.
1118
 */
1119
function render_specimen_typedesignation_dto($specimen_typedesignation_dtos, $show_type_specimen = FALSE, $enclosing_tag = 'ul', $element_tag = 'li'){
1120

    
1121
  // need to add element to render path since type designations
1122
  // need other name render template
1123
  RenderHints::pushToRenderStack('typedesignations');
1124

    
1125
  $out = '<' . $enclosing_tag .' class="typeDesignations">';
1126
  $separator = ',';
1127

    
1128
  if (!empty($specimen_typedesignation_dtos)) {
1129
    // usort($specimen_type_designations, "compare_specimen_type_designation"); // FIXME create compare function for SpecimenTypedesignationDTO
1130
    foreach ($specimen_typedesignation_dtos as $std_dto) {
1131
      $type_citation_markup = '';
1132

    
1133
      if (!empty($std_dto->designationSource->citation)) {
1134

    
1135
        $citation_footnote_str = cdm_reference_markup($std_dto->designationSource->citation, null, false, true);
1136
        $author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $std_dto->designationSource->citation->uuid);
1137

    
1138
        if (!empty($author_team->titleCache)) {
1139
          $year = @timePeriodToString($std_dto->designationSource->citation->datePublished, true, 'YYYY');
1140
          $authorteam_str = $author_team->titleCache . ($year ? ' ' : '') . $year;
1141
          if ($authorteam_str == $std_dto->designationSource->citation->titleCache) {
1142
            $citation_footnote_str = '';
1143
          }
1144
        } else {
1145
          $authorteam_str = $citation_footnote_str;
1146
          // no need for a footnote in case in case it is used as replacement for missing author teams
1147
          $citation_footnote_str = '';
1148
        }
1149

    
1150
        // for being registered a typedesignation MUST HAVE a citation, so it is save to handle the
1151
        // Registration output in the conditional block which has been checked that the citation is present
1152
        $registration_markup = render_registrations($std_dto->registrations);
1153
        $citation_footnote_str .= ($citation_footnote_str ? ' ' : '') . $registration_markup;
1154

    
1155
        $footnote_key_markup = '';
1156
        if ($citation_footnote_str) {
1157
          // footnotes should be rendered in the parent element so we
1158
          // are relying on the FootnoteListKey set there
1159
          $_fkey2 = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), $citation_footnote_str);
1160
          $footnote_key_markup = render_footnote_key($_fkey2, $separator, TRUE);
1161
        }
1162

    
1163
        $type_citation_markup .= '&nbsp;(' . t('designated by') . '&nbsp;<span class="typeReference">' . $authorteam_str . '</span>';
1164
        if (!empty($std_dto->designationSource->citationMicroReference)) {
1165
          $type_citation_markup .= ': ' . trim($std_dto->designationSource->citationMicroReference);
1166
        }
1167
        $type_citation_markup .= $footnote_key_markup . ')';
1168
      }
1169

    
1170
      $out .= '<'. $element_tag .' class="' . html_class_attribute_ref($std_dto) . '">';
1171
      $out .= type_designation_dto_status_label_markup($std_dto) . $type_citation_markup;
1172

    
1173
      if($show_type_specimen){
1174
        $derivedUnitFacadeInstance = null;
1175
        if (isset($std_dto->typeSpecimen)) {
1176
          $derivedUnitFacadeInstance = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, $std_dto->typeSpecimen->uuid);
1177
        }
1178

    
1179
        if (!empty($derivedUnitFacadeInstance->titleCache)) {
1180
          $specimen_markup = $derivedUnitFacadeInstance->titleCache;
1181
          if(isset($derivedUnitFacadeInstance->specimenLabel) && $derivedUnitFacadeInstance->specimenLabel){
1182
            $specimen_markup = str_replace($derivedUnitFacadeInstance->specimenLabel, l($derivedUnitFacadeInstance->specimenLabel, path_to_specimen($std_dto->typeSpecimen->uuid)), $specimen_markup);
1183
          }
1184
          RenderHints::setAnnotationsAndSourceConfig(annotations_and_sources_config_typedesignations());
1185
          $annotations_and_sources = handle_annotations_and_sources($derivedUnitFacadeInstance);
1186
          $out .= ': <span class="' . html_class_attribute_ref($std_dto->typeSpecimen) . '">'
1187
            . $specimen_markup
1188
            . '</span>'; // . ': ' . theme('cdm_specimen', array('specimenTypeDesignation' => $derivedUnitFacadeInstance));
1189
          if(!empty($derivedUnitFacadeInstance->preferredStableUri)){
1190
            $out .= ' ' . l($derivedUnitFacadeInstance->preferredStableUri, $derivedUnitFacadeInstance->preferredStableUri, array('absolute' => true));
1191
          }
1192
          $out .= $annotations_and_sources->footNoteKeysMarkup();
1193
        }
1194
      }
1195

    
1196
      $out .= '</'. $element_tag .'>';
1197
    }
1198
    RenderHints::popFromRenderStack();
1199
  }
1200
  return $out;
1201
}
1202

    
1203

    
1204
/**
1205
 * Composes the textual representation for the type designation of taxon name identified by the uuid in with a map for the location data.
1206
 *
1207
 * @param $taxon_name_uuid
1208
 * @param $show_specimen_details
1209
 * @return array
1210
 *    A drupal render array with the following elements:
1211
 *    - 'type_designations'
1212
 *    - 'map'
1213
 *    - 'specimens'
1214
 *
1215
 * @ingroup compose
1216
 */
1217
function compose_type_designations($taxon_name_uuid, $show_specimen_details = false)
1218
{
1219
  $render_array = array(
1220
    'type_designations' => array(),
1221
    'map' => array(),
1222
    );
1223
  $type_designations = cdm_ws_get(CDM_WS_PORTAL_NAME_TYPEDESIGNATIONS, $taxon_name_uuid);
1224
  if ($type_designations) {
1225
    usort($type_designations, 'compare_specimen_type_designation');
1226
    $render_array['type_designations'] = markup_to_render_array(
1227
      render_type_designations($type_designations, 'div', 'div')
1228
    );
1229

    
1230
    $render_array['map'] = compose_type_designations_map($type_designations);
1231
  }
1232
  return $render_array;
1233
}
1234

    
1235

    
1236
/**
1237
 * Composes the TypedEntityReference to name type designations passed as associatve array.
1238
 *
1239
 * @param $type_entity_refs_by_status array
1240
 *   an associative array of name type type => TypedEntityReference for name type designations as
1241
 *   produced by the eu.etaxonomy.cdm.api.service.name.TypeDesignationSetManager
1242
 *
1243
 * @ingroup compose
1244
 */
1245
function compose_name_type_designations($type_entity_refs_by_status){
1246
  $render_array = array();
1247
  $preferredStableUri = '';
1248
  foreach($type_entity_refs_by_status as $type_status => $name_type_entityRefs){
1249
    foreach ($name_type_entityRefs as $name_type_entity_ref){
1250
      $type_designation = cdm_ws_get(CDM_WS_TYPEDESIGNATION, array($name_type_entity_ref->uuid, 'preferredUri'));
1251
      $footnote_keys = '';
1252

    
1253
      if(isset($type_designation->typeSpecimen->preferredStableUri) && $type_designation->typeSpecimen->preferredStableUri){
1254
        $preferredStableUri = $type_designation->typeSpecimen->preferredStableUri;
1255
      }
1256
      // annotations and sources for the $derived_unit_facade_dto
1257
      RenderHints::setAnnotationsAndSourceConfig(annotations_and_sources_config_typedesignations());
1258
      $annotations_and_sources = handle_annotations_and_sources($name_type_entity_ref);
1259

    
1260
      $render_array[] = markup_to_render_array('<div class="name_type_designation ' . html_class_attribute_ref($name_type_entity_ref)  .
1261
        '"><span class="type-status">'. ucfirst($type_status) . "</span>: "
1262
        . cdm_tagged_text_to_markup($name_type_entity_ref->taggedText)
1263
        . ($preferredStableUri ? " ". l($preferredStableUri,  $preferredStableUri) : '')
1264
        . $annotations_and_sources->footNoteKeysMarkup()
1265
        . '</div>');
1266
      }
1267
  }
1268
  return $render_array;
1269
}
1270

    
1271
/**
1272
 * Composes the specimen type designations with map from the the $type_entity_refs
1273
 *
1274
 * @param $type_entity_refs array
1275
 *   an associative array of specimen type type => TypedEntityReference for specimen type designations as
1276
 *   produced by the eu.etaxonomy.cdm.api.service.name.TypeDesignationSetManager
1277
 *
1278
 * @param $show_media_specimen
1279
 * @return array
1280
 *    A drupal render array with the following elements:
1281
 *    - 'type_designations'
1282
 *    - 'map'
1283
 *
1284
 * @ingroup compose
1285
 *
1286
 */
1287
function compose_specimen_type_designations($type_entity_refs, $show_media_specimen){
1288

    
1289
  $render_array = array();
1290

    
1291
  $type_designation_list = array();
1292
  uksort($type_entity_refs, "compare_type_designation_status_labels");
1293
  foreach($type_entity_refs as $type_status => $type_designation_entity_refs){
1294
    foreach($type_designation_entity_refs as $type_designation_entity_ref){
1295

    
1296
      $type_designation = cdm_ws_get(CDM_WS_PORTAL_TYPEDESIGNATION, array($type_designation_entity_ref->uuid));
1297
      $type_designation_list[] = $type_designation; // collect for the map
1298

    
1299
      $derived_unit_facade_dto = cdm_ws_get(CDM_WS_PORTAL_DERIVEDUNIT_FACADE, $type_designation->typeSpecimen->uuid);
1300
      // the media specimen is not contained in the $type_designation returned by CDM_PORTAL_TYPEDESIGNATION, so we need to fetch it separately
1301
      $mediaSpecimen = cdm_ws_get(CDM_WS_PORTAL_OCCURRENCE, array($type_designation->typeSpecimen->uuid, 'mediaSpecimen'));
1302

    
1303

    
1304
      $preferredStableUri = '';
1305
      $citation_markup = '';
1306
      $media = '';
1307

    
1308
      // annotations and sources for the $derived_unit_facade_dto
1309
      RenderHints::setAnnotationsAndSourceConfig(annotations_and_sources_config_typedesignations());
1310
      $annotations_and_sources = handle_annotations_and_sources($derived_unit_facade_dto);
1311
      $source_citations = $annotations_and_sources->getSourceReferences();
1312
      $foot_note_keys = $annotations_and_sources->footNoteKeysMarkup();
1313

    
1314
      // preferredStableUri
1315
      if(isset($type_designation->typeSpecimen->preferredStableUri) && $type_designation->typeSpecimen->preferredStableUri){
1316
        $preferredStableUri = $type_designation->typeSpecimen->preferredStableUri;
1317
      }
1318

    
1319
      if($show_media_specimen && $mediaSpecimen){
1320
        // compose output
1321
        // mediaURI
1322
        if(isset($mediaSpecimen->representations[0])) {
1323
          $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
1324
          $captionElements = array(
1325
            '#uri' => t('open media'),
1326
            'elements' => array('-none-'),
1327
            'sources_as_content' => true
1328
          );
1329
          $media = compose_cdm_media_gallery(array(
1330
            'mediaList' => array($mediaSpecimen),
1331
            'galleryName' => CDM_DATAPORTAL_TYPE_SPECIMEN_GALLERY_NAME . '_' . $type_designation_entity_ref->uuid,
1332
            'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
1333
            'cols' => $gallery_settings['cdm_dataportal_media_cols'],
1334
            'captionElements' => $captionElements,
1335
          ));
1336
        }
1337
        // citation and detail for the media specimen
1338
        RenderHints::setAnnotationsAndSourceConfig(annotations_and_sources_config_typedesignations());
1339
        $annotations_and_sources = handle_annotations_and_sources($mediaSpecimen);
1340
        if($annotations_and_sources->hasSourceReferences()){
1341
          $source_citations = array_merge($source_citations, $annotations_and_sources->getSourceReferences());
1342
        }
1343
        if($annotations_and_sources->hasFootnoteKeys()){
1344
          $foot_note_keys .= ', ' . $annotations_and_sources->footNoteKeysMarkup();
1345
        }
1346
      }
1347

    
1348
      $citation_markup = join(', ', $source_citations);
1349

    
1350
      $specimen_markup = $derived_unit_facade_dto->titleCache;
1351
      if(isset($derived_unit_facade_dto->specimenLabel) && $derived_unit_facade_dto->specimenLabel){
1352
        $specimen_markup = str_replace(
1353
          $derived_unit_facade_dto->specimenLabel,
1354
          l($derived_unit_facade_dto->specimenLabel, path_to_specimen($type_designation->typeSpecimen->uuid)), $specimen_markup);
1355
      }
1356

    
1357
      $type_designation_render_array = markup_to_render_array(
1358
        '<div class="type_designation_entity_ref ' . html_class_attribute_ref($type_designation_entity_ref)  . '">
1359
          <span class="type-status">' . ucfirst($type_status) . "</span>: "
1360
        . $specimen_markup . $foot_note_keys
1361
        . ($citation_markup ? ' '. $citation_markup : '')
1362
        . ($preferredStableUri ? " ". l($preferredStableUri,  $preferredStableUri) : '')
1363
        . $media
1364
        . '</div>');
1365

    
1366
      $render_array['type_designations'][] = $type_designation_render_array;
1367
    }
1368
  }
1369
  if(count($type_designation_list) > 0 ){
1370
    $render_array['map'] = compose_type_designations_map($type_designation_list);
1371
  } else {
1372
    $render_array['map'] = array();
1373
  }
1374
  return $render_array;
1375
}
1376

    
1377
/**
1378
 * Creates the markup for the given name relationship.
1379
 *
1380
 * For the footnotes see handle_annotations_and_sources().
1381
 *
1382
 * @param $other_name
1383
 *      The other name from the NameRelationship see get_other_name()
1384
 * @param $current_taxon_uuid
1385
 * @param $show_name_cache_only
1386
 *    The nameCache will be shown instead of the titleCache if this parameter is true.
1387
 * @return null|string
1388
 *    The markup or null
1389
 *
1390
 * @see \get_other_name
1391
 */
1392
function name_relationship_markup($current_name_uuid, $name_rel, $current_taxon_uuid, $show_name_cache_only = false){
1393

    
1394
  $relationship_markup = null;
1395

    
1396
  $other_name = get_other_name($current_name_uuid, $name_rel);
1397

    
1398
  cdm_load_tagged_full_title($other_name);
1399

    
1400
  $highlited_synonym_uuid = isset ($other_name->taxonBases[0]->uuid) ? $other_name->taxonBases[0]->uuid : '';
1401
  if($show_name_cache_only){
1402
    $relationship_markup = l(
1403
      '<span class="' . html_class_attribute_ref($other_name) . '"">' . $other_name->nameCache . '</span>',
1404
      path_to_name($other_name->uuid, $current_taxon_uuid, $highlited_synonym_uuid, false),
1405
      array('html' => true)
1406
    );
1407
    $annotations_and_sources = handle_annotations_and_sources($other_name);
1408
    $relationship_markup .= $annotations_and_sources->footNoteKeysMarkup();
1409
  } else {
1410
    $relationship_markup = render_taxon_or_name($other_name,
1411
      url(path_to_name($other_name->uuid, $current_taxon_uuid, $highlited_synonym_uuid, false))
1412
    );
1413
  }
1414

    
1415
  return $relationship_markup;
1416
}
1417

    
1418
/**
1419
 * Determined the other name which is contained in the NameRelationship entity.
1420
 *
1421
 * @param $current_name_uuid
1422
 *   The uuid of this name.
1423
 * @param $name_rel
1424
 *   The cdm NameRelationship entity
1425
 *
1426
 * @return object
1427
 *   The other cdm Name entity.
1428
 */
1429
function get_other_name($current_name_uuid, $name_rel) {
1430
  $current_name_is_toName = $current_name_uuid == $name_rel->toName->uuid;
1431

    
1432
  if ($current_name_is_toName) {
1433
    $name = $name_rel->fromName;
1434
  }
1435
  else {
1436
    $name = $name_rel->toName;
1437
  }
1438
  return $name;
1439
}
1440

    
1441

    
1442
/**
1443
 * Composes an inline representation of selected name relationships
1444
 *
1445
 * The output of this function will be usually appended to taxon name representations.
1446
 * Only the following types are displayed: LATER_HOMONYM, TREATED_AS_LATER_HOMONYM, BLOCKING_NAME_FOR, ORTHOGRAPHIC_VARIANT
1447
 *
1448
 * LATER_HOMONYM, TREATED_AS_LATER_HOMONYM, BLOCKING_NAME_FOR are displayed as
1449
 * non {titleCache} nec {titleCache} nec {titleCache} whereas the related names
1450
 * are ordered alphabetically.
1451
 *
1452
 * ORTHOGRAPHIC_VARIANT is displayed as 'ort. var. {nameCache}'
1453
 *
1454
 * Related issues:
1455
 *   - https://dev.e-taxonomy.eu/redmine/issues/5697 "Show name conserved against as [non xxx]"
1456
 *   - https://dev.e-taxonomy.eu/redmine/issues/6678 "How to correctly show name relationship "orth. var." in dataportal"
1457
 *   - https://dev.e-taxonomy.eu/redmine/issues/5857
1458
 *   - https://dev.e-taxonomy.eu/redmine/issues/2001 "[Cichorieae Portal] Name Relationship -> blocking name are not shown"
1459
 *
1460
 * @param $name_relations
1461
 *    The list of CDM NameRelationsips
1462
 * @param $current_name_uuid
1463
 *    The Uuid of the name for which the relations are to be rendered, the current name will be hidden when
1464
 *    rendering the relation an only the other name is shown. Parameter is REQUIRED.
1465
 * @param $suppress_if_current_name_is_source
1466
 *    The display of the relation will be
1467
 *    suppressed is the current name is on the source of the relation edge.
1468
 *    That is if it is on the from side of the relation. Except for 'blocking name for' which is
1469
 *    an inverse relation. For this relation type the toName is taken in to account.
1470
 * @param $current_taxon_uuid
1471
 *    The taxon to be omitted from related taxa. This is only used to create links, see path_to_name()
1472
 * @return array
1473
 *    A drupal render array
1474
 *
1475
 * @ingroup Compose
1476
 */
1477
function compose_name_relationships_inline($name_relations, $current_name_uuid, $current_taxon_uuid, $suppress_if_current_name_is_source = true) {
1478

    
1479
  RenderHints::pushToRenderStack('homonym');
1480
  // the render stack element homonyms is being used in the default render templates !!!, see NameRenderConfiguration::CDM_NAME_RENDER_TEMPLATES_DEFAULT
1481

    
1482
  $selected_name_rel_uuids = variable_get(CDM_NAME_RELATIONSHIP_INLINE_TYPES, unserialize(CDM_NAME_RELATIONSHIP_INLINE_TYPES_DEFAULT));
1483
  $name_rel_type_filter = array('direct' => array(), 'inverse' => array());
1484
  foreach ($selected_name_rel_uuids as $uuid){
1485
    $name_rel_type_filter['direct'][$uuid] = $uuid;
1486
    if($uuid != UUID_NAMERELATIONSHIPTYPE_MISSPELLING){
1487
      $name_rel_type_filter['inverse'][$uuid] = $uuid;
1488
    }
1489
  }
1490

    
1491
  $list_prefix = '<span class="name_relationships">[';
1492
  $list_suffix = ']</span>';
1493
  $item_prefix = '<span class="item">';
1494
  $item_suffix = '</span> ';
1495
  $render_array = compose_name_relationships($name_relations, $name_rel_type_filter, $current_name_uuid, $current_taxon_uuid, $list_prefix, $list_suffix, $item_prefix, $item_suffix);
1496

    
1497
  // remove the glue space from the last item element which has been added by the $item_suffix = '</span> '
1498
  $items_ctn = count($render_array['list']['items']);
1499
  if($items_ctn){
1500
    $render_array['list']['items'][$items_ctn - 1]['#suffix'] = '</span>';
1501
  }
1502

    
1503
  RenderHints::popFromRenderStack();
1504
  return $render_array;
1505
}
1506

    
1507
/**
1508
 * Composes an list representation of the name relationships.
1509
 *
1510
 * The output of this function will be usually appended to taxon name representations.
1511
 *
1512
 * Related issues:
1513
 *   - https://dev.e-taxonomy.eu/redmine/issues/5697 "Show name conserved against as [non xxx]"
1514
 *   - https://dev.e-taxonomy.eu/redmine/issues/6678 "How to correctly show name relationship "orth. var." in dataportal"
1515
 *   - https://dev.e-taxonomy.eu/redmine/issues/5857
1516
 *
1517
 * @param $name_relations
1518
 *    The list of CDM NameRelationsips
1519
 * @param $current_name_uuid
1520
 *    The Uuid of the name for which the relations are to be rendered, the current name will be hidden when
1521
 *    rendering the relation an only the other name is shown. Parameter is REQUIRED.
1522
 * @param $current_taxon_uuid
1523
 *    The taxon to be omitted from related taxa. This is only used to create links, see path_to_name()
1524
 * @return array
1525
 *    A drupal render array
1526
 *
1527
 * @ingroup Compose
1528
 */
1529
function compose_name_relationships_list($name_relations, $current_name_uuid, $current_taxon_uuid) {
1530

    
1531
  // $ordered_name_relation_type_uuids = array_keys(cdm_terms_by_type_as_option('NameRelationshipType', CDM_ORDER_BY_ORDER_INDEX_ASC));
1532

    
1533
  $key = 'name_relationships';
1534
  RenderHints::pushToRenderStack($key);
1535
  if(RenderHints::isUnsetFootnoteListKey()){
1536
    RenderHints::setFootnoteListKey($key);
1537
  }
1538
  // the render stack element homonyms is being used in the default render templates !!!, see CDM_NAME_RENDER_TEMPLATES_DEFAULT
1539

    
1540
  $selected_name_rel_uuids = variable_get(CDM_NAME_RELATIONSHIP_LIST_TYPES, cdm_vocabulary_as_defaults(UUID_NAME_RELATIONSHIP_TYPE));
1541
  $name_rel_type_filter = array('direct' => array(), 'inverse' => array());
1542
  foreach ($selected_name_rel_uuids as $uuid){
1543
    $name_rel_type_filter['direct'][$uuid] = $uuid;
1544
    $name_rel_type_filter['inverse'][$uuid] = $uuid;
1545
  }
1546

    
1547
  $list_prefix = '<div class="relationships_list name_relationships">';
1548
  $list_suffix = '</div>';
1549
  $item_prefix = '<div class="item">';
1550
  $item_suffix = '</div>';
1551

    
1552
  $render_array = compose_name_relationships($name_relations, $name_rel_type_filter, $current_name_uuid, $current_taxon_uuid, $list_prefix, $list_suffix, $item_prefix, $item_suffix);
1553

    
1554
  RenderHints::popFromRenderStack();
1555
  if(RenderHints::getFootnoteListKey() == $key) {
1556
    $render_array['footnotes'] = markup_to_render_array(render_footnotes(RenderHints::getFootnoteListKey()));
1557
    RenderHints::clearFootnoteListKey();
1558
  }
1559
  return $render_array;
1560
}
1561

    
1562
/**
1563
 * @param $name_relations
1564
 * @param $name_rel_type_filter
1565
 *   Associative array with two keys:
1566
 *   - 'direct': the relationship type uuids for the direct direction of the relation edge to be included
1567
 *   - 'inverse': the relationship type uuids for the direct direction of the relation edge to be included
1568
 * @param $current_name_uuid
1569
 * @param $current_taxon_uuid
1570
 * @param $list_prefix
1571
 * @param $list_suffix
1572
 * @param $item_prefix
1573
 * @param $item_suffix
1574
 * @return array
1575
 *
1576
 * @ingroup Compose
1577
 */
1578
function compose_name_relationships($name_relations, $name_rel_type_filter, $current_name_uuid, $current_taxon_uuid,
1579
                                    $list_prefix, $list_suffix, $item_prefix, $item_suffix)
1580
{
1581
  $non_nec_name_reltype_uuids = array(UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM,
1582
    UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM,
1583
    UUID_NAMERELATIONSHIPTYPE_CONSERVED_AGAINST,
1584
    UUID_NAMERELATIONSHIPTYPE_MISSPELLING,
1585
    UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR);
1586

    
1587
  $render_array = array(
1588
    'list' => array(
1589
      '#prefix' => $list_prefix,
1590
      '#suffix' => $list_suffix,
1591
      'items' => array()
1592
    ),
1593
    'footnotes' => array()
1594
  );
1595

    
1596
  if ($name_relations) {
1597

    
1598
    // remove all relations which are not selected in the settings and
1599
    // separate all LATER_HOMONYM, TREATED_AS_LATER_HOMONYM, BLOCKING_NAME_FOR relations and ORTHOGRAPHIC_VARIANTs
1600
    // for special handling
1601
    $filtered_name_rels = array();
1602
    $non_nec_name_rels = array();
1603
    $orthographic_variants = array();
1604
    foreach ($name_relations as $name_rel) {
1605
      $rel_type_uuid = $name_rel->type->uuid;
1606
      $is_inverse_relation = $current_name_uuid == $name_rel->toName->uuid;
1607
      if ((!$is_inverse_relation && isset($name_rel_type_filter['direct'][$rel_type_uuid]) && $name_rel_type_filter['direct'][$rel_type_uuid])
1608
        ||($is_inverse_relation && isset($name_rel_type_filter['inverse'][$rel_type_uuid]) && $name_rel_type_filter['inverse'][$rel_type_uuid])) {
1609

    
1610
        if (array_search($rel_type_uuid, $non_nec_name_reltype_uuids) !== false && (
1611
            $current_name_uuid == $name_rel->fromName->uuid && $rel_type_uuid != UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR
1612
            || $current_name_uuid == $name_rel->toName->uuid && $rel_type_uuid == UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR
1613
          )
1614
        ){
1615
          $non_nec_name_rels[] = $name_rel;
1616
        } else if (UUID_NAMERELATIONSHIPTYPE_ORTHOGRAPHIC_VARIANT == $rel_type_uuid) {
1617
          $orthographic_variants[] = $name_rel;
1618
        } else {
1619

    
1620
          $filtered_name_rels[] = $name_rel;
1621
        }
1622
      }
1623
    }
1624
    $name_relations = $filtered_name_rels;
1625

    
1626
    usort($name_relations, 'compare_name_relations_by_term_order_index');
1627

    
1628
    // compose
1629
    $show_name_cache_only = FALSE;
1630
    foreach ($name_relations as $name_rel) {
1631

    
1632
      $is_inverse_relation = $current_name_uuid == $name_rel->toName->uuid;
1633
      $rel_footnote_key_markup = render_footnote_key(handle_name_relationship_as_footnote($name_rel),'');
1634
      $relationship_markup = name_relationship_markup($current_name_uuid, $name_rel, $current_taxon_uuid, $show_name_cache_only);
1635
      $label = cdm_relationship_type_term_abbreviated_label($name_rel->type, $is_inverse_relation);
1636

    
1637
      $symbol = cdm_relationship_type_term_symbol($name_rel->type, $is_inverse_relation);
1638
      $symbol_markup = '<span class="symbol" title="' . $label . '">' . $symbol . '</span>' . $rel_footnote_key_markup . ' ';
1639
      $relationship_markup = $symbol_markup . $relationship_markup;
1640
      if ($relationship_markup) {
1641
        $render_array['list']['items'][] = markup_to_render_array($relationship_markup,
1642
          null,
1643
          $item_prefix,
1644
          $item_suffix);
1645
      }
1646
    }
1647

    
1648
    // name relationships to be displayed as non nec
1649
    if (count($non_nec_name_rels) > 0) {
1650
      $non_nec_markup = '';
1651
      $show_name_cache_only = FALSE;
1652
      foreach ($non_nec_name_rels as $name_rel) {
1653

    
1654
        $is_inverse_relation = $current_name_uuid == $name_rel->toName->uuid;
1655
        $rel_footnote_key_markup = render_footnote_key(handle_name_relationship_as_footnote($name_rel),'');
1656
        $relationship_markup = name_relationship_markup($current_name_uuid, $name_rel, $current_taxon_uuid, $show_name_cache_only);
1657
        $label = cdm_relationship_type_term_abbreviated_label($name_rel->type, $is_inverse_relation);
1658

    
1659
        $symbol = $non_nec_markup ? ' nec ' : 'non';
1660
        $symbol_markup = '<span class="symbol" title="' . $label . '">' . $symbol . '</span>' . $rel_footnote_key_markup .  ' ';
1661
        $non_nec_markup .= $symbol_markup . $relationship_markup;
1662
      }
1663
      if ($non_nec_markup) {
1664
        $render_array['list']['items'][] = markup_to_render_array($non_nec_markup,
1665
          null,
1666
          $item_prefix,
1667
          $item_suffix);
1668
      }
1669
    }
1670

    
1671
    // orthographic variants
1672
    if (count($orthographic_variants) > 0) {
1673
      $show_name_cache_only = TRUE;
1674
      foreach ($orthographic_variants as $name_rel) {
1675

    
1676
        $is_inverse_relation = $current_name_uuid == $name_rel->toName->uuid;
1677
        $rel_footnote_key_markup = render_footnote_key(handle_name_relationship_as_footnote($name_rel),'');
1678
        $relationship_markup = name_relationship_markup($current_name_uuid, $name_rel, $current_taxon_uuid, $show_name_cache_only);
1679
        $label = cdm_relationship_type_term_abbreviated_label($name_rel->type, $is_inverse_relation);
1680
        $symbol = cdm_relationship_type_term_symbol($name_rel->type, $is_inverse_relation);
1681
        $symbol_markup = '<span class="symbol" title="' . $label . '">' . $symbol . '</span>' . $rel_footnote_key_markup .  ' ';
1682
        $relationship_markup = $symbol_markup . $relationship_markup;
1683
      }
1684
      if (isset($relationship_markup) && $relationship_markup) {
1685
        $render_array['list']['items'][] = markup_to_render_array($relationship_markup,
1686
          null,
1687
          $item_prefix,
1688
          $item_suffix);
1689
      }
1690
    }
1691
  }
1692
  return $render_array;
1693
}
1694

    
1695

    
1696

    
1697
/**
1698
 * @param $taxon
1699
 * @return array
1700
 */
1701
function cdm_name_relationships_for_taxon($taxon)
1702
{
1703
  $from_name_relations = cdm_ws_get(CDM_WS_PORTAL_TAXON_FROM_NAMERELATIONS, $taxon->uuid);
1704
  $to_name_relations = cdm_ws_get(CDM_WS_PORTAL_TAXON_TO_NAMERELATIONS, $taxon->uuid);
1705
  $name_relations = array_merge($from_name_relations, $to_name_relations);
1706
  return $name_relations;
1707
}
1708

    
1709

    
1710
/**
1711
 * Recursively searches the array for the $key and sets the given value.
1712
 *
1713
 * Expects the key to be used only once in nested array structures.
1714
 *
1715
 * @param mixed $key
1716
 *   Key to search for.
1717
 * @param mixed $value
1718
 *   Value to set.'
1719
 * @param array $array
1720
 *   Array to search in.
1721
 *
1722
 * @return array
1723
 *   The array the key has been found.
1724
 */
1725
function &array_setr($key, $value, array &$array) {
1726
  $res = NULL;
1727
  foreach ($array as $k => &$v) {
1728
    if ($key == $k) {
1729
      $v = $value;
1730
      return $array;
1731
    }
1732
    elseif (is_array($v)) {
1733
      $innerArray = array_setr($key, $value, $v);
1734
      if ($innerArray) {
1735
        return $array;
1736
      }
1737
    }
1738
  }
1739
  return $res;
1740
}
1741

    
1742
/**
1743
 * Recursively searches the array for the $key and sets is to $new_key
1744
 *
1745
 * Expects the key to be used only once in nested array structures.
1746
 *
1747
 * @param mixed $key
1748
 *   Key to search for.
1749
 * @param mixed $new_key
1750
 *   The new key to use
1751
 * @param array $array
1752
 *   Array to search in.
1753
 *
1754
 * @return bool
1755
 *   True if the key has been found.
1756
 */
1757
function array_replace_keyr($key, $new_key, array &$array) {
1758
  $res = NULL;
1759
  if(array_key_exists($key, $array)){
1760
    $value = $array[$key];
1761
    unset($array[$key]);
1762
    $array[$new_key] = $value;
1763
    return true;
1764
  } else {
1765
    // search in next level
1766
    foreach ($array as &$v) {
1767
        if (is_array($v)) {
1768
          array_replace_keyr($key, $new_key, $v);
1769
        }
1770
      }
1771
  }
1772

    
1773
  return false;
1774
}
1775

    
1776
/**
1777
 * @todo Please document this function.
1778
 * @see http://drupal.org/node/1354
1779
 */
1780
function &get_preceding_contentElement($contentElementKey, array &$renderTemplate) {
1781
  $res = NULL;
1782
  $precedingElement = NULL;
1783
  foreach ($renderTemplate as &$part) {
1784
    foreach ($part as $key => &$element) {
1785
      if ($key == $contentElementKey) {
1786
        return $precedingElement;
1787
      }
1788
      $precedingElement = $element;
1789
    }
1790
  }
1791
  return $res;
1792
}
1793

    
1794
/**
1795
 * @todo Please document this function.
1796
 * @see http://drupal.org/node/1354
1797
 */
1798
function &get_preceding_contentElementKey($contentElementKey, array &$renderTemplate) {
1799
  $res = NULL;
1800
  $precedingKey = NULL;
1801
  foreach ($renderTemplate as &$part) {
1802
    if (is_array($part)) {
1803
      foreach ($part as $key => &$element) {
1804
        if ($key == $contentElementKey) {
1805
          return $precedingKey;
1806
        }
1807
        if (!str_beginsWith($key, '#')) {
1808
          $precedingKey = $key;
1809
        }
1810
      }
1811
    }
1812
  }
1813
  return $res;
1814
}
1815

    
1816
function nameTypeToDTYPE($dtype){
1817
  static $nameTypeLabelMap = array(
1818
    "ICNB" => "BacterialName",
1819
    "ICNAFP" => "BotanicalName",
1820
    "ICNCP" => "CultivarPlantName",
1821
    "ICZN" => "ZoologicalName",
1822
    "ICVCN" => "ViralName",
1823
    "Any taxon name" => "TaxonName",
1824
    "NonViral" => "TaxonName",
1825
    "Fungus" => "BotanicalName",
1826
    "Plant" => "BotanicalName",
1827
    "Algae" => "BotanicalName",
1828
  );
1829
  return $nameTypeLabelMap[$dtype];
1830

    
1831
}
1832

    
1833

    
1834
function compare_name_relations_by_term_order_index($name_rel1, $name_rel2){
1835
  return compare_terms_by_order_index($name_rel1->type, $name_rel2->type);
1836
}
1837

    
1838
/**
1839
 * Provides an array with the different registration types covered by the passed registration.
1840
 *
1841
 * The labels in the returned array are translatable.
1842
 *
1843
 * See also https://dev.e-taxonomy.eu/redmine/issues/8016
1844
 *
1845
 * @param $registration_dto
1846
 * @return array
1847
 *    An array of the labels describing the different registration types covered by the passed registration.
1848
 */
1849
function registration_types($registration_dto){
1850
  $reg_type_labels = array();
1851
  if(isset($registration_dto->nameRef)){
1852
    $reg_type_labels["name"] = t("new name");
1853
    $reg_type_labels["taxon"] = t("new taxon");
1854
    $name_relations = cdm_ws_fetch_all(str_replace("$0", $registration_dto->nameRef->uuid, CDM_WS_PORTAL_NAME_NAME_RELATIONS));
1855
    $is_new_combination = true;
1856
    foreach($name_relations as $name_rel){
1857
      if(isset($name_rel->type->uuid)){
1858
        $name_is_from_name = $registration_dto->nameRef->uuid == $name_rel->fromName->uuid;
1859
        switch($name_rel->type->uuid) {
1860
          case UUID_NAMERELATIONSHIPTYPE_BASIONYM:
1861
            if(!$name_is_from_name){
1862
              $reg_type_labels["basionym"] = t("new combination");
1863
              $is_new_combination = true;
1864
            }
1865
            break;
1866
          case UUID_NAMERELATIONSHIPTYPE_REPLACED_SYNONYM:
1867
            if(!$name_is_from_name) {
1868
              $is_new_combination = true;
1869
            }
1870
            break;
1871
          case UUID_NAMERELATIONSHIPTYPE_VALIDATED_BY_NAME:
1872
            if(!$name_is_from_name) {
1873
              $reg_type_labels["validation"] = t("validation");
1874
            }
1875
            break;
1876
          case UUID_NAMERELATIONSHIPTYPE_ORTHOGRAPHIC_VARIANT:
1877
            if(!$name_is_from_name) {
1878
              $reg_type_labels["orth_var"] = t("orthographical correction");
1879
            }break;
1880
          default:
1881
            // NOTHING
1882
        }
1883
      }
1884
    }
1885
    if($is_new_combination){
1886
      unset($reg_type_labels["taxon"]);
1887
    }
1888
  }
1889
  if(isset($registration_dto->orderedTypeDesignationWorkingSets)){
1890
    $reg_type_labels[] = t("new nomenclatural type");
1891
  }
1892
  return $reg_type_labels;
1893
}
1894

    
1895
/**
1896
 * Collects and deduplicates the type designations associated with the passes synonyms.
1897
 *
1898
 * @param $synonymy_group
1899
 *    An array containing a homotypic or heterotypic group of names.
1900
 * @param $accepted_taxon_name_uuid
1901
 *    The uuid of the accepted taxon name. Optional parameter which is required when composing
1902
 *    the information for the homotypic group. In this case the accepted taxon is not included
1903
 *    in the $synonymy_group and must therefor passed in this second parameter.
1904
 *
1905
 * @return array
1906
 *    The CDM TypeDesignation entities
1907
 */
1908
function type_designations_for_synonymy_group($synonymy_group, $accepted_taxon_name_uuid = null)
1909
{
1910
  if (count($synonymy_group) > 0) {
1911
    $name_uuid = array_pop($synonymy_group)->name->uuid;
1912
  } else {
1913
    $name_uuid = $accepted_taxon_name_uuid;
1914
  }
1915
  if ($name_uuid) {
1916
   $type_designations = cdm_ws_get(CDM_WS_PORTAL_NAME_TYPEDESIGNATIONS_IN_HOMOTYPICAL_GROUP, $name_uuid);
1917
    if ($type_designations) {
1918
      return $type_designations;
1919
    }
1920
  }
1921

    
1922
  return array();
1923
}
1924

    
1925

    
1926
/**
1927
 * Compares two SpecimenTypeDesignations
1928
 *
1929
 * @param object $a
1930
 *   A SpecimenTypeDesignation.
1931
 * @param object $b
1932
 *   SpecimenTypeDesignation.
1933
 */
1934
function compare_specimen_type_designation($a, $b) {
1935

    
1936
  $cmp_by_status = compare_type_designations_by_status($a,$b);
1937
  if($cmp_by_status !== 0){
1938
    return $cmp_by_status;
1939
  }
1940

    
1941
  $aQuantifier = FALSE;
1942
  $bQuantifier = FALSE;
1943
  if ($aQuantifier == $bQuantifier) {
1944
    // Sort alphabetically.
1945
    $a_text =  isset($a->typeSpecimen->titleCache) ? preg_replace('/[\[\]\"]/', '', $a->typeSpecimen->titleCache) : '';
1946
    $b_text =  isset($b->typeSpecimen->titleCache) ? preg_replace('/[\[\]\"]/', '', $b->typeSpecimen->titleCache) : '';
1947
    return strcasecmp($a_text, $b_text);
1948
  }
1949
  return ($aQuantifier < $bQuantifier) ? -1 : (($aQuantifier > $bQuantifier) ? 1 : 0);
1950
}
1951

    
1952
/**
1953
 * Compares the status of two TypeDesignations
1954
 *
1955
 * @param object $a
1956
 *   A TypeDesignation
1957
 * @param object $b
1958
 *   TypeDesignation
1959
 */
1960
function compare_type_designations_by_status($a, $b) {
1961
  $status_a = isset($a->typeStatus) ? $a->typeStatus : null;
1962
  $status_b = isset($b->typeStatus) ? $b->typeStatus : null;
1963
  return compare_type_designation_status($status_a, $status_b);
1964
}
1965

    
1966
/**
1967
 * Compares two TypeDesignationStatusBase
1968
 *
1969
 * @param object $a
1970
 *   A TypeDesignationStatusBase.
1971
 * @param object $b
1972
 *   TypeDesignationStatusBase.
1973
 */
1974
function compare_type_designation_status($a, $b) {
1975
  $type_status_order = type_status_order();
1976
  $aQuantifier = FALSE;
1977
  $bQuantifier = FALSE;
1978
  if (isset($a->label) && isset($b->label)) {
1979
    $aQuantifier = array_search($a->label, $type_status_order);
1980
    $bQuantifier = array_search($b->label, $type_status_order);
1981
  }
1982
  return ($aQuantifier < $bQuantifier) ? -1 : (($aQuantifier > $bQuantifier) ? 1 : 0);
1983
}
1984

    
1985
/**
1986
 * Compares the two TextualTypeDesignations
1987
 *
1988
 * @param object $a
1989
 *   A TextualTypeDesignations.
1990
 * @param object $b
1991
 *   TextualTypeDesignations.
1992
 */
1993
function compare_textual_type_designation($a, $b) {
1994

    
1995
  $cmp_by_status = compare_type_designations_by_status($a,$b);
1996
  if($cmp_by_status !== 0){
1997
    return $cmp_by_status;
1998
  }
1999

    
2000
  $aQuantifier = FALSE;
2001
  $bQuantifier = FALSE;
2002
  if ($aQuantifier == $bQuantifier) {
2003
    // Sort alphabetically.
2004
    $a_text =  isset($a->text_L10n->text) ? $a->text_L10n->text : '';
2005
    $b_text =  isset($b->text_L10n->text) ? $b->text_L10n->text : '';
2006
    return strcasecmp($a_text, $b_text);
2007
  }
2008
  return ($aQuantifier < $bQuantifier) ? -1 : (($aQuantifier > $bQuantifier) ? 1 : 0);
2009
}
2010

    
2011

    
2012
/**
2013
 * Compares two SpecimenTypeDesignation status labels
2014
 *
2015
 * @param string $a
2016
 *   A TypeDesignationStatus label.
2017
 * @param string $b
2018
 *   A TypeDesignationStatus label.
2019
 */
2020
function compare_type_designation_status_labels($a, $b) {
2021

    
2022
  $type_status_order = type_status_order();
2023

    
2024
  $aQuantifier = FALSE;
2025
  $bQuantifier = FALSE;
2026
  if (isset($a) && isset($b)) {
2027
    $aQuantifier = array_search(ucfirst($a), $type_status_order);
2028
    $bQuantifier = array_search(ucfirst($b), $type_status_order);
2029
  }
2030
  return ($aQuantifier < $bQuantifier) ? -1 : 1;
2031
}
2032

    
2033
/**
2034
 * Preliminary implementation of a preset to define a sort order for
2035
 * type designation status.
2036
 *
2037
 * TODO this is only preliminary and may break in future,
2038
 *      see https://dev.e-taxonomy.eu/redmine/issues/8402?issue_count=96&issue_position=4&next_issue_id=8351&prev_issue_id=7966#note-4
2039
 * @return array
2040
 *   The array of orderd type labels
2041
 */
2042
function type_status_order()
2043
{
2044
  /*
2045
    This is the desired sort order as of now: Holotype Isotype Lectotype
2046
    Isolectotype Syntype.
2047
    TODO Basically, what we are trying to do is, we define
2048
    an ordered array of TypeDesignation-states and use the index of this array
2049
    for comparison. This array has to be filled with the cdm- TypeDesignation
2050
    states and the order should be parameterisable inside the dataportal.
2051
    */
2052
  static $type_status_order = array(
2053
    'Epitype',
2054
    'Holotype',
2055
    'Isotype',
2056
    'Lectotype',
2057
    'Isolectotype',
2058
    'Syntype',
2059
    'Paratype'
2060
  );
2061
  return $type_status_order;
2062
}
2063

    
2064
/**
2065
 * Return HTML for the lectotype citation with the correct layout.
2066
 *
2067
 * This function prints the lectotype citation with the correct layout.
2068
 * Lectotypes are renderized in the synonymy tab of a taxon if they exist.
2069
 *
2070
 * @param mixed $typeDesignation
2071
 *   Object containing the lectotype citation to print.
2072
 *
2073
 * @return string
2074
 *   Valid html string.
2075
 */
2076
function type_designation_citation_layout($typeDesignation, $footnote_separator = ',') {
2077
  $res = '';
2078
  $citation = $typeDesignation->designationSource->citation;
2079
  $pages = $typeDesignation->designationSource->citationMicroReference;
2080
  if(isset($typeDesignation->typeStatus->uuid) && isset($typeDesignation->typeStatus->representation_L10n)) {
2081
    if ( $typeDesignation->typeStatus->uuid == UUID_NTD_ORIGINAL_DESIGNATION || $typeDesignation->typeStatus->uuid == UUID_NTD_MONOTYPY) {
2082
      $res = ' (' . $typeDesignation->typeStatus->representation_L10n . ')';
2083
      return $res;
2084
    }
2085
  }
2086

    
2087
  if ($citation) {
2088
    // $type = $typeDesignation_citation->type;
2089
    $year = isset($citation->datePublished->start) ? substr($citation->datePublished->start, 0, 4) : '';
2090
    $author = isset($citation->authorship->titleCache) ? $citation->authorship->titleCache : '';
2091
    $res .= ' (designated by ';
2092
    $res .= $author;
2093
    $res .= ($year ? ' ' . $year : '');
2094
    $res .= ($pages ? ': ' . $pages : '');
2095
    // $res .= ')';
2096

    
2097
    // footnotes should be rendered in the parent element so we
2098
    // are relying on the FootnoteListKey set there
2099
    $fkey_typeDesignation = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), $citation->titleCache);
2100
    $res .= render_footnote_key($fkey_typeDesignation, $footnote_separator,TRUE) . ')';
2101
  }
2102
  return $res;
2103
}
2104

    
2105
/**
2106
 * 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"
2107
 *
2108
 * @param $type_designation
2109
 * @return string
2110
 */
2111
function type_designation_status_label_markup($type_designation)
2112
{
2113
  return '<span class="type-status">'
2114
    . ((isset($type_designation->typeStatus->representation_L10n)) ? ucfirst($type_designation->typeStatus->representation_L10n) : t('Type')) . '</span>'
2115
    ;
2116
}
2117

    
2118
/**
2119
 * Creates markup for the status of a type designation DTO.
2120
 * In case the status or its representation is missing the label will be set to "Type"
2121
 *
2122
 * @param $type_designation
2123
 * @return string
2124
 */
2125
function type_designation_dto_status_label_markup($type_designation)
2126
{
2127
  return '<span class="type-status">'
2128
    . ((isset($type_designation->typeStatus_L10n)) ? ucfirst($type_designation->typeStatus_L10n) : t('Type')) . '</span>'
2129
    ;
2130
}
(7-7/16)