Project

General

Profile

Download (23.6 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
          // full name with relation symbol, rel sec as deduplication key
86
          // the sensu part will be removed from the key below in case it is present
87
          $symbol_text = join(' ', cdm_tagged_text_values($taxon_relation->taggedText, array('symbol')));
88
          $name_text = join(' ', cdm_tagged_text_values($taxon_relation->taggedText, array('name')));
89
          // remove quotes surrounding the name
90
          $name_text = str_replace('"', '', $name_text);
91
          $name_text = str_replace('&quot;', '', $name_text);
92
          $full_name_key = $name_text . ' ' . cdm_tagged_text_to_string($taxon_relation->taggedText, array('name', 'symbol')) . " " . $symbol_text;
93

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

    
99

    
100
          if (isset($sensu_tagged_text[1])) {
101
            // everything else needs to be equal except for MAN.sec and MAN.secDetail. see #7658#note-21
102
            $full_name_key = str_replace(cdm_tagged_text_to_string($sensu_tagged_text), ' ', $full_name_key);
103
            array_shift($sensu_tagged_text); // remove first element which contains the "sensu", this will be added later in this code
104
            $sensu_citation_short_markup = cdm_tagged_text_to_markup($sensu_tagged_text);
105
            $sensu_citation_short = cdm_tagged_text_to_string($sensu_tagged_text);
106
            $sensu_uuid = $sensu_tagged_text[0]->entityReference->uuid;
107
            $misapplied[$full_name_key]['sensu_uuids'][] = $sensu_uuid;
108
            if (!isset($joined_refs[$sensu_uuid])) {
109
              $joined_refs[$sensu_uuid] = array(
110
                'order_by_key' => $sensu_citation_short,
111
                'markup' => $sensu_citation_short_markup // the footnote key will be appended later
112
              );
113
            }
114

    
115
            if (isset($relsec_tagged_text[1])) {
116
              array_shift($relsec_tagged_text); // remove first element which contains the "err. sec", this will be added later in this code
117
              $relsec_citation_short_markup = cdm_tagged_text_to_markup($relsec_tagged_text);
118
              $relsec_citation_short = cdm_tagged_text_to_string($relsec_tagged_text);
119
              $relsec_uuid = $relsec_tagged_text[0]->entityReference->uuid;
120
              $misapplied[$full_name_key]['relsec_uuids'][] = $relsec_uuid;
121
              if (!isset($joined_refs[$relsec_uuid])) {
122
                $joined_refs[$relsec_uuid] = array(
123
                  'order_by_key' => $relsec_citation_short,
124
                  'markup' => $relsec_citation_short_markup // the footnote key will be appended later
125
                );
126
              }
127
            }
128

    
129
            if (!isset($misapplied[$full_name_key]['out'])) {
130
              $misapplied[$full_name_key]['out'] = cdm_tagged_text_to_markup($taxon_relation->taggedText);
131
            } else {
132
              // We need to add the anchors for all of the other misapplied names not
133
              // being rendered explicitly.
134
              $misapplied[$full_name_key]['out'] = uuid_anchor($taxon_relation->taxonUuid, $misapplied[$full_name_key]['out']);
135
            }
136
          } else {
137
            RenderHints::pushToRenderStack('other_taxon_relationship');
138
            // All relationship types except misapplied_name_for and invalid_designation_for.
139
            $taxon_relationships_lines[] = cdm_taxonRelationship($taxon_relation, TRUE, _is_invers_taxonRelationship($taxon_relation, $focusedTaxon));
140
          }
141

    
142
          RenderHints::popFromRenderStack();
143
        }
144
      }
145
    } // END loop over $taxonRelationshipsDTO->relations
146
  }
147

    
148
  // Sort the $joined_refs and create footnotes and footnote keys.
149
  uasort($joined_refs, function($a, $b) {
150
    if ($a['order_by_key'] == $b['order_by_key']) {
151
      return 0;
152
    }
153
    return ($a['order_by_key'] < $b['order_by_key']) ? -1 : 1;
154
  });
155

    
156

    
157
  foreach ($joined_refs as $sensu_uuid => $sensu_strings) {
158
    $footnote_key = '';
159
    if(!empty($sensu_strings)) {
160
      $sensu_reference = cdm_ws_get(CDM_WS_REFERENCE, $sensu_uuid);
161
      if(!$sensu_reference){
162
        drupal_set_message("Problem fetching sensu reference with uuid " . $sensu_uuid, 'error');
163
      }
164
      if($sensu_strings['order_by_key'] != $sensu_reference->titleCache){
165
        $footnote_key = FootnoteManager::addNewFootnote($footnote_list_key, $sensu_reference->titleCache);
166
        $footnote_key = theme('cdm_footnote_key', array('footnoteKey' => $footnote_key));
167

    
168
        $joined_refs[$sensu_uuid]['markup'] = '<span class="sensu">' . $sensu_strings['markup'] . $footnote_key . '</span>';
169
      }
170
    }
171
  }
172

    
173
  // ---- Generate output ---- //
174
  $out = '<div class="taxon-relationships">';
175
  if (is_array($misapplied) && count($misapplied) > 0) {
176
    ksort($misapplied); // order the misapplied by scientific name
177
    $out .= '<ul class="misapplied">';
178

    
179
    foreach ($misapplied as $misapplied_name) {
180
      $misapplied_name_markup = $misapplied_name['out'];
181

    
182
      if (isset($misapplied_name['sensu_uuids'])) {
183
        $sensu_refs_with_fkey = array();
184
        foreach ($misapplied_name['sensu_uuids'] as $sensu_uuid) {
185
          $sensu_refs_with_fkey[$joined_refs[$sensu_uuid]['order_by_key']] = $joined_refs[$sensu_uuid]['markup'];
186
        }
187
        ksort($sensu_refs_with_fkey);
188
        $sensu_refs_with_fkey_markup = join('; ', $sensu_refs_with_fkey);
189
        $misapplied_name_markup = str_replace('{PLACEHOLDER_secReference}', ' sensu ' . $sensu_refs_with_fkey_markup, $misapplied_name_markup);
190
      }
191

    
192
      if (isset($misapplied_name['relsec_uuids'])) {
193
        $relsec_refs_with_fkey = array();
194
        foreach ($misapplied_name['relsec_uuids'] as $relsec_uuid) {
195
          $relsec_refs_with_fkey[$joined_refs[$relsec_uuid]['order_by_key']] = $joined_refs[$relsec_uuid]['markup'];
196
        }
197
        ksort($relsec_refs_with_fkey);
198
        $relsec_refs_with_fkey_markup = join('; ', $relsec_refs_with_fkey);
199
        $misapplied_name_markup = str_replace('{PLACEHOLDER_relSecReference}', ', err. sec. ' . $relsec_refs_with_fkey_markup, $misapplied_name_markup);
200
      }
201

    
202
      $out .= '<li class="synonym"><span class="misapplied">' . $misapplied_name_markup . ' </span>';
203
      $out .= '</li>';
204
    }
205
    $out .= '</ul>';
206
  }
207

    
208
  if (isset($taxon_relationships_lines) && is_array($taxon_relationships_lines) && count($taxon_relationships_lines) > 0) {
209
    $out .= '<ul class="taxonRelationships">';
210
    foreach ($taxon_relationships_lines as $taxon_relationship_line) {
211
      $out .= '<li class="synonym">' . $taxon_relationship_line . '</li>';
212
    }
213
    $out .= '</ul>';
214
  }
215

    
216
  $footnotes = theme('cdm_footnotes', array('footnoteListKey' => $footnote_list_key, 'enclosingTag' => 'li'));
217
  $footnotes .= theme('cdm_annotation_footnotes', array('footnoteListKey' => $footnote_list_key, 'enclosingTag' => 'li'));
218

    
219
  $out .= '<ul class="footnotes">' . $footnotes . '</ul>';
220
  $out .= '</div>';
221

    
222
  RenderHints::popFromRenderStack();
223
  return $out;
224
}
225

    
226

    
227
/**
228
 * Renders a representation of the given taxon relationship.
229
 *
230
 * According name relationships are also being rendered.
231
 *
232
 * @param $taxonRelationship
233
 * @param boolean $doLinkTaxon
234
 *     whether to create a link to the related taxon
235
 * @param boolean $inverse
236
 *     whether the $taxonRelationship should be treaded as invers relation
237
 *
238
 * @return string
239
 *
240
 */
241
function cdm_taxonRelationship($taxonRelationship, $doLinkTaxon = FALSE, $inverse = FALSE) {
242

    
243
  // Validate object.
244
  if (!(isset($taxonRelationship->toTaxon) && isset($taxonRelationship->fromTaxon) && isset($taxonRelationship->type))) {
245
    return null;
246
  }
247

    
248
  $taxonRelationType = $taxonRelationship->type;
249

    
250
  if ($inverse) {
251
    $toTaxon = $taxonRelationship->fromTaxon;
252
    $relsign = $taxonRelationType->inverseSymbol;
253
    $reltype_representation = $taxonRelationType->inverseRepresentation_L10n;
254
  }
255
  else {
256
    $toTaxon = $taxonRelationship->toTaxon;
257
    $relsign = $taxonRelationType->symbol;
258
    $reltype_representation = $taxonRelationType->representation_L10n;
259
  }
260

    
261
  return cdm_related_taxon($toTaxon, NULL, $relsign, $reltype_representation, $taxonRelationship->doubtful, $doLinkTaxon);
262
}
263

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

    
298
  // 'taxonRelationships';
299
  $footnoteListKey = NULL;
300

    
301
  $skip_tags = array();
302

    
303
  $is_invalid = false;
304

    
305
  if (!$relsign) {
306

    
307
    switch ($reltype_uuid) {
308
      case UUID_HETEROTYPIC_SYNONYM_OF:
309
      case UUID_SYNONYM_OF:
310
        $relsign = $relsign_hetero;
311
        break;
312

    
313
      case UUID_HOMOTYPIC_SYNONYM_OF:
314
        $relsign = $relsign_homo;
315
        break;
316

    
317
      case UUID_MISAPPLIED_NAME_FOR:
318
      case UUID_INVALID_DESIGNATION_FOR:
319
        $skip_tags[] = 'authors';
320
        $is_invalid = true;
321
        $relsign = $relsign_invalid;
322

    
323
        break;
324

    
325
      default:
326
        $relsign = $relsign_invalid;
327
    }
328

    
329
  }
330

    
331
  if($doubtful) {
332
    $relsign = '?' . $relsign;
333
  }
334

    
335
  /*
336
  Names with status invalid or nudum are to be displayed with the
337
  $relsign_invalid, these names appear at the end of all names in their
338
  homotypic group (ordered correctly by the java cdm_lib).
339
  */
340
  if (isset($taxon->name->status) && is_array($taxon->name->status)) {
341
    foreach ($taxon->name->status as $status) {
342
      if (in_array($status->type->uuid , $nom_status_invalid_type_uuids)) {
343
        $relsign = $relsign_invalid;
344
        break;
345
      }
346
    }
347
  }
348

    
349
  // Now rendering starts ..
350
  RenderHints::pushToRenderStack('related_taxon');
351

    
352
  if (isset($taxon->name->nomenclaturalReference)) {
353
    $referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
354
  }
355
  $taxonUri = '';
356
  if ($doLinkTaxon) {
357
    $taxonUri = url(path_to_taxon($taxon->uuid, "synonymy"));
358
  }
359
  // Printing the taxonName and the handling the special case of annotations.
360
  if (!isset($referenceUri)) {
361
    $referenceUri = FALSE;
362
  }
363
  $out_taxon_part = render_taxon_or_name($taxon, $taxonUri, $referenceUri, TRUE, FALSE, $skip_tags, $is_invalid);
364
  $taxon_footnotes = theme('cdm_annotations_as_footnotekeys',
365
    array('cdmBase_list' => array(
366
      $taxon->name,
367
      $taxon,
368
    ),
369
      'footnote_list_key' => $footnoteListKey)
370
  );
371

    
372
  $homonyms = cdm_name_relationships_of($taxon);
373

    
374
  $out = '<span class="relation_sign" title="' . $reltype_representation . '">' . $relsign . '</span>'
375
    . $out_taxon_part . $taxon_footnotes . ' '  . $homonyms;
376

    
377
  $out = uuid_anchor($taxon->uuid, $out);
378

    
379
  RenderHints::popFromRenderStack();
380

    
381
  return $out;
382
}
383

    
384

    
385
/**
386
 * Creates markup for a taxon which is the accepted of another one
387
 *
388
 * @param $accepted_for_uuid
389
 *   The uuid of the accepted taxon
390
 */
391
function cdm_accepted_for($accepted_for_uuid) {
392

    
393
  if(!is_uuid($accepted_for_uuid)){
394
    return '';
395
  }
396

    
397
  RenderHints::pushToRenderStack('acceptedFor');
398
  $out = '';
399

    
400
  $synonym = cdm_ws_get(CDM_WS_PORTAL_TAXON, $accepted_for_uuid);
401
  if ($synonym) {
402
    $out .= '<span class="acceptedFor">';
403
    $out .= t('is accepted for ');
404
    if (isset($synonym->name->nomenclaturalReference)) {
405
      $referenceUri = url(path_to_reference($synonym->name->nomenclaturalReference->uuid));
406
    }
407
    $out .= render_taxon_or_name($synonym->name, NULL, $referenceUri);
408
    $out .= theme('cdm_annotations_as_footnotekeys', array('cdmBase_list' => $synonym));
409
    $out .= '</span>';
410
  }
411
  RenderHints::popFromRenderStack();
412
  return $out;
413
}
414

    
415
/**
416
 * Compose function for a list of taxa.
417
 *
418
 * This function is for used to:
419
 *
420
 * 1. Display search results
421
 * 2. List the taxa for a taxon name in the name page.
422
 *
423
 * @param $taxon_list array
424
 *   The list of CDM Taxon entities. e.g. The records array as contained in a pager object.
425
 * @param $freetext_search_results array
426
 * @param $show_classification boolean
427
 *
428
 * @ingroup compose
429
 *
430
 */
431
function compose_list_of_taxa($taxon_list, $freetext_search_results = array(), $show_classification = false) {
432

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

    
435
  RenderHints::pushToRenderStack('list_of_taxa');
436

    
437
  $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SEARCH_GALLERY_NAME);
438

    
439
  $showMedia_taxa = $gallery_settings['cdm_dataportal_show_taxon_thumbnails'];
440
  $showMedia_synonyms = $gallery_settings['cdm_dataportal_show_synonym_thumbnails'];
441
  $searched_in_classification = cdm_dataportal_searched_in_classification();
442
  $searched_in_classification_uuid = null;
443
  if(isset($searched_in_classification->uuid)){
444
    $searched_in_classification_uuid = $searched_in_classification->uuid;
445
  }
446

    
447
  // .. Well, for sure not as performant as before, but better than nothing.
448
  $synonym_uuids = array();
449
  $misappied_uuids = array();
450
  foreach ($taxon_list as $taxon) {
451
    if ($taxon->class == "Synonym") {
452
      if (!array_key_exists($taxon->uuid, $synonym_uuids)) {
453
        $synonym_uuids[$taxon->uuid] = $taxon->uuid;
454
      }
455
    }
456
    elseif (!_cdm_dataportal_acceptedByCurrentView($taxon)) {
457
      // Assuming that it is a misappied name, will be further examined below.
458
      $misappied_uuids[$taxon->uuid] = $taxon->uuid;
459
    }
460
  }
461

    
462
  // Batch service not jet implemented:
463
  // $table_of_accepted = cdm_ws_property(CDM_WS_PORTAL_TAXON_ACCEPTED,
464
  // join(',', $synonym_uuids));
465
  // thus ...
466
  $table_of_accepted = array();
467

    
468
  foreach ($synonym_uuids as $relatedUuid) {
469
    $classification_filter = '';
470
    if($searched_in_classification_uuid){
471
      $classification_filter = 'classificationFilter=' . $searched_in_classification_uuid;
472
    }
473
    $table_of_accepted[$relatedUuid] = cdm_ws_get(
474
      CDM_WS_PORTAL_TAXON_ACCEPTED,
475
      array($relatedUuid),
476
      $classification_filter
477
    );
478
  }
479

    
480
  foreach ($misappied_uuids as $relatedUuid) {
481
    $taxonRelations = cdm_ws_get(CDM_WS_PORTAL_TAXON_RELATIONS, array(
482
      $relatedUuid,
483
    ));
484
    foreach ($taxonRelations as $relation) {
485
      if ($relation->type->uuid == UUID_MISAPPLIED_NAME_FOR && _cdm_dataportal_acceptedByCurrentView($relation->toTaxon)) {
486
        $table_of_accepted[$relatedUuid][] = $relation->toTaxon;
487
      }
488
    }
489
  }
490

    
491
  $out = '<div class="cdm-item-list" style="background-image: none;">';
492
  $itemCnt = -1;
493
  foreach ($taxon_list as $taxon) {
494
    $itemCnt++;
495
    if (isset($table_of_accepted[$taxon->uuid])) {
496
      // Its a synonym or misapplied name.
497
      $is_synonym = isset($synonym_uuids[$taxon->uuid]); //TODO better use the $taxon->class attribute?
498
      $taxon_type = $is_synonym ? TAXON_TYPE_SYNONYM :TAXON_TYPE_MISAPPLIEDNAME;
499

    
500
      $acceptedTaxa = $table_of_accepted[$taxon->uuid];
501

    
502
      if (!is_array($acceptedTaxa)) {
503
        $acceptedTaxa = array($acceptedTaxa);
504
      }
505

    
506
      foreach ($acceptedTaxa as $acceptedTaxon) {
507
        if (is_object($acceptedTaxon)) {
508

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

    
569
      if ($showMedia_taxa) {
570
        $out .= theme('cdm_taxon_list_thumbnails', array('taxon' => $taxon));
571
      }
572
    }
573

    
574
    /*
575
     * the score field will be empty in case of MultiTermQueries like
576
     * WildcardQueries, since these are  constant score by default
577
     * since Lucene 2.9
578
     */
579
    if(isset($freetext_search_results[$itemCnt]) && $freetext_search_results[$itemCnt]->score && $freetext_search_results[$itemCnt]->maxScore){
580
      $percentage =  ( $freetext_search_results[$itemCnt]->score / $freetext_search_results[$itemCnt]->maxScore ) * 100;
581
      $out .= '<div class="score-bar"><div class="score-bar-indicator" style="width:' . $percentage .'% "></div></div>';
582
      $out .= '<div class="score-bar-value">' . number_format($percentage, 2) .'%</div>';
583
    }
584

    
585
    // Render highlighted fragments, these are made available by free text
586
    // searches.
587
    if (isset($freetext_search_results[$itemCnt]->fieldHighlightMap)) {
588
      $field_fragments = (array) $freetext_search_results[$itemCnt]->fieldHighlightMap;
589
      if (count($field_fragments) > 0) {
590
        $fragments_out = '';
591
        foreach ($field_fragments as $fieldName => $fragments) {
592
          $fragments_out .= '... <span class="' . $fieldName. '">' . filter_xss(join(" ... ", $fragments), array('b') ) . '</span>';
593
        }
594
        $out .= '<div class="fragment_highlight">' . $fragments_out . ' ...</div>';
595
      }
596
    }
597

    
598
    $out .= '</div>';
599
  }
600

    
601
  $out .= '</div>';
602
  RenderHints::popFromRenderStack();
603

    
604
  return markup_to_render_array($out); // TODO create render array of all list items in function
605
}
606

    
607

    
608
/**
609
 * Compose function for the taxonomic children
610
 *
611
 * @param $taxon_uuid
612
 *    The uuuid of the taxon to compose the list of taxonomic children for
613
 * @return
614
 *   A drupal render array.
615
 *
616
 * @ingroup compose
617
 */
618
function compose_taxonomic_children($taxon_uuid){
619

    
620
  $render_array = array();
621
  
622
  if($taxon_uuid) {
623
    $children = cdm_ws_get(CDM_WS_PORTAL_TAXONOMY_CHILDNODES_OF_TAXON, array(
624
      get_current_classification_uuid(),
625
      $taxon_uuid
626
      ));
627
    if($children){
628
      $taxonomic_children = theme('cdm_taxontree', array('tree' => $children));
629
      $render_array = markup_to_render_array($taxonomic_children);
630
    }
631
  }
632
  return $render_array;
633
}
634

    
(10-10/10)