1
|
<?php
|
2
|
/**
|
3
|
* @file
|
4
|
* Functions for dealing with CDM entities of type SpecimenOrOccurrences
|
5
|
* This file contains new functions which are to replace functions in
|
6
|
* occurrences.inc and should be merged with the latter one.
|
7
|
*
|
8
|
* @see http://www.mozilla.org/MPL/MPL-1.1.html
|
9
|
*
|
10
|
* @copyright
|
11
|
* (C) 2007-2021 EDIT
|
12
|
* European Distributed Institute of Taxonomy
|
13
|
* http://www.e-taxonomy.eu
|
14
|
*
|
15
|
* The contents of this module are subject to the Mozilla
|
16
|
* Public License Version 1.1.
|
17
|
* @author
|
18
|
* - Andreas Kohlbecker <a.kohlbecker@BGBM.org>
|
19
|
*/
|
20
|
|
21
|
|
22
|
/**
|
23
|
* Composes the view on specimens and occurrences as derivate tree
|
24
|
* starting from the field unit including all derivatives.
|
25
|
*
|
26
|
* @param array $root_unit_dtos
|
27
|
* list of SpecimenOrObservationDTOs
|
28
|
*
|
29
|
* @return array
|
30
|
* The Drupal render array
|
31
|
*
|
32
|
* @ingroup compose
|
33
|
* @see CDM_SPECIMEN_LIST_VIEW_MODE_OPTION_DERIVATE_TREE
|
34
|
*
|
35
|
*/
|
36
|
function compose_specimen_table_top_down_new(array $root_unit_dtos) {
|
37
|
// add icons
|
38
|
$expand_icon = font_awesome_icon_markup(
|
39
|
'fa-plus-square-o',
|
40
|
[
|
41
|
'alt' => 'Show details',
|
42
|
'class' => ['expand_icon'],
|
43
|
]
|
44
|
);
|
45
|
$collapse_icon = font_awesome_icon_markup(
|
46
|
'fa-minus-square-o',
|
47
|
[
|
48
|
'alt' => 'Show details',
|
49
|
'class' => ['collapse_icon'],
|
50
|
]
|
51
|
);
|
52
|
|
53
|
$derivation_tree = derived_units_tree($root_unit_dtos);
|
54
|
|
55
|
$render_array = [];
|
56
|
$render_array['derived-unit-tree'] = $derivation_tree;
|
57
|
|
58
|
_add_js_derivation_tree('.derived-unit-tree');
|
59
|
|
60
|
return $render_array;
|
61
|
}
|
62
|
|
63
|
/**
|
64
|
* Creates the root levels and trees for all subordinate derivatives.
|
65
|
*
|
66
|
* See derived_units_sub_tree()
|
67
|
*
|
68
|
* @param array $root_unit_dtos
|
69
|
* list of SpecimenOrObservationDTOs
|
70
|
*
|
71
|
* @return array
|
72
|
* An array which can be used in render arrays to be passed to the
|
73
|
* theme_table() and theme_list().
|
74
|
*/
|
75
|
function derived_units_tree(array $root_unit_dtos) {
|
76
|
|
77
|
$root_items = [];
|
78
|
//we need one more item to contain the items of one level (fieldunit, derivate data etc.)
|
79
|
foreach ($root_unit_dtos as &$sob_dto) {
|
80
|
$field_unit_dto_render_array = compose_cdm_specimen_or_observation_dto($sob_dto);
|
81
|
$root_item = [
|
82
|
'#prefix' => '<div class="derived-unit-tree">',
|
83
|
'#suffix' => '</div>',
|
84
|
'#type' => 'container',
|
85
|
'#attributes' => [
|
86
|
'class' => [
|
87
|
'derived-unit-item derived-unit-tree-root',
|
88
|
html_class_attribute_ref($sob_dto),
|
89
|
],
|
90
|
],
|
91
|
'div-container' => [
|
92
|
'root-item-and-sub-tree' => [
|
93
|
markup_to_render_array('<div class="unit-header"><div class="unit-label">' . $sob_dto->label . '</div></div>'
|
94
|
. '<div class="unit-content-wrapper">' // allows to apply the borders between .derived-unit-tree-root and .unit-content
|
95
|
. '<div class="unit-content">' . drupal_render($field_unit_dto_render_array) . '</div>'
|
96
|
. '</div>'),
|
97
|
],
|
98
|
],
|
99
|
|
100
|
];
|
101
|
if (isset($sob_dto->derivatives) && sizeof($sob_dto->derivatives) > 0) {
|
102
|
usort($sob_dto->derivatives, 'compare_specimen_or_observation_dtos');
|
103
|
// children are displayed in a nested list.
|
104
|
$root_item['div-container']['root-item-and-sub-tree'][] = derived_units_sub_tree($sob_dto->derivatives);
|
105
|
}
|
106
|
$root_items[] = $root_item;
|
107
|
}
|
108
|
|
109
|
return $root_items;
|
110
|
}
|
111
|
|
112
|
/**
|
113
|
* @param array $unit_dtos
|
114
|
*
|
115
|
* @return array
|
116
|
*/
|
117
|
function derived_units_sub_tree(array $unit_dtos) {
|
118
|
|
119
|
$list_items = derived_units_as_list_items($unit_dtos);
|
120
|
|
121
|
$derivation_tree = [
|
122
|
'#theme' => 'item_list',
|
123
|
'#type' => 'ul',
|
124
|
'#attributes' => [
|
125
|
'class' => CDM_SPECIMEN_LIST_VIEW_MODE_OPTION_DERIVATE_TREE . ' derived-unit-sub-tree',
|
126
|
],
|
127
|
'#items' => $list_items,
|
128
|
];
|
129
|
return $derivation_tree;
|
130
|
}
|
131
|
|
132
|
/**
|
133
|
* Creates render array items for FieldUnitDTO or DerivedUnitDTO.
|
134
|
*
|
135
|
* @param array $root_unit_dtos
|
136
|
* list of SpecimenOrObservationDTOs
|
137
|
*
|
138
|
* @return array
|
139
|
* An array which can be used in render arrays to be passed to the
|
140
|
* theme_table() and theme_list().
|
141
|
*/
|
142
|
function derived_units_as_list_items(array $root_unit_dtos) {
|
143
|
|
144
|
$list_items = [];
|
145
|
//we need one more item to contain the items of one level (fieldunit, derivate data etc.)
|
146
|
foreach ($root_unit_dtos as &$sob_dto) {
|
147
|
$item = [];
|
148
|
$item['class'] = ['derived-unit-item ', html_class_attribute_ref($sob_dto)];
|
149
|
// data" element of the array is used as the contents of the list item
|
150
|
$item['data'] = [];
|
151
|
$units_render_array = compose_cdm_specimen_or_observation_dto($sob_dto);
|
152
|
$item['data'] = '<div class="unit-header"><div class="unit-label">' . $sob_dto->label . '</div></div>'
|
153
|
. '<div class="unit-content">' . drupal_render($units_render_array) . '</div>';
|
154
|
if (isset($sob_dto->derivatives) && sizeof($sob_dto->derivatives) > 0) {
|
155
|
usort($sob_dto->derivatives, 'compare_specimen_or_observation_dtos');
|
156
|
// children are displayed in a nested list.
|
157
|
$item['children'] = derived_units_as_list_items($sob_dto->derivatives);
|
158
|
}
|
159
|
$list_items[] = $item;
|
160
|
}
|
161
|
|
162
|
return $list_items;
|
163
|
}
|
164
|
|
165
|
/**
|
166
|
* Compose an render array from a CDM SpecimenOrObservationDTO, without
|
167
|
* subordinate derivatives.
|
168
|
*
|
169
|
* The resulting render array will contain separate DOM block level elements
|
170
|
* with header line for the various kind of information like, location,
|
171
|
* gathering, specimen/observation, DNA, etc.
|
172
|
*
|
173
|
* For showing the derivation hierarchy see methods like
|
174
|
* derived_units_sub_tree()
|
175
|
*
|
176
|
* compose_hook() implementation
|
177
|
*
|
178
|
* @param object $sob_dto
|
179
|
* the CDM FieldUnitDTO or DerivedUnitDTO to compose
|
180
|
* the render array for.
|
181
|
* @param bool $compact_mode
|
182
|
* Currently unused, but added for compatibility with
|
183
|
* compose_cdm_specimen_or_observation($specimen_or_observation,
|
184
|
* $isSpecimen_page = false, &$derivatives = null)
|
185
|
* @param array $derivatives
|
186
|
* the render array which contains the compositions of the derivatives
|
187
|
* of the supplied $specimenOrObservation
|
188
|
*
|
189
|
* @return array
|
190
|
* The render array for the SpecimenOrObservationDTO
|
191
|
*
|
192
|
* @ingroup compose
|
193
|
*/
|
194
|
function compose_cdm_specimen_or_observation_dto($sob_dto, $compact_mode = FALSE, &$derivatives = NULL) {
|
195
|
//TODO !!!! add derivation event information like method, etc
|
196
|
$render_array = [];
|
197
|
if (!$sob_dto) {
|
198
|
return $render_array;
|
199
|
}
|
200
|
if ($sob_dto->type == 'FieldUnit') {
|
201
|
$render_array['field-unit'] = compose_cdm_field_unit_dto_location($sob_dto, $compact_mode);
|
202
|
if (isset($sob_dto->gatheringEvent)) {
|
203
|
$render_array['gathering'] = compose_cdm_gathering_dto($sob_dto->gatheringEvent, $compact_mode);
|
204
|
}
|
205
|
}
|
206
|
|
207
|
return $render_array;
|
208
|
}
|
209
|
|
210
|
/**
|
211
|
* Compose an render array from a CDM FieldUnitDTO, without subordinate
|
212
|
* derivatives.
|
213
|
*
|
214
|
* The resulting DOM block level element will have a header line and details.
|
215
|
*
|
216
|
* For showing the derivation hierarchy see methods like
|
217
|
* derived_units_sub_tree()
|
218
|
*
|
219
|
* compose_hook() implementation
|
220
|
*
|
221
|
* @param object $fu_dto
|
222
|
* the CDM FieldUnitDTO
|
223
|
* the render array for.
|
224
|
* @param bool $compact_mode
|
225
|
* Currently unused,
|
226
|
*
|
227
|
* @return array
|
228
|
* The render array for the SpecimenOrObservationDTO
|
229
|
*
|
230
|
* @ingroup compose
|
231
|
*/
|
232
|
function compose_cdm_field_unit_dto_location($fu_dto, $compact_mode = FALSE) {
|
233
|
|
234
|
$table_row_data = [];
|
235
|
if (isset_not_empty($fu_dto->sex)) {
|
236
|
$table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('sex'), cdm_term_representation($fu_dto->sex));
|
237
|
}
|
238
|
if (isset_not_empty($fu_dto->lifeStage)) {
|
239
|
$table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('lifeStage'), cdm_term_representation($fu_dto->lifeStage));
|
240
|
}
|
241
|
if (isset_not_empty($fu_dto->kindOfUnit)) {
|
242
|
$table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('kindOfUnit'), cdm_term_representation($fu_dto->kindOfUnit));
|
243
|
}
|
244
|
if (isset_not_empty($fu_dto->individualCount)) {
|
245
|
$table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('individualCount'), $fu_dto->individualCount);
|
246
|
}
|
247
|
if (isset_not_empty($fu_dto->definition)) {
|
248
|
$table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('definition'), $fu_dto->definition);
|
249
|
}
|
250
|
if (isset_not_empty($fu_dto->fieldNumber)) {
|
251
|
$table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('fieldNumber'), $fu_dto->fieldNumber);
|
252
|
}
|
253
|
if (isset_not_empty($fu_dto->primaryCollector)) {
|
254
|
$table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('primaryCollector'), $fu_dto->primaryCollector);
|
255
|
}
|
256
|
if (isset_not_empty($fu_dto->fieldNotes)) {
|
257
|
$table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('fieldNotes'), $fu_dto->fieldNotes);
|
258
|
}
|
259
|
|
260
|
return cdm_sob_dto_table(t("Field unit"), $table_row_data, $fu_dto, 2);
|
261
|
}
|
262
|
|
263
|
/**
|
264
|
* Compose an render array from a CDM FieldUnitDTO, without subordinate
|
265
|
* derivatives.
|
266
|
*
|
267
|
* The resulting DOM block level element will have a header line and details.
|
268
|
*
|
269
|
* For showing the derivation hierarchy see methods like
|
270
|
* derived_units_sub_tree()
|
271
|
*
|
272
|
* compose_hook() implementation
|
273
|
*
|
274
|
* @param object $gathering_dto
|
275
|
* the CDM FieldUnitDTO
|
276
|
* the render array for.
|
277
|
* @param bool $compact_mode
|
278
|
* Currently unused,
|
279
|
*
|
280
|
* @return array
|
281
|
* The render array for the SpecimenOrObservationDTO
|
282
|
*
|
283
|
* @ingroup compose
|
284
|
*/
|
285
|
function compose_cdm_gathering_dto($gathering_dto, $compact_mode = FALSE) {
|
286
|
|
287
|
$table_row_data = [];
|
288
|
if (isset_not_empty($gathering_dto->date)) {
|
289
|
$table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('date'),
|
290
|
partialToDate($gathering_dto->date));
|
291
|
}
|
292
|
if (isset_not_empty($gathering_dto->collector)) {
|
293
|
$table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('collector'),
|
294
|
$gathering_dto->collector);
|
295
|
}
|
296
|
if (isset_not_empty($gathering_dto->description)) {
|
297
|
$table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('description'),
|
298
|
$gathering_dto->description);
|
299
|
}
|
300
|
if (isset_not_empty($gathering_dto->locality)) {
|
301
|
$table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('locality'),
|
302
|
$gathering_dto->locality);
|
303
|
}
|
304
|
if (isset_not_empty($gathering_dto->country)) {
|
305
|
$table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('country'),
|
306
|
$gathering_dto->country);
|
307
|
}
|
308
|
if (isset_not_empty($gathering_dto->collectingMethod)) {
|
309
|
$table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('collectingMethod'),
|
310
|
$gathering_dto->collectingMethod);
|
311
|
}
|
312
|
if (isset($gathering_dto->exactLocation)) {
|
313
|
$table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('exactLocation'),
|
314
|
render_point($gathering_dto->exactLocation));
|
315
|
}
|
316
|
if (isset($gathering_dto->absoluteElevation)) {
|
317
|
$table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('absoluteElevation'),
|
318
|
statistical_values_from_gathering_event($gathering_dto, 'absoluteElevation'));
|
319
|
}
|
320
|
if (isset($gathering_dto->distanceToGround) && $gathering_dto->distanceToGround > 0) {
|
321
|
$table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('distanceToGround'),
|
322
|
statistical_values_from_gathering_event($gathering_dto, 'distanceToGround'));
|
323
|
}
|
324
|
if (isset($gathering_dto->distanceToWaterSurface) && $gathering_dto->distanceToWaterSurface > 0) {
|
325
|
$table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('distanceToWaterSurface'),
|
326
|
statistical_values_from_gathering_event($gathering_dto, 'distanceToWaterSurface'));
|
327
|
}
|
328
|
if (isset_not_empty($gathering_dto->collectingAreas)) {
|
329
|
$area_representations = [];
|
330
|
foreach ($gathering_dto->collectingAreas as $area) {
|
331
|
// $area_representations[] = l($area->representation_L10n, path_to_named_area($area->uuid));
|
332
|
$area_representations[] = $area;
|
333
|
}
|
334
|
if (!empty($area_representations)) {
|
335
|
$table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('collectingAreas'),
|
336
|
implode(', ', $area_representations)
|
337
|
);
|
338
|
}
|
339
|
}
|
340
|
|
341
|
return cdm_sob_dto_table(t("Gathering & Location"), $table_row_data, $gathering_dto, 1);
|
342
|
}
|
343
|
|
344
|
/**
|
345
|
* Creates a form array for showing details of SpecimenOrObservationDTO in a
|
346
|
* tabular form with heading.
|
347
|
*
|
348
|
* @param $table_heading
|
349
|
* @param array $table_row_data
|
350
|
* @param $sob_dto
|
351
|
* @param $weight
|
352
|
* The weight determining the order of the drupal render element
|
353
|
*
|
354
|
* @return array|null
|
355
|
*/
|
356
|
function cdm_sob_dto_table($table_heading, array $table_row_data, $sob_dto, $weight = NULL) {
|
357
|
if (count($table_row_data) > 0) {
|
358
|
$sob_table = [
|
359
|
'#theme' => 'table',
|
360
|
'#prefix' => '<div class="table-wrapper">',
|
361
|
'#suffix' => '</div>',
|
362
|
'#header' => [
|
363
|
[
|
364
|
'data' => $table_heading,
|
365
|
'colspan' => 2,
|
366
|
],
|
367
|
],
|
368
|
"#rows" => $table_row_data,
|
369
|
"#attributes" => [
|
370
|
"class" => [
|
371
|
'specimen-or-observation-details',
|
372
|
html_class_attribute_ref($sob_dto),
|
373
|
],
|
374
|
],
|
375
|
];
|
376
|
if ($weight) {
|
377
|
$sob_table['#weight'] = $weight;
|
378
|
}
|
379
|
return $sob_table;
|
380
|
}
|
381
|
return NULL;
|
382
|
}
|
383
|
|
384
|
function cdm_sob_dto_table_row($label, $value) {
|
385
|
if ($value) {
|
386
|
return [
|
387
|
'data' => [
|
388
|
[
|
389
|
'data' => str_replace(':', '', $label),
|
390
|
'class' => [
|
391
|
'label',
|
392
|
],
|
393
|
],
|
394
|
$value,
|
395
|
],
|
396
|
'no_striping' => TRUE,
|
397
|
];
|
398
|
}
|
399
|
return NULL;
|
400
|
}
|