1
|
<?php
|
2
|
/**
|
3
|
* @file
|
4
|
* Functions for dealing with CDM entities of type SpeciemenOrOccurrences
|
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
|
* Compose an render array from a CDM DerivedUnitFacade object.
|
21
|
*
|
22
|
* compose_hook() implementation
|
23
|
*
|
24
|
* @param object $specimenOrObservation
|
25
|
* the CDM instance of type SpecimenOrObservation to compose
|
26
|
* the render array for
|
27
|
* @param array $derivatives
|
28
|
* the render array which contains the compositions of the derivatives
|
29
|
* of the supplied $specimenOrObservation
|
30
|
*
|
31
|
* @return array
|
32
|
* the supplied render array $derivatives to which the composition of the supplied
|
33
|
* $specimenOrObservation has been added to
|
34
|
*/
|
35
|
function compose_cdm_specimenOrObservation($specimenOrObservation, &$derivatives = null) {
|
36
|
|
37
|
static $excludeFields = array(
|
38
|
'derivationEvents',
|
39
|
'titleCache',
|
40
|
'derivedUnitMedia',
|
41
|
'created',
|
42
|
'updated',
|
43
|
'class',
|
44
|
'uuid'
|
45
|
);
|
46
|
|
47
|
// only show uuid it the user is logged in
|
48
|
if(user_is_logged_in()) {
|
49
|
unset($excludeFields[array_search('uuid', $excludeFields)]);
|
50
|
}
|
51
|
|
52
|
if (!isset($derivatives)) {
|
53
|
$derivatives = array();
|
54
|
}
|
55
|
|
56
|
$descriptions = null;
|
57
|
$derivedFrom = null;
|
58
|
|
59
|
if (is_object($specimenOrObservation)) {
|
60
|
|
61
|
// request again for deeper initialization
|
62
|
$specimenOrObservation = cdm_ws_get("portal/" . CDM_WS_OCCURRENCE, $specimenOrObservation->uuid);
|
63
|
|
64
|
|
65
|
$type_label = $specimenOrObservation->class;
|
66
|
RenderHints::setFootnoteListKey($type_label . '-' . $specimenOrObservation->uuid);
|
67
|
|
68
|
// collect typeStatus as label
|
69
|
if (isset($specimenOrObservation->specimenTypeDesignations)) {
|
70
|
$type_status = array();
|
71
|
foreach ($specimenOrObservation->specimenTypeDesignations as $typeDesignation) {
|
72
|
if (isset($typeDesignation->typeStatus->representation_L10n)){
|
73
|
$type_status[] = $typeDesignation->typeStatus->representation_L10n;
|
74
|
}
|
75
|
}
|
76
|
if (count($type_status) > 0){
|
77
|
$type_label = implode(', ', $type_status);
|
78
|
}
|
79
|
}
|
80
|
|
81
|
$title = $type_label . ': '. $specimenOrObservation->titleCache;
|
82
|
|
83
|
$groups = array();
|
84
|
// --- add initialized fields
|
85
|
foreach (get_object_vars($specimenOrObservation) as $field => $value) {
|
86
|
if (!in_array($field, $excludeFields) && ($value && (!is_object($value) || isset($value->class)))) {
|
87
|
switch ($field) {
|
88
|
|
89
|
/* ---- java.lang.Object --- */
|
90
|
case 'class':
|
91
|
if($value != '' /* FieldObservation' */){
|
92
|
@_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value);
|
93
|
}
|
94
|
break;
|
95
|
|
96
|
/* ---- SpecimenOrObservationBase --- */
|
97
|
case 'sex':
|
98
|
case 'lifeStage':
|
99
|
@_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value->representation_L10n);
|
100
|
break;
|
101
|
|
102
|
case 'definition':
|
103
|
// TODO
|
104
|
break;
|
105
|
|
106
|
case 'specimenTypeDesignations':
|
107
|
@_description_list_group_add(
|
108
|
$groups,
|
109
|
cdm_occurrence_field_name_label($field),
|
110
|
array(
|
111
|
'#markup'=>theme('cdm_typedesignations', array('typeDesignations' => $value)),
|
112
|
)
|
113
|
);
|
114
|
break;
|
115
|
|
116
|
case 'determinations':
|
117
|
$dd_elements = array();
|
118
|
$glue = ', ';
|
119
|
|
120
|
foreach ($value as $determinationEvent){
|
121
|
$timeperiod_string = NULL;
|
122
|
if (isset($determinationEvent->timeperiod)) {
|
123
|
$timeperiod_string = timePeriodToString($determinationEvent->timeperiod);
|
124
|
}
|
125
|
$weight = isset($determinationEvent->preferred) && $determinationEvent->preferred == 1 ? '0' : ($timeperiod_string ? $timeperiod_string : '1');
|
126
|
// check key exists
|
127
|
while (array_key_exists($weight, $dd_elements)) {
|
128
|
$weight .= '0';
|
129
|
}
|
130
|
$taxon_name = cdm_ws_get(CDM_WS_TAXON . '/$0/name', $determinationEvent->taxon->uuid);
|
131
|
$taxon_html = theme('cdm_taxonName',
|
132
|
array(
|
133
|
'taxonName' => $taxon_name,
|
134
|
'nameLink' => path_to_taxon($determinationEvent->taxon->uuid),
|
135
|
)
|
136
|
);
|
137
|
$dd_elements[$weight] = $taxon_html;
|
138
|
if (isset($determinationEvent->modifier)) {
|
139
|
$dd_elements[$weight] .= cdm_term_representation($determinationEvent->modifier);
|
140
|
}
|
141
|
if ($timeperiod_string) {
|
142
|
$dd_elements[$weight] .= $glue . $timeperiod_string;
|
143
|
}
|
144
|
if (isset($determinationEvent->actor->titleCache)) {
|
145
|
$dd_elements[$weight] .= $glue . $determinationEvent->actor->titleCache;
|
146
|
}
|
147
|
if (isset($determinationEvent->description)) {
|
148
|
$dd_elements[$weight] .= $glue . $determinationEvent->description;
|
149
|
}
|
150
|
}
|
151
|
ksort($dd_elements);
|
152
|
@_description_list_group_add($groups, cdm_occurrence_field_name_label('determinations'), $dd_elements);
|
153
|
break;
|
154
|
|
155
|
case 'descriptions':
|
156
|
$descriptions = $value;
|
157
|
$occurrence_featureTree = cdm_get_occurrence_featureTree();
|
158
|
$dd_elements = array();
|
159
|
|
160
|
foreach ($value as $description) {
|
161
|
$description = cdm_ws_get(CDM_WS_PORTAL_DESCRIPTION, $description->uuid);
|
162
|
$elements_by_feature = _mergeFeatureTreeDescriptions($occurrence_featureTree->root->children, $description->elements);
|
163
|
$rendered_description = theme(
|
164
|
'cdm_feature_nodes',
|
165
|
array('mergedFeatureNodes' => $elements_by_feature)
|
166
|
);
|
167
|
$description_render_elements = array();
|
168
|
// $description_render_elements[] = array('#markup' => '<h4>'. $description->titleCache . '</h4>');
|
169
|
$description_render_elements[] = array('#markup' => $rendered_description);
|
170
|
$dd_elements[] = $description_render_elements;
|
171
|
}
|
172
|
|
173
|
@_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
|
174
|
break;
|
175
|
|
176
|
case 'sources':
|
177
|
$dd_elements = array();
|
178
|
foreach ($value as $identifiable_source) {
|
179
|
$dd_elements[] = theme('cdm_OriginalSource', array('source' => $identifiable_source));
|
180
|
}
|
181
|
@_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
|
182
|
break;
|
183
|
|
184
|
|
185
|
/* ---- DerivedUnitBase --- */
|
186
|
case 'derivedFrom':
|
187
|
$derivedFrom = $value;
|
188
|
break;
|
189
|
|
190
|
case 'collection':
|
191
|
$sub_dl_groups = array();
|
192
|
@_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('code'), $value->code, NULL, 1);
|
193
|
@_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('codeStandard'), $value->codeStandard, NULL, 2);
|
194
|
@_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('institute'), $value->institute, NULL, 3);
|
195
|
@_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('townOrLocation'), $value->townOrLocation, NULL, 4);
|
196
|
// TODO "superCollection"
|
197
|
// TODO may have media
|
198
|
|
199
|
@_description_list_group_add($groups, cdm_occurrence_field_name_label($field),
|
200
|
array(
|
201
|
array('#markup' => $value->titleCache),
|
202
|
array('#theme' => 'description_list', '#groups' => $sub_dl_groups)
|
203
|
)
|
204
|
);
|
205
|
break;
|
206
|
|
207
|
case 'storedUnder':
|
208
|
@_description_list_group_add($groups, cdm_occurrence_field_name_label('storedUnder'), theme('cdm_taxonName', $value));
|
209
|
break;
|
210
|
|
211
|
|
212
|
/* ---- Specimen --- */
|
213
|
// TODO preservation
|
214
|
// TODO exsiccatum
|
215
|
|
216
|
|
217
|
/* ---- FieldObservation --- */
|
218
|
case 'gatheringEvent':
|
219
|
@_description_list_group_add($groups, cdm_occurrence_field_name_label('collector'), $value->actor->titleCache);
|
220
|
@_description_list_group_add($groups, t('Gathering time'), timePeriodToString($value->timeperiod));
|
221
|
@_description_list_group_add($groups, cdm_occurrence_field_name_label('description'), $value->description);
|
222
|
@_description_list_group_add($groups, cdm_occurrence_field_name_label('locality'), $value->locality);
|
223
|
@_description_list_group_add($groups, cdm_occurrence_field_name_label('country'), $value->country->representation_L10n);
|
224
|
@_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingMethod'), $value->collectingMethod);
|
225
|
@_description_list_group_add($groups, cdm_occurrence_field_name_label('absoluteElevation'), $value->absoluteElevation, ' m');
|
226
|
@_description_list_group_add($groups, cdm_occurrence_field_name_label('absoluteElevationError'), $value->absoluteElevationError, ' m');
|
227
|
@_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToGround'), $value->distanceToGround, ' m');
|
228
|
@_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToWaterSurface'), $value->distanceToWaterSurface, ' m');
|
229
|
if (isset($value->collectingAreas)) {
|
230
|
$area_representations = array();
|
231
|
foreach($value->collectingAreas as $area) {
|
232
|
$area_representations[] = $area->representation_L10n;
|
233
|
}
|
234
|
@_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingAreas'), implode(', ', $area_representations));
|
235
|
}
|
236
|
if (isset($value->exactLocation)) {
|
237
|
$sub_dl_groups = array();
|
238
|
@_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('errorRadius'), $value->exactLocation->errorRadius, ' m', 1);
|
239
|
@_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('longitude'), $value->exactLocation->longitude, '°', 2);
|
240
|
@_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('latitude'), $value->exactLocation->latitude, '°', 3);
|
241
|
if (isset($value->exactLocation->referenceSystem)) {
|
242
|
@_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('referenceSystem'), $value->exactLocation->referenceSystem->representation_L10n, '', 4);
|
243
|
}
|
244
|
|
245
|
@_description_list_group_add($groups, cdm_occurrence_field_name_label('exactLocation'),
|
246
|
array(
|
247
|
array('#markup' => $value->exactLocation->sexagesimalString),
|
248
|
array(
|
249
|
'#theme' => 'description_list',
|
250
|
'#groups' => $sub_dl_groups
|
251
|
),
|
252
|
)
|
253
|
);
|
254
|
}
|
255
|
break;
|
256
|
|
257
|
default:
|
258
|
if(is_object($value) || is_array($value)){
|
259
|
drupal_set_message("Unhandled type in compose_cdm_specimenOrObservation() for field " . $field, "warning");
|
260
|
} else {
|
261
|
_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value);
|
262
|
}
|
263
|
|
264
|
}
|
265
|
|
266
|
}
|
267
|
} // END of loop over $derivedUnitFacade fields
|
268
|
|
269
|
|
270
|
$occurrence_elements = array(
|
271
|
'#title' => $title,
|
272
|
'#theme' => 'description_list',
|
273
|
'#groups' => $groups,
|
274
|
'#attributes' => array('class' => html_class_atttibute_ref($specimenOrObservation)),
|
275
|
);
|
276
|
$derivatives[] = $occurrence_elements;
|
277
|
// all footnotes which has been assembled so far (e.g. from typeDesignations) to here
|
278
|
$foonote_li_elements = theme('cdm_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey(), 'enclosingTag' => 'span'));
|
279
|
if (!empty($foonote_li_elements)) {
|
280
|
$derivatives[] = array(
|
281
|
'#markup' => '<div class="footnotes">' . $foonote_li_elements . '</div>',
|
282
|
);
|
283
|
}
|
284
|
|
285
|
// --- recurse into originals
|
286
|
if (!isset($derivedFrom)) {
|
287
|
$derivedFrom = cdm_ws_get(
|
288
|
CDM_WS_OCCURRENCE,
|
289
|
array($specimenOrObservation->uuid, 'derivedFrom')
|
290
|
);
|
291
|
}
|
292
|
|
293
|
if (isset($derivedFrom)) {
|
294
|
if (isset($derivedFrom->originals)) {
|
295
|
$derived_from_label = t('derived');
|
296
|
if(isset($derivedFrom->type)){
|
297
|
$derived_from_label = $derivedFrom->representation_L10n;
|
298
|
}
|
299
|
if (count($groups) > 0) {
|
300
|
// only display the derived from information when the derivative has any element which will be diplayed
|
301
|
$derivatives[] = array(
|
302
|
'#markup' => '<div>' . $derived_from_label . ' ' . t('from') . ': </div>',
|
303
|
);
|
304
|
}
|
305
|
foreach ($derivedFrom->originals as $original) {
|
306
|
compose_cdm_specimenOrObservation($original, $derivatives);
|
307
|
}
|
308
|
}
|
309
|
}
|
310
|
|
311
|
} // END of $specimenOrObservation exists
|
312
|
|
313
|
return $derivatives;
|
314
|
}
|