Project

General

Profile

Download (83.9 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
        // TODO is this case still relevant? The tagged text should already contain all information!
418
        $citation = cdm_ws_getNomenclaturalReference($taxon_name->nomenclaturalSource->citation->uuid, $microreference);
419
        // Find preceding element of the reference.
420
        $precedingKey = get_preceding_contentElementKey('reference', $renderTemplate);
421
        if (str_beginsWith($citation, ", in")) {
422
          $citation = substr($citation, 2);
423
          $separator = ' ';
424
        }
425
        elseif (!str_beginsWith($citation, "in") && $precedingKey == 'authors') {
426
          $separator = ', ';
427
        } else {
428
          $separator = ' ';
429
        }
430
        $referenceArray['#separator'] = $separator;
431
        $referenceArray['#html'] = '<span class="reference">' . $citation . '</span>' . $registration_markup;
432
      } else {
433
        // this is the case for taxon names
434
        $referenceArray['#html'] = cdm_tagged_text_to_markup($nomref_tagged_text);
435
      }
436

    
437
      array_setr('reference', $referenceArray, $renderTemplate);
438
    }
439

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

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

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

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

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

    
511
    // ---------------
512

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

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

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

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

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

    
618

    
619

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

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

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

    
655
    '#suffix' => '</div>'
656
  );
657

    
658
  $typified_name = null;
659

    
660
  // Nomenclatural act block element
661
  $last_footnote_listkey = RenderHints::setFootnoteListKey("nomenclatural_act");
662
  // name
663
  $name_relations = null;
664
  if(isset($registration_dto->nameRef) && $registration_dto->nameRef){
665
    $name = cdm_ws_get(CDM_WS_PORTAL_NAME, $registration_dto->nameRef->uuid);
666
    cdm_load_tagged_full_title($name);
667
    $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);
668
    $name_relations = cdm_ws_fetch_all(str_replace("$0", $registration_dto->nameRef->uuid, CDM_WS_PORTAL_NAME_NAME_RELATIONS));
669
    // need to create the name relationships later, so that the foot notes are in correct order, see section // name relations
670
  } else {
671
    // in this case the registration must have a
672
    // typified name will be rendered later
673
    $typified_name = cdm_ws_get(CDM_WS_PORTAL_NAME, $registration_dto->typifiedNameRef->uuid);
674

    
675
  }
676

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

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

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

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

    
739
  $render_array['nomenclatural_act']['footnotes'] = markup_to_render_array(render_footnotes(),100);
740

    
741
  // END of nomenclatural act block
742
  RenderHints::setFootnoteListKey($last_footnote_listkey );
743

    
744
  if($typified_name){
745
    $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);
746
  }
747

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

    
756
  $render_array['page_footnotes'] = markup_to_render_array(render_footnotes(), 110);
757

    
758
  return $render_array;
759
}
760

    
761

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

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

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

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

    
829
  return $render_array;
830
}
831

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

    
860

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

    
879

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

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

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

    
916

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

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

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

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

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

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

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

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

    
998
      if (!empty($specimen_type_designation->designationSource->citation)) {
999

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

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

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

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

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

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

    
1038

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

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

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

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

    
1098
  RenderHints::popFromRenderStack();
1099

    
1100
  return $out;
1101
}
1102

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

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

    
1123
  $out = '<' . $enclosing_tag .' class="typeDesignations">';
1124
  $separator = ',';
1125

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

    
1131
      if (!empty($std_dto->designationSource->citation)) {
1132

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

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

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

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

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

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

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

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

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

    
1201

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

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

    
1233

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

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

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

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

    
1287
  $render_array = array();
1288

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

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

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

    
1301

    
1302
      $preferredStableUri = '';
1303
      $citation_markup = '';
1304
      $media = '';
1305

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

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

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

    
1346
      $citation_markup = join(', ', $source_citations);
1347

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

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

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

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

    
1392
  $relationship_markup = null;
1393

    
1394
  $other_name = get_other_name($current_name_uuid, $name_rel);
1395

    
1396
  cdm_load_tagged_full_title($other_name);
1397

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

    
1413
  return $relationship_markup;
1414
}
1415

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

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

    
1439

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

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

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

    
1489
  $list_prefix = '<span class="name_relationships">[';
1490
  $list_suffix = ']</span>';
1491
  $item_prefix = '<span class="item">';
1492
  $item_suffix = '</span> ';
1493
  $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);
1494

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

    
1501
  RenderHints::popFromRenderStack();
1502
  return $render_array;
1503
}
1504

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

    
1529
  // $ordered_name_relation_type_uuids = array_keys(cdm_terms_by_type_as_option('NameRelationshipType', CDM_ORDER_BY_ORDER_INDEX_ASC));
1530

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

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

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

    
1550
  $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);
1551

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

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

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

    
1594
  if ($name_relations) {
1595

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

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

    
1618
          $filtered_name_rels[] = $name_rel;
1619
        }
1620
      }
1621
    }
1622
    $name_relations = $filtered_name_rels;
1623

    
1624
    usort($name_relations, 'compare_name_relations_by_term_order_index');
1625

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

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

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

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

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

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

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

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

    
1693

    
1694

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

    
1707

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

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

    
1771
  return false;
1772
}
1773

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

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

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

    
1829
}
1830

    
1831

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

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

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

    
1920
  return array();
1921
}
1922

    
1923

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

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

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

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

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

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

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

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

    
2009

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

    
2020
  $type_status_order = type_status_order();
2021

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

    
2031
/**
2032
 * Preliminary implementation of a preset to define a sort order for
2033
 * type designation status.
2034
 *
2035
 * TODO this is only preliminary and may break in future,
2036
 *      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
2037
 * @return array
2038
 *   The array of orderd type labels
2039
 */
2040
function type_status_order()
2041
{
2042
  /*
2043
    This is the desired sort order as of now: Holotype Isotype Lectotype
2044
    Isolectotype Syntype.
2045
    TODO Basically, what we are trying to do is, we define
2046
    an ordered array of TypeDesignation-states and use the index of this array
2047
    for comparison. This array has to be filled with the cdm- TypeDesignation
2048
    states and the order should be parameterisable inside the dataportal.
2049
    */
2050
  static $type_status_order = array(
2051
    'Epitype',
2052
    'Holotype',
2053
    'Isotype',
2054
    'Lectotype',
2055
    'Isolectotype',
2056
    'Syntype',
2057
    'Paratype'
2058
  );
2059
  return $type_status_order;
2060
}
2061

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

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

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

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

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