Project

General

Profile

Download (24.2 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/**
3
 * @file
4
 * Functions for dealing with CDM entities from the package model.name
5
 *
6
 * @copyright
7
 *   (C) 2007-2015 EDIT
8
 *   European Distributed Institute of Taxonomy
9
 *   http://www.e-taxonomy.eu
10
 *
11
 *   The contents of this module are subject to the Mozilla
12
 *   Public License Version 1.1.
13
 * @see http://www.mozilla.org/MPL/MPL-1.1.html
14
 *
15
 * @author
16
 *   - Andreas Kohlbecker <a.kohlbecker@BGBM.org>
17
 */
18

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

    
33

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

    
78

    
79
  if (!isset($default_render_templates)) {
80
    $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
81
  }
82
  if($split_render_templates == NULL) {
83
    $render_templates = variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates);
84
    // needs to be converted to an array
85
    $render_templates = (convert_to_array($render_templates));
86

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

    
100
  // get the base element of the renderPath
101
  if (($separatorPos = strpos($render_path, '.')) > 0) {
102
    $renderPath_base = substr($render_path, 0, $separatorPos);
103
  } else {
104
    $renderPath_base = $render_path;
105
  }
106

    
107
  $template = NULL;
108
  // 1. try to find a template using the render path base element
109
  if(array_key_exists($renderPath_base, $split_render_templates)){
110
    $template = (array)$split_render_templates[$renderPath_base];
111
  }
112

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

    
127

    
128
  // 3. Otherwise get default RenderTemplate from theme.
129
  if (!is_array($template)) {
130
    $template = $split_render_templates['#DEFAULT'];
131
  }
132

    
133
  // --- set the link uris to the according template fields if they exist
134
  if(isset($template['nameAuthorPart']) && isset($template['nameAuthorPart']['#uri'])) {
135
    if ($nameLink) {
136
      $template['nameAuthorPart']['#uri'] = $nameLink;
137
    }
138
    else {
139
      unset($template['nameAuthorPart']['#uri']);
140
    }
141
  }
142

    
143
  if ($nameLink && isset($template['namePart']['#uri'])) {
144
    $template['namePart']['#uri'] = $nameLink;
145
  }
146
  else {
147
    unset($template['namePart']['#uri']);
148
  }
149

    
150
  if ($referenceLink && isset($template['referencePart']['#uri'])) {
151
    $template['referencePart']['#uri'] = $referenceLink;
152
  }
153
  else {
154
    unset($template['referencePart']['#uri']);
155
  }
156

    
157
  return $template;
158
}
159

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

    
222
  static $default_part_definitions = null;
223
  if (!isset($default_part_definitions)) {
224
    $default_part_definitions= unserialize(CDM_PART_DEFINITIONS_DEFAULT);
225
  }
226

    
227
  static $part_definitions = null;
228
  if (!isset($part_definitions)) {
229
    $part_definitions = convert_to_array(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions));
230
  }
231

    
232
  if (array_key_exists($taxonNameType, $part_definitions)) {
233
    return $part_definitions[$taxonNameType];
234
  } else {
235
    return $part_definitions['#DEFAULT']; // covers ViralNames and general NonViralNames
236
  }
237

    
238
}
239

    
240

    
241
/**
242
 * Renders the markup for a CDM TaxonName instance.
243
 *
244
 * The layout of the name representation is configured by the
245
 * part_definitions and render_templates (see get_partDefinition() and
246
 * get_nameRenderTemplate())
247
 *
248
 * @param $taxonName
249
 *    cdm TaxonNameBase instance
250
 * @param $sec
251
 *    the sec reference of a taxon having this name (optional)
252
 * @param $nameLink
253
 *    URI to the taxon, @see path_to_taxon(), must be processed by url() before passing to this method
254
 * @param $refenceLink
255
 *    URI to the reference, @see path_to_reference(), must be processed by url() before passing to this method
256
 * @param $show_annotations
257
 *    turns the display of annotations on
258
 * @param $is_type_designation
259
 *    To indicate that the supplied taxon name is a name type designation.
260
 * @param $skiptags
261
 *    an array of name elements tags like 'name', 'rank' to skip. The name part
262
 *          'authors' will not ber affected by this filter. This part is managed though the render template
263
 *          mechanism.
264
 * @param $is_invalid
265
 *   Indicates that this taxon is invalid. In this case the name part will be shown in double quotes.
266
 *   This is useful when rendering taxon relation ships.
267
 *
268
 * @return string
269
 *  The markup for a taxon name.
270
 *
271
 */
272
function render_taxon_or_name($taxon_name_or_taxon_base, $nameLink = NULL, $refenceLink = NULL,
273
  $show_annotations = true, $is_type_designation = false, $skiptags = array(), $is_invalid = false) {
274

    
275
  $is_doubtful = false;
276

    
277
  if($taxon_name_or_taxon_base->class == 'Taxon' || $taxon_name_or_taxon_base->class == 'Synonym'){
278
    $taxonName = $taxon_name_or_taxon_base->name;
279
    $is_doubtful = $taxon_name_or_taxon_base->doubtful;
280
    // use the TaxonBase.taggedTitle so we have the secRef
281
    $taggedTitle = $taxon_name_or_taxon_base->taggedTitle;
282
  } else {
283
    // assuming this is a TaxonNameBase
284
    $taxonName = $taxon_name_or_taxon_base;
285
    $taggedTitle = $taxon_name_or_taxon_base->taggedName;
286
  }
287

    
288

    
289
  $renderTemplate = get_nameRenderTemplate(RenderHints::getRenderPath(), $nameLink, $refenceLink);
290
  $partDefinition = get_partDefinition($taxonName->class);
291

    
292
  // Apply definitions to template.
293
  foreach ($renderTemplate as $part => $uri) {
294

    
295
    if (isset($partDefinition[$part])) {
296
      $renderTemplate[$part] = $partDefinition[$part];
297
    }
298
    if (is_array($uri) && isset($uri['#uri'])) {
299
      $renderTemplate[$part]['#uri'] = $uri['#uri'];
300
    }
301
  }
302

    
303
  $secref_tagged_text = split_secref_from_tagged_text($taggedTitle);
304
  $nom_status_tagged_text = split_nomstatus_from_tagged_text($taggedTitle);
305
  $appended_phrase_tagged_text = array(); // this is filled later
306

    
307
  normalize_tagged_text($taggedTitle);
308

    
309
  $firstEntryIsValidNamePart =
310
    isset($taggedTitle)
311
    && is_array($taggedTitle)
312
    && isset($taggedTitle[0]->text)
313
    && is_string($taggedTitle[0]->text)
314
    && $taggedTitle[0]->text != ''
315
    && isset($taggedTitle[0]->type)
316
    && $taggedTitle[0]->type == 'name';
317
  $lastAuthorElementString = FALSE;
318

    
319
  $name_encasement = $is_invalid ? '"' : '';
320
  $doubtful_marker = $is_doubtful ? '? ' : '';
321

    
322
  // split off all appendedPhrase item  from the end of the array (usually there only should  be one)
323
  while($taggedTitle[count($taggedTitle)-1]->type == "appendedPhrase"){
324
    $appended_phrase_tagged_text[] = array_pop($taggedTitle);
325
  }
326

    
327
  // Got to use second entry as first one, see ToDo comment below ...
328
  if ($firstEntryIsValidNamePart) {
329

    
330
    $taggedName = $taggedTitle;
331
    $hasNamePart_with_Authors = isset($renderTemplate['namePart']) && isset($renderTemplate['namePart']['authors']);
332
    $hasNameAuthorPart_with_Authors = isset($renderTemplate['nameAuthorPart']) && isset($renderTemplate['nameAuthorPart']['authors']);
333

    
334

    
335
    if (!(($hasNamePart_with_Authors) || ($hasNameAuthorPart_with_Authors))) {
336
      // Find author and split off from name.
337
      // TODO expecting to find the author as the last element.
338
      /*
339
      if($taggedName[count($taggedName)- 1]->type == 'authors'){
340
        $authorTeam = $taggedName[count($taggedName)- 1]->text;
341
        unset($taggedName[count($taggedName)- 1]);
342
      }
343
      */
344

    
345
      // Remove all authors.
346
      $taggedNameNew = array();
347
      foreach ($taggedName as $element) {
348
        if ($element->type != 'authors') {
349
          $taggedNameNew[] = $element;
350
        }
351
        else {
352
          $lastAuthorElementString = $element->text;
353
        }
354
      }
355
      $taggedName = $taggedNameNew;
356
      unset($taggedNameNew);
357
    }
358
    $name = '<span class="' . $taxonName->class . '">' . $doubtful_marker . $name_encasement . cdm_tagged_text_to_markup($taggedName, 'span', ' ', $skiptags) . $name_encasement . '</span>';
359
  }
360
  else {
361
    $name = '<span class="' . $taxonName->class . '_titleCache">' . $doubtful_marker . $name_encasement . $taxonName->titleCache . $name_encasement . '</span>';
362
  }
363

    
364

    
365
  if(isset($appended_phrase_tagged_text[0])){
366
    $name .= ' '. cdm_tagged_text_to_markup($appended_phrase_tagged_text);
367
  }
368

    
369
  // Fill name into $renderTemplate.
370
  array_setr('name', $name , $renderTemplate);
371

    
372
  // Fill with authorTeam.
373
  /*
374
  if($authorTeam){
375
    $authorTeamHtml = ' <span class="authorTeam">'.$authorTeam.'</span>';
376
    array_setr('authorTeam', $authorTeamHtml, $renderTemplate);
377
  }
378
  */
379

    
380
  // Fill with reference.
381
  if (isset($renderTemplate['referencePart']) && !$is_type_designation) {
382

    
383
    // default separator
384
    $separator = '';
385

    
386
    // [Eckhard]:"Komma nach dem Taxonnamen ist grunsätzlich falsch,
387
    // Komma nach dem Autornamen ist überall dort falsch, wo ein "in" folgt."
388
    if (isset($renderTemplate['referencePart']['reference']) && isset($taxonName->nomenclaturalReference)) {
389
      $microreference = NULL;
390
      if (isset($renderTemplate['referencePart']['microreference'])&& isset($taxonName->nomenclaturalMicroReference)) {
391
        $microreference = $taxonName->nomenclaturalMicroReference;
392
      }
393
      $citation = cdm_ws_getNomenclaturalReference($taxonName->nomenclaturalReference->uuid, $microreference);
394

    
395
      // Find preceding element of the reference.
396
      $precedingKey = get_preceding_contentElementKey('reference', $renderTemplate);
397
      if (str_beginsWith($citation, ", in")) {
398
        $citation = substr($citation, 2);
399
        $separator = ' ';
400
      }
401
      elseif (!str_beginsWith($citation, "in") && $precedingKey == 'authors') {
402
        $separator = ', ';
403
      } else {
404
        $separator = ' ';
405
      }
406

    
407

    
408
      $referenceArray['#separator'] = $separator;
409
      $referenceArray['#html'] = '<span class="reference">' . $citation . '</span>';
410
      array_setr('reference', $referenceArray, $renderTemplate);
411
    }
412

    
413
    // If authors have been removed from the name part the last named authorteam
414
    // should be added to the reference citation, otherwise, keep the separator
415
    // out of the reference.
416
    if (isset($renderTemplate['referencePart']['authors']) && $lastAuthorElementString) {
417
      // If the nomenclaturalReference citation is not included in the
418
      // reference part but diplay of the microreference
419
      // is wanted, append the microreference to the authorTeam.
420
      $citation = '';
421
      if (!isset($renderTemplate['referencePart']['reference']) && isset($renderTemplate['referencePart']['microreference'])) {
422
        $separator = ": ";
423
        $citation = $taxonName->nomenclaturalMicroReference;
424
      }
425
      $referenceArray['#html'] = ' <span class="reference">' . $lastAuthorElementString . $separator . $citation . '</span>';
426
      array_setr('authors', $referenceArray, $renderTemplate);
427
    }
428
  }
429

    
430
  $is_reference_year = false;
431
  if (isset($renderTemplate['referenceYearPart']['reference.year'])) {
432
    if(isset($taxonName->nomenclaturalReference->datePublished)){
433
      $referenceArray['#html'] = ' <span class="reference">' . timePeriodToString($taxonName->nomenclaturalReference->datePublished) . '</span>';
434
      array_setr('reference.year', $referenceArray, $renderTemplate);
435
      $is_reference_year = true;
436
    }
437
  }
438

    
439
  // Fill with status.
440
  if(isset($renderTemplate['statusPart']['status'])){
441
    if (isset($nom_status_tagged_text[0])) {
442
        array_setr('status', '<span class="nomenclatural_status">' . cdm_tagged_text_to_markup($nom_status_tagged_text, 'span', '', array('postSeparator')) . '</span>', $renderTemplate);
443
    }
444
  }
445

    
446
  if (isset($renderTemplate['secReferencePart'])){
447
    if(isset($secref_tagged_text[1])){
448
      $post_separator_markup = $is_reference_year ? '.': '';
449
      if(isset($nom_status_tagged_text[count($nom_status_tagged_text) - 1]) && ($nom_status_tagged_text[count($nom_status_tagged_text) - 1]->type ==  'postSeparator')){
450
        $post_separator_markup = cdm_tagged_text_to_markup(array($nom_status_tagged_text[count($nom_status_tagged_text) - 1 ]));
451
      };
452
      array_setr('secReference',
453
        $post_separator_markup
454
          . ' <span class="sec_reference">'
455
          . join(' ', cdm_tagged_text_values($secref_tagged_text))
456
          . '</span>', $renderTemplate);
457
    }
458
  }
459

    
460
  // Fill with protologues etc...
461
  $descriptionHtml = '';
462
  if (array_setr('description', TRUE, $renderTemplate)) {
463
    $descriptions = cdm_ws_get(CDM_WS_PORTAL_NAME_DESCRIPTIONS, $taxonName->uuid);
464
    foreach ($descriptions as $description) {
465
      if (!empty($description)) {
466
        foreach ($description->elements as $description_element) {
467
          $second_citation = '';
468
          if (isset($description_element->multilanguageText_L10n) && $description_element->multilanguageText_L10n->text) {
469
            $second_citation = '[& ' . $description_element->multilanguageText_L10n->text . '].';
470
          }
471
          $descriptionHtml .= $second_citation;
472
          $descriptionHtml .= theme("cdm_media", array(
473
              'descriptionElement' => $description_element,
474
              'mimeTypePreference' => array(
475
                'application/pdf',
476
                'image/png',
477
                'image/jpeg',
478
                'image/gif',
479
                'text/html',
480
              )
481
            )
482
          );
483

    
484
        }
485
      }
486
    }
487
    array_setr('description', $descriptionHtml, $renderTemplate);
488
  }
489

    
490
  // Render.
491
  $out = '';
492
  if(isset($_REQUEST['RENDER_PATH'])){
493
    // developer option to show the render path with each taxon name
494
    $out .= '<span class="render-path">' . RenderHints::getRenderPath() . '</span>';
495
  }
496
  $out .= '<span class="' . html_class_attribute_ref($taxon_name_or_taxon_base)
497
    . '" data-cdm-ref="/name/' . $taxonName->uuid . '" data-cdm-render-path="' . RenderHints::getRenderPath() .'">';
498

    
499
  foreach ($renderTemplate as $partName => $part) {
500
    $separator = '';
501
    $partHtml = '';
502
    $uri = FALSE;
503
    if (!is_array($part)) {
504
      continue;
505
    }
506
    if (isset($part['#uri']) && is_string($part['#uri'])) {
507
      $uri = $part['#uri'];
508
      unset($part['#uri']);
509
    }
510
    foreach ($part as $key => $content) {
511
      $html = '';
512
      if (is_array($content)) {
513
        $html = $content['#html'];
514
        if(isset($content['#separator'])) {
515
          $separator = $content['#separator'];
516
        }
517
      }
518
      elseif (is_string($content)) {
519
        $html = $content;
520
      }
521
      $partHtml .= '<span class="' . $key . '">' . $html . '</span>';
522
    }
523
    if ($uri) {
524
      // cannot use l() here since the #uri aleady should have been processed through uri() at this point
525
      $out .= $separator . '<a href="' . $uri . '" class="' . $partName . '">' . $partHtml . '</a>';
526

    
527
    }
528
    else {
529
      $out .= $separator . $partHtml;
530
    }
531
  }
532
  $out .= '</span>';
533
  if ($show_annotations) {
534
    // $out .= theme('cdm_annotations_as_footnotekeys', $taxonName);
535
  }
536
  return $out;
537
}
538

    
539
/**
540
 * Renders the string of Homonyms for a given taxon.
541
 *
542
 * @param $taxon
543
 *    A CDM Taxon instance
544
 * @return String
545
 *    The string of homomyns
546
 *
547
 * @throws \Exception
548
 */
549
function cdm_name_relationships_of($taxon) {
550

    
551
  static $inverse_name_rels_uuids = array(UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR);
552

    
553
  // =========== START OF HOMONYMS ========== //
554
  RenderHints::pushToRenderStack('homonym');
555
  // the render stack element homonyms is being used in the default render templates !!!, see CDM_NAME_RENDER_TEMPLATES_DEFAULT
556

    
557
  $selected_name_rel_uuids = variable_get(CDM_NAME_RELATIONSHIP_TYPES, unserialize(CDM_NAME_RELATIONSHIP_TYPES_DEFAULT));
558

    
559
  $from_name_relations = cdm_ws_get(CDM_WS_PORTAL_TAXON_FROM_NAMERELATIONS,
560
    $taxon->uuid);
561
  $to_name_relations = cdm_ws_get(CDM_WS_PORTAL_TAXON_TO_NAMERELATIONS,
562
    $taxon->uuid);
563
  $name_relations = array_merge($from_name_relations, $to_name_relations);
564

    
565
  $homonyms_array = array();
566

    
567
  if ($name_relations) {
568

    
569
    foreach ($name_relations as $element) {
570

    
571
      if(!(isset($selected_name_rel_uuids[$element->type->uuid]) && $selected_name_rel_uuids[$element->type->uuid])){
572
        // skip if not selected in the settings
573
        continue;
574
      }
575
      $taxon_html = null;
576
      if(array_search($element->type->uuid, $inverse_name_rels_uuids) !== false) {
577
        // case of UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR
578
        //to relation ships -> only shown at toName-synonym
579
        $elementTaxonBasesUuid = isset ($element->fromName->taxonBases [0]->uuid) ? $element->fromName->taxonBases [0]->uuid : '';
580
        if ($taxon->name->uuid == $element->toName->uuid) {
581
          $taxon_html = render_taxon_or_name($element->fromName,
582
            url(path_to_name($element->fromName->uuid, $taxon->uuid, $elementTaxonBasesUuid))
583
          );
584
        }
585

    
586
      } else {
587
        $elementTaxonBasesUuid = isset ($element->toName->taxonBases [0]->uuid) ? $element->toName->taxonBases [0]->uuid : '';
588
        //from relation ships -> only shown at fromName-synonym
589
        if ($taxon->name->uuid == $element->fromName->uuid) {
590
          $taxon_html = render_taxon_or_name($element->toName,
591
            url(path_to_name($element->toName->uuid, $taxon->uuid, $elementTaxonBasesUuid))
592
          );
593
        }
594
      }
595

    
596
      if($taxon_html){
597
        if (count($homonyms_array)) {
598
          // lat: "non nec" == german: "weder noch"
599
          $homonyms_array [] = 'nec ' . $taxon_html;
600
        } else {
601
          $homonyms_array [] = 'non ' . $taxon_html;
602
        }
603
      }
604

    
605
    }
606
  }
607

    
608
  RenderHints::popFromRenderStack();
609
  return (count($homonyms_array) ?'[' . trim(join(" ", $homonyms_array)) . ']' : '');
610
}
611

    
612

    
613
  /**
614
 * Recursively searches the array for the $key and sets the given value.
615
 *
616
 * @param mixed $key
617
 *   Key to search for.
618
 * @param mixed $value
619
 *   Value to set.'
620
 * @param array $array
621
 *   Array to search in.
622
 *
623
 * @return bool
624
 *   True if the key has been found.
625
 */
626
function &array_setr($key, $value, array &$array) {
627
  $res = NULL;
628
  foreach ($array as $k => &$v) {
629
    if ($key == $k) {
630
      $v = $value;
631
      return $array;
632
    }
633
    elseif (is_array($v)) {
634
      $innerArray = array_setr($key, $value, $v);
635
      if ($innerArray) {
636
        return $array;
637
      }
638
    }
639
  }
640
  return $res;
641
}
642

    
643
/**
644
 * @todo Please document this function.
645
 * @see http://drupal.org/node/1354
646
 */
647
function &get_preceding_contentElement($contentElementKey, array &$renderTemplate) {
648
  $res = NULL;
649
  $precedingElement = NULL;
650
  foreach ($renderTemplate as &$part) {
651
    foreach ($part as $key => &$element) {
652
      if ($key == $contentElementKey) {
653
        return $precedingElement;
654
      }
655
      $precedingElement = $element;
656
    }
657
  }
658
  return $res;
659
}
660

    
661
/**
662
 * @todo Please document this function.
663
 * @see http://drupal.org/node/1354
664
 */
665
function &get_preceding_contentElementKey($contentElementKey, array &$renderTemplate) {
666
  $res = NULL;
667
  $precedingKey = NULL;
668
  foreach ($renderTemplate as &$part) {
669
    if (is_array($part)) {
670
      foreach ($part as $key => &$element) {
671
        if ($key == $contentElementKey) {
672
          return $precedingKey;
673
        }
674
        if (!str_beginsWith($key, '#')) {
675
          $precedingKey = $key;
676
        }
677
      }
678
    }
679
  }
680
  return $res;
681
}
(5-5/10)