Project

General

Profile

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

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

    
57
  RenderHints::pushToRenderStack('taxon_relationships');
58
  $footnote_list_key = 'taxon_relationships';
59
  RenderHints::setFootnoteListKey($footnote_list_key);
60

    
61
  $misapplied = array();
62
  $joined_sensu_refs = array();
63

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

    
66
  // Aggregate misapplied names having the same fullname:
67
  //  - deduplicate misapplied names, so that the same name it not shown multiple times in case it
68
  //    the duplicates only have different sensu references/author teams (see #5647)
69
  //  - show only the author team as short citation for the sec reference
70
  //  - show the according reference as footnote to this short citation
71
  //
72
  // Example:
73
  // "Xenoxylum foobar" sensu Grumbach¹; sensu Lem²
74
  //    1. Novel marsian species, Grumbach, 2022
75
  //    2. Flora solaris, Lem, 2019
76
  if (isset($taxonRelationshipsDTO->relations[0])) {
77
    foreach($taxonRelationshipsDTO->relations as $taxon_relation){
78

    
79
      if (in_array($taxon_relation->type->uuid, $taxon_relationship_types)) {
80

    
81
        if ($taxon_relation->type->uuid == UUID_MISAPPLIED_NAME_FOR || $taxon_relation->type->uuid == UUID_INVALID_DESIGNATION_FOR) {
82

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

    
85
          // using name tags + author as full name key
86
          $full_name_key = join(' ', cdm_tagged_text_values($taxon_relation->taggedText, array('name', 'authors')));
87

    
88
          // Render the first name found as representative for all others.
89
          //###OLD: $misapplied[$name]['out'] = cdm_related_taxon($taxon_relation->fromTaxon, UUID_MISAPPLIED_NAME_FOR);
90
          $sensu_tagged_text = tagged_text_extract_secref($taxon_relation->taggedText, "secReference", true);
91
          $relsec_tagged_text = tagged_text_extract_secref($taxon_relation->taggedText, "relSecReference", true);
92

    
93
          if (isset($sensu_tagged_text[1])) {
94
            array_shift($sensu_tagged_text); // remove first element which contains the "sensu", this will be added later in this code
95
            $sensu_citation_short_markup = cdm_tagged_text_to_markup($sensu_tagged_text);
96
            $sensu_citation_short = cdm_tagged_text_to_string($sensu_tagged_text);
97
            $sensu_uuid = $sensu_tagged_text[0]->entityReference->uuid;
98
            $misapplied[$full_name_key]['sensu_uuids'][] = $sensu_uuid;
99
            if (!isset($joined_sensu_refs[$sensu_uuid])) {
100
              $joined_sensu_refs[$sensu_uuid] = array(
101
                'short_citation' => $sensu_citation_short,
102
                'markup' => $sensu_citation_short_markup // to be expanded later as short_citation + footnote key
103
              );
104
            }
105

    
106
            if (isset($relsec_tagged_text[1])) {
107
              array_shift($relsec_tagged_text); // remove first element which contains the "err. sec", this will be added later in this code
108
              $relsec_citation_short_markup = cdm_tagged_text_to_markup($relsec_tagged_text);
109
              $relsec_citation_short = cdm_tagged_text_to_string($relsec_tagged_text);
110
              $relsec_uuid = $relsec_tagged_text[0]->entityReference->uuid;
111
              $misapplied[$full_name_key]['relsec_uuids'][] = $relsec_uuid;
112
              if (!isset($joined_sensu_refs[$relsec_uuid])) {
113
                $joined_sensu_refs[$relsec_uuid] = array(
114
                  'short_citation' => $relsec_citation_short,
115
                  'markup' => $relsec_citation_short_markup // to be expanded later as short_citation + footnote key
116
                );
117
              }
118
            }
119

    
120
            if (!isset($misapplied[$full_name_key]['out'])) {
121
              $misapplied[$full_name_key]['out'] = cdm_tagged_text_to_markup($taxon_relation->taggedText);
122
            } else {
123
              // We need to add the anchors for all of the other misapplied names not
124
              // being rendered explicitly.
125
              $misapplied[$full_name_key]['out'] = uuid_anchor($taxon_relation->taxonUuid, $misapplied[$full_name_key]['out']);
126
            }
127
          } else {
128
            RenderHints::pushToRenderStack('other_taxon_relationship');
129
            // All relationship types except misapplied_name_for and invalid_designation_for.
130
            $taxon_relationships_lines[] = cdm_taxonRelationship($taxon_relation, TRUE, _is_invers_taxonRelationship($taxon_relation, $focusedTaxon));
131
          }
132

    
133
          RenderHints::popFromRenderStack();
134
        }
135
      }
136
    } // END loop over $taxonRelationshipsDTO->relations
137
  }
138

    
139
  // Sort the $joined_sensu_refs and create footnotes and footnote keys.
140
  uasort($joined_sensu_refs, function($a, $b) {
141
    if ($a['short_citation'] == $b['short_citation']) {
142
      return 0;
143
    }
144
    return ($a['short_citation'] < $b['short_citation']) ? -1 : 1;
145
  });
146

    
147

    
148
  foreach ($joined_sensu_refs as $sensu_uuid => $sensu_strings) {
149
    $footnote_key = '';
150
    if(!empty($sensu_strings)) {
151
      $sensu_reference = cdm_ws_get(CDM_WS_REFERENCE, $sensu_uuid);
152
      if(!$sensu_reference){
153
        drupal_set_message("Problem fetching sensu reference with uuid " . $sensu_uuid, 'error');
154
      }
155
      $footnote_key = FootnoteManager::addNewFootnote($footnote_list_key, $sensu_reference->titleCache);
156
      $footnote_key = theme('cdm_footnote_key', array('footnoteKey' => $footnote_key));
157
    }
158
    $joined_sensu_refs[$sensu_uuid]['markup'] = '<span class="sensu">' . $sensu_strings['markup'] . $footnote_key . '</span>';
159
  }
160

    
161
  // ---- Generate output ---- //
162
  $out = '<div class="taxon-relationships">';
163
  if (is_array($misapplied) && count($misapplied) > 0) {
164
    ksort($misapplied); // order the misapplied by scientific name
165
    $out .= '<ul class="misapplied">';
166

    
167
    foreach ($misapplied as $misapplied_name) {
168
      $misapplied_name_markup = $misapplied_name['out'];
169

    
170
      if (isset($misapplied_name['sensu_uuids'])) {
171
        $sensu_refs_with_fkey = array();
172
        foreach ($misapplied_name['sensu_uuids'] as $sensu_uuid) {
173
          $sensu_refs_with_fkey[$joined_sensu_refs[$sensu_uuid]['short_citation']] = $joined_sensu_refs[$sensu_uuid]['markup'];
174
        }
175
        ksort($sensu_refs_with_fkey);
176
        $sensu_refs_with_fkey_markup = join('; ', $sensu_refs_with_fkey);
177
        $misapplied_name_markup = str_replace('{PLACEHOLDER_secReference}', ' sensu ' . $sensu_refs_with_fkey_markup, $misapplied_name_markup);
178
      }
179

    
180
      if (isset($misapplied_name['relsec_uuids'])) {
181
        $relsec_refs_with_fkey = array();
182
        foreach ($misapplied_name['relsec_uuids'] as $relsec_uuid) {
183
          $relsec_refs_with_fkey[$joined_sensu_refs[$relsec_uuid]['short_citation']] = $joined_sensu_refs[$relsec_uuid]['markup'];
184
        }
185
        ksort($relsec_refs_with_fkey);
186
        $relsec_refs_with_fkey_markup = join('; ', $relsec_refs_with_fkey);
187
        $misapplied_name_markup = str_replace('{PLACEHOLDER_relSecReference}', ', err. sec. ' . $relsec_refs_with_fkey_markup, $misapplied_name_markup);
188
      }
189

    
190
      $out .= '<li class="synonym"><span class="misapplied">' . $misapplied_name_markup . ' </span>';
191
      $out .= '</li>';
192
    }
193
    $out .= '</ul>';
194
  }
195

    
196
  if (isset($taxon_relationships_lines) && is_array($taxon_relationships_lines) && count($taxon_relationships_lines) > 0) {
197
    $out .= '<ul class="taxonRelationships">';
198
    foreach ($taxon_relationships_lines as $taxon_relationship_line) {
199
      $out .= '<li class="synonym">' . $taxon_relationship_line . '</li>';
200
    }
201
    $out .= '</ul>';
202
  }
203

    
204
  $footnotes = theme('cdm_footnotes', array('footnoteListKey' => $footnote_list_key, 'enclosingTag' => 'li'));
205
  $footnotes .= theme('cdm_annotation_footnotes', array('footnoteListKey' => $footnote_list_key, 'enclosingTag' => 'li'));
206

    
207
  $out .= '<ul class="footnotes">' . $footnotes . '</ul>';
208
  $out .= '</div>';
209

    
210
  RenderHints::popFromRenderStack();
211
  return $out;
212
}
213

    
214

    
215
/**
216
 * Renders a representation of the given taxon relationship.
217
 *
218
 * According name relationships are also being rendered.
219
 *
220
 * @param $taxonRelationship
221
 * @param boolean $doLinkTaxon
222
 *     whether to create a link to the related taxon
223
 * @param boolean $inverse
224
 *     whether the $taxonRelationship should be treaded as invers relation
225
 *
226
 * @return string
227
 *
228
 */
229
function cdm_taxonRelationship($taxonRelationship, $doLinkTaxon = FALSE, $inverse = FALSE) {
230

    
231
  // Validate object.
232
  if (!(isset($taxonRelationship->toTaxon) && isset($taxonRelationship->fromTaxon) && isset($taxonRelationship->type))) {
233
    return null;
234
  }
235

    
236
  $taxonRelationType = $taxonRelationship->type;
237

    
238
  if ($inverse) {
239
    $toTaxon = $taxonRelationship->fromTaxon;
240
    $relsign = $taxonRelationType->inverseSymbol;
241
    $reltype_representation = $taxonRelationType->inverseRepresentation_L10n;
242
  }
243
  else {
244
    $toTaxon = $taxonRelationship->toTaxon;
245
    $relsign = $taxonRelationType->symbol;
246
    $reltype_representation = $taxonRelationType->representation_L10n;
247
  }
248

    
249
  return cdm_related_taxon($toTaxon, NULL, $relsign, $reltype_representation, $taxonRelationship->doubtful, $doLinkTaxon);
250
}
251

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

    
286
  // 'taxonRelationships';
287
  $footnoteListKey = NULL;
288

    
289
  $skip_tags = array();
290

    
291
  $is_invalid = false;
292

    
293
  if (!$relsign) {
294

    
295
    switch ($reltype_uuid) {
296
      case UUID_HETEROTYPIC_SYNONYM_OF:
297
      case UUID_SYNONYM_OF:
298
        $relsign = $relsign_hetero;
299
        break;
300

    
301
      case UUID_HOMOTYPIC_SYNONYM_OF:
302
        $relsign = $relsign_homo;
303
        break;
304

    
305
      case UUID_MISAPPLIED_NAME_FOR:
306
      case UUID_INVALID_DESIGNATION_FOR:
307
        $skip_tags[] = 'authors';
308
        $is_invalid = true;
309
        $relsign = $relsign_invalid;
310

    
311
        break;
312

    
313
      default:
314
        $relsign = $relsign_invalid;
315
    }
316

    
317
  }
318

    
319
  if($doubtful) {
320
    $relsign = '?' . $relsign;
321
  }
322

    
323
  /*
324
  Names with status invalid or nudum are to be displayed with the
325
  $relsign_invalid, these names appear at the end of all names in their
326
  homotypic group (ordered correctly by the java cdm_lib).
327
  */
328
  if (isset($taxon->name->status) && is_array($taxon->name->status)) {
329
    foreach ($taxon->name->status as $status) {
330
      if (in_array($status->type->uuid , $nom_status_invalid_type_uuids)) {
331
        $relsign = $relsign_invalid;
332
        break;
333
      }
334
    }
335
  }
336

    
337
  // Now rendering starts ..
338
  RenderHints::pushToRenderStack('related_taxon');
339

    
340
  if (isset($taxon->name->nomenclaturalReference)) {
341
    $referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
342
  }
343
  $taxonUri = '';
344
  if ($doLinkTaxon) {
345
    $taxonUri = url(path_to_taxon($taxon->uuid, "synonymy"));
346
  }
347
  // Printing the taxonName and the handling the special case of annotations.
348
  if (!isset($referenceUri)) {
349
    $referenceUri = FALSE;
350
  }
351
  $out_taxon_part = render_taxon_or_name($taxon, $taxonUri, $referenceUri, TRUE, FALSE, $skip_tags, $is_invalid);
352
  $taxon_footnotes = theme('cdm_annotations_as_footnotekeys',
353
    array('cdmBase_list' => array(
354
      $taxon->name,
355
      $taxon,
356
    ),
357
      'footnote_list_key' => $footnoteListKey)
358
  );
359

    
360
  $homonyms = cdm_name_relationships_of($taxon);
361

    
362
  $out = '<span class="relation_sign" title="' . $reltype_representation . '">' . $relsign . '</span>'
363
    . $out_taxon_part . $taxon_footnotes . ' '  . $homonyms;
364

    
365
  $out = uuid_anchor($taxon->uuid, $out);
366

    
367
  RenderHints::popFromRenderStack();
368

    
369
  return $out;
370
}
371

    
372

    
373
/**
374
 * Creates markup for a taxon which is the accepted of another one
375
 *
376
 * @param $accepted_for_uuid
377
 *   The uuid of the accepted taxon
378
 */
379
function cdm_accepted_for($accepted_for_uuid) {
380

    
381
  if(!is_uuid($accepted_for_uuid)){
382
    return '';
383
  }
384

    
385
  RenderHints::pushToRenderStack('acceptedFor');
386
  $out = '';
387

    
388
  $synonym = cdm_ws_get(CDM_WS_PORTAL_TAXON, $accepted_for_uuid);
389
  if ($synonym) {
390
    $out .= '<span class="acceptedFor">';
391
    $out .= t('is accepted for ');
392
    if (isset($synonym->name->nomenclaturalReference)) {
393
      $referenceUri = url(path_to_reference($synonym->name->nomenclaturalReference->uuid));
394
    }
395
    $out .= render_taxon_or_name($synonym->name, NULL, $referenceUri);
396
    $out .= theme('cdm_annotations_as_footnotekeys', array('cdmBase_list' => $synonym));
397
    $out .= '</span>';
398
  }
399
  RenderHints::popFromRenderStack();
400
  return $out;
401
}
402

    
403
/**
404
 * Compose function for a list of taxa.
405
 *
406
 * This function is for used to:
407
 *
408
 * 1. Display search results
409
 * 2. List the taxa for a taxon name in the name page.
410
 *
411
 * @param $taxon_list array
412
 *   The list of CDM Taxon entities. e.g. The records array as contained in a pager object.
413
 * @param $freetext_search_results array
414
 * @param $show_classification boolean
415
 *
416
 * @ingroup compose
417
 *
418
 */
419
function compose_list_of_taxa($taxon_list, $freetext_search_results = array(), $show_classification = false) {
420

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

    
423
  RenderHints::pushToRenderStack('list_of_taxa');
424

    
425
  $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SEARCH_GALLERY_NAME);
426

    
427
  $showMedia_taxa = $gallery_settings['cdm_dataportal_show_taxon_thumbnails'];
428
  $showMedia_synonyms = $gallery_settings['cdm_dataportal_show_synonym_thumbnails'];
429
  $searched_in_classification = cdm_dataportal_searched_in_classification();
430
  $searched_in_classification_uuid = null;
431
  if(isset($searched_in_classification->uuid)){
432
    $searched_in_classification_uuid = $searched_in_classification->uuid;
433
  }
434

    
435
  // .. Well, for sure not as performant as before, but better than nothing.
436
  $synonym_uuids = array();
437
  $misappied_uuids = array();
438
  foreach ($taxon_list as $taxon) {
439
    if ($taxon->class == "Synonym") {
440
      if (!array_key_exists($taxon->uuid, $synonym_uuids)) {
441
        $synonym_uuids[$taxon->uuid] = $taxon->uuid;
442
      }
443
    }
444
    elseif (!_cdm_dataportal_acceptedByCurrentView($taxon)) {
445
      // Assuming that it is a misappied name, will be further examined below.
446
      $misappied_uuids[$taxon->uuid] = $taxon->uuid;
447
    }
448
  }
449

    
450
  // Batch service not jet implemented:
451
  // $table_of_accepted = cdm_ws_property(CDM_WS_PORTAL_TAXON_ACCEPTED,
452
  // join(',', $synonym_uuids));
453
  // thus ...
454
  $table_of_accepted = array();
455

    
456
  foreach ($synonym_uuids as $relatedUuid) {
457
    $classification_filter = '';
458
    if($searched_in_classification_uuid){
459
      $classification_filter = 'classificationFilter=' . $searched_in_classification_uuid;
460
    }
461
    $table_of_accepted[$relatedUuid] = cdm_ws_get(
462
      CDM_WS_PORTAL_TAXON_ACCEPTED,
463
      array($relatedUuid),
464
      $classification_filter
465
    );
466
  }
467

    
468
  foreach ($misappied_uuids as $relatedUuid) {
469
    $taxonRelations = cdm_ws_get(CDM_WS_PORTAL_TAXON_RELATIONS, array(
470
      $relatedUuid,
471
    ));
472
    foreach ($taxonRelations as $relation) {
473
      if ($relation->type->uuid == UUID_MISAPPLIED_NAME_FOR && _cdm_dataportal_acceptedByCurrentView($relation->toTaxon)) {
474
        $table_of_accepted[$relatedUuid][] = $relation->toTaxon;
475
      }
476
    }
477
  }
478

    
479
  $out = '<div class="cdm-item-list" style="background-image: none;">';
480
  $itemCnt = -1;
481
  foreach ($taxon_list as $taxon) {
482
    $itemCnt++;
483
    if (isset($table_of_accepted[$taxon->uuid])) {
484
      // Its a synonym or misapplied name.
485
      $is_synonym = isset($synonym_uuids[$taxon->uuid]); //TODO better use the $taxon->class attribute?
486
      $taxon_type = $is_synonym ? TAXON_TYPE_SYNONYM :TAXON_TYPE_MISAPPLIEDNAME;
487

    
488
      $acceptedTaxa = $table_of_accepted[$taxon->uuid];
489

    
490
      if (!is_array($acceptedTaxa)) {
491
        $acceptedTaxa = array($acceptedTaxa);
492
      }
493

    
494
      foreach ($acceptedTaxa as $acceptedTaxon) {
495
        if (is_object($acceptedTaxon)) {
496

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

    
557
      if ($showMedia_taxa) {
558
        $out .= theme('cdm_taxon_list_thumbnails', array('taxon' => $taxon));
559
      }
560
    }
561

    
562
    /*
563
     * the score field will be empty in case of MultiTermQueries like
564
     * WildcardQueries, since these are  constant score by default
565
     * since Lucene 2.9
566
     */
567
    if(isset($freetext_search_results[$itemCnt]) && $freetext_search_results[$itemCnt]->score && $freetext_search_results[$itemCnt]->maxScore){
568
      $percentage =  ( $freetext_search_results[$itemCnt]->score / $freetext_search_results[$itemCnt]->maxScore ) * 100;
569
      $out .= '<div class="score-bar"><div class="score-bar-indicator" style="width:' . $percentage .'% "></div></div>';
570
      $out .= '<div class="score-bar-value">' . number_format($percentage, 2) .'%</div>';
571
    }
572

    
573
    // Render highlighted fragments, these are made available by free text
574
    // searches.
575
    if (isset($freetext_search_results[$itemCnt]->fieldHighlightMap)) {
576
      $field_fragments = (array) $freetext_search_results[$itemCnt]->fieldHighlightMap;
577
      if (count($field_fragments) > 0) {
578
        $fragments_out = '';
579
        foreach ($field_fragments as $fieldName => $fragments) {
580
          $fragments_out .= '... <span class="' . $fieldName. '">' . filter_xss(join(" ... ", $fragments), array('b') ) . '</span>';
581
        }
582
        $out .= '<div class="fragment_highlight">' . $fragments_out . ' ...</div>';
583
      }
584
    }
585

    
586
    $out .= '</div>';
587
  }
588

    
589
  $out .= '</div>';
590
  RenderHints::popFromRenderStack();
591

    
592
  return markup_to_render_array($out); // TODO create render array of all list items in function
593
}
594

    
595

    
596
/**
597
 * Compose function for the taxonomic children
598
 *
599
 * @param $taxon_uuid
600
 *    The uuuid of the taxon to compose the list of taxonomic children for
601
 * @return
602
 *   A drupal render array.
603
 *
604
 * @ingroup compose
605
 */
606
function compose_taxonomic_children($taxon_uuid){
607

    
608
  $render_array = array();
609
  
610
  if($taxon_uuid) {
611
    $children = cdm_ws_get(CDM_WS_PORTAL_TAXONOMY_CHILDNODES_OF_TAXON, array(
612
      get_current_classification_uuid(),
613
      $taxon_uuid
614
      ));
615
    if($children){
616
      $taxonomic_children = theme('cdm_taxontree', array('tree' => $children));
617
      $render_array = markup_to_render_array($taxonomic_children);
618
    }
619
  }
620
  return $render_array;
621
}
622

    
(10-10/10)