1 |
2bdf5f11
|
Andreas Kohlbecker
|
<?php
|
2 |
f19f47fa
|
Andreas Kohlbecker
|
/**
|
3 |
|
|
* @file
|
4 |
|
|
* Functions for dealing with CDM entities from the package model.common
|
5 |
|
|
*
|
6 |
|
|
* @copyright
|
7 |
|
|
* (C) 2007-2012 EDIT
|
8 |
|
|
* European Distributed Institute of Taxonomy
|
9 |
|
|
* http://www.e-taxonomy.eu
|
10 |
|
|
*
|
11 |
|
|
* The contents of this module are subject to the Mozilla
|
12 |
|
|
* Public License Version 1.1.
|
13 |
|
|
* @see http://www.mozilla.org/MPL/MPL-1.1.html
|
14 |
|
|
*
|
15 |
|
|
* @author
|
16 |
|
|
* - Andreas Kohlbecker <a.kohlbecker@BGBM.org>
|
17 |
2bdf5f11
|
Andreas Kohlbecker
|
*/
|
18 |
|
|
|
19 |
5b26b91a
|
Andreas Kohlbecker
|
/**
|
20 |
|
|
* @defgroup compose Compose functions
|
21 |
|
|
* @{
|
22 |
|
|
* Functions which are composing Drupal render arays
|
23 |
|
|
*
|
24 |
31765b7b
|
Andreas Kohlbecker
|
* The cdm_dataportal module needs to compose rather complex render arrays from
|
25 |
ce29c528
|
Andreas Kohlbecker
|
* the data returned by the CDM REST service. The compose functions are
|
26 |
|
|
* responsible for creating the render arrays.
|
27 |
5b26b91a
|
Andreas Kohlbecker
|
*
|
28 |
ce29c528
|
Andreas Kohlbecker
|
* All these functions are also implementations of the compose_hook()
|
29 |
|
|
* which is used in the proxy_content() function.
|
30 |
5b26b91a
|
Andreas Kohlbecker
|
* @}
|
31 |
|
|
*/
|
32 |
|
|
|
33 |
df2eb131
|
Andreas Kohlbecker
|
|
34 |
|
|
/**
|
35 |
|
|
* Composes an HTML element class attribute value composed of
|
36 |
|
|
* the short-name of the cdm class and the uuid of the entity.
|
37 |
|
|
* This class attribute should be used wherever an cdm-entity is rendered.
|
38 |
|
|
*
|
39 |
|
|
* In case of Taxon entities or TaxonNodeDTOs the secReference is also added
|
40 |
|
|
* to the class attributes as 'sec_uuid:<uuid>'. In case of TaxonNodeDTOs the
|
41 |
|
|
* Taxon uuid is added also as taxon_uuid:<uuid>
|
42 |
|
|
*
|
43 |
|
|
* These according class selectors in css must be escaped, eg:
|
44 |
|
|
* .cdm\:TextData
|
45 |
|
|
*
|
46 |
|
|
* @param $cdm_entity
|
47 |
|
|
* A CDM entity, TaxonNodeDTO or TypedEntityReference
|
48 |
|
|
*/
|
49 |
|
|
function html_class_attribute_ref($cdm_entity) {
|
50 |
|
|
|
51 |
|
|
$attributes = '';
|
52 |
|
|
if (is_cdm_entity($cdm_entity)) {
|
53 |
|
|
$attributes = "cdm:" . $cdm_entity->class . " uuid:" . $cdm_entity->uuid;
|
54 |
|
|
} elseif (isset($cdm_entity->class)) {
|
55 |
|
|
switch ($cdm_entity->class){
|
56 |
|
|
case 'TypedEntityReference':
|
57 |
|
|
$attributes = "cdm:" . $cdm_entity->type . " uuid:" . $cdm_entity->uuid;
|
58 |
|
|
break;
|
59 |
|
|
case 'TaxonNodeDto':
|
60 |
|
|
$attributes .= " taxon_uuid:" . $cdm_entity->taxonUuid . " sec_uuid:" . $cdm_entity->secUuid;;
|
61 |
|
|
break;
|
62 |
|
|
case 'Taxon':
|
63 |
|
|
if(isset($cdm_entity->sec->uuid)){
|
64 |
|
|
$attributes .= " sec_uuid:" . $cdm_entity->sec->uuid;
|
65 |
|
|
}
|
66 |
|
|
break;
|
67 |
|
|
}
|
68 |
|
|
}
|
69 |
|
|
|
70 |
|
|
return $attributes;
|
71 |
|
|
}
|
72 |
|
|
|
73 |
|
|
|
74 |
2bdf5f11
|
Andreas Kohlbecker
|
/**
|
75 |
|
|
* Compose an render array from a CDM Marker object.
|
76 |
|
|
*
|
77 |
|
|
* compose_hook() implementation
|
78 |
|
|
*
|
79 |
|
|
* @param object $marker
|
80 |
|
|
* CDM instance of type Marker
|
81 |
|
|
* @return array
|
82 |
|
|
* A drupal render array
|
83 |
5b26b91a
|
Andreas Kohlbecker
|
*
|
84 |
|
|
* @ingroup compose
|
85 |
2bdf5f11
|
Andreas Kohlbecker
|
*/
|
86 |
|
|
function compose_cdm_marker($marker) {
|
87 |
|
|
|
88 |
|
|
$render_array = array(
|
89 |
|
|
// ---- generic
|
90 |
|
|
// these entries should be common to all cdm enitiy render arrays
|
91 |
|
|
'#theme' => 'cdm_marker', // TODO add alternative theme funcitons: 'cdm_marker_' . marker.type.label
|
92 |
f19f47fa
|
Andreas Kohlbecker
|
'#attributes' => array('class' => html_class_attribute_ref($marker)),
|
93 |
2bdf5f11
|
Andreas Kohlbecker
|
|
94 |
|
|
// ---- individual
|
95 |
|
|
'#label' => $marker->markerType->representation_L10n . ': ' . (($marker->flag !== TRUE ? t('yes') : t('no'))),
|
96 |
|
|
);
|
97 |
|
|
|
98 |
|
|
return $render_array;
|
99 |
|
|
}
|
100 |
19e097a3
|
Andreas Kohlbecker
|
|
101 |
|
|
/**
|
102 |
|
|
* Checks if the given $cdm_entitiy has a marker the type references by the
|
103 |
|
|
* $marker_type_uuid and returns TRUE if a matching marker has been found.
|
104 |
|
|
*
|
105 |
ce29c528
|
Andreas Kohlbecker
|
* @param object $cdm_entitiy A CDM Entity
|
106 |
19e097a3
|
Andreas Kohlbecker
|
* @param string $marker_type_uuid
|
107 |
|
|
*/
|
108 |
|
|
function cdm_entity_has_marker($cdm_entitiy, $marker_type_uuid) {
|
109 |
|
|
if(isset($cdm_entitiy->markers[0]) && !is_uuid($marker_type_uuid)){
|
110 |
|
|
foreach ($cdm_entitiy->markers as $marker) {
|
111 |
|
|
if(isset($marker->markerType) && $marker->markerType->uuid == $marker_type_uuid){
|
112 |
|
|
return TRUE;
|
113 |
|
|
}
|
114 |
|
|
}
|
115 |
|
|
}
|
116 |
|
|
return FALSE;
|
117 |
c2486c6b
|
Andreas Kohlbecker
|
}
|
118 |
|
|
|
119 |
|
|
/**
|
120 |
c7c53f4e
|
Andreas Kohlbecker
|
* Sorts an array of CDM IdentifiableSource instances by 1. by the
|
121 |
ce29c528
|
Andreas Kohlbecker
|
* author teams family names and 2. by the publication date.
|
122 |
c2486c6b
|
Andreas Kohlbecker
|
*
|
123 |
ce29c528
|
Andreas Kohlbecker
|
* @param array $sources
|
124 |
c2486c6b
|
Andreas Kohlbecker
|
* The array of CDM IdentifiableSource instances
|
125 |
bb93d5d1
|
Andreas Kohlbecker
|
* @return array
|
126 |
|
|
* An array of drupal render arrays
|
127 |
c2486c6b
|
Andreas Kohlbecker
|
*/
|
128 |
bb93d5d1
|
Andreas Kohlbecker
|
function oder_and_render_original_sources($sources){
|
129 |
c2486c6b
|
Andreas Kohlbecker
|
$sort_array = array();
|
130 |
|
|
foreach ($sources as $source) {
|
131 |
c7c53f4e
|
Andreas Kohlbecker
|
|
132 |
|
|
$order_key = '';
|
133 |
|
|
|
134 |
|
|
// find the familynames
|
135 |
1ce9afb7
|
Patric Plitzner
|
if(isset($source->citation->uuid) && !isset($source->citation->authorship)){
|
136 |
c7c53f4e
|
Andreas Kohlbecker
|
$authorteam = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $source->citation->uuid);
|
137 |
|
|
|
138 |
|
|
$persons = array();
|
139 |
|
|
if($authorteam->class == 'Team'){
|
140 |
|
|
if(isset($authorteam->teamMembers)){
|
141 |
|
|
$persons = $authorteam->teamMembers;
|
142 |
|
|
}
|
143 |
|
|
} else {
|
144 |
|
|
$persons[] = $authorteam;
|
145 |
|
|
}
|
146 |
|
|
|
147 |
|
|
foreach($persons as $person){
|
148 |
|
|
if(!empty($person->lastname)){
|
149 |
|
|
$order_key .= $person->lastname;
|
150 |
|
|
} else {
|
151 |
|
|
$order_key .= $person->titleCache;
|
152 |
|
|
}
|
153 |
|
|
}
|
154 |
|
|
if(empty($order_key)){
|
155 |
|
|
$order_key = $authorteam->titleCache;
|
156 |
|
|
}
|
157 |
|
|
|
158 |
c2486c6b
|
Andreas Kohlbecker
|
}
|
159 |
c7c53f4e
|
Andreas Kohlbecker
|
$order_key = str_pad($order_key, 50);
|
160 |
|
|
|
161 |
|
|
// add publication date to the key
|
162 |
|
|
if(isset($source->citation->datePublished)){
|
163 |
|
|
$order_key .= '_' . timePeriodAsOrderKey($source->citation->datePublished);
|
164 |
|
|
} else {
|
165 |
|
|
$order_key .= '_' . "0000";
|
166 |
c2486c6b
|
Andreas Kohlbecker
|
}
|
167 |
c7c53f4e
|
Andreas Kohlbecker
|
|
168 |
|
|
// padd key until unique
|
169 |
c2486c6b
|
Andreas Kohlbecker
|
while(array_key_exists($order_key, $sort_array)){
|
170 |
|
|
$order_key .= "_";
|
171 |
|
|
}
|
172 |
c7c53f4e
|
Andreas Kohlbecker
|
|
173 |
bb93d5d1
|
Andreas Kohlbecker
|
$sort_array[$order_key] = render_original_source($source);
|
174 |
c2486c6b
|
Andreas Kohlbecker
|
}
|
175 |
|
|
ksort($sort_array);
|
176 |
|
|
return array_values ($sort_array);
|
177 |
ce29c528
|
Andreas Kohlbecker
|
}
|
178 |
|
|
|
179 |
9e2aa1ff
|
Andreas Kohlbecker
|
/**
|
180 |
|
|
* Compare callback to be used in usort to sort image sources of CDM OriginalSource instances.
|
181 |
|
|
*
|
182 |
bb93d5d1
|
Andreas Kohlbecker
|
* TODO the compare strategy implemented in oder_and_render_original_sources() is probably better but is not taking the
|
183 |
9e2aa1ff
|
Andreas Kohlbecker
|
* originalName into account.
|
184 |
|
|
*
|
185 |
|
|
* @param $a
|
186 |
|
|
* @param $b
|
187 |
|
|
*/
|
188 |
|
|
function compare_original_sources($a, $b){
|
189 |
|
|
|
190 |
7c0c59d8
|
Andreas Kohlbecker
|
$a_string = '';
|
191 |
|
|
if(isset($a->citation->titleCache)) {
|
192 |
|
|
$a_string = $a->citation->titleCache;
|
193 |
|
|
}
|
194 |
9e2aa1ff
|
Andreas Kohlbecker
|
if((isset($a->nameUsedInSource))){
|
195 |
|
|
$a_string .= $a->nameUsedInSource->titleCache;
|
196 |
|
|
} elseif (isset($a->originalNameString)){
|
197 |
|
|
$a_string .= $a->originalNameString;
|
198 |
|
|
}
|
199 |
|
|
|
200 |
7c0c59d8
|
Andreas Kohlbecker
|
$b_string = '';
|
201 |
|
|
if(isset($b->citation->titleCache)) {
|
202 |
|
|
$b_string = $b->citation->titleCache;
|
203 |
|
|
};
|
204 |
9e2aa1ff
|
Andreas Kohlbecker
|
if((isset($b->nameUsedInSource))){
|
205 |
|
|
$b_string .= $b->nameUsedInSource->titleCache;
|
206 |
|
|
} elseif (isset($b->originalNameString)){
|
207 |
|
|
$b_string .= $b->originalNameString;
|
208 |
|
|
}
|
209 |
|
|
|
210 |
|
|
if ($a_string == $b_string) {
|
211 |
|
|
return 0;
|
212 |
|
|
}
|
213 |
|
|
return ($a_string < $b_string) ? -1 : 1;
|
214 |
|
|
}
|
215 |
|
|
|
216 |
|
|
/**
|
217 |
|
|
* Compare callback to be used in usort to sort image sources of CDM Media instances.
|
218 |
|
|
*
|
219 |
|
|
* @param $a
|
220 |
|
|
* @param $b
|
221 |
|
|
*/
|
222 |
50a67433
|
Andreas Kohlbecker
|
function compare_text_data($a, $b) {
|
223 |
9e2aa1ff
|
Andreas Kohlbecker
|
|
224 |
|
|
if ($a->multilanguageText_L10n->text == $b->multilanguageText_L10n->text) {
|
225 |
|
|
return 0;
|
226 |
|
|
}
|
227 |
|
|
return ($a->multilanguageText_L10n->text < $b->multilanguageText_L10n->text) ? -1 : 1;
|
228 |
|
|
}
|
229 |
|
|
|
230 |
ce29c528
|
Andreas Kohlbecker
|
/**
|
231 |
|
|
* Compare two different footnotes objects.
|
232 |
|
|
*
|
233 |
|
|
* The comparison is based on the footnote key. The one which is
|
234 |
|
|
* displayed as footnote number.
|
235 |
|
|
*
|
236 |
|
|
* @param mixed $a
|
237 |
|
|
* Footnote object $a.
|
238 |
|
|
* @param mixed $b
|
239 |
|
|
* Footnote object $b.
|
240 |
|
|
*/
|
241 |
|
|
function footnotes_key_compare($a, $b) {
|
242 |
|
|
$res = 0;
|
243 |
|
|
if (empty($a) || empty($b)) {
|
244 |
|
|
return $res;
|
245 |
|
|
}
|
246 |
|
|
if ($a->keyStr < $b->keyStr) {
|
247 |
|
|
$res = -1;
|
248 |
|
|
}
|
249 |
|
|
elseif ($a->keyStr > $b->keyStr) {
|
250 |
|
|
$res = 1;
|
251 |
|
|
}
|
252 |
|
|
return $res;
|
253 |
|
|
}
|
254 |
74ee6b54
|
Andreas Kohlbecker
|
|
255 |
cd3ea2e8
|
Andreas Kohlbecker
|
/**
|
256 |
2f4646e0
|
Andreas Kohlbecker
|
* Provides an explanatory text on the statistical values representation as generated by statistical_values()
|
257 |
cd3ea2e8
|
Andreas Kohlbecker
|
*
|
258 |
|
|
* @return string
|
259 |
|
|
* the text
|
260 |
|
|
*/
|
261 |
|
|
function statistical_values_explanation(){
|
262 |
|
|
return t("A single or the first number in square brackets denotes sample size");
|
263 |
|
|
}
|
264 |
74ee6b54
|
Andreas Kohlbecker
|
|
265 |
|
|
/**
|
266 |
2f4646e0
|
Andreas Kohlbecker
|
* Creates an array suitable to be used in statistical_values()
|
267 |
f63479ae
|
Andreas Kohlbecker
|
* The min max structure is suitable for being used in the context
|
268 |
2eb6acb7
|
Andreas Kohlbecker
|
* of GatheringEvents and StatisticalMeasures (see render_quantitative_statistics()).
|
269 |
|
|
*
|
270 |
|
|
* The order of the items is important for the display and must not be changed.
|
271 |
74ee6b54
|
Andreas Kohlbecker
|
*
|
272 |
|
|
* @return array
|
273 |
|
|
*/
|
274 |
2f4646e0
|
Andreas Kohlbecker
|
function statistical_values_array() {
|
275 |
f63479ae
|
Andreas Kohlbecker
|
|
276 |
|
|
$min_max = [
|
277 |
b94b1aec
|
Andreas Kohlbecker
|
'ExactValue' => NULL,
|
278 |
f63479ae
|
Andreas Kohlbecker
|
'Min' => NULL,
|
279 |
|
|
'TypicalLowerBoundary' => NULL,
|
280 |
|
|
'TypicalUpperBoundary' => NULL,
|
281 |
|
|
'Max' => NULL,
|
282 |
2eb6acb7
|
Andreas Kohlbecker
|
'SampleSize' => NULL,
|
283 |
|
|
'Average' => NULL,
|
284 |
f63479ae
|
Andreas Kohlbecker
|
'Variance' => NULL,
|
285 |
b94b1aec
|
Andreas Kohlbecker
|
'StandardDeviation' => NULL
|
286 |
f63479ae
|
Andreas Kohlbecker
|
];
|
287 |
74ee6b54
|
Andreas Kohlbecker
|
return $min_max;
|
288 |
|
|
}
|
289 |
|
|
|
290 |
|
|
/**
|
291 |
5a079dbf
|
Andreas Kohlbecker
|
* Creates markup from a min max array.
|
292 |
|
|
*
|
293 |
2f4646e0
|
Andreas Kohlbecker
|
* NOTE: use statistical_values_array() to create an appropriate array
|
294 |
74ee6b54
|
Andreas Kohlbecker
|
*
|
295 |
f63479ae
|
Andreas Kohlbecker
|
* Internally Min will be translated to TypicalLowerBoundary if no such value is present.
|
296 |
|
|
* The same also accounts for Max and TypicalUpperBoundary.
|
297 |
|
|
*
|
298 |
|
|
* For further details see #3742, #8766
|
299 |
|
|
*
|
300 |
2f4646e0
|
Andreas Kohlbecker
|
* @param $stat_vals_arr
|
301 |
|
|
* the statistical values array as produced by statistical_values_array()
|
302 |
5a079dbf
|
Andreas Kohlbecker
|
* @param $unit
|
303 |
|
|
* Defaults to no unit
|
304 |
74ee6b54
|
Andreas Kohlbecker
|
* @return string
|
305 |
|
|
*/
|
306 |
2f4646e0
|
Andreas Kohlbecker
|
function statistical_values($stat_vals_arr, $unit = '') {
|
307 |
74ee6b54
|
Andreas Kohlbecker
|
|
308 |
df2eb131
|
Andreas Kohlbecker
|
static $xbar_equals = 'x̄='; // x̄ is x-bar (http://www.personal.psu.edu/ejp10/blogs/gotunicode/2010/03/dealing-with-x-bar-x-and-p-hat.html)
|
309 |
2eb6acb7
|
Andreas Kohlbecker
|
|
310 |
b94b1aec
|
Andreas Kohlbecker
|
$exact_markup = '';
|
311 |
74ee6b54
|
Andreas Kohlbecker
|
$min_max_markup = '';
|
312 |
2eb6acb7
|
Andreas Kohlbecker
|
$other_vals_array = [];
|
313 |
f63479ae
|
Andreas Kohlbecker
|
|
314 |
|
|
// --- sanitize values
|
315 |
dd80884c
|
Andreas Kohlbecker
|
if(statistical_values_num_equals($stat_vals_arr, 'Min', 'TypicalLowerBoundary')){
|
316 |
2f4646e0
|
Andreas Kohlbecker
|
$stat_vals_arr['Min'] = NULL;
|
317 |
f63479ae
|
Andreas Kohlbecker
|
}
|
318 |
|
|
|
319 |
dd80884c
|
Andreas Kohlbecker
|
if(statistical_values_num_equals($stat_vals_arr, 'Max', 'TypicalUpperBoundary')){
|
320 |
2f4646e0
|
Andreas Kohlbecker
|
$stat_vals_arr['Max'] = NULL;
|
321 |
f63479ae
|
Andreas Kohlbecker
|
}
|
322 |
|
|
|
323 |
2f4646e0
|
Andreas Kohlbecker
|
if($stat_vals_arr['TypicalLowerBoundary'] === null && $stat_vals_arr['Min'] !== null){
|
324 |
|
|
$stat_vals_arr['TypicalLowerBoundary'] = $stat_vals_arr['Min'];
|
325 |
|
|
$stat_vals_arr['Min'] = NULL;
|
326 |
f63479ae
|
Andreas Kohlbecker
|
}
|
327 |
|
|
|
328 |
2f4646e0
|
Andreas Kohlbecker
|
if($stat_vals_arr['TypicalUpperBoundary'] === null && $stat_vals_arr['Max'] !== null){
|
329 |
|
|
$stat_vals_arr['TypicalUpperBoundary'] = $stat_vals_arr['Max'];
|
330 |
|
|
$stat_vals_arr['Max'] = NULL;
|
331 |
f63479ae
|
Andreas Kohlbecker
|
}
|
332 |
|
|
|
333 |
dd80884c
|
Andreas Kohlbecker
|
if (statistical_values_num_equals($stat_vals_arr, 'TypicalUpperBoundary', 'TypicalLowerBoundary')) {
|
334 |
2f4646e0
|
Andreas Kohlbecker
|
$stat_vals_arr['Average'] = $stat_vals_arr['TypicalUpperBoundary'];
|
335 |
|
|
$stat_vals_arr['TypicalLowerBoundary'] = NULL;
|
336 |
|
|
$stat_vals_arr['TypicalUpperBoundary'] = NULL;
|
337 |
74ee6b54
|
Andreas Kohlbecker
|
}
|
338 |
|
|
|
339 |
f63479ae
|
Andreas Kohlbecker
|
// --- check for inconsistent cases, eg. only Max and average given
|
340 |
2f4646e0
|
Andreas Kohlbecker
|
if ($stat_vals_arr['TypicalLowerBoundary'] === NULL && $stat_vals_arr['TypicalUpperBoundary'] !== null) {
|
341 |
5a079dbf
|
Andreas Kohlbecker
|
// min missing
|
342 |
2f4646e0
|
Andreas Kohlbecker
|
$stat_vals_arr['TypicalLowerBoundary'] = '?';
|
343 |
74ee6b54
|
Andreas Kohlbecker
|
}
|
344 |
2f4646e0
|
Andreas Kohlbecker
|
if ($stat_vals_arr['TypicalLowerBoundary'] !== null && $stat_vals_arr['TypicalUpperBoundary'] === NULL) {
|
345 |
5a079dbf
|
Andreas Kohlbecker
|
// max missing
|
346 |
2f4646e0
|
Andreas Kohlbecker
|
$stat_vals_arr['TypicalUpperBoundary'] = '?';
|
347 |
74ee6b54
|
Andreas Kohlbecker
|
}
|
348 |
|
|
|
349 |
8867b63b
|
Andreas Kohlbecker
|
if(statistical_values_is_numeric($stat_vals_arr['Average']) && statistical_values_is_numeric($stat_vals_arr['TypicalUpperBoundary']) && statistical_values_is_numeric($stat_vals_arr['TypicalLowerBoundary'])) {
|
350 |
793df790
|
Andreas Kohlbecker
|
statistical_values_adjust_significant_figures($stat_vals_arr['Average'], $stat_vals_arr['TypicalLowerBoundary'], $stat_vals_arr['TypicalUpperBoundary']);
|
351 |
|
|
}
|
352 |
|
|
|
353 |
2f4646e0
|
Andreas Kohlbecker
|
foreach ($stat_vals_arr as $key => $statistical_val) {
|
354 |
2eb6acb7
|
Andreas Kohlbecker
|
|
355 |
74ee6b54
|
Andreas Kohlbecker
|
if ($statistical_val !== NULL) {
|
356 |
|
|
if ($statistical_val == '?') {
|
357 |
|
|
$val_markup = $statistical_val;
|
358 |
dd80884c
|
Andreas Kohlbecker
|
}
|
359 |
|
|
else {
|
360 |
|
|
if (is_numeric($statistical_val->_value)) {
|
361 |
|
|
$val_markup = '<span class="'
|
362 |
74ee6b54
|
Andreas Kohlbecker
|
. html_class_attribute_ref($statistical_val) . ' '
|
363 |
dd80884c
|
Andreas Kohlbecker
|
. (isset($statistical_val->type) ? $statistical_val->type->termType : '') . ' ' . $key . '" title="' . $key . '">'
|
364 |
74ee6b54
|
Andreas Kohlbecker
|
. $statistical_val->_value . '</span>';
|
365 |
dd80884c
|
Andreas Kohlbecker
|
|
366 |
|
|
}
|
367 |
|
|
else {
|
368 |
|
|
$val_markup = NULL;
|
369 |
|
|
}
|
370 |
74ee6b54
|
Andreas Kohlbecker
|
}
|
371 |
|
|
|
372 |
dd80884c
|
Andreas Kohlbecker
|
if ($val_markup) {
|
373 |
|
|
switch ($key) {
|
374 |
b94b1aec
|
Andreas Kohlbecker
|
case 'ExactValue':
|
375 |
|
|
$exact_markup = $val_markup;
|
376 |
|
|
break;
|
377 |
dd80884c
|
Andreas Kohlbecker
|
// ---- min_max_element
|
378 |
|
|
case 'Min':
|
379 |
|
|
$min_max_markup .= "($val_markup–)";
|
380 |
|
|
break;
|
381 |
|
|
case 'Max':
|
382 |
|
|
$min_max_markup .= "(–$val_markup)";
|
383 |
|
|
break;
|
384 |
|
|
case 'TypicalLowerBoundary':
|
385 |
|
|
$min_max_markup .= "$val_markup";
|
386 |
|
|
break;
|
387 |
|
|
case 'TypicalUpperBoundary':
|
388 |
|
|
$min_max_markup .= "–$val_markup";
|
389 |
|
|
break;
|
390 |
2eb6acb7
|
Andreas Kohlbecker
|
// ---- other values
|
391 |
dd80884c
|
Andreas Kohlbecker
|
case 'SampleSize':
|
392 |
|
|
$other_vals_array[$key] = $val_markup;
|
393 |
|
|
break;
|
394 |
|
|
case 'Average':
|
395 |
|
|
$other_vals_array[$key] = $xbar_equals . $val_markup;
|
396 |
|
|
break;
|
397 |
|
|
case 'Variance':
|
398 |
|
|
$other_vals_array[$key] = 'σ²=' . $val_markup;
|
399 |
|
|
break;
|
400 |
|
|
case 'StandardDeviation':
|
401 |
|
|
$other_vals_array[$key] = 'σ=' . $val_markup;
|
402 |
|
|
break;
|
403 |
|
|
}
|
404 |
74ee6b54
|
Andreas Kohlbecker
|
}
|
405 |
|
|
}
|
406 |
|
|
}
|
407 |
f63479ae
|
Andreas Kohlbecker
|
|
408 |
b94b1aec
|
Andreas Kohlbecker
|
$full_markup = $exact_markup . ($exact_markup ? ' ' : '') . $min_max_markup;
|
409 |
|
|
|
410 |
|
|
if(!$full_markup && !empty($other_vals_array['Average'])){
|
411 |
2eb6acb7
|
Andreas Kohlbecker
|
// this could be the case in which we only have one value for Average
|
412 |
|
|
// this trivial case needs to be displayed a simpler way
|
413 |
b94b1aec
|
Andreas Kohlbecker
|
$full_markup = str_replace($xbar_equals, '' , $other_vals_array['Average']);
|
414 |
dd80884c
|
Andreas Kohlbecker
|
unset($other_vals_array['Average']);
|
415 |
7f36e33a
|
Andreas Kohlbecker
|
}
|
416 |
3603b96e
|
Andreas Kohlbecker
|
if($unit){
|
417 |
b94b1aec
|
Andreas Kohlbecker
|
$full_markup .= ' ' . $unit;
|
418 |
3603b96e
|
Andreas Kohlbecker
|
}
|
419 |
7f36e33a
|
Andreas Kohlbecker
|
if(count($other_vals_array)){
|
420 |
b94b1aec
|
Andreas Kohlbecker
|
$full_markup .= ' [' . join(';', $other_vals_array) . ']';
|
421 |
2eb6acb7
|
Andreas Kohlbecker
|
}
|
422 |
f63479ae
|
Andreas Kohlbecker
|
|
423 |
b94b1aec
|
Andreas Kohlbecker
|
return $full_markup;
|
424 |
5a079dbf
|
Andreas Kohlbecker
|
}
|
425 |
|
|
|
426 |
793df790
|
Andreas Kohlbecker
|
/**
|
427 |
7f36e33a
|
Andreas Kohlbecker
|
* Calculates the required precision for the target value to be significantly different from min and may and rounds it.
|
428 |
793df790
|
Andreas Kohlbecker
|
*
|
429 |
|
|
* @param $target
|
430 |
|
|
* The statistical value to be rounded to the least significant precision
|
431 |
|
|
* @param $min
|
432 |
|
|
* The lower bound to calculate the least significant precision
|
433 |
|
|
* @param $max
|
434 |
|
|
* The upper bound to calculate the least significant precision
|
435 |
|
|
* @param int $threshold
|
436 |
|
|
* Per default 1, but can be set to any other value > 0 and < 1 to define
|
437 |
|
|
* another threshold for the transition to the next precision level.
|
438 |
|
|
* E.g. A value of 0.5 will cause values > 50 and <= 500 to be shown with
|
439 |
|
|
* a precision of 2, whereas with a threshold of 1 the values > 10 and <= 100
|
440 |
|
|
* will be shown with a precision of 2 figures
|
441 |
|
|
*/
|
442 |
|
|
function statistical_values_adjust_significant_figures(&$target, $min, $max, $threshold = 1){
|
443 |
|
|
|
444 |
|
|
$precision = 1;
|
445 |
|
|
if($min->_value !== $max->_value){
|
446 |
|
|
$precision = floor(log10(abs($max->_value - $min->_value) * (1 / $threshold)));
|
447 |
|
|
// increase precision by one
|
448 |
|
|
$precision += $precision < 0 ? - 1 : 1;
|
449 |
|
|
}
|
450 |
|
|
|
451 |
|
|
$target->_value = sigFig($target->_value, $precision);
|
452 |
|
|
}
|
453 |
|
|
|
454 |
|
|
/**
|
455 |
|
|
* based on an idea taken from https://stackoverflow.com/questions/37618679/format-number-to-n-significant-digits-in-php#answer-48283297
|
456 |
|
|
*
|
457 |
|
|
* @param $value
|
458 |
|
|
* @param $digits
|
459 |
|
|
*
|
460 |
|
|
* @return float|string
|
461 |
|
|
*/
|
462 |
|
|
function sigFig($value, $digits, $round_only = true)
|
463 |
|
|
{
|
464 |
|
|
if ($value == 0) {
|
465 |
|
|
$decimalPlaces = $digits - 1;
|
466 |
|
|
} elseif ($value < 0) {
|
467 |
|
|
$decimalPlaces = $digits - floor(log10($value * -1)) - 1;
|
468 |
|
|
} else {
|
469 |
|
|
$decimalPlaces = $digits - floor(log10($value)) - 1;
|
470 |
|
|
}
|
471 |
|
|
|
472 |
|
|
$answer = ($decimalPlaces > 0) && !$round_only ?
|
473 |
|
|
number_format($value, $decimalPlaces) : round($value, abs($decimalPlaces));
|
474 |
|
|
return $answer;
|
475 |
|
|
}
|
476 |
|
|
|
477 |
|
|
|
478 |
|
|
|
479 |
f63479ae
|
Andreas Kohlbecker
|
/**
|
480 |
dd80884c
|
Andreas Kohlbecker
|
* Used internally in statistical_values() do determine numerically equality of stat_vals_arr values
|
481 |
f63479ae
|
Andreas Kohlbecker
|
*
|
482 |
2f4646e0
|
Andreas Kohlbecker
|
* @param $stat_vals_arr
|
483 |
f63479ae
|
Andreas Kohlbecker
|
* @param $key1
|
484 |
|
|
* @param $key2
|
485 |
|
|
*
|
486 |
|
|
* @return bool
|
487 |
|
|
*/
|
488 |
dd80884c
|
Andreas Kohlbecker
|
function statistical_values_num_equals($stat_vals_arr, $key1, $key2){
|
489 |
f63479ae
|
Andreas Kohlbecker
|
|
490 |
dd80884c
|
Andreas Kohlbecker
|
return $stat_vals_arr[$key1] !== NULL && $stat_vals_arr[$key2] !== NULL && $stat_vals_arr[$key1]->_value == $stat_vals_arr[$key2]->_value && is_numeric($stat_vals_arr[$key1]->_value);
|
491 |
f63479ae
|
Andreas Kohlbecker
|
}
|
492 |
|
|
|
493 |
8867b63b
|
Andreas Kohlbecker
|
function statistical_values_is_numeric($stat_val){
|
494 |
|
|
return $stat_val !== null && is_numeric($stat_val->_value);
|
495 |
|
|
}
|
496 |
|
|
|
497 |
5a079dbf
|
Andreas Kohlbecker
|
/**
|
498 |
|
|
* Creates min max markup to represent a min-average-max measure optionally with an error value.
|
499 |
|
|
*
|
500 |
|
|
* The fields that are taken into account are:
|
501 |
|
|
* - field_base_name = min
|
502 |
|
|
* - field_base_nameMax = max
|
503 |
|
|
* - field_base_nameText = free text
|
504 |
|
|
* - field_base_nameError = error value
|
505 |
|
|
*
|
506 |
|
|
* @param $object
|
507 |
f63479ae
|
Andreas Kohlbecker
|
* The object having min max measurement fields e.g.: GatheringEvent
|
508 |
5a079dbf
|
Andreas Kohlbecker
|
* @param string $field_base_name
|
509 |
|
|
* The base name for all measurement fields. This name is at the same time the full name of the
|
510 |
|
|
* min value.
|
511 |
dbc2bfa9
|
Andreas Kohlbecker
|
* @return string
|
512 |
|
|
* The markup for the min max
|
513 |
2f4646e0
|
Andreas Kohlbecker
|
*
|
514 |
|
|
* @see statistical_values()
|
515 |
5a079dbf
|
Andreas Kohlbecker
|
*/
|
516 |
2f4646e0
|
Andreas Kohlbecker
|
function statistical_values_from_gathering_event($object, $field_base_name)
|
517 |
5a079dbf
|
Andreas Kohlbecker
|
{
|
518 |
|
|
static $default_unit = 'm';
|
519 |
|
|
|
520 |
|
|
$field_name = $field_base_name . 'Text';
|
521 |
0820cdc0
|
Andreas Kohlbecker
|
if (@is_string($object->$field_name)) {
|
522 |
dbc2bfa9
|
Andreas Kohlbecker
|
// Freetext overrides all other data
|
523 |
|
|
$min_max_markup = ' ' . $object->$field_name;
|
524 |
|
|
} else {
|
525 |
|
|
// create markup for the atomized min max data
|
526 |
2f4646e0
|
Andreas Kohlbecker
|
$min_max_array = statistical_values_array();
|
527 |
dbc2bfa9
|
Andreas Kohlbecker
|
if (@is_numeric($object->$field_base_name)) {
|
528 |
|
|
$min_max_array['Min'] = new stdClass();
|
529 |
|
|
$min_max_array['Min']->_value = $object->$field_base_name;
|
530 |
|
|
}
|
531 |
|
|
$field_name = $field_base_name . 'Max';
|
532 |
|
|
if (@is_numeric($object->$field_name)) {
|
533 |
|
|
$min_max_array['Max'] = new stdClass();
|
534 |
|
|
$min_max_array['Max']->_value = $object->$field_name;
|
535 |
|
|
}
|
536 |
2f4646e0
|
Andreas Kohlbecker
|
$min_max_markup = statistical_values($min_max_array, $default_unit);
|
537 |
5a079dbf
|
Andreas Kohlbecker
|
}
|
538 |
dbc2bfa9
|
Andreas Kohlbecker
|
|
539 |
74ee6b54
|
Andreas Kohlbecker
|
return $min_max_markup;
|
540 |
|
|
}
|
541 |
d9763fd3
|
Andreas Kohlbecker
|
|
542 |
|
|
// TODO move below code into new file: agent.inc
|
543 |
|
|
|
544 |
|
|
/*
|
545 |
|
|
* Compose an render array from a CDM TaxonNodeAgentRelation object as Taxon Expert.
|
546 |
|
|
*
|
547 |
|
|
* compose_hook() implementation
|
548 |
|
|
*
|
549 |
|
|
* @param object $taxon_node_agent_relation
|
550 |
|
|
* CDM instance of type TaxonNodeAgentRelation
|
551 |
|
|
* @return array
|
552 |
|
|
* A drupal render array
|
553 |
|
|
*
|
554 |
|
|
* @ingroup compose
|
555 |
|
|
*/
|
556 |
|
|
function compose_cdm_taxon_expert($taxon_node_agent_relation) {
|
557 |
|
|
|
558 |
df2eb131
|
Andreas Kohlbecker
|
$agent_details = null;
|
559 |
|
|
|
560 |
d9763fd3
|
Andreas Kohlbecker
|
$label_suffix = ':';
|
561 |
|
|
|
562 |
|
|
if($taxon_node_agent_relation->class == 'DefaultPagerImpl'){
|
563 |
|
|
// oops this is a pager
|
564 |
|
|
// this situation will occur when this compose is executed
|
565 |
|
|
// through the proxy_content() method
|
566 |
|
|
$taxon_node_agent_relation = $taxon_node_agent_relation->records[0];
|
567 |
|
|
|
568 |
|
|
}
|
569 |
|
|
|
570 |
|
|
if(is_object($taxon_node_agent_relation->agent)) {
|
571 |
|
|
$agent_details = compose_cdm_team_or_person_base($taxon_node_agent_relation->agent);
|
572 |
|
|
// all data will be added to the groups of the agent_details render array
|
573 |
|
|
$groups = &$agent_details[0]['#groups'];
|
574 |
|
|
|
575 |
bf90783c
|
Andreas Kohlbecker
|
@_description_list_group_add($groups, t('Role'). $label_suffix, $taxon_node_agent_relation->type->representation_L10n);
|
576 |
d9763fd3
|
Andreas Kohlbecker
|
|
577 |
|
|
$family_tnars = cdm_ws_fetch_all(CDM_WS_PORTAL_AGENT . '/' . $taxon_node_agent_relation->agent->uuid . '/taxonNodeAgentRelations', array("rank"=>"Familia"));
|
578 |
|
|
|
579 |
|
|
$taxa_markup = array(
|
580 |
|
|
'#theme_wrappers' => array('container'),
|
581 |
|
|
'#attributes' => array('class' => array('managed_taxa')),
|
582 |
|
|
'#wrapper_attributes' => array('class' => 'sublist-container')
|
583 |
|
|
);
|
584 |
|
|
foreach($family_tnars as $tnar){
|
585 |
|
|
if(is_object($tnar->taxonNode->taxon)){
|
586 |
bf2387cc
|
Andreas Kohlbecker
|
$taxa_markup[$tnar->taxonNode->taxon->titleCache] = markup_to_render_array(render_taxon_or_name($tnar->taxonNode->taxon, url(path_to_taxon($tnar->taxonNode->taxon->uuid))));
|
587 |
d9763fd3
|
Andreas Kohlbecker
|
}
|
588 |
|
|
}
|
589 |
|
|
ksort($taxa_markup);
|
590 |
|
|
|
591 |
|
|
@_description_list_group_add($groups, t('Families'). $label_suffix, array($taxa_markup));
|
592 |
|
|
|
593 |
|
|
}
|
594 |
|
|
|
595 |
|
|
return $agent_details;
|
596 |
|
|
}
|
597 |
|
|
|
598 |
|
|
|
599 |
|
|
/*
|
600 |
|
|
* Compose an render array from a CDM TeamOrPersonBase object.
|
601 |
|
|
*
|
602 |
|
|
* compose_hook() implementation
|
603 |
|
|
*
|
604 |
|
|
* TODO: currently mainly implemented for Agent, add Team details
|
605 |
|
|
*
|
606 |
|
|
* @param object $team_or_person
|
607 |
|
|
* CDM instance of type TeamOrPersonBase
|
608 |
|
|
* @return array
|
609 |
|
|
* A drupal render array
|
610 |
|
|
*
|
611 |
|
|
* @ingroup compose
|
612 |
|
|
*/
|
613 |
|
|
function compose_cdm_team_or_person_base($team_or_person, $data = array()) {
|
614 |
|
|
|
615 |
|
|
$groups = array();
|
616 |
|
|
|
617 |
|
|
$label_suffix = ':';
|
618 |
|
|
|
619 |
|
|
// $weight = 0;
|
620 |
|
|
if($team_or_person){
|
621 |
|
|
|
622 |
|
|
if(is_object($team_or_person->lifespan)){
|
623 |
|
|
// ToDo render as date* - date†?
|
624 |
|
|
@_description_list_group_add($groups, t('Lifespan'). $label_suffix, timePeriodToString($team_or_person->lifespan) /*, '' , $weight++ */);
|
625 |
|
|
}
|
626 |
|
|
|
627 |
|
|
// nomenclaturalTitle
|
628 |
|
|
@_description_list_group_add($groups, "Nomenclatural Title". $label_suffix, $team_or_person->nomenclaturalTitle);
|
629 |
|
|
// collectorTitle
|
630 |
|
|
@_description_list_group_add($groups, "Collector Title". $label_suffix, $team_or_person->collectorTitle);
|
631 |
|
|
|
632 |
|
|
// institutionalMemberships
|
633 |
|
|
if(is_array($team_or_person->institutionalMemberships)){
|
634 |
|
|
|
635 |
|
|
$institutes_ra = array();
|
636 |
|
|
foreach($team_or_person->institutionalMemberships as $membership) {
|
637 |
|
|
$membership_groups = array();
|
638 |
|
|
@_description_list_group_add($membership_groups, t('Department'). $label_suffix, $membership->department);
|
639 |
|
|
@_description_list_group_add($membership_groups, t('Role'). $label_suffix, $membership->role);
|
640 |
|
|
if(is_object($membership->period)){
|
641 |
|
|
@_description_list_group_add($membership_groups, t('Period'). $label_suffix, timePeriodToString($membership->period));
|
642 |
|
|
}
|
643 |
|
|
if(is_object($membership->institute->contact)){
|
644 |
|
|
$institute_contact_details = compose_cdm_contact($membership->institute->contact, $membership->institute->titleCache);
|
645 |
|
|
if(is_array($institute_contact_details[0]['#groups'])){
|
646 |
|
|
$membership_groups = array_merge($membership_groups, $institute_contact_details[0]['#groups']);
|
647 |
|
|
}
|
648 |
|
|
}
|
649 |
|
|
if(count($membership_groups) > 0){
|
650 |
|
|
$institutes_ra[] = array(
|
651 |
|
|
'#title' => $membership->institute->titleCache,
|
652 |
|
|
'#theme' => 'description_list',
|
653 |
|
|
'#groups' => $membership_groups,
|
654 |
|
|
'#attributes' => array('class' => html_class_attribute_ref($membership)),
|
655 |
|
|
'#wrapper_attributes' => array('class' => 'sublist-container')
|
656 |
|
|
);
|
657 |
|
|
} else {
|
658 |
|
|
// no further details for the membership, display the title
|
659 |
|
|
$institutes_ra[] = markup_to_render_array('<h3>' . $membership->institute->titleCache . '</h3>');
|
660 |
|
|
}
|
661 |
|
|
|
662 |
|
|
}
|
663 |
|
|
|
664 |
|
|
$label = count($institutes_ra) > 1 ? t('Institutes'): t('Institute');
|
665 |
|
|
@_description_list_group_add($groups, $label. $label_suffix, $institutes_ra /*, '' , $weight++ */);
|
666 |
|
|
}
|
667 |
|
|
|
668 |
|
|
|
669 |
|
|
// Contact
|
670 |
|
|
$agent_contact_details = compose_cdm_contact($team_or_person->contact, $team_or_person->titleCache);
|
671 |
|
|
if(is_array($agent_contact_details[0]['#groups'])){
|
672 |
|
|
$groups = array_merge($groups, $agent_contact_details[0]['#groups']);
|
673 |
|
|
}
|
674 |
|
|
|
675 |
|
|
// additional data
|
676 |
|
|
foreach($data as $key=>$value){
|
677 |
7cc085da
|
Andreas Kohlbecker
|
@_description_list_group_add($sub_dl_groups, t('@key', array('@key' => $key)), $value /*, '' , $weight++ */);
|
678 |
d9763fd3
|
Andreas Kohlbecker
|
}
|
679 |
|
|
|
680 |
|
|
}
|
681 |
|
|
|
682 |
|
|
$team_or_person_details = array(
|
683 |
|
|
'#title' => $team_or_person->titleCache,
|
684 |
|
|
'#theme' => 'description_list',
|
685 |
|
|
'#groups' => $groups,
|
686 |
|
|
'#attributes' => array('class' => html_class_attribute_ref($team_or_person)),
|
687 |
|
|
);
|
688 |
|
|
return array($team_or_person_details);
|
689 |
|
|
}
|
690 |
|
|
|
691 |
|
|
|
692 |
|
|
/*
|
693 |
|
|
* Compose an render array from a CDM Contact object.
|
694 |
|
|
*
|
695 |
|
|
* compose_hook() implementation
|
696 |
|
|
*
|
697 |
|
|
* TODO: currently mainly implemented for Agent, add Team details
|
698 |
|
|
*
|
699 |
|
|
* @param object $contact
|
700 |
|
|
* CDM instance of type Contact
|
701 |
|
|
* @param $title
|
702 |
|
|
* The title for the description list header
|
703 |
|
|
* @param $weight
|
704 |
|
|
* Optional weight for the description list entries
|
705 |
|
|
* @return array
|
706 |
|
|
* A drupal render array
|
707 |
|
|
*
|
708 |
|
|
* @ingroup compose
|
709 |
|
|
*/
|
710 |
|
|
function compose_cdm_contact($contact, $title, $weight = 0)
|
711 |
|
|
{
|
712 |
|
|
|
713 |
|
|
$groups = array();
|
714 |
|
|
|
715 |
0820cdc0
|
Andreas Kohlbecker
|
$contact_details = null;
|
716 |
|
|
|
717 |
d9763fd3
|
Andreas Kohlbecker
|
$label_suffix = ':';
|
718 |
|
|
|
719 |
|
|
$contact_field_names_map = array(
|
720 |
|
|
'emailAddresses' => t('Email'),
|
721 |
|
|
'urls' => t('Urls'),
|
722 |
|
|
'phoneNumbers' => t('Phone'),
|
723 |
|
|
'faxNumbers' => t('Fax'),
|
724 |
|
|
);
|
725 |
|
|
|
726 |
|
|
// Contact
|
727 |
|
|
if(is_object($contact)){
|
728 |
|
|
if(isset($contact->addresses)){
|
729 |
|
|
// TODO ....
|
730 |
|
|
// $sub_groups = array();
|
731 |
|
|
// foreach($contact->addresses as $address){
|
732 |
|
|
// @_description_list_group_add($sub_groups, $label, $contact->$fieldName, '', $weight++);
|
733 |
|
|
// }
|
734 |
|
|
}
|
735 |
|
|
foreach($contact_field_names_map as $fieldName => $label){
|
736 |
|
|
if(is_array($contact->$fieldName)){
|
737 |
|
|
@_description_list_group_add($groups, $label . $label_suffix, $contact->$fieldName, '', $weight++);
|
738 |
|
|
}
|
739 |
|
|
}
|
740 |
|
|
$contact_details = array(
|
741 |
|
|
'#title' => $title,
|
742 |
|
|
'#theme' => 'description_list',
|
743 |
|
|
'#groups' => $groups
|
744 |
|
|
);
|
745 |
|
|
|
746 |
|
|
|
747 |
|
|
} else if(is_string($title)) {
|
748 |
|
|
// if the contact entity is empty but the title is given anyway
|
749 |
|
|
// we are only adding the title, using the description_list
|
750 |
|
|
// structure is not possible since it would be empty due to
|
751 |
|
|
// missing group data
|
752 |
|
|
$contact_details = array('#markup' => '<h3>' . $title . '</h3>');
|
753 |
|
|
}
|
754 |
|
|
|
755 |
|
|
return array($contact_details);
|
756 |
|
|
|
757 |
|
|
}
|
758 |
0820cdc0
|
Andreas Kohlbecker
|
|
759 |
db9c6559
|
Andreas Kohlbecker
|
function visible_extensions_sorted($cdm_entity) {
|
760 |
|
|
|
761 |
|
|
$visible_extensions_sorted = [];
|
762 |
|
|
$extension_types_visible = variable_get(EXTENSION_TYPES_VISIBLE, unserialize(EXTENSION_TYPES_VISIBLE_DEFAULT));
|
763 |
|
|
if (isset($cdm_entity->extensions)) {
|
764 |
|
|
foreach ($cdm_entity->extensions as $ext) {
|
765 |
|
|
if (array_search($ext->type->uuid, $extension_types_visible)) {
|
766 |
|
|
if (!array_key_exists($ext->type->uuid, $visible_extensions_sorted)) {
|
767 |
|
|
$visible_extensions_sorted[$ext->type->uuid] = [];
|
768 |
|
|
}
|
769 |
|
|
$visible_extensions_sorted[$ext->type->uuid][] = $ext;
|
770 |
|
|
}
|
771 |
|
|
}
|
772 |
|
|
}
|
773 |
|
|
return $visible_extensions_sorted;
|
774 |
|
|
}
|
775 |
|
|
|
776 |
0820cdc0
|
Andreas Kohlbecker
|
/**
|
777 |
|
|
* Compose an render array from a CDM Extension objects.
|
778 |
|
|
*
|
779 |
|
|
* @param $extensions
|
780 |
|
|
* An array of CDM Extension objects
|
781 |
|
|
* @return array
|
782 |
|
|
* A render array containing the fields of the supplied $sequence
|
783 |
|
|
*
|
784 |
|
|
* @ingroup compose
|
785 |
|
|
*/
|
786 |
|
|
function compose_extensions($extensions)
|
787 |
|
|
{
|
788 |
e2617c7e
|
Andreas Kohlbecker
|
$render_array= null;
|
789 |
0820cdc0
|
Andreas Kohlbecker
|
$extensions_by_type = array();
|
790 |
|
|
foreach ($extensions as $extension) {
|
791 |
|
|
if (@is_string($extension->value)) {
|
792 |
|
|
if (!isset($extensions_by_type[$extension->type->representation_L10n])) {
|
793 |
|
|
$extensions_by_type[$extension->type->representation_L10n] = array();
|
794 |
|
|
}
|
795 |
|
|
$extensions_by_type[$extension->type->representation_L10n][] = markup_to_render_array($extension->value);
|
796 |
|
|
}
|
797 |
|
|
}
|
798 |
|
|
|
799 |
|
|
if (count($extensions_by_type)) {
|
800 |
|
|
$sub_dl_groups = array();
|
801 |
|
|
foreach ($extensions_by_type as $type_label => $text_list) {
|
802 |
|
|
@_description_list_group_add($sub_dl_groups, $type_label . ':', $text_list);
|
803 |
|
|
}
|
804 |
e2617c7e
|
Andreas Kohlbecker
|
$render_array = array(
|
805 |
0820cdc0
|
Andreas Kohlbecker
|
array('#theme' => 'description_list', '#groups' => $sub_dl_groups)
|
806 |
|
|
);
|
807 |
e2617c7e
|
Andreas Kohlbecker
|
return $render_array;
|
808 |
0820cdc0
|
Andreas Kohlbecker
|
}
|
809 |
e2617c7e
|
Andreas Kohlbecker
|
return $render_array;
|
810 |
|
|
}
|
811 |
|
|
|
812 |
|
|
/**
|
813 |
|
|
* Compose an render array from a CDM Identifier objects.
|
814 |
|
|
*
|
815 |
|
|
* @param $extensions
|
816 |
|
|
* An array of CDM Identifier objects
|
817 |
|
|
* @return array
|
818 |
|
|
* A render array containing the fields of the supplied $sequence
|
819 |
|
|
*
|
820 |
|
|
* @ingroup compose
|
821 |
|
|
*/
|
822 |
|
|
function compose_identifiers($identifiers){
|
823 |
|
|
|
824 |
|
|
$render_array = [];
|
825 |
1344691f
|
Andreas Kohlbecker
|
// // urn:lsid:ipni.org:authors:20009164-1 UUID_IDENTIFIER_TYPE_LSID
|
826 |
e2617c7e
|
Andreas Kohlbecker
|
foreach($identifiers as $identifier){
|
827 |
|
|
if($identifier->identifier){
|
828 |
|
|
$render_array[] = markup_to_render_array('<span class="label">' . $identifier->type->representation_L10n . ':</span> ' . $identifier->identifier, null, '<span class="'. html_class_attribute_ref($identifier) . '">', '</span>');
|
829 |
|
|
}
|
830 |
|
|
}
|
831 |
|
|
|
832 |
|
|
return $render_array;
|
833 |
|
|
|
834 |
0820cdc0
|
Andreas Kohlbecker
|
}
|
835 |
eaff53f7
|
Andreas Kohlbecker
|
|
836 |
6eaec849
|
Katja Luther
|
function formatParams($params) {
|
837 |
df2eb131
|
Andreas Kohlbecker
|
$paramString = null;
|
838 |
6eaec849
|
Katja Luther
|
if (is_array($params)){
|
839 |
|
|
$keys =array_keys($params);
|
840 |
|
|
$paramString = '';
|
841 |
|
|
foreach ($keys as $k ){
|
842 |
|
|
if ($k != 'pageNumber' && $k != 'pageSize'){
|
843 |
|
|
$paramString .= ' -'.$k.'='.urlencode($params[$k]);
|
844 |
|
|
}
|
845 |
|
|
}
|
846 |
|
|
}
|
847 |
|
|
return $paramString;
|
848 |
|
|
}
|
849 |
eaff53f7
|
Andreas Kohlbecker
|
|
850 |
72d57201
|
Katja Luther
|
function formatWSParams($params) {
|
851 |
df2eb131
|
Andreas Kohlbecker
|
$paramString = null;
|
852 |
72d57201
|
Katja Luther
|
if (is_array($params)){
|
853 |
|
|
$keys =array_keys($params);
|
854 |
|
|
$paramString = '';
|
855 |
|
|
foreach ($keys as $k ){
|
856 |
|
|
if ($k != 'pageNumber' && $k != 'pageSize'){
|
857 |
|
|
$paramString .= '&'.$k.'='.urlencode($params[$k]);
|
858 |
|
|
}
|
859 |
|
|
}
|
860 |
|
|
}
|
861 |
|
|
return $paramString;
|
862 |
|
|
}
|
863 |
|
|
|
864 |
fe3a5674
|
Andreas Kohlbecker
|
/**
|
865 |
|
|
*
|
866 |
|
|
* @param $cdm_entity
|
867 |
|
|
*
|
868 |
|
|
* @return string the markup
|
869 |
|
|
*/
|
870 |
ab025781
|
Andreas Kohlbecker
|
function render_cdm_entity_link($cdm_entity) {
|
871 |
fe3a5674
|
Andreas Kohlbecker
|
|
872 |
|
|
switch ($cdm_entity->class) {
|
873 |
|
|
case 'TaxonDescription':
|
874 |
2d78d276
|
Andreas Kohlbecker
|
case 'NameDescription':
|
875 |
|
|
case 'SpecimenDescription':
|
876 |
92e522db
|
Andreas Kohlbecker
|
$link = '<span class="' . html_class_attribute_ref($cdm_entity) . '">' . $cdm_entity->titleCache . '</span> ' . icon_link(path_to_description($cdm_entity->uuid));
|
877 |
fe3a5674
|
Andreas Kohlbecker
|
break;
|
878 |
|
|
default:
|
879 |
ab025781
|
Andreas Kohlbecker
|
$link = '<span class="error">UNSUPPORTED CDM ENTITY TYPE</span>';
|
880 |
fe3a5674
|
Andreas Kohlbecker
|
}
|
881 |
ab025781
|
Andreas Kohlbecker
|
return $link;
|
882 |
fe3a5674
|
Andreas Kohlbecker
|
}
|
883 |
|
|
|
884 |
ab025781
|
Andreas Kohlbecker
|
/**
|
885 |
|
|
* Creates an icon which links to the given path
|
886 |
|
|
* @param $path
|
887 |
|
|
*
|
888 |
|
|
* @return string
|
889 |
|
|
*/
|
890 |
fec3fd41
|
Andreas Kohlbecker
|
function icon_link($path, $fragment = '') {
|
891 |
|
|
$iconlink = l(custom_icon_font_markup('icon-interal-link-alt-solid', ['class' => ['superscript']]), $path, ['html' => TRUE, 'fragment' => $fragment] );
|
892 |
ab025781
|
Andreas Kohlbecker
|
return $iconlink;
|
893 |
|
|
}
|