Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

cdm-dataportal / modules / cdm_dataportal / includes / taxon.inc @ 116fb348

History | View | Annotate | Download (21.5 KB)

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 object taxonRelationships
43
 *   A TaxonRelationshipsDTO, see taxon/{uuid}/taxonRelationshipsDTO
44
 *
45
 * @param object focusedTaxon
46
 *  The taxon being in the focus of the applicaton
47
 *
48
 * @return string
49
 *    the rendered html
50
 */
51
function cdm_taxonRelationships($taxonRelationshipsDTO, $focusedTaxon){
52

    
53
  static $NULL_AUTHORTEAM = 'NULL_AUTHORTEAM';
54

    
55
  if (!$taxonRelationshipsDTO || $taxonRelationshipsDTO->size < 1) {
56
    return null;
57
  }
58

    
59
  RenderHints::pushToRenderStack('taxon_relationships');
60
  $footnoteListKey = 'taxon_relationships';
61
  RenderHints::setFootnoteListKey($footnoteListKey);
62

    
63
  $misapplied = array();
64
  $joinedAuthorTeams = array();
65

    
66

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

    
81
      if (in_array($taxonRelation->type->uuid, $taxon_relationship_types)) {
82

    
83
        if ($taxonRelation->type->uuid == UUID_MISAPPLIED_NAME_FOR || $taxonRelation->type->uuid == UUID_INVALID_DESIGNATION_FOR) {
84

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

    
87
          $name = $taxonRelation->fromTaxon->name->titleCache;
88

    
89
          $sensu_citation_footnote_str = null;
90

    
91
          if (isset($taxonRelation->fromTaxon->sec)) {
92

    
93
            $sensu_citation_footnote_str = theme('cdm_reference', array('reference' => $taxonRelation->fromTaxon->sec));
94
            $authorteam = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $taxonRelation->fromTaxon->sec->uuid);
95

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

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

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

    
129
          }
130

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

    
138
        RenderHints::popFromRenderStack();
139
      }
140
    }
141
  }
142

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

    
159
  // ---- Generate output ---- //
160

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

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

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

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

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

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

    
200
  $out .= '<ul class="footnotes">' . $footnotes . '</ul>';
201

    
202
  $out .= '</div>';
203

    
204
  RenderHints::popFromRenderStack();
205
  return $out;
206
}
207

    
208

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

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

    
229
  $taxonRelationType = $taxonRelationship->type;
230

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

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

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

    
277
  // 'taxonRelationships';
278
  $footnoteListKey = NULL;
279

    
280
  $skip_tags = array();
281

    
282
  $is_invalid = false;
283

    
284
  if (!$relsign) {
285

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

    
292
      case UUID_HOMOTYPIC_SYNONYM_OF:
293
        $relsign = $relsign_homo;
294
        break;
295

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

    
302
        break;
303

    
304
      default:
305
        $relsign = $relsign_invalid;
306
    }
307

    
308
  }
309

    
310
  if($doubtful) {
311
    $relsign = '?' . $relsign;
312
  }
313

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

    
328
  // Now rendering starts ..
329
  RenderHints::pushToRenderStack('related_taxon');
330

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

    
351
  $homonyms = cdm_name_relationships_of($taxon);
352

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

    
356
  $out = uuid_anchor($taxon->uuid, $out);
357

    
358
  RenderHints::popFromRenderStack();
359

    
360
  return $out;
361
}
362

    
363

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

    
372
  if(!is_uuid($accepted_for_uuid)){
373
    return '';
374
  }
375

    
376
  RenderHints::pushToRenderStack('acceptedFor');
377
  $out = '';
378

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

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

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

    
414
  RenderHints::pushToRenderStack('list_of_taxa');
415

    
416
  $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SEARCH_GALLERY_NAME);
417

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

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

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

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

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

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

    
479
      $acceptedTaxa = $table_of_accepted[$taxon->uuid];
480

    
481
      if (!is_array($acceptedTaxa)) {
482
        $acceptedTaxa = array($acceptedTaxa);
483
      }
484

    
485
      foreach ($acceptedTaxa as $acceptedTaxon) {
486
        if (is_object($acceptedTaxon)) {
487

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

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

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

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

    
577
    $out .= '</div>';
578
  }
579

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

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

    
586

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

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

    
Add picture from clipboard (Maximum size: 40 MB)