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