Project

General

Profile

Download (21.2 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2

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

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

    
34
define('TAXON_TYPE_SYNONYM', 'Synonym');
35
define('TAXON_TYPE_MISAPPLIEDNAME', 'misapplied-name');
36

    
37
/**
38
 * Returns HTML for misapplied names and invalid designations.
39
 *
40
 * Both relation types are currently treated the same!
41
 *
42
 * @param taxonRelationships
43
 * @param focusedTaxon
44
 *
45
 * @return string
46
 *    the rendered html
47
 */
48
function cdm_taxonRelationships($taxonRelationships, $focusedTaxon){
49

    
50
  static $NULL_AUTHORTEAM = 'NULL_AUTHORTEAM';
51

    
52
  if (!$taxonRelationships) {
53
    return null;
54
  }
55

    
56
  RenderHints::pushToRenderStack('taxon_relationships');
57
  $footnoteListKey = 'taxon_relationships';
58
  RenderHints::setFootnoteListKey($footnoteListKey);
59

    
60
  $misapplied = array();
61
  $joinedAuthorTeams = array();
62

    
63
  $taxon_relationship_types = variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT));
64

    
65
  // Aggregate misapplied names having the same fullname:
66
  //  - deduplicate misapplied names, so that the same name it not shown multiple times in case it
67
  //    the duplicates only have different sensu references/author teams (see #5647)
68
  //  - show the author team as sec reference
69
  //  - show the according reference as footnote to this author team
70
  //  - if the sec reference has no author team it should show instead the title cache
71
  //
72
  // Example:
73
  // "Xenoxylum foobar" sensu Grumbach¹; sensu Lem²
74
  //    1. Novel marsian species, Grumbach, 2022
75
  //    2. Flora solaris, Lem, 2019
76
  foreach ($taxonRelationships as $taxonRelation) {
77

    
78
    if (in_array($taxonRelation->type->uuid, $taxon_relationship_types)) {
79

    
80
      if ($taxonRelation->type->uuid == UUID_MISAPPLIED_NAME_FOR || $taxonRelation->type->uuid == UUID_INVALID_DESIGNATION_FOR) {
81

    
82
        RenderHints::pushToRenderStack('misapplied_name_for'); // TODO the render path string should in future come from $taxonRelation->type->...
83

    
84
        $name = $taxonRelation->fromTaxon->name->titleCache;
85

    
86
        $sensu_citation_footnote_str = null;
87

    
88
        if(isset($taxonRelation->fromTaxon->sec)) {
89

    
90
          $sensu_citation_footnote_str = theme('cdm_reference', array('reference' => $taxonRelation->fromTaxon->sec));
91
          $authorteam = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $taxonRelation->fromTaxon->sec->uuid);
92

    
93
          if(isset($authorteam->titleCache)){
94
            $authorteam_str = $authorteam->titleCache;
95
            if($taxonRelation->fromTaxon->sec->titleCache == $authorteam->titleCache){
96
              // no need for a footnote in case the reference only consists of the author team
97
              $sensu_citation_footnote_str = '';
98
            }
99
          } else {
100
            $authorteam_str = $sensu_citation_footnote_str;
101
            // no need for a footnote in case in case it is used as replacement for missing author teams
102
            $sensu_citation_footnote_str = '';
103
          }
104
        } else {
105
          // taxa not always are have a sec reference (e.g. doubtful taxa)
106
          // use the NULL_AUTHORTEAM in this case
107
          $authorteam_str = $NULL_AUTHORTEAM;
108
        }
109

    
110
        if (!isset($misapplied[$name])) {
111
          // Render the first name found as representative for all others.
112
          $misapplied[$name]['out'] = cdm_related_taxon($taxonRelation->fromTaxon, UUID_MISAPPLIED_NAME_FOR);
113
        }
114
        else {
115
          // We need to add the anchors for all of the other misapplied names not
116
          // being rendered explicitly.
117
          $misapplied[$name]['out'] = uuid_anchor($taxonRelation->fromTaxon->uuid, $misapplied[$name]['out']);
118
        }
119

    
120
        // Collect all authors for this fullname.
121
        if (isset($authorteam_str) && $authorteam_str != $NULL_AUTHORTEAM) {
122
          // prepare entry for the footnote key of the sensu citation footnote
123
          $misapplied[$name]['authorteam'][$authorteam_str] = '';
124
          // map sensu citation footnote to the authorteam string
125
          $joinedAuthorTeams[$authorteam_str] = $sensu_citation_footnote_str;
126

    
127
        }
128

    
129
      }
130
      else {
131
        RenderHints::pushToRenderStack('other_taxon_relationship');
132
        // All relationsship types but misapplied_name_for
133
        // invalid_designation_for.
134
        $taxon_relationships_lines[] = cdm_taxonRelationship($taxonRelation, TRUE, _is_invers_taxonRelationship($taxonRelation, $focusedTaxon));
135
      }
136

    
137
      RenderHints::popFromRenderStack();
138
    }
139
  }
140

    
141
  // Sort the joinedAuthorTeams and create footnotes and footnotekeys.
142
  ksort($joinedAuthorTeams);
143
  $author_team_cnt = 0;
144
  foreach ($joinedAuthorTeams as $authorteam_str => $sensu_citation) {
145
    $footnoteKey = '';
146
    if(!empty($sensu_citation)) {
147
      $footnoteKey = FootnoteManager::addNewFootnote($footnoteListKey, $sensu_citation);
148
      $footnoteKey = theme('cdm_footnote_key', array('footnoteKey' => $footnoteKey));
149
    }
150
    $sensu = '';
151
    if($authorteam_str != $NULL_AUTHORTEAM){
152
      $sensu = ++$author_team_cnt == 0 ? '' : 'sensu ' . $authorteam_str;
153
    }
154
    $joinedAuthorTeams[$authorteam_str] = '<span class="sensu">' . $sensu . $footnoteKey .'</span>';
155
  }
156

    
157
  // ---- Generate output ---- //
158

    
159
  $out = '<div class="taxon-relationships">';
160
  if (is_array($misapplied) && count($misapplied) > 0) {
161
    $out .= '<ul class="misapplied">';
162
    foreach ($misapplied as $misapplied_name) {
163

    
164
      $out .= '<li class="synonym"><span class="misapplied">' . $misapplied_name['out'] . ' </span>';
165

    
166
      if (isset($misapplied_name['authorteam'])) {
167
        // Fill authors with the renderedFootnoteKey and sorting 'em.
168
        foreach ($misapplied_name['authorteam'] as $authorteam_str => &$renderedFootnoteKey) {
169
          $renderedFootnoteKey = $joinedAuthorTeams[$authorteam_str];
170
        }
171
        ksort($misapplied_name['authorteam']);
172
        $out .= join('; ', $misapplied_name['authorteam']);
173
      }
174
      $out .= '</li>';
175
    }
176
    $out .= '</ul>';
177
  }
178

    
179
  if (isset($taxon_relationships_lines) && is_array($taxon_relationships_lines) && count($taxon_relationships_lines) > 0) {
180
    $out .= '<ul class="taxonRelationships">';
181
    foreach ($taxon_relationships_lines as $taxon_relationship_line) {
182
      $out .= '<li class="synonym">' . $taxon_relationship_line . '</li>';
183
    }
184
    $out .= '</ul>';
185
  }
186

    
187
  $footnotes = theme('cdm_footnotes', array('footnoteListKey' => $footnoteListKey, 'enclosingTag' => 'li'));
188
  $footnotes .= theme('cdm_annotation_footnotes', array('footnoteListKey' => $footnoteListKey, 'enclosingTag' => 'li'));
189

    
190
// AK: why splitting footnotes at the sensu string ??? this is weired and hacky
191
//     TODO remove below dead code
192
//   $tr_footnotes_exploded = explode('sensu', $tr_footnotes);
193
//   $tr_footnotes_aux = '';
194
//   foreach ($tr_footnotes_exploded as $element) {
195
//     $tr_footnotes_aux .= $element;
196
//   }
197

    
198
  $out .= '<ul class="footnotes">' . $footnotes . '</ul>';
199

    
200
  $out .= '</div>';
201

    
202
  RenderHints::popFromRenderStack();
203
  return $out;
204
}
205

    
206

    
207
/**
208
 * Renders a representation of the given taxon relationship.
209
 *
210
 * According name relationships are also being rendered.
211
 *
212
 * @param $taxonRelationship
213
 * @param boolean $doLinkTaxon
214
 *     whether to create a link to the related taxon
215
 * @param boolean $inverse
216
 *     whether the $taxonRelationship should be treaded as invers relation
217
 *
218
 * @return void|string
219
 */
220
function cdm_taxonRelationship($taxonRelationship, $doLinkTaxon = FALSE, $inverse = FALSE) {
221

    
222
  // Validate object.
223
  if (!(isset($taxonRelationship->toTaxon) && isset($taxonRelationship->fromTaxon) && isset($taxonRelationship->type))) {
224
    return null;
225
  }
226

    
227
  $taxonRelationType = $taxonRelationship->type;
228

    
229
  if ($inverse) {
230
    $toTaxon = $taxonRelationship->fromTaxon;
231
    $relsign = $taxonRelationType->inverseSymbol;
232
    $reltype_representation = $taxonRelationType->inverseRepresentation_L10n;
233
  }
234
  else {
235
    $toTaxon = $taxonRelationship->toTaxon;
236
    $relsign = $taxonRelationType->symbol;
237
    $reltype_representation = $taxonRelationType->representation_L10n;
238
  }
239

    
240
  return cdm_related_taxon($toTaxon, NULL, $relsign, $reltype_representation, $taxonRelationship->doubtful, $doLinkTaxon);
241
}
242

    
243
/**
244
 * Renders a representation of the given taxon relationship.
245
 *
246
 * According name relationships are also being rendered.
247
 *
248
 * @param $taxon
249
 *  The CDM TaxonBase entity
250
 * @param $reltype_uuid
251
 *  The UUID of the TaxonRelationshipType
252
 * @param $relsign
253
 *  Optional. Can be  used to override the internal decision strategy on finding a suitable icon for the relationship
254
 * @param $reltype_representation
255
 *   Optional: Defines the value for the title attribute of the html element enclosing the relsign
256
 * @param $doubtful
257
 *   TODO
258
 * @param $doLinkTaxon
259
 *   The taxon will be rendered as clickable link when true.
260
 *
261
 * @return string
262
 *   Markup for the taxon relationship.
263
 */
264
function cdm_related_taxon($taxon, $reltype_uuid = NULL, $relsign = NULL, $reltype_representation = NULL, $doubtful=false, $doLinkTaxon = FALSE) {
265
  static $relsign_homo = '≡';
266
  static $relsign_hetero = '=';
267
  static $relsign_invalid = '&ndash;';
268
  static $nom_status_invalid_type_uuids =  array(
269
    UUID_NOMENCLATURALSTATUS_TYPE_INVALID,
270
    UUID_NOMENCLATURALSTATUS_TYPE_NUDUM,
271
    UUID_NOMENCLATURALSTATUS_TYPE_COMBINATIONINVALID,
272
    UUID_NOMENCLATURALSTATUS_TYPE_PROVISIONAL
273
  );
274

    
275
  // 'taxonRelationships';
276
  $footnoteListKey = NULL;
277

    
278
  $skip_tags = array();
279

    
280
  $is_invalid = false;
281

    
282
  if (!$relsign) {
283

    
284
    switch ($reltype_uuid) {
285
      case UUID_HETEROTYPIC_SYNONYM_OF:
286
      case UUID_SYNONYM_OF:
287
        $relsign = $relsign_hetero;
288
        break;
289

    
290
      case UUID_HOMOTYPIC_SYNONYM_OF:
291
        $relsign = $relsign_homo;
292
        break;
293

    
294
      case UUID_MISAPPLIED_NAME_FOR:
295
      case UUID_INVALID_DESIGNATION_FOR:
296
        $skip_tags[] = 'authors';
297
        $is_invalid = true;
298
        $relsign = $relsign_invalid;
299

    
300
        break;
301

    
302
      default:
303
        $relsign = $relsign_invalid;
304
    }
305

    
306
  }
307

    
308
  if($doubtful) {
309
    $relsign = '?' . $relsign;
310
  }
311

    
312
  /*
313
  Names with status invalid or nudum are to be displayed with the
314
  $relsign_invalid, these names appear at the end of all names in their
315
  homotypic group (ordered correctly by the java cdm_lib).
316
  */
317
  if (isset($taxon->name->status) && is_array($taxon->name->status)) {
318
    foreach ($taxon->name->status as $status) {
319
      if (in_array($status->type->uuid , $nom_status_invalid_type_uuids)) {
320
        $relsign = $relsign_invalid;
321
        break;
322
      }
323
    }
324
  }
325

    
326
  // Now rendering starts ..
327
  RenderHints::pushToRenderStack('related_taxon');
328

    
329
  if (isset($taxon->name->nomenclaturalReference)) {
330
    $referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
331
  }
332
  $taxonUri = '';
333
  if ($doLinkTaxon) {
334
    $taxonUri = url(path_to_taxon($taxon->uuid, "synonymy"));
335
  }
336
  // Printing the taxonName and the handling the special case of annotations.
337
  if (!isset($referenceUri)) {
338
    $referenceUri = FALSE;
339
  }
340
  $out_taxon_part = render_taxon_or_name($taxon, $taxonUri, $referenceUri, TRUE, FALSE, $skip_tags, $is_invalid);
341
  $taxon_footnotes = theme('cdm_annotations_as_footnotekeys',
342
    array('cdmBase_list' => array(
343
      $taxon->name,
344
      $taxon,
345
    ),
346
      'footnote_list_key' => $footnoteListKey)
347
  );
348

    
349
  $homonyms = cdm_name_relationships_of($taxon);
350

    
351
  $out = '<span class="relation_sign" title="' . $reltype_representation . '">' . $relsign . '</span>'
352
    . $out_taxon_part . $taxon_footnotes . ' '  . $homonyms;
353

    
354
  $out = uuid_anchor($taxon->uuid, $out);
355

    
356
  RenderHints::popFromRenderStack();
357

    
358
  return $out;
359
}
360

    
361

    
362
/**
363
 * Creates markup for a taxon which is the accepted of another one
364
 *
365
 * @param $accepted_for_uuid
366
 *   The uuid of the accepted taxon
367
 */
368
function cdm_accepted_for($accepted_for_uuid) {
369

    
370
  if(!is_uuid($accepted_for_uuid)){
371
    return '';
372
  }
373

    
374
  RenderHints::pushToRenderStack('acceptedFor');
375
  $out = '';
376

    
377
  $synonym = cdm_ws_get(CDM_WS_PORTAL_TAXON, $accepted_for_uuid);
378
  if ($synonym) {
379
    $out .= '<span class="acceptedFor">';
380
    $out .= t('is accepted for ');
381
    if (isset($synonym->name->nomenclaturalReference)) {
382
      $referenceUri = url(path_to_reference($synonym->name->nomenclaturalReference->uuid));
383
    }
384
    $out .= render_taxon_or_name($synonym->name, NULL, $referenceUri);
385
    $out .= theme('cdm_annotations_as_footnotekeys', array('cdmBase_list' => $synonym));
386
    $out .= '</span>';
387
  }
388
  RenderHints::popFromRenderStack();
389
  return $out;
390
}
391

    
392
/**
393
 * Compose function for a list of taxa.
394
 *
395
 * This function is for used to:
396
 *
397
 * 1. Display search results
398
 * 2. List the taxa for a taxon name in the name page.
399
 *
400
 * @param $taxon_list array
401
 *   The list of CDM Taxon entities. e.g. The records array as contained in a pager object.
402
 * @param $freetext_search_results array
403
 * @param $show_classification boolean
404
 *
405
 * @ingroup compose
406
 *
407
 */
408
function compose_list_of_taxa($taxon_list, $freetext_search_results = array(), $show_classification = false) {
409

    
410
  $unclassified_snippet = '<span class="unclassified">' . t('unclassified') . '</span>';
411

    
412
  RenderHints::pushToRenderStack('list_of_taxa');
413

    
414
  $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SEARCH_GALLERY_NAME);
415

    
416
  $showMedia_taxa = $gallery_settings['cdm_dataportal_show_taxon_thumbnails'];
417
  $showMedia_synonyms = $gallery_settings['cdm_dataportal_show_synonym_thumbnails'];
418
  $searched_in_classification = cdm_dataportal_searched_in_classification();
419
  $searched_in_classification_uuid = null;
420
  if(isset($searched_in_classification->uuid)){
421
    $searched_in_classification_uuid = $searched_in_classification->uuid;
422
  }
423

    
424
  // .. Well, for sure not as performant as before, but better than nothing.
425
  $synonym_uuids = array();
426
  $misappied_uuids = array();
427
  foreach ($taxon_list as $taxon) {
428
    if ($taxon->class == "Synonym") {
429
      if (!array_key_exists($taxon->uuid, $synonym_uuids)) {
430
        $synonym_uuids[$taxon->uuid] = $taxon->uuid;
431
      }
432
    }
433
    elseif (!_cdm_dataportal_acceptedByCurrentView($taxon)) {
434
      // Assuming that it is a misappied name, will be further examined below.
435
      $misappied_uuids[$taxon->uuid] = $taxon->uuid;
436
    }
437
  }
438

    
439
  // Batch service not jet implemented:
440
  // $table_of_accepted = cdm_ws_property(CDM_WS_PORTAL_TAXON_ACCEPTED,
441
  // join(',', $synonym_uuids));
442
  // thus ...
443
  $table_of_accepted = array();
444

    
445
  foreach ($synonym_uuids as $relatedUuid) {
446
    $classification_filter = '';
447
    if($searched_in_classification_uuid){
448
      $classification_filter = 'classificationFilter=' . $searched_in_classification_uuid;
449
    }
450
    $table_of_accepted[$relatedUuid] = cdm_ws_get(
451
      CDM_WS_PORTAL_TAXON_ACCEPTED,
452
      array($relatedUuid),
453
      $classification_filter
454
    );
455
  }
456

    
457
  foreach ($misappied_uuids as $relatedUuid) {
458
    $taxonRelations = cdm_ws_get(CDM_WS_PORTAL_TAXON_RELATIONS, array(
459
      $relatedUuid,
460
    ));
461
    foreach ($taxonRelations as $relation) {
462
      if ($relation->type->uuid == UUID_MISAPPLIED_NAME_FOR && _cdm_dataportal_acceptedByCurrentView($relation->toTaxon)) {
463
        $table_of_accepted[$relatedUuid][] = $relation->toTaxon;
464
      }
465
    }
466
  }
467

    
468
  $out = '<div class="cdm-item-list" style="background-image: none;">';
469
  $itemCnt = -1;
470
  foreach ($taxon_list as $taxon) {
471
    $itemCnt++;
472
    if (isset($table_of_accepted[$taxon->uuid])) {
473
      // Its a synonym or misapplied name.
474
      $is_synonym = isset($synonym_uuids[$taxon->uuid]); //TODO better use the $taxon->class attribute?
475
      $taxon_type = $is_synonym ? TAXON_TYPE_SYNONYM :TAXON_TYPE_MISAPPLIEDNAME;
476

    
477
      $acceptedTaxa = $table_of_accepted[$taxon->uuid];
478

    
479
      if (!is_array($acceptedTaxa)) {
480
        $acceptedTaxa = array($acceptedTaxa);
481
      }
482

    
483
      foreach ($acceptedTaxa as $acceptedTaxon) {
484
        if (is_object($acceptedTaxon)) {
485

    
486
          $taxonUri = uri_to_synonym($taxon->uuid, $acceptedTaxon->uuid);
487
          $referenceUri = '';
488
          if (isset($acceptedTaxon->name->nomenclaturalReference)) {
489
            $referenceUri = url(path_to_reference($acceptedTaxon->name->nomenclaturalReference->uuid));
490
          }
491
          $taxon_or_name = $is_synonym ? $taxon->name : $taxon;
492
          // $taxon_or_name this is a trick to suppress the sec reference for synonyms
493
          // supplying the name will cause render_taxon_or_name() to not show the sec reference
494
          $out .= "<div class=\"item " . $taxon_type . "\">" . render_taxon_or_name($taxon_or_name, $taxonUri, $referenceUri);
495
          if($taxon_type == TAXON_TYPE_MISAPPLIEDNAME && is_object($taxon->sec)){
496
            if(isset($taxon->sec->authorship)){
497
              $authorship = $taxon->sec->authorship->titleCache;
498
            } else {
499
              $authorship = $taxon->sec->titleCache;
500
            }
501
            $out .=  ' sensu ' . $authorship;
502
          }
503
          if ($show_classification) {
504
            $classifications = get_classifications_for_taxon($taxon);
505
            $classification_titles = array();
506
            foreach ($classifications as $classification) {
507
              if (isset($classification->titleCache)) {
508
                $classification_titles[] = $classification->titleCache;
509
              }
510
            }
511
            if (count($classification_titles) == 0) {
512
              $classification_titles[] = $unclassified_snippet;
513
            }
514
            $out .= '<span class="classifications"><span class="separator"> : </span>' . implode(', ', $classification_titles) . '</span>';
515
          }
516
          $out .= theme('cdm_annotations_as_footnotekeys', array('cdmBase_list' => $taxon));
517
          if ($showMedia_synonyms) {
518
            $out .= theme('cdm_taxon_list_thumbnails', array('taxon' => $acceptedTaxon));
519
          }
520
        }
521
      }
522
    }
523
    else {
524
      // Its a Taxon.
525
      $taxonUri = url(path_to_taxon($taxon->uuid));
526
      $referenceUri = '';
527
      if (isset($taxon->name->nomenclaturalReference)) {
528
        $referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
529
      }
530
      $out .= '<div class="item Taxon">' . render_taxon_or_name($taxon, $taxonUri, $referenceUri);
531
      if ($show_classification) {
532
        $classifications = get_classifications_for_taxon($taxon);
533
        $classification_titles = array();
534
        foreach ($classifications as $classification) {
535
          if (isset($classification->titleCache)) {
536
            $classification_titles[] = $classification->titleCache;
537
          }
538
        }
539
        if(count($classification_titles) == 0){
540
          $classification_titles[] = $unclassified_snippet;
541
        }
542
        $out .= '<span class="classifications"><span class="separator"> : </span>' . implode(', ', $classification_titles) . '</span>';
543
      }
544
      $out .= theme('cdm_annotations_as_footnotekeys', array('cdmBase_list' => $taxon));
545

    
546
      if ($showMedia_taxa) {
547
        $out .= theme('cdm_taxon_list_thumbnails', array('taxon' => $taxon));
548
      }
549
    }
550

    
551
    /*
552
     * the score field will be empty in case of MultiTermQueries like
553
     * WildcardQueries, since these are  constant score by default
554
     * since Lucene 2.9
555
     */
556
    if(isset($freetext_search_results[$itemCnt]) && $freetext_search_results[$itemCnt]->score && $freetext_search_results[$itemCnt]->maxScore){
557
      $percentage =  ( $freetext_search_results[$itemCnt]->score / $freetext_search_results[$itemCnt]->maxScore ) * 100;
558
      $out .= '<div class="score-bar"><div class="score-bar-indicator" style="width:' . $percentage .'% "></div></div>';
559
      $out .= '<div class="score-bar-value">' . number_format($percentage, 2) .'%</div>';
560
    }
561

    
562
    // Render highlighted fragments, these are made available by free text
563
    // searches.
564
    if (isset($freetext_search_results[$itemCnt]->fieldHighlightMap)) {
565
      $field_fragments = (array) $freetext_search_results[$itemCnt]->fieldHighlightMap;
566
      if (count($field_fragments) > 0) {
567
        $fragments_out = '';
568
        foreach ($field_fragments as $fieldName => $fragments) {
569
          $fragments_out .= '... <span class="' . $fieldName. '">' . filter_xss(join(" ... ", $fragments), array('b') ) . '</span>';
570
        }
571
        $out .= '<div class="fragment_highlight">' . $fragments_out . ' ...</div>';
572
      }
573
    }
574

    
575
    $out .= '</div>';
576
  }
577

    
578
  $out .= '</div>';
579
  RenderHints::popFromRenderStack();
580

    
581
  return markup_to_render_array($out); // TODO create render array of all list items in function
582
}
583

    
584

    
585
/**
586
 * Compose function for the taxonomic children
587
 *
588
 * @param $taxon_uuid
589
 *    The uuuid of the taxon to compose the list of taxonomic children for
590
 * @return
591
 *   A drupal render array.
592
 *
593
 * @ingroup compose
594
 */
595
function compose_taxonomic_children($taxon_uuid){
596

    
597
  $render_array = array();
598
  
599
  if($taxon_uuid) {
600
    $children = cdm_ws_get(CDM_WS_PORTAL_TAXONOMY_CHILDNODES_OF_TAXON, array(
601
      get_current_classification_uuid(),
602
      $taxon_uuid
603
      ));
604
    if($children){
605
      $taxonomic_children = theme('cdm_taxontree', array('tree' => $children));
606
      $render_array = markup_to_render_array($taxonomic_children);
607
    }
608
  }
609
  return $render_array;
610
}
611

    
(10-10/10)