Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

cdm-dataportal / modules / cdm_dataportal / includes / name.inc @ 275b2642

History | View | Annotate | Download (24.3 KB)

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 ? '?&#8239;' : ''; // 	&#8239; =  NARROW NO-BREAK SPACE
321
  $doubtful_marker_markup = '';
322

    
323
  if($doubtful_marker){
324
    $doubtful_marker_markup = '<span class="doubtful">' . $doubtful_marker . '</span>';
325
  }
326

    
327
  // split off all appendedPhrase item  from the end of the array (usually there only should  be one)
328
  while($taggedTitle[count($taggedTitle)-1]->type == "appendedPhrase"){
329
    $appended_phrase_tagged_text[] = array_pop($taggedTitle);
330
  }
331

    
332
  // Got to use second entry as first one, see ToDo comment below ...
333
  if ($firstEntryIsValidNamePart) {
334

    
335
    $taggedName = $taggedTitle;
336
    $hasNamePart_with_Authors = isset($renderTemplate['namePart']) && isset($renderTemplate['namePart']['authors']);
337
    $hasNameAuthorPart_with_Authors = isset($renderTemplate['nameAuthorPart']) && isset($renderTemplate['nameAuthorPart']['authors']);
338

    
339

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

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

    
369

    
370
  if(isset($appended_phrase_tagged_text[0])){
371
    $name .= ' <span class="appended-phrase">'. cdm_tagged_text_to_markup($appended_phrase_tagged_text) . '</span>';
372
  }
373

    
374
  // Fill name into $renderTemplate.
375
  array_setr('name', $name , $renderTemplate);
376

    
377
  // Fill with authorTeam.
378
  /*
379
  if($authorTeam){
380
    $authorTeamHtml = ' <span class="authorTeam">'.$authorTeam.'</span>';
381
    array_setr('authorTeam', $authorTeamHtml, $renderTemplate);
382
  }
383
  */
384

    
385
  // Fill with reference.
386
  if (isset($renderTemplate['referencePart']) && !$is_type_designation) {
387

    
388
    // default separator
389
    $separator = '';
390

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

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

    
412

    
413
      $referenceArray['#separator'] = $separator;
414
      $referenceArray['#html'] = '<span class="reference">' . $citation . '</span>';
415
      array_setr('reference', $referenceArray, $renderTemplate);
416
    }
417

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

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

    
444
  // Fill with status.
445
  if(isset($renderTemplate['statusPart']['status'])){
446
    if (isset($nom_status_tagged_text[0])) {
447
        array_setr('status', '<span class="nomenclatural_status">' . cdm_tagged_text_to_markup($nom_status_tagged_text, 'span', '', array('postSeparator')) . '</span>', $renderTemplate);
448
    }
449
  }
450

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

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

    
488
        }
489
      }
490
    }
491
    array_setr('description', $descriptionHtml, $renderTemplate);
492
  }
493

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

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

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

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

    
555
  static $inverse_name_rels_uuids = array(UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR);
556

    
557
  // =========== START OF HOMONYMS ========== //
558
  RenderHints::pushToRenderStack('homonym');
559
  // the render stack element homonyms is being used in the default render templates !!!, see CDM_NAME_RENDER_TEMPLATES_DEFAULT
560

    
561
  $selected_name_rel_uuids = variable_get(CDM_NAME_RELATIONSHIP_TYPES, unserialize(CDM_NAME_RELATIONSHIP_TYPES_DEFAULT));
562

    
563
  $from_name_relations = cdm_ws_get(CDM_WS_PORTAL_TAXON_FROM_NAMERELATIONS,
564
    $taxon->uuid);
565
  $to_name_relations = cdm_ws_get(CDM_WS_PORTAL_TAXON_TO_NAMERELATIONS,
566
    $taxon->uuid);
567
  $name_relations = array_merge($from_name_relations, $to_name_relations);
568

    
569
  $homonyms_array = array();
570

    
571
  if ($name_relations) {
572

    
573
    foreach ($name_relations as $element) {
574

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

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

    
600
      if($taxon_html){
601
        if (count($homonyms_array)) {
602
          // lat: "non nec" == german: "weder noch"
603
          $homonyms_array [] = 'nec ' . $taxon_html;
604
        } else {
605
          $homonyms_array [] = 'non ' . $taxon_html;
606
        }
607
      }
608

    
609
    }
610
  }
611

    
612
  RenderHints::popFromRenderStack();
613
  return (count($homonyms_array) ?'[' . trim(join(" ", $homonyms_array)) . ']' : '');
614
}
615

    
616

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

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

    
665
/**
666
 * @todo Please document this function.
667
 * @see http://drupal.org/node/1354
668
 */
669
function &get_preceding_contentElementKey($contentElementKey, array &$renderTemplate) {
670
  $res = NULL;
671
  $precedingKey = NULL;
672
  foreach ($renderTemplate as &$part) {
673
    if (is_array($part)) {
674
      foreach ($part as $key => &$element) {
675
        if ($key == $contentElementKey) {
676
          return $precedingKey;
677
        }
678
        if (!str_beginsWith($key, '#')) {
679
          $precedingKey = $key;
680
        }
681
      }
682
    }
683
  }
684
  return $res;
685
}
Add picture from clipboard (Maximum size: 40 MB)