Project

General

Profile

Download (22.8 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_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_refs[$sensu_uuid])) {
100
              $joined_refs[$sensu_uuid] = array(
101
                'order_by_key' => $sensu_citation_short,
102
                'markup' => $sensu_citation_short_markup // the footnote key will be appended later
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_refs[$relsec_uuid])) {
113
                $joined_refs[$relsec_uuid] = array(
114
                  'order_by_key' => $relsec_citation_short,
115
                  'markup' => $relsec_citation_short_markup // the footnote key will be appended later
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_refs and create footnotes and footnote keys.
140
  uasort($joined_refs, function($a, $b) {
141
    if ($a['order_by_key'] == $b['order_by_key']) {
142
      return 0;
143
    }
144
    return ($a['order_by_key'] < $b['order_by_key']) ? -1 : 1;
145
  });
146

    
147

    
148
  foreach ($joined_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
      if($sensu_strings['order_by_key'] != $sensu_reference->titleCache){
156
        $footnote_key = FootnoteManager::addNewFootnote($footnote_list_key, $sensu_reference->titleCache);
157
        $footnote_key = theme('cdm_footnote_key', array('footnoteKey' => $footnote_key));
158

    
159
        $joined_refs[$sensu_uuid]['markup'] = '<span class="sensu">' . $sensu_strings['markup'] . $footnote_key . '</span>';
160
      }
161
    }
162
  }
163

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

    
170
    foreach ($misapplied as $misapplied_name) {
171
      $misapplied_name_markup = $misapplied_name['out'];
172

    
173
      if (isset($misapplied_name['sensu_uuids'])) {
174
        $sensu_refs_with_fkey = array();
175
        foreach ($misapplied_name['sensu_uuids'] as $sensu_uuid) {
176
          $sensu_refs_with_fkey[$joined_refs[$sensu_uuid]['order_by_key']] = $joined_refs[$sensu_uuid]['markup'];
177
        }
178
        ksort($sensu_refs_with_fkey);
179
        $sensu_refs_with_fkey_markup = join('; ', $sensu_refs_with_fkey);
180
        $misapplied_name_markup = str_replace('{PLACEHOLDER_secReference}', ' sensu ' . $sensu_refs_with_fkey_markup, $misapplied_name_markup);
181
      }
182

    
183
      if (isset($misapplied_name['relsec_uuids'])) {
184
        $relsec_refs_with_fkey = array();
185
        foreach ($misapplied_name['relsec_uuids'] as $relsec_uuid) {
186
          $relsec_refs_with_fkey[$joined_refs[$relsec_uuid]['order_by_key']] = $joined_refs[$relsec_uuid]['markup'];
187
        }
188
        ksort($relsec_refs_with_fkey);
189
        $relsec_refs_with_fkey_markup = join('; ', $relsec_refs_with_fkey);
190
        $misapplied_name_markup = str_replace('{PLACEHOLDER_relSecReference}', ', err. sec. ' . $relsec_refs_with_fkey_markup, $misapplied_name_markup);
191
      }
192

    
193
      $out .= '<li class="synonym"><span class="misapplied">' . $misapplied_name_markup . ' </span>';
194
      $out .= '</li>';
195
    }
196
    $out .= '</ul>';
197
  }
198

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

    
207
  $footnotes = theme('cdm_footnotes', array('footnoteListKey' => $footnote_list_key, 'enclosingTag' => 'li'));
208
  $footnotes .= theme('cdm_annotation_footnotes', array('footnoteListKey' => $footnote_list_key, 'enclosingTag' => 'li'));
209

    
210
  $out .= '<ul class="footnotes">' . $footnotes . '</ul>';
211
  $out .= '</div>';
212

    
213
  RenderHints::popFromRenderStack();
214
  return $out;
215
}
216

    
217

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

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

    
239
  $taxonRelationType = $taxonRelationship->type;
240

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

    
252
  return cdm_related_taxon($toTaxon, NULL, $relsign, $reltype_representation, $taxonRelationship->doubtful, $doLinkTaxon);
253
}
254

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

    
289
  // 'taxonRelationships';
290
  $footnoteListKey = NULL;
291

    
292
  $skip_tags = array();
293

    
294
  $is_invalid = false;
295

    
296
  if (!$relsign) {
297

    
298
    switch ($reltype_uuid) {
299
      case UUID_HETEROTYPIC_SYNONYM_OF:
300
      case UUID_SYNONYM_OF:
301
        $relsign = $relsign_hetero;
302
        break;
303

    
304
      case UUID_HOMOTYPIC_SYNONYM_OF:
305
        $relsign = $relsign_homo;
306
        break;
307

    
308
      case UUID_MISAPPLIED_NAME_FOR:
309
      case UUID_INVALID_DESIGNATION_FOR:
310
        $skip_tags[] = 'authors';
311
        $is_invalid = true;
312
        $relsign = $relsign_invalid;
313

    
314
        break;
315

    
316
      default:
317
        $relsign = $relsign_invalid;
318
    }
319

    
320
  }
321

    
322
  if($doubtful) {
323
    $relsign = '?' . $relsign;
324
  }
325

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

    
340
  // Now rendering starts ..
341
  RenderHints::pushToRenderStack('related_taxon');
342

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

    
363
  $homonyms = cdm_name_relationships_of($taxon);
364

    
365
  $out = '<span class="relation_sign" title="' . $reltype_representation . '">' . $relsign . '</span>'
366
    . $out_taxon_part . $taxon_footnotes . ' '  . $homonyms;
367

    
368
  $out = uuid_anchor($taxon->uuid, $out);
369

    
370
  RenderHints::popFromRenderStack();
371

    
372
  return $out;
373
}
374

    
375

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

    
384
  if(!is_uuid($accepted_for_uuid)){
385
    return '';
386
  }
387

    
388
  RenderHints::pushToRenderStack('acceptedFor');
389
  $out = '';
390

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

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

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

    
426
  RenderHints::pushToRenderStack('list_of_taxa');
427

    
428
  $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SEARCH_GALLERY_NAME);
429

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

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

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

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

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

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

    
491
      $acceptedTaxa = $table_of_accepted[$taxon->uuid];
492

    
493
      if (!is_array($acceptedTaxa)) {
494
        $acceptedTaxa = array($acceptedTaxa);
495
      }
496

    
497
      foreach ($acceptedTaxa as $acceptedTaxon) {
498
        if (is_object($acceptedTaxon)) {
499

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

    
560
      if ($showMedia_taxa) {
561
        $out .= theme('cdm_taxon_list_thumbnails', array('taxon' => $taxon));
562
      }
563
    }
564

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

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

    
589
    $out .= '</div>';
590
  }
591

    
592
  $out .= '</div>';
593
  RenderHints::popFromRenderStack();
594

    
595
  return markup_to_render_array($out); // TODO create render array of all list items in function
596
}
597

    
598

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

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

    
(10-10/10)