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
|
static $dedup_rel_type_uuids = array(
|
58
|
UUID_MISAPPLIED_NAME_FOR,
|
59
|
UUID_INVALID_DESIGNATION_FOR,
|
60
|
UUID_PARTIAL_MISAPPLIEDNAME_FOR,
|
61
|
UUID_PROPARTE_MISAPPLIEDNAME_FOR
|
62
|
);
|
63
|
|
64
|
RenderHints::pushToRenderStack('taxon_relationships');
|
65
|
$footnote_list_key = 'taxon_relationships';
|
66
|
RenderHints::setFootnoteListKey($footnote_list_key);
|
67
|
|
68
|
$misapplied = array();
|
69
|
$joined_refs = array();
|
70
|
|
71
|
$taxon_relationship_types = variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT));
|
72
|
|
73
|
// Aggregate misapplied names having the same fullname:
|
74
|
// - deduplicate misapplied names, so that the same name it not shown multiple times in case it
|
75
|
// the duplicates only have different sensu references with detail and appended phrase (see #5647)
|
76
|
// - show only the author team as short citation for the sec reference
|
77
|
// - show the according reference as footnote to this short citation
|
78
|
//
|
79
|
// Example:
|
80
|
// "Xenoxylum foobar" sensu Grumbach¹; sensu Lem²
|
81
|
// 1. Novel marsian species, Grumbach, 2022
|
82
|
// 2. Flora solaris, Lem, 2019
|
83
|
if (isset($taxonRelationshipsDTO->relations[0])) {
|
84
|
foreach($taxonRelationshipsDTO->relations as $taxon_relation){
|
85
|
|
86
|
if (in_array($taxon_relation->type->uuid, $taxon_relationship_types)) {
|
87
|
|
88
|
if (in_array($taxon_relation->type->uuid, $dedup_rel_type_uuids)) {
|
89
|
|
90
|
RenderHints::pushToRenderStack('misapplied_name_for'); // TODO the render path string should in future come from $taxonRelation->type->...
|
91
|
|
92
|
// full name with relation symbol, rel sec as de-duplication key
|
93
|
// the sensu part will be removed from the key below in case it is present
|
94
|
$name_text = join(' ', cdm_tagged_text_values($taxon_relation->taggedText, array('name')));
|
95
|
$full_name_key = cdm_tagged_text_to_string($taxon_relation->taggedText, array('symbol', 'appendedPhrase'));
|
96
|
$symbol_text = join(' ', cdm_tagged_text_values($taxon_relation->taggedText, array('symbol')));
|
97
|
$full_name_key = $name_text . ' ' . str_replace($name_text, '', $full_name_key) . ' ' . $symbol_text;
|
98
|
|
99
|
cdm_taxonRelationships_process_relationship_dto($taxon_relation, $misapplied, $joined_refs, $full_name_key);
|
100
|
|
101
|
RenderHints::popFromRenderStack();
|
102
|
} else {
|
103
|
RenderHints::pushToRenderStack('other_taxon_relationship');
|
104
|
// All relationship types except misapplied_name_for and invalid_designation_for.
|
105
|
|
106
|
$taxon_relationships_lines[] = cdm_tagged_text_to_markup($taxon_relation->taggedText);
|
107
|
|
108
|
RenderHints::popFromRenderStack();
|
109
|
}
|
110
|
}
|
111
|
} // END loop over $taxonRelationshipsDTO->relations
|
112
|
|
113
|
}
|
114
|
|
115
|
// Sort the $joined_refs and create footnotes and footnote keys.
|
116
|
uasort($joined_refs, function($a, $b) {
|
117
|
if ($a['order_by_key'] == $b['order_by_key']) {
|
118
|
return 0;
|
119
|
}
|
120
|
return ($a['order_by_key'] < $b['order_by_key']) ? -1 : 1;
|
121
|
});
|
122
|
|
123
|
|
124
|
foreach ($joined_refs as $ref_key => $sensu_strings) {
|
125
|
if(!empty($sensu_strings)) {
|
126
|
$ref_key_tokens = explode('#', $ref_key);
|
127
|
$sensu_uuid = $ref_key_tokens[0];
|
128
|
$sensu_reference = cdm_ws_get(CDM_WS_REFERENCE, $sensu_uuid);
|
129
|
if(!$sensu_reference){
|
130
|
drupal_set_message("Problem fetching sensu reference with uuid " . $sensu_uuid, 'error');
|
131
|
}
|
132
|
if($sensu_strings['order_by_key'] != $sensu_reference->titleCache){
|
133
|
$sensu_reference_markup = theme('cdm_reference', array(
|
134
|
'reference' => $sensu_reference,
|
135
|
'microReference' => NULL,
|
136
|
'doLink' => false,
|
137
|
));
|
138
|
$footnote_key = FootnoteManager::addNewFootnote($footnote_list_key, $sensu_reference_markup);
|
139
|
$footnote_key = theme('cdm_footnote_key', array('footnoteKey' => $footnote_key));
|
140
|
$joined_refs[$ref_key]['markup'] = '<span class="sensu">' . $sensu_strings['markup'] . $footnote_key . '</span>';
|
141
|
}
|
142
|
}
|
143
|
}
|
144
|
|
145
|
// ---- Generate output ---- //
|
146
|
$out = '<div class="taxon-relationships">';
|
147
|
if (count($misapplied) > 0) {
|
148
|
ksort($misapplied); // order the misapplied by scientific name
|
149
|
$out .= '<ul class="misapplied">';
|
150
|
|
151
|
// create the list entries per misapplied name
|
152
|
foreach ($misapplied as $misapplied_name) {
|
153
|
$misapplied_name_markup = $misapplied_name['out'];
|
154
|
// all sensu and auct. for this MAN
|
155
|
if (isset($misapplied_name['sensu_uuids'])) {
|
156
|
$sensu_refs_with_fkey = array();
|
157
|
foreach ($misapplied_name['sensu_uuids'] as $sensu_data) {
|
158
|
if($sensu_data['uuid']){
|
159
|
$joined_ref_key = $sensu_data['uuid'] . ($sensu_data['citation_detail'] ? '#' . $sensu_data['citation_detail'] : '');
|
160
|
$sensu_refs_with_fkey[$sensu_data['prefix'] . $joined_refs[$joined_ref_key]['order_by_key']] = $sensu_data['prefix'] . $joined_refs[$joined_ref_key]['markup'];
|
161
|
} else {
|
162
|
$sensu_refs_with_fkey[$sensu_data['prefix']] = $sensu_data['prefix'];
|
163
|
}
|
164
|
}
|
165
|
ksort($sensu_refs_with_fkey);
|
166
|
$sensu_refs_with_fkey_markup = join('; ', $sensu_refs_with_fkey);
|
167
|
if(strpos($misapplied_name_markup, '{PLACEHOLDER_secReference}') !== false){
|
168
|
$misapplied_name_markup = str_replace('{PLACEHOLDER_secReference}', $sensu_refs_with_fkey_markup, $misapplied_name_markup);
|
169
|
// just remove the appendedPhrase placeholder as was included in the sensu_refs_with_fkey_markup
|
170
|
$misapplied_name_markup = str_replace('{PLACEHOLDER_appendedPhrase}', '', $misapplied_name_markup);
|
171
|
} else {
|
172
|
// no sec ref so there could only be the appended phrase
|
173
|
$misapplied_name_markup = str_replace('{PLACEHOLDER_appendedPhrase}', $sensu_refs_with_fkey_markup, $misapplied_name_markup);
|
174
|
}
|
175
|
}
|
176
|
|
177
|
// append the err. sec. if there is any for this MAN
|
178
|
if (isset($misapplied_name['relsec_uuids'])) {
|
179
|
$relsec_refs_with_fkey = array();
|
180
|
foreach ($misapplied_name['relsec_uuids'] as $relsec_data) {
|
181
|
if($relsec_data['uuid']) {
|
182
|
$relsec_refs_with_fkey[$relsec_data['prefix'] . $joined_refs[$relsec_data['uuid']]['order_by_key']] = $relsec_data['prefix'] . $joined_refs[$relsec_data['uuid']]['markup'];
|
183
|
}
|
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}', $relsec_refs_with_fkey_markup, $misapplied_name_markup);
|
188
|
}
|
189
|
// final line
|
190
|
$out .= '<li class="synonym"><span class="misapplied">' . $misapplied_name_markup . ' </span></li>';
|
191
|
}
|
192
|
$out .= '</ul>';
|
193
|
}
|
194
|
|
195
|
if (isset($taxon_relationships_lines) && is_array($taxon_relationships_lines) && count($taxon_relationships_lines) > 0) {
|
196
|
$out .= '<ul class="taxonRelationships">';
|
197
|
foreach ($taxon_relationships_lines as $taxon_relationship_line) {
|
198
|
$out .= '<li class="synonym">' . $taxon_relationship_line . '</li>';
|
199
|
}
|
200
|
$out .= '</ul>';
|
201
|
}
|
202
|
|
203
|
$footnotes = theme('cdm_footnotes', array('footnoteListKey' => $footnote_list_key, 'enclosingTag' => 'li'));
|
204
|
$footnotes .= theme('cdm_annotation_footnotes', array('footnoteListKey' => $footnote_list_key, 'enclosingTag' => 'li'));
|
205
|
|
206
|
$out .= '<ul class="footnotes">' . $footnotes . '</ul>';
|
207
|
$out .= '</div>';
|
208
|
|
209
|
RenderHints::popFromRenderStack();
|
210
|
return $out;
|
211
|
}
|
212
|
|
213
|
/**
|
214
|
* @param $taxon_relation
|
215
|
* @param $name_dedup_key
|
216
|
* @param $misapplied
|
217
|
* @param $joined_refs
|
218
|
|
219
|
*/
|
220
|
function cdm_taxonRelationships_process_relationship_dto($taxon_relation, &$misapplied, &$joined_refs, $name_dedup_key = null) {
|
221
|
$appended_phrase_text = join(' ', cdm_tagged_text_values($taxon_relation->taggedText, array('appendedPhrase')));
|
222
|
// remove/extract appendedPhrase, secReference, relSecReference and add placeholders if needed
|
223
|
tagged_text_extract($taxon_relation->taggedText, 'appendedPhrase', true);
|
224
|
$sensu_tagged_text = tagged_text_extract_secref($taxon_relation->taggedText, "secReference", true);
|
225
|
$relsec_tagged_text = tagged_text_extract_secref($taxon_relation->taggedText, "relSecReference", true);
|
226
|
|
227
|
if (isset($sensu_tagged_text[1])) {
|
228
|
// for de-duplication everything else needs to be equal except for appendedPhrase + MAN.sec + MAN.secDetail. see #7658#note-21
|
229
|
$name_dedup_key = str_replace(cdm_tagged_text_to_string($sensu_tagged_text), ' ', $name_dedup_key);
|
230
|
$appended_phrase_text = $appended_phrase_text . array_shift($sensu_tagged_text)->text; // remove first element which contains the "sensu", this will be added later in this code
|
231
|
$sensu_citation_detail = trim(join(' ', cdm_tagged_text_values($sensu_tagged_text, array('secMicroReference'))));
|
232
|
$sensu_citation_short_markup = cdm_tagged_text_to_markup($sensu_tagged_text);
|
233
|
$sensu_citation_short = cdm_tagged_text_to_string($sensu_tagged_text);
|
234
|
$sensu_uuid = $sensu_tagged_text[0]->entityReference->uuid;
|
235
|
$name_dedup_key = preg_replace('/\s+/', ' ', $name_dedup_key); // sanitize multiple whitespace characters
|
236
|
$misapplied[$name_dedup_key]['sensu_uuids'][] = array('uuid' => $sensu_uuid, 'prefix' => $appended_phrase_text, 'citation_detail' => $sensu_citation_detail);
|
237
|
$ref_key = $sensu_uuid . ($sensu_citation_detail ? '#' . $sensu_citation_detail : '');
|
238
|
if (!isset($joined_refs[$ref_key])) {
|
239
|
$joined_refs[$ref_key] = array(
|
240
|
'order_by_key' => $sensu_citation_short,
|
241
|
'markup' => $sensu_citation_short_markup // the footnote key will be appended later
|
242
|
);
|
243
|
}
|
244
|
} else if ($appended_phrase_text) {
|
245
|
// appended phrase without reference
|
246
|
$name_dedup_key = preg_replace('/\s+/', ' ', $name_dedup_key); // sanitize multiple whitespace characters
|
247
|
$misapplied[$name_dedup_key]['sensu_uuids'][] = array('uuid' => null, 'prefix' => $appended_phrase_text);
|
248
|
}
|
249
|
|
250
|
if (isset($relsec_tagged_text[1])) {
|
251
|
$appended_phrase_text = array_shift($relsec_tagged_text)->text; // remove first element which contains the "err. sec", this will be added later in this code
|
252
|
$relsec_citation_detail = trim(join(' ', cdm_tagged_text_values($relsec_tagged_text, array('secMicroReference'))));
|
253
|
$relsec_citation_short_markup = cdm_tagged_text_to_markup($relsec_tagged_text);
|
254
|
$relsec_citation_short = cdm_tagged_text_to_string($relsec_tagged_text);
|
255
|
$relsec_uuid = $relsec_tagged_text[0]->entityReference->uuid;
|
256
|
$misapplied[$name_dedup_key]['relsec_uuids'][] = array('uuid' => $relsec_uuid, 'prefix' => $appended_phrase_text, 'citation_detail' => $relsec_citation_detail);;
|
257
|
$ref_key = $relsec_uuid . ($relsec_citation_detail ? '#' . $relsec_citation_detail : '');
|
258
|
if (!isset($joined_refs[$ref_key])) {
|
259
|
$joined_refs[$ref_key] = array(
|
260
|
'order_by_key' => $relsec_citation_short,
|
261
|
'markup' => $relsec_citation_short_markup // the footnote key will be appended later
|
262
|
);
|
263
|
}
|
264
|
}
|
265
|
|
266
|
if (!isset($misapplied[$name_dedup_key]['out'])) {
|
267
|
$misapplied[$name_dedup_key]['out'] = cdm_tagged_text_to_markup($taxon_relation->taggedText);
|
268
|
} else {
|
269
|
// We need to add the anchors for all of the other misapplied names not
|
270
|
// being rendered explicitly.
|
271
|
$misapplied[$name_dedup_key]['out'] = uuid_anchor($taxon_relation->taxonUuid, $misapplied[$name_dedup_key]['out']);
|
272
|
}
|
273
|
}
|
274
|
|
275
|
/**
|
276
|
* Renders a representation of the given taxon relationship.
|
277
|
*
|
278
|
* According name relationships are also being rendered.
|
279
|
*
|
280
|
* @param $taxon
|
281
|
* The CDM TaxonBase entity
|
282
|
* @param $reltype_uuid
|
283
|
* The UUID of the TaxonRelationshipType
|
284
|
* @param $relsign
|
285
|
* Optional. Can be used to override the internal decision strategy on finding a suitable icon for the relationship
|
286
|
* @param $reltype_representation
|
287
|
* Optional: Defines the value for the title attribute of the html element enclosing the relsign
|
288
|
* @param $doubtful
|
289
|
* TODO
|
290
|
* @param $doLinkTaxon
|
291
|
* The taxon will be rendered as clickable link when true.
|
292
|
*
|
293
|
* @return string
|
294
|
* Markup for the taxon relationship.
|
295
|
*
|
296
|
* @throws Exception
|
297
|
*/
|
298
|
function cdm_related_taxon($taxon, $reltype_uuid = NULL, $relsign = NULL, $reltype_representation = NULL, $doubtful=false, $doLinkTaxon = FALSE) {
|
299
|
static $relsign_homo = '≡';
|
300
|
static $relsign_hetero = '=';
|
301
|
static $relsign_invalid = '–';
|
302
|
static $nom_status_invalid_type_uuids = array(
|
303
|
UUID_NOMENCLATURALSTATUS_TYPE_INVALID,
|
304
|
UUID_NOMENCLATURALSTATUS_TYPE_NUDUM,
|
305
|
UUID_NOMENCLATURALSTATUS_TYPE_COMBINATIONINVALID,
|
306
|
UUID_NOMENCLATURALSTATUS_TYPE_PROVISIONAL
|
307
|
);
|
308
|
|
309
|
// 'taxonRelationships';
|
310
|
$footnoteListKey = NULL;
|
311
|
|
312
|
$skip_tags = array();
|
313
|
|
314
|
$is_invalid = false;
|
315
|
|
316
|
if (!$relsign) {
|
317
|
|
318
|
switch ($reltype_uuid) {
|
319
|
case UUID_HETEROTYPIC_SYNONYM_OF:
|
320
|
case UUID_SYNONYM_OF:
|
321
|
$relsign = $relsign_hetero;
|
322
|
break;
|
323
|
|
324
|
case UUID_HOMOTYPIC_SYNONYM_OF:
|
325
|
$relsign = $relsign_homo;
|
326
|
break;
|
327
|
|
328
|
case UUID_MISAPPLIED_NAME_FOR:
|
329
|
case UUID_INVALID_DESIGNATION_FOR:
|
330
|
$skip_tags[] = 'authors';
|
331
|
$is_invalid = true;
|
332
|
$relsign = $relsign_invalid;
|
333
|
|
334
|
break;
|
335
|
|
336
|
default:
|
337
|
$relsign = $relsign_invalid;
|
338
|
}
|
339
|
|
340
|
}
|
341
|
|
342
|
if($doubtful) {
|
343
|
$relsign = '?' . $relsign;
|
344
|
}
|
345
|
|
346
|
/*
|
347
|
Names with status invalid or nudum are to be displayed with the
|
348
|
$relsign_invalid, these names appear at the end of all names in their
|
349
|
homotypic group (ordered correctly by the java cdm_lib).
|
350
|
*/
|
351
|
if (isset($taxon->name->status) && is_array($taxon->name->status)) {
|
352
|
foreach ($taxon->name->status as $status) {
|
353
|
if (in_array($status->type->uuid , $nom_status_invalid_type_uuids)) {
|
354
|
$relsign = $relsign_invalid;
|
355
|
break;
|
356
|
}
|
357
|
}
|
358
|
}
|
359
|
|
360
|
// Now rendering starts ..
|
361
|
RenderHints::pushToRenderStack('related_taxon');
|
362
|
|
363
|
if (isset($taxon->name->nomenclaturalReference)) {
|
364
|
$referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
|
365
|
}
|
366
|
$taxonUri = '';
|
367
|
if ($doLinkTaxon) {
|
368
|
$taxonUri = url(path_to_taxon($taxon->uuid, "synonymy"));
|
369
|
}
|
370
|
// Printing the taxonName and the handling the special case of annotations.
|
371
|
if (!isset($referenceUri)) {
|
372
|
$referenceUri = FALSE;
|
373
|
}
|
374
|
$out_taxon_part = render_taxon_or_name($taxon, $taxonUri, $referenceUri, TRUE, FALSE, $skip_tags, $is_invalid);
|
375
|
$taxon_footnotes = theme('cdm_annotations_as_footnotekeys',
|
376
|
array('cdmBase_list' => array(
|
377
|
$taxon->name,
|
378
|
$taxon,
|
379
|
),
|
380
|
'footnote_list_key' => $footnoteListKey)
|
381
|
);
|
382
|
|
383
|
$homonyms = cdm_name_relationships_of($taxon);
|
384
|
|
385
|
$out = '<span class="relation_sign" title="' . $reltype_representation . '">' . $relsign . '</span>'
|
386
|
. $out_taxon_part . $taxon_footnotes . ' ' . $homonyms;
|
387
|
|
388
|
$out = uuid_anchor($taxon->uuid, $out);
|
389
|
|
390
|
RenderHints::popFromRenderStack();
|
391
|
|
392
|
return $out;
|
393
|
}
|
394
|
|
395
|
|
396
|
/**
|
397
|
* Creates markup for a taxon which is the accepted of another one
|
398
|
*
|
399
|
* @param $accepted_for_uuid
|
400
|
* The uuid of the accepted taxon
|
401
|
*/
|
402
|
function cdm_accepted_for($accepted_for_uuid) {
|
403
|
|
404
|
if(!is_uuid($accepted_for_uuid)){
|
405
|
return '';
|
406
|
}
|
407
|
|
408
|
RenderHints::pushToRenderStack('acceptedFor');
|
409
|
$out = '';
|
410
|
|
411
|
$synonym = cdm_ws_get(CDM_WS_PORTAL_TAXON, $accepted_for_uuid);
|
412
|
if ($synonym) {
|
413
|
$out .= '<span class="acceptedFor">';
|
414
|
$out .= t('is accepted for ');
|
415
|
if (isset($synonym->name->nomenclaturalReference)) {
|
416
|
$referenceUri = url(path_to_reference($synonym->name->nomenclaturalReference->uuid));
|
417
|
}
|
418
|
$out .= render_taxon_or_name($synonym->name, NULL, $referenceUri);
|
419
|
$out .= theme('cdm_annotations_as_footnotekeys', array('cdmBase_list' => $synonym));
|
420
|
$out .= '</span>';
|
421
|
}
|
422
|
RenderHints::popFromRenderStack();
|
423
|
return $out;
|
424
|
}
|
425
|
|
426
|
/**
|
427
|
* Compose function for a list of taxa.
|
428
|
*
|
429
|
* This function is for used to:
|
430
|
*
|
431
|
* 1. Display search results
|
432
|
* 2. List the taxa for a taxon name in the name page.
|
433
|
*
|
434
|
* @param $taxon_list array
|
435
|
* The list of CDM Taxon entities. e.g. The records array as contained in a pager object.
|
436
|
* @param $freetext_search_results array
|
437
|
* @param $show_classification boolean
|
438
|
*
|
439
|
* @ingroup compose
|
440
|
*
|
441
|
*/
|
442
|
function compose_list_of_taxa($taxon_list, $freetext_search_results = array(), $show_classification = false) {
|
443
|
|
444
|
$unclassified_snippet = '<span class="unclassified">' . t('unclassified') . '</span>';
|
445
|
|
446
|
RenderHints::pushToRenderStack('list_of_taxa');
|
447
|
|
448
|
$gallery_settings = getGallerySettings(CDM_DATAPORTAL_SEARCH_GALLERY_NAME);
|
449
|
|
450
|
$showMedia_taxa = $gallery_settings['cdm_dataportal_show_taxon_thumbnails'];
|
451
|
$showMedia_synonyms = $gallery_settings['cdm_dataportal_show_synonym_thumbnails'];
|
452
|
$searched_in_classification = cdm_dataportal_searched_in_classification();
|
453
|
$searched_in_classification_uuid = null;
|
454
|
if(isset($searched_in_classification->uuid)){
|
455
|
$searched_in_classification_uuid = $searched_in_classification->uuid;
|
456
|
}
|
457
|
|
458
|
// .. Well, for sure not as performant as before, but better than nothing.
|
459
|
$synonym_uuids = array();
|
460
|
$misappied_uuids = array();
|
461
|
foreach ($taxon_list as $taxon) {
|
462
|
if ($taxon->class == "Synonym") {
|
463
|
if (!array_key_exists($taxon->uuid, $synonym_uuids)) {
|
464
|
$synonym_uuids[$taxon->uuid] = $taxon->uuid;
|
465
|
}
|
466
|
}
|
467
|
elseif (!_cdm_dataportal_acceptedByCurrentView($taxon)) {
|
468
|
// Assuming that it is a misappied name, will be further examined below.
|
469
|
$misappied_uuids[$taxon->uuid] = $taxon->uuid;
|
470
|
}
|
471
|
}
|
472
|
|
473
|
// Batch service not jet implemented:
|
474
|
// $table_of_accepted = cdm_ws_property(CDM_WS_PORTAL_TAXON_ACCEPTED,
|
475
|
// join(',', $synonym_uuids));
|
476
|
// thus ...
|
477
|
$table_of_accepted = array();
|
478
|
|
479
|
foreach ($synonym_uuids as $relatedUuid) {
|
480
|
$classification_filter = '';
|
481
|
if($searched_in_classification_uuid){
|
482
|
$classification_filter = 'classificationFilter=' . $searched_in_classification_uuid;
|
483
|
}
|
484
|
$table_of_accepted[$relatedUuid] = cdm_ws_get(
|
485
|
CDM_WS_PORTAL_TAXON_ACCEPTED,
|
486
|
array($relatedUuid),
|
487
|
$classification_filter
|
488
|
);
|
489
|
}
|
490
|
|
491
|
foreach ($misappied_uuids as $relatedUuid) {
|
492
|
$taxonRelations = cdm_ws_get(CDM_WS_PORTAL_TAXON_RELATIONS, array(
|
493
|
$relatedUuid,
|
494
|
));
|
495
|
foreach ($taxonRelations as $relation) {
|
496
|
if ($relation->type->uuid == UUID_MISAPPLIED_NAME_FOR && _cdm_dataportal_acceptedByCurrentView($relation->toTaxon)) {
|
497
|
$table_of_accepted[$relatedUuid][] = $relation->toTaxon;
|
498
|
}
|
499
|
}
|
500
|
}
|
501
|
|
502
|
$out = '<div class="cdm-item-list" style="background-image: none;">';
|
503
|
$itemCnt = -1;
|
504
|
foreach ($taxon_list as $taxon) {
|
505
|
$itemCnt++;
|
506
|
if (isset($table_of_accepted[$taxon->uuid])) {
|
507
|
// Its a synonym or misapplied name.
|
508
|
$is_synonym = isset($synonym_uuids[$taxon->uuid]); //TODO better use the $taxon->class attribute?
|
509
|
$taxon_type = $is_synonym ? TAXON_TYPE_SYNONYM :TAXON_TYPE_MISAPPLIEDNAME;
|
510
|
|
511
|
$acceptedTaxa = $table_of_accepted[$taxon->uuid];
|
512
|
|
513
|
if (!is_array($acceptedTaxa)) {
|
514
|
$acceptedTaxa = array($acceptedTaxa);
|
515
|
}
|
516
|
|
517
|
foreach ($acceptedTaxa as $acceptedTaxon) {
|
518
|
if (is_object($acceptedTaxon)) {
|
519
|
|
520
|
$taxonUri = uri_to_synonym($taxon->uuid, $acceptedTaxon->uuid);
|
521
|
$referenceUri = '';
|
522
|
if (isset($acceptedTaxon->name->nomenclaturalReference)) {
|
523
|
$referenceUri = url(path_to_reference($acceptedTaxon->name->nomenclaturalReference->uuid));
|
524
|
}
|
525
|
$taxon_or_name = $is_synonym ? $taxon->name : $taxon;
|
526
|
// $taxon_or_name this is a trick to suppress the sec reference for synonyms
|
527
|
// supplying the name will cause render_taxon_or_name() to not show the sec reference
|
528
|
$out .= "<div class=\"item " . $taxon_type . "\">" . render_taxon_or_name($taxon_or_name, $taxonUri, $referenceUri);
|
529
|
if($taxon_type == TAXON_TYPE_MISAPPLIEDNAME && is_object($taxon->sec)){
|
530
|
if(isset($taxon->sec->authorship)){
|
531
|
$authorship = $taxon->sec->authorship->titleCache;
|
532
|
} else {
|
533
|
$authorship = $taxon->sec->titleCache;
|
534
|
}
|
535
|
$out .= ' sensu ' . $authorship;
|
536
|
}
|
537
|
if ($show_classification) {
|
538
|
$classifications = get_classifications_for_taxon($taxon);
|
539
|
$classification_titles = array();
|
540
|
foreach ($classifications as $classification) {
|
541
|
if (isset($classification->titleCache)) {
|
542
|
$classification_titles[] = $classification->titleCache;
|
543
|
}
|
544
|
}
|
545
|
if (count($classification_titles) == 0) {
|
546
|
$classification_titles[] = $unclassified_snippet;
|
547
|
}
|
548
|
$out .= '<span class="classifications"><span class="separator"> : </span>' . implode(', ', $classification_titles) . '</span>';
|
549
|
}
|
550
|
$out .= theme('cdm_annotations_as_footnotekeys', array('cdmBase_list' => $taxon));
|
551
|
if ($showMedia_synonyms) {
|
552
|
$out .= theme('cdm_taxon_list_thumbnails', array('taxon' => $acceptedTaxon));
|
553
|
}
|
554
|
}
|
555
|
}
|
556
|
}
|
557
|
else {
|
558
|
// Its a Taxon.
|
559
|
$taxonUri = url(path_to_taxon($taxon->uuid));
|
560
|
$referenceUri = '';
|
561
|
if (isset($taxon->name->nomenclaturalReference)) {
|
562
|
$referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
|
563
|
}
|
564
|
$out .= '<div class="item Taxon">' . render_taxon_or_name($taxon, $taxonUri, $referenceUri);
|
565
|
if ($show_classification) {
|
566
|
$classifications = get_classifications_for_taxon($taxon);
|
567
|
$classification_titles = array();
|
568
|
foreach ($classifications as $classification) {
|
569
|
if (isset($classification->titleCache)) {
|
570
|
$classification_titles[] = $classification->titleCache;
|
571
|
}
|
572
|
}
|
573
|
if(count($classification_titles) == 0){
|
574
|
$classification_titles[] = $unclassified_snippet;
|
575
|
}
|
576
|
$out .= '<span class="classifications"><span class="separator"> : </span>' . implode(', ', $classification_titles) . '</span>';
|
577
|
}
|
578
|
$out .= theme('cdm_annotations_as_footnotekeys', array('cdmBase_list' => $taxon));
|
579
|
|
580
|
if ($showMedia_taxa) {
|
581
|
$out .= theme('cdm_taxon_list_thumbnails', array('taxon' => $taxon));
|
582
|
}
|
583
|
}
|
584
|
|
585
|
/*
|
586
|
* the score field will be empty in case of MultiTermQueries like
|
587
|
* WildcardQueries, since these are constant score by default
|
588
|
* since Lucene 2.9
|
589
|
*/
|
590
|
if(isset($freetext_search_results[$itemCnt]) && $freetext_search_results[$itemCnt]->score && $freetext_search_results[$itemCnt]->maxScore){
|
591
|
$percentage = ( $freetext_search_results[$itemCnt]->score / $freetext_search_results[$itemCnt]->maxScore ) * 100;
|
592
|
$out .= '<div class="score-bar"><div class="score-bar-indicator" style="width:' . $percentage .'% "></div></div>';
|
593
|
$out .= '<div class="score-bar-value">' . number_format($percentage, 2) .'%</div>';
|
594
|
}
|
595
|
|
596
|
// Render highlighted fragments, these are made available by free text
|
597
|
// searches.
|
598
|
if (isset($freetext_search_results[$itemCnt]->fieldHighlightMap)) {
|
599
|
$field_fragments = (array) $freetext_search_results[$itemCnt]->fieldHighlightMap;
|
600
|
if (count($field_fragments) > 0) {
|
601
|
$fragments_out = '';
|
602
|
foreach ($field_fragments as $fieldName => $fragments) {
|
603
|
$fragments_out .= '... <span class="' . $fieldName. '">' . filter_xss(join(" ... ", $fragments), array('b') ) . '</span>';
|
604
|
}
|
605
|
$out .= '<div class="fragment_highlight">' . $fragments_out . ' ...</div>';
|
606
|
}
|
607
|
}
|
608
|
|
609
|
$out .= '</div>';
|
610
|
}
|
611
|
|
612
|
$out .= '</div>';
|
613
|
RenderHints::popFromRenderStack();
|
614
|
|
615
|
return markup_to_render_array($out); // TODO create render array of all list items in function
|
616
|
}
|
617
|
|
618
|
|
619
|
/**
|
620
|
* Compose function for the taxonomic children
|
621
|
*
|
622
|
* @param $taxon_uuid
|
623
|
* The uuuid of the taxon to compose the list of taxonomic children for
|
624
|
* @return
|
625
|
* A drupal render array.
|
626
|
*
|
627
|
* @ingroup compose
|
628
|
*/
|
629
|
function compose_taxonomic_children($taxon_uuid){
|
630
|
|
631
|
$render_array = array();
|
632
|
|
633
|
if($taxon_uuid) {
|
634
|
$children = cdm_ws_get(CDM_WS_PORTAL_TAXONOMY_CHILDNODES_OF_TAXON, array(
|
635
|
get_current_classification_uuid(),
|
636
|
$taxon_uuid
|
637
|
));
|
638
|
if($children){
|
639
|
$taxonomic_children = theme('cdm_taxontree', array('tree' => $children));
|
640
|
$render_array = markup_to_render_array($taxonomic_children);
|
641
|
}
|
642
|
}
|
643
|
return $render_array;
|
644
|
}
|
645
|
|