1
|
<?php
|
2
|
/**
|
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
|
*/
|
18
|
|
19
|
/**
|
20
|
* @defgroup compose Compose functions
|
21
|
* @{
|
22
|
* Functions which are composing Drupal render arays
|
23
|
*
|
24
|
* The cdm_dataportal module needs to compose rather complex render arrays from
|
25
|
* the data returned by the CDM REST service. The compose functions are
|
26
|
* responsible for creating the render arrays.
|
27
|
*
|
28
|
* All these functions are also implementations of the compose_hook()
|
29
|
* which is used in the proxy_content() function.
|
30
|
* @}
|
31
|
*/
|
32
|
|
33
|
/**
|
34
|
* Compose an render array from a CDM Marker object.
|
35
|
*
|
36
|
* compose_hook() implementation
|
37
|
*
|
38
|
* @param object $marker
|
39
|
* CDM instance of type Marker
|
40
|
* @return array
|
41
|
* A drupal render array
|
42
|
*
|
43
|
* @ingroup compose
|
44
|
*/
|
45
|
function compose_cdm_marker($marker) {
|
46
|
|
47
|
$render_array = array(
|
48
|
// ---- generic
|
49
|
// these entries should be common to all cdm enitiy render arrays
|
50
|
'#theme' => 'cdm_marker', // TODO add alternative theme funcitons: 'cdm_marker_' . marker.type.label
|
51
|
'#attributes' => array('class' => html_class_attribute_ref($marker)),
|
52
|
|
53
|
// ---- individual
|
54
|
'#label' => $marker->markerType->representation_L10n . ': ' . (($marker->flag !== TRUE ? t('yes') : t('no'))),
|
55
|
);
|
56
|
|
57
|
return $render_array;
|
58
|
}
|
59
|
|
60
|
/**
|
61
|
* Checks if the given $cdm_entitiy has a marker the type references by the
|
62
|
* $marker_type_uuid and returns TRUE if a matching marker has been found.
|
63
|
*
|
64
|
* @param object $cdm_entitiy A CDM Entity
|
65
|
* @param string $marker_type_uuid
|
66
|
*/
|
67
|
function cdm_entity_has_marker($cdm_entitiy, $marker_type_uuid) {
|
68
|
if(isset($cdm_entitiy->markers[0]) && !is_uuid($marker_type_uuid)){
|
69
|
foreach ($cdm_entitiy->markers as $marker) {
|
70
|
if(isset($marker->markerType) && $marker->markerType->uuid == $marker_type_uuid){
|
71
|
return TRUE;
|
72
|
}
|
73
|
}
|
74
|
}
|
75
|
return FALSE;
|
76
|
}
|
77
|
|
78
|
/**
|
79
|
* Sorts an array of CDM IdentifiableSource instances by 1. by the
|
80
|
* author teams family names and 2. by the publication date.
|
81
|
*
|
82
|
* @param array $sources
|
83
|
* The array of CDM IdentifiableSource instances
|
84
|
* @return array
|
85
|
* An array of drupal render arrays
|
86
|
*/
|
87
|
function oder_and_render_original_sources($sources){
|
88
|
$sort_array = array();
|
89
|
foreach ($sources as $source) {
|
90
|
|
91
|
$order_key = '';
|
92
|
|
93
|
// find the familynames
|
94
|
if(isset($source->citation->uuid) && !isset($source->citation->authorship)){
|
95
|
$authorteam = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $source->citation->uuid);
|
96
|
|
97
|
$persons = array();
|
98
|
if($authorteam->class == 'Team'){
|
99
|
if(isset($authorteam->teamMembers)){
|
100
|
$persons = $authorteam->teamMembers;
|
101
|
}
|
102
|
} else {
|
103
|
$persons[] = $authorteam;
|
104
|
}
|
105
|
|
106
|
foreach($persons as $person){
|
107
|
if(!empty($person->lastname)){
|
108
|
$order_key .= $person->lastname;
|
109
|
} else {
|
110
|
$order_key .= $person->titleCache;
|
111
|
}
|
112
|
}
|
113
|
if(empty($order_key)){
|
114
|
$order_key = $authorteam->titleCache;
|
115
|
}
|
116
|
|
117
|
}
|
118
|
$order_key = str_pad($order_key, 50);
|
119
|
|
120
|
// add publication date to the key
|
121
|
if(isset($source->citation->datePublished)){
|
122
|
$order_key .= '_' . timePeriodAsOrderKey($source->citation->datePublished);
|
123
|
} else {
|
124
|
$order_key .= '_' . "0000";
|
125
|
}
|
126
|
|
127
|
// padd key until unique
|
128
|
while(array_key_exists($order_key, $sort_array)){
|
129
|
$order_key .= "_";
|
130
|
}
|
131
|
|
132
|
$sort_array[$order_key] = render_original_source($source);
|
133
|
}
|
134
|
ksort($sort_array);
|
135
|
return array_values ($sort_array);
|
136
|
}
|
137
|
|
138
|
/**
|
139
|
* Compare callback to be used in usort to sort image sources of CDM OriginalSource instances.
|
140
|
*
|
141
|
* TODO the compare strategy implemented in oder_and_render_original_sources() is probably better but is not taking the
|
142
|
* originalName into account.
|
143
|
*
|
144
|
* @param $a
|
145
|
* @param $b
|
146
|
*/
|
147
|
function compare_original_sources($a, $b){
|
148
|
|
149
|
$a_string = '';
|
150
|
if(isset($a->citation->titleCache)) {
|
151
|
$a_string = $a->citation->titleCache;
|
152
|
}
|
153
|
if((isset($a->nameUsedInSource))){
|
154
|
$a_string .= $a->nameUsedInSource->titleCache;
|
155
|
} elseif (isset($a->originalNameString)){
|
156
|
$a_string .= $a->originalNameString;
|
157
|
}
|
158
|
|
159
|
$b_string = '';
|
160
|
if(isset($b->citation->titleCache)) {
|
161
|
$b_string = $b->citation->titleCache;
|
162
|
};
|
163
|
if((isset($b->nameUsedInSource))){
|
164
|
$b_string .= $b->nameUsedInSource->titleCache;
|
165
|
} elseif (isset($b->originalNameString)){
|
166
|
$b_string .= $b->originalNameString;
|
167
|
}
|
168
|
|
169
|
if ($a_string == $b_string) {
|
170
|
return 0;
|
171
|
}
|
172
|
return ($a_string < $b_string) ? -1 : 1;
|
173
|
}
|
174
|
|
175
|
/**
|
176
|
* Compare callback to be used in usort to sort image sources of CDM Media instances.
|
177
|
*
|
178
|
* @param $a
|
179
|
* @param $b
|
180
|
*/
|
181
|
function compare_text_data($a, $b) {
|
182
|
|
183
|
if ($a->multilanguageText_L10n->text == $b->multilanguageText_L10n->text) {
|
184
|
return 0;
|
185
|
}
|
186
|
return ($a->multilanguageText_L10n->text < $b->multilanguageText_L10n->text) ? -1 : 1;
|
187
|
}
|
188
|
|
189
|
/**
|
190
|
* Compare two different footnotes objects.
|
191
|
*
|
192
|
* The comparison is based on the footnote key. The one which is
|
193
|
* displayed as footnote number.
|
194
|
*
|
195
|
* @param mixed $a
|
196
|
* Footnote object $a.
|
197
|
* @param mixed $b
|
198
|
* Footnote object $b.
|
199
|
*/
|
200
|
function footnotes_key_compare($a, $b) {
|
201
|
$res = 0;
|
202
|
if (empty($a) || empty($b)) {
|
203
|
return $res;
|
204
|
}
|
205
|
if ($a->keyStr < $b->keyStr) {
|
206
|
$res = -1;
|
207
|
}
|
208
|
elseif ($a->keyStr > $b->keyStr) {
|
209
|
$res = 1;
|
210
|
}
|
211
|
return $res;
|
212
|
}
|
213
|
|
214
|
/**
|
215
|
* Provides an explanatory text on the statistical values representation as generated by min_max_markup()
|
216
|
*
|
217
|
* @return string
|
218
|
* the text
|
219
|
*/
|
220
|
function statistical_values_explanation(){
|
221
|
return t("A single or the first number in square brackets denotes sample size");
|
222
|
}
|
223
|
|
224
|
/**
|
225
|
* Creates an array suitable to be used in min_max_markup()
|
226
|
* The min max structure is suitable for being used in the context
|
227
|
* of GatheringEvents and StatisticalMeasures (see render_quantitative_statistics()).
|
228
|
*
|
229
|
* The order of the items is important for the display and must not be changed.
|
230
|
*
|
231
|
* @return array
|
232
|
*/
|
233
|
function min_max_array() {
|
234
|
|
235
|
$min_max = [
|
236
|
'Min' => NULL,
|
237
|
'TypicalLowerBoundary' => NULL,
|
238
|
'TypicalUpperBoundary' => NULL,
|
239
|
'Max' => NULL,
|
240
|
'SampleSize' => NULL,
|
241
|
'Average' => NULL,
|
242
|
'Variance' => NULL,
|
243
|
'StandardDeviation' => NULL,
|
244
|
];
|
245
|
return $min_max;
|
246
|
}
|
247
|
|
248
|
/**
|
249
|
* Creates markup from a min max array.
|
250
|
*
|
251
|
* NOTE: use min_max_array() to create an appropriate array
|
252
|
*
|
253
|
* Internally Min will be translated to TypicalLowerBoundary if no such value is present.
|
254
|
* The same also accounts for Max and TypicalUpperBoundary.
|
255
|
*
|
256
|
* For further details see #3742, #8766
|
257
|
*
|
258
|
* @param $min_max
|
259
|
* the min-max array
|
260
|
* @param $unit
|
261
|
* Defaults to no unit
|
262
|
* @return string
|
263
|
*/
|
264
|
function min_max_markup($min_max, $unit = '') {
|
265
|
|
266
|
static $xbar_equals = 'x̄='; // x̄ is x-bar
|
267
|
|
268
|
$min_max_markup = '';
|
269
|
$other_vals_array = [];
|
270
|
|
271
|
// --- sanitize values
|
272
|
if(min_max_equals($min_max, 'Min', 'TypicalLowerBoundary')){
|
273
|
$min_max['Min'] = NULL;
|
274
|
}
|
275
|
|
276
|
if(min_max_equals($min_max, 'Max', 'TypicalUpperBoundary')){
|
277
|
$min_max['Max'] = NULL;
|
278
|
}
|
279
|
|
280
|
if($min_max['TypicalLowerBoundary'] === null && $min_max['Min'] !== null){
|
281
|
$min_max['TypicalLowerBoundary'] = $min_max['Min'];
|
282
|
$min_max['Min'] = NULL;
|
283
|
}
|
284
|
|
285
|
if($min_max['TypicalUpperBoundary'] === null && $min_max['Max'] !== null){
|
286
|
$min_max['TypicalUpperBoundary'] = $min_max['Max'];
|
287
|
$min_max['Max'] = NULL;
|
288
|
}
|
289
|
|
290
|
if (min_max_equals($min_max, 'TypicalUpperBoundary', 'TypicalLowerBoundary')) {
|
291
|
$min_max['Average'] = $min_max['TypicalUpperBoundary'];
|
292
|
$min_max['TypicalLowerBoundary'] = NULL;
|
293
|
$min_max['TypicalUpperBoundary'] = NULL;
|
294
|
}
|
295
|
|
296
|
// --- check for inconsistent cases, eg. only Max and average given
|
297
|
if ($min_max['TypicalLowerBoundary'] === NULL && $min_max['TypicalUpperBoundary'] !== null) {
|
298
|
// min missing
|
299
|
$min_max['TypicalLowerBoundary'] = '?';
|
300
|
}
|
301
|
if ($min_max['TypicalLowerBoundary'] !== null && $min_max['TypicalUpperBoundary'] === NULL) {
|
302
|
// max missing
|
303
|
$min_max['TypicalUpperBoundary'] = '?';
|
304
|
}
|
305
|
|
306
|
foreach ($min_max as $key => $statistical_val) {
|
307
|
|
308
|
if ($statistical_val !== NULL) {
|
309
|
if ($statistical_val == '?') {
|
310
|
$val_markup = $statistical_val;
|
311
|
} else {
|
312
|
$val_markup = '<span class="'
|
313
|
. html_class_attribute_ref($statistical_val) . ' '
|
314
|
. (isset($statistical_val->type) ? $statistical_val->type->termType : '') . ' ' . $key .'" title="'. $key. '">'
|
315
|
. $statistical_val->_value . '</span>';
|
316
|
}
|
317
|
|
318
|
switch ($key) {
|
319
|
// ---- min_max_element
|
320
|
case 'Min':
|
321
|
$min_max_markup .= "($val_markup–)";
|
322
|
break;
|
323
|
case 'Max':
|
324
|
$min_max_markup .= "(–$val_markup)";
|
325
|
break;
|
326
|
case 'TypicalLowerBoundary':
|
327
|
$min_max_markup .= "$val_markup";
|
328
|
break;
|
329
|
case 'TypicalUpperBoundary':
|
330
|
$min_max_markup .= "–$val_markup";
|
331
|
break;
|
332
|
// ---- other values
|
333
|
case 'SampleSize':
|
334
|
$other_vals_array[$key] = $val_markup;
|
335
|
break;
|
336
|
case 'Average':
|
337
|
$other_vals_array[$key] = $xbar_equals . $val_markup;
|
338
|
break;
|
339
|
case 'Variance':
|
340
|
$other_vals_array[$key] = 'σ²=' . $val_markup;
|
341
|
break;
|
342
|
case 'StandardDeviation':
|
343
|
$other_vals_array[$key] = 'σ=' . $val_markup;
|
344
|
break;
|
345
|
}
|
346
|
}
|
347
|
}
|
348
|
|
349
|
if(!$min_max_markup && $other_vals_array['Average']){
|
350
|
// this could be the case in which we only have one value for Average
|
351
|
// this trivial case needs to be displayed a simpler way
|
352
|
$min_max_markup = str_replace($xbar_equals, '' ,$other_vals_array['Average']);
|
353
|
if($other_vals_array['SampleSize']){
|
354
|
$min_max_markup .= '['. $other_vals_array['SampleSize'] .']';
|
355
|
}
|
356
|
} else {
|
357
|
if(count($other_vals_array)){
|
358
|
$min_max_markup .= '[' . join(';', $other_vals_array) . ']';
|
359
|
}
|
360
|
}
|
361
|
|
362
|
return $min_max_markup . ($unit ? ' ' . $unit : '');
|
363
|
}
|
364
|
|
365
|
/**
|
366
|
* Used internally in min_max_markup() do determine equality of min_max values
|
367
|
*
|
368
|
* @param $min_max
|
369
|
* @param $key1
|
370
|
* @param $key2
|
371
|
*
|
372
|
* @return bool
|
373
|
*/
|
374
|
function min_max_equals($min_max, $key1, $key2){
|
375
|
|
376
|
return $min_max[$key1] !== NULL && $min_max[$key2] !== NULL && $min_max[$key1]->_value == $min_max[$key2]->_value;
|
377
|
}
|
378
|
|
379
|
/**
|
380
|
* Creates min max markup to represent a min-average-max measure optionally with an error value.
|
381
|
*
|
382
|
* The fields that are taken into account are:
|
383
|
* - field_base_name = min
|
384
|
* - field_base_nameMax = max
|
385
|
* - field_base_nameText = free text
|
386
|
* - field_base_nameError = error value
|
387
|
*
|
388
|
* @param $object
|
389
|
* The object having min max measurement fields e.g.: GatheringEvent
|
390
|
* @param string $field_base_name
|
391
|
* The base name for all measurement fields. This name is at the same time the full name of the
|
392
|
* min value.
|
393
|
* @return string
|
394
|
* The markup for the min max
|
395
|
*/
|
396
|
function min_max_measure($object, $field_base_name)
|
397
|
{
|
398
|
static $default_unit = 'm';
|
399
|
|
400
|
$field_name = $field_base_name . 'Text';
|
401
|
if (@is_string($object->$field_name)) {
|
402
|
// Freetext overrides all other data
|
403
|
$min_max_markup = ' ' . $object->$field_name;
|
404
|
} else {
|
405
|
// create markup for the atomized min max data
|
406
|
$min_max_array = min_max_array();
|
407
|
if (@is_numeric($object->$field_base_name)) {
|
408
|
$min_max_array['Min'] = new stdClass();
|
409
|
$min_max_array['Min']->_value = $object->$field_base_name;
|
410
|
}
|
411
|
$field_name = $field_base_name . 'Max';
|
412
|
if (@is_numeric($object->$field_name)) {
|
413
|
$min_max_array['Max'] = new stdClass();
|
414
|
$min_max_array['Max']->_value = $object->$field_name;
|
415
|
}
|
416
|
$min_max_markup = min_max_markup($min_max_array, $default_unit);
|
417
|
}
|
418
|
|
419
|
return $min_max_markup;
|
420
|
}
|
421
|
|
422
|
// TODO move below code into new file: agent.inc
|
423
|
|
424
|
/*
|
425
|
* Compose an render array from a CDM TaxonNodeAgentRelation object as Taxon Expert.
|
426
|
*
|
427
|
* compose_hook() implementation
|
428
|
*
|
429
|
* @param object $taxon_node_agent_relation
|
430
|
* CDM instance of type TaxonNodeAgentRelation
|
431
|
* @return array
|
432
|
* A drupal render array
|
433
|
*
|
434
|
* @ingroup compose
|
435
|
*/
|
436
|
function compose_cdm_taxon_expert($taxon_node_agent_relation) {
|
437
|
|
438
|
$label_suffix = ':';
|
439
|
|
440
|
if($taxon_node_agent_relation->class == 'DefaultPagerImpl'){
|
441
|
// oops this is a pager
|
442
|
// this situation will occur when this compose is executed
|
443
|
// through the proxy_content() method
|
444
|
$taxon_node_agent_relation = $taxon_node_agent_relation->records[0];
|
445
|
|
446
|
}
|
447
|
|
448
|
if(is_object($taxon_node_agent_relation->agent)) {
|
449
|
$agent_details = compose_cdm_team_or_person_base($taxon_node_agent_relation->agent);
|
450
|
// all data will be added to the groups of the agent_details render array
|
451
|
$groups = &$agent_details[0]['#groups'];
|
452
|
|
453
|
@_description_list_group_add($groups, t('Role'). $label_suffix, $taxon_node_agent_relation->type->representation_L10n);
|
454
|
|
455
|
$family_tnars = cdm_ws_fetch_all(CDM_WS_PORTAL_AGENT . '/' . $taxon_node_agent_relation->agent->uuid . '/taxonNodeAgentRelations', array("rank"=>"Familia"));
|
456
|
|
457
|
$taxa_markup = array(
|
458
|
'#theme_wrappers' => array('container'),
|
459
|
'#attributes' => array('class' => array('managed_taxa')),
|
460
|
'#wrapper_attributes' => array('class' => 'sublist-container')
|
461
|
);
|
462
|
foreach($family_tnars as $tnar){
|
463
|
if(is_object($tnar->taxonNode->taxon)){
|
464
|
$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))));
|
465
|
}
|
466
|
}
|
467
|
ksort($taxa_markup);
|
468
|
|
469
|
@_description_list_group_add($groups, t('Families'). $label_suffix, array($taxa_markup));
|
470
|
|
471
|
}
|
472
|
|
473
|
return $agent_details;
|
474
|
}
|
475
|
|
476
|
|
477
|
/*
|
478
|
* Compose an render array from a CDM TeamOrPersonBase object.
|
479
|
*
|
480
|
* compose_hook() implementation
|
481
|
*
|
482
|
* TODO: currently mainly implemented for Agent, add Team details
|
483
|
*
|
484
|
* @param object $team_or_person
|
485
|
* CDM instance of type TeamOrPersonBase
|
486
|
* @return array
|
487
|
* A drupal render array
|
488
|
*
|
489
|
* @ingroup compose
|
490
|
*/
|
491
|
function compose_cdm_team_or_person_base($team_or_person, $data = array()) {
|
492
|
|
493
|
$groups = array();
|
494
|
|
495
|
$label_suffix = ':';
|
496
|
|
497
|
// $weight = 0;
|
498
|
if($team_or_person){
|
499
|
|
500
|
if(is_object($team_or_person->lifespan)){
|
501
|
// ToDo render as date* - date† ?
|
502
|
@_description_list_group_add($groups, t('Lifespan'). $label_suffix, timePeriodToString($team_or_person->lifespan) /*, '' , $weight++ */);
|
503
|
}
|
504
|
|
505
|
// nomenclaturalTitle
|
506
|
@_description_list_group_add($groups, "Nomenclatural Title". $label_suffix, $team_or_person->nomenclaturalTitle);
|
507
|
// collectorTitle
|
508
|
@_description_list_group_add($groups, "Collector Title". $label_suffix, $team_or_person->collectorTitle);
|
509
|
|
510
|
// institutionalMemberships
|
511
|
if(is_array($team_or_person->institutionalMemberships)){
|
512
|
|
513
|
$institutes_ra = array();
|
514
|
foreach($team_or_person->institutionalMemberships as $membership) {
|
515
|
$membership_groups = array();
|
516
|
@_description_list_group_add($membership_groups, t('Department'). $label_suffix, $membership->department);
|
517
|
@_description_list_group_add($membership_groups, t('Role'). $label_suffix, $membership->role);
|
518
|
if(is_object($membership->period)){
|
519
|
@_description_list_group_add($membership_groups, t('Period'). $label_suffix, timePeriodToString($membership->period));
|
520
|
}
|
521
|
if(is_object($membership->institute->contact)){
|
522
|
$institute_contact_details = compose_cdm_contact($membership->institute->contact, $membership->institute->titleCache);
|
523
|
if(is_array($institute_contact_details[0]['#groups'])){
|
524
|
$membership_groups = array_merge($membership_groups, $institute_contact_details[0]['#groups']);
|
525
|
}
|
526
|
}
|
527
|
if(count($membership_groups) > 0){
|
528
|
$institutes_ra[] = array(
|
529
|
'#title' => $membership->institute->titleCache,
|
530
|
'#theme' => 'description_list',
|
531
|
'#groups' => $membership_groups,
|
532
|
'#attributes' => array('class' => html_class_attribute_ref($membership)),
|
533
|
'#wrapper_attributes' => array('class' => 'sublist-container')
|
534
|
);
|
535
|
} else {
|
536
|
// no further details for the membership, display the title
|
537
|
$institutes_ra[] = markup_to_render_array('<h3>' . $membership->institute->titleCache . '</h3>');
|
538
|
}
|
539
|
|
540
|
}
|
541
|
|
542
|
$label = count($institutes_ra) > 1 ? t('Institutes'): t('Institute');
|
543
|
@_description_list_group_add($groups, $label. $label_suffix, $institutes_ra /*, '' , $weight++ */);
|
544
|
}
|
545
|
|
546
|
|
547
|
// Contact
|
548
|
$agent_contact_details = compose_cdm_contact($team_or_person->contact, $team_or_person->titleCache);
|
549
|
if(is_array($agent_contact_details[0]['#groups'])){
|
550
|
$groups = array_merge($groups, $agent_contact_details[0]['#groups']);
|
551
|
}
|
552
|
|
553
|
// additional data
|
554
|
foreach($data as $key=>$value){
|
555
|
@_description_list_group_add($sub_dl_groups, t('@key', array('@key' => $key)), $value /*, '' , $weight++ */);
|
556
|
}
|
557
|
|
558
|
}
|
559
|
|
560
|
$team_or_person_details = array(
|
561
|
'#title' => $team_or_person->titleCache,
|
562
|
'#theme' => 'description_list',
|
563
|
'#groups' => $groups,
|
564
|
'#attributes' => array('class' => html_class_attribute_ref($team_or_person)),
|
565
|
);
|
566
|
return array($team_or_person_details);
|
567
|
}
|
568
|
|
569
|
|
570
|
/*
|
571
|
* Compose an render array from a CDM Contact object.
|
572
|
*
|
573
|
* compose_hook() implementation
|
574
|
*
|
575
|
* TODO: currently mainly implemented for Agent, add Team details
|
576
|
*
|
577
|
* @param object $contact
|
578
|
* CDM instance of type Contact
|
579
|
* @param $title
|
580
|
* The title for the description list header
|
581
|
* @param $weight
|
582
|
* Optional weight for the description list entries
|
583
|
* @return array
|
584
|
* A drupal render array
|
585
|
*
|
586
|
* @ingroup compose
|
587
|
*/
|
588
|
function compose_cdm_contact($contact, $title, $weight = 0)
|
589
|
{
|
590
|
|
591
|
$groups = array();
|
592
|
|
593
|
$contact_details = null;
|
594
|
|
595
|
$label_suffix = ':';
|
596
|
|
597
|
$contact_field_names_map = array(
|
598
|
'emailAddresses' => t('Email'),
|
599
|
'urls' => t('Urls'),
|
600
|
'phoneNumbers' => t('Phone'),
|
601
|
'faxNumbers' => t('Fax'),
|
602
|
);
|
603
|
|
604
|
// Contact
|
605
|
if(is_object($contact)){
|
606
|
if(isset($contact->addresses)){
|
607
|
// TODO ....
|
608
|
// $sub_groups = array();
|
609
|
// foreach($contact->addresses as $address){
|
610
|
// @_description_list_group_add($sub_groups, $label, $contact->$fieldName, '', $weight++);
|
611
|
// }
|
612
|
}
|
613
|
foreach($contact_field_names_map as $fieldName => $label){
|
614
|
if(is_array($contact->$fieldName)){
|
615
|
@_description_list_group_add($groups, $label . $label_suffix, $contact->$fieldName, '', $weight++);
|
616
|
}
|
617
|
}
|
618
|
$contact_details = array(
|
619
|
'#title' => $title,
|
620
|
'#theme' => 'description_list',
|
621
|
'#groups' => $groups
|
622
|
);
|
623
|
|
624
|
|
625
|
} else if(is_string($title)) {
|
626
|
// if the contact entity is empty but the title is given anyway
|
627
|
// we are only adding the title, using the description_list
|
628
|
// structure is not possible since it would be empty due to
|
629
|
// missing group data
|
630
|
$contact_details = array('#markup' => '<h3>' . $title . '</h3>');
|
631
|
}
|
632
|
|
633
|
return array($contact_details);
|
634
|
|
635
|
}
|
636
|
|
637
|
/**
|
638
|
* Compose an render array from a CDM Extension objects.
|
639
|
*
|
640
|
* @param $extensions
|
641
|
* An array of CDM Extension objects
|
642
|
* @return array
|
643
|
* A render array containing the fields of the supplied $sequence
|
644
|
*
|
645
|
* @ingroup compose
|
646
|
*/
|
647
|
function compose_extensions($extensions)
|
648
|
{
|
649
|
$extensions_render_array= null;
|
650
|
$extensions_by_type = array();
|
651
|
foreach ($extensions as $extension) {
|
652
|
if (@is_string($extension->value)) {
|
653
|
if (!isset($extensions_by_type[$extension->type->representation_L10n])) {
|
654
|
$extensions_by_type[$extension->type->representation_L10n] = array();
|
655
|
}
|
656
|
$extensions_by_type[$extension->type->representation_L10n][] = markup_to_render_array($extension->value);
|
657
|
}
|
658
|
}
|
659
|
|
660
|
if (count($extensions_by_type)) {
|
661
|
$sub_dl_groups = array();
|
662
|
foreach ($extensions_by_type as $type_label => $text_list) {
|
663
|
@_description_list_group_add($sub_dl_groups, $type_label . ':', $text_list);
|
664
|
}
|
665
|
$extensions_render_array = array(
|
666
|
array('#theme' => 'description_list', '#groups' => $sub_dl_groups)
|
667
|
);
|
668
|
return $extensions_render_array;
|
669
|
}
|
670
|
return $extensions_render_array;
|
671
|
}
|
672
|
|
673
|
function formatParams($params) {
|
674
|
if (is_array($params)){
|
675
|
$keys =array_keys($params);
|
676
|
$paramString = '';
|
677
|
foreach ($keys as $k ){
|
678
|
if ($k != 'pageNumber' && $k != 'pageSize'){
|
679
|
$paramString .= ' -'.$k.'='.urlencode($params[$k]);
|
680
|
}
|
681
|
}
|
682
|
}
|
683
|
return $paramString;
|
684
|
}
|
685
|
|
686
|
function formatWSParams($params) {
|
687
|
if (is_array($params)){
|
688
|
$keys =array_keys($params);
|
689
|
$paramString = '';
|
690
|
foreach ($keys as $k ){
|
691
|
if ($k != 'pageNumber' && $k != 'pageSize'){
|
692
|
$paramString .= '&'.$k.'='.urlencode($params[$k]);
|
693
|
}
|
694
|
}
|
695
|
}
|
696
|
return $paramString;
|
697
|
}
|
698
|
|
699
|
/**
|
700
|
*
|
701
|
* @param $cdm_entity
|
702
|
*
|
703
|
* @return string the markup
|
704
|
*/
|
705
|
function render_cdm_entity_link($cdm_entity) {
|
706
|
|
707
|
switch ($cdm_entity->class) {
|
708
|
case 'TaxonDescription':
|
709
|
case 'NameDescription':
|
710
|
case 'SpecimenDescription':
|
711
|
$link = '<span class="' . html_class_attribute_ref($cdm_entity) . '">' . $cdm_entity->titleCache . '</span> ' . icon_link(path_to_description($cdm_entity->uuid));
|
712
|
break;
|
713
|
default:
|
714
|
$link = '<span class="error">UNSUPPORTED CDM ENTITY TYPE</span>';
|
715
|
}
|
716
|
return $link;
|
717
|
}
|
718
|
|
719
|
/**
|
720
|
* Creates an icon which links to the given path
|
721
|
* @param $path
|
722
|
*
|
723
|
* @return string
|
724
|
*/
|
725
|
function icon_link($path, $fragment = '') {
|
726
|
$iconlink = l(custom_icon_font_markup('icon-interal-link-alt-solid', ['class' => ['superscript']]), $path, ['html' => TRUE, 'fragment' => $fragment] );
|
727
|
return $iconlink;
|
728
|
}
|