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
|
|
38
|
$derivation_tree = derived_units_tree($root_unit_dtos);
|
39
|
|
40
|
$render_array = [];
|
41
|
$render_array['derived-unit-tree'] = $derivation_tree;
|
42
|
|
43
|
_add_js_derivation_tree('.derived-unit-tree');
|
44
|
|
45
|
return $render_array;
|
46
|
}
|
47
|
|
48
|
/**
|
49
|
* Creates the root levels and trees for all subordinate derivatives.
|
50
|
*
|
51
|
* See derived_units_sub_tree()
|
52
|
*
|
53
|
* @param array $root_unit_dtos
|
54
|
* list of SpecimenOrObservationDTOs
|
55
|
*
|
56
|
* @return array
|
57
|
* An array which can be used in render arrays to be passed to the
|
58
|
* theme_table() and theme_list().
|
59
|
*/
|
60
|
function derived_units_tree(array $root_unit_dtos) {
|
61
|
|
62
|
RenderHints::pushToRenderStack('derived-unit-tree');
|
63
|
RenderHints::setFootnoteListKey('derived-unit-tree');
|
64
|
|
65
|
$root_items = [];
|
66
|
//we need one more item to contain the items of one level (fieldunit, derivate data etc.)
|
67
|
foreach ($root_unit_dtos as &$sob_dto) {
|
68
|
$field_unit_dto_render_array = compose_cdm_specimen_or_observation_dto_details_grid($sob_dto);
|
69
|
$root_item = [
|
70
|
'#prefix' => '<div class="derived-unit-tree">',
|
71
|
'#suffix' => '</div>',
|
72
|
'#type' => 'container',
|
73
|
'#attributes' => [
|
74
|
'class' => [
|
75
|
'derived-unit-item derived-unit-tree-root',
|
76
|
html_class_attribute_ref($sob_dto),
|
77
|
],
|
78
|
],
|
79
|
'div-container' => [
|
80
|
'root-item-and-sub-tree' => [
|
81
|
markup_to_render_array(derived_units_tree_node_header($sob_dto)
|
82
|
. '<div class="unit-content-wrapper">' // allows to apply the borders between .derived-unit-tree-root and .unit-content
|
83
|
. '<div class="unit-content">' . drupal_render($field_unit_dto_render_array) . '</div>'
|
84
|
. '</div>'),
|
85
|
],
|
86
|
],
|
87
|
|
88
|
];
|
89
|
if (isset($sob_dto->derivatives) && sizeof($sob_dto->derivatives) > 0) {
|
90
|
usort($sob_dto->derivatives, 'compare_specimen_or_observation_dtos');
|
91
|
// children are displayed in a nested list.
|
92
|
$root_item['div-container']['root-item-and-sub-tree'][] = derived_units_sub_tree($sob_dto->derivatives);
|
93
|
}
|
94
|
$root_items[] = $root_item;
|
95
|
}
|
96
|
|
97
|
$root_items['footnotes'] = markup_to_render_array(render_footnotes());
|
98
|
RenderHints::popFromRenderStack();
|
99
|
|
100
|
return $root_items;
|
101
|
}
|
102
|
|
103
|
/**
|
104
|
* @param array $unit_dtos
|
105
|
*
|
106
|
* @return array
|
107
|
*/
|
108
|
function derived_units_sub_tree(array $unit_dtos) {
|
109
|
|
110
|
$list_items = derived_units_as_list_items($unit_dtos);
|
111
|
|
112
|
$derivation_tree = [
|
113
|
'#theme' => 'item_list',
|
114
|
'#type' => 'ul',
|
115
|
'#attributes' => [
|
116
|
// NOTE: class attribute "derived-unit-item" is important for consistency with subordinate <ul> elements produced by the drupal theme function
|
117
|
'class' => CDM_SPECIMEN_LIST_VIEW_MODE_OPTION_DERIVATE_TREE . ' derived-unit-item derived-unit-sub-tree',
|
118
|
],
|
119
|
'#items' => $list_items,
|
120
|
];
|
121
|
return $derivation_tree;
|
122
|
}
|
123
|
|
124
|
/**
|
125
|
* Creates render array items for FieldUnitDTO or DerivedUnitDTO.
|
126
|
*
|
127
|
* @param array $root_unit_dtos
|
128
|
* list of SpecimenOrObservationDTOs
|
129
|
*
|
130
|
* @return array
|
131
|
* An array which can be used in render arrays to be passed to the
|
132
|
* theme_table() and theme_list().
|
133
|
*/
|
134
|
function derived_units_as_list_items(array $root_unit_dtos) {
|
135
|
|
136
|
$list_items = [];
|
137
|
//we need one more item to contain the items of one level (fieldunit, derivate data etc.)
|
138
|
foreach ($root_unit_dtos as &$sob_dto) {
|
139
|
$item = [];
|
140
|
$item['class'] = ['derived-unit-item ', html_class_attribute_ref($sob_dto)];
|
141
|
// data" element of the array is used as the contents of the list item
|
142
|
$item['data'] = [];
|
143
|
$units_render_array = compose_cdm_specimen_or_observation_dto_details_grid($sob_dto);
|
144
|
$item['data'] = derived_units_tree_node_header($sob_dto)
|
145
|
. '<div class="unit-content derived-unit-details-grid">' . drupal_render($units_render_array) . '</div>';
|
146
|
if (isset($sob_dto->derivatives) && sizeof($sob_dto->derivatives) > 0) {
|
147
|
usort($sob_dto->derivatives, 'compare_specimen_or_observation_dtos');
|
148
|
// children are displayed in a nested list.
|
149
|
$item['children'] = derived_units_as_list_items($sob_dto->derivatives);
|
150
|
}
|
151
|
$list_items[] = $item;
|
152
|
}
|
153
|
|
154
|
return $list_items;
|
155
|
}
|
156
|
|
157
|
/**
|
158
|
* @param $sob_dto
|
159
|
*
|
160
|
* @return string
|
161
|
*/
|
162
|
function derived_units_tree_node_header($sob_dto) {
|
163
|
$link = cdm_internal_link(path_to_specimen($sob_dto->uuid), null);
|
164
|
return '<div class="unit-header"><div class="unit-label">' . $sob_dto->label . '<span class="page-link">' . $link . '</span></div></div>';
|
165
|
}
|
166
|
|
167
|
/**
|
168
|
* Compose grid of details tabled for a CDM SpecimenOrObservationDTO
|
169
|
*
|
170
|
* The resulting render array will contain separate DOM block level elements
|
171
|
* with header line for the various kind of information like, location,
|
172
|
* gathering, specimen/observation, DNA, etc.
|
173
|
*
|
174
|
*
|
175
|
* Subordinate derivatives will not be included. For showing the derivation
|
176
|
* hierarchy see methods like derived_units_sub_tree()
|
177
|
*
|
178
|
* compose_hook() implementation
|
179
|
*
|
180
|
* @param object $sob_dto
|
181
|
* the CDM FieldUnitDTO or DerivedUnitDTO to compose
|
182
|
* the render array for.
|
183
|
* @param bool $compact_mode
|
184
|
* Currently unused, but added for compatibility with
|
185
|
* compose_cdm_specimen_or_observation($specimen_or_observation,
|
186
|
* $isSpecimen_page = false, &$derivatives = null)
|
187
|
* @param array $derivatives
|
188
|
* the render array which contains the compositions of the derivatives
|
189
|
* of the supplied $specimenOrObservation
|
190
|
*
|
191
|
* @return array
|
192
|
* The render array for the SpecimenOrObservationDTO
|
193
|
*
|
194
|
* @ingroup compose
|
195
|
*/
|
196
|
function compose_cdm_specimen_or_observation_dto_details_grid($sob_dto, $compact_mode = FALSE, &$derivatives = NULL) {
|
197
|
$render_array = [];
|
198
|
if (!$sob_dto) {
|
199
|
return $render_array;
|
200
|
}
|
201
|
if ($sob_dto->type == 'FieldUnit') {
|
202
|
$render_array['field-unit'] = compose_cdm_field_unit_dto_details($sob_dto, $compact_mode);
|
203
|
if (isset($sob_dto->gatheringEvent)) {
|
204
|
$render_array['gathering'] = compose_cdm_gathering_dto_details($sob_dto->gatheringEvent, $compact_mode);
|
205
|
}
|
206
|
} else {
|
207
|
if(isset($sob_dto->derivationEvent)){
|
208
|
$render_array['derivation-event'] = compose_cdm_derivation_event($sob_dto->derivationEvent);
|
209
|
}
|
210
|
$render_array['storage'] = compose_cdm_derived_unit_dto_storage_details($sob_dto, $compact_mode);
|
211
|
$render_array['type-designations'] = compose_cdm_unit_dto_type_designations($sob_dto, $compact_mode);
|
212
|
if($sob_dto->type == 'DnaSample'){
|
213
|
// FIXME:
|
214
|
$render_array['dna-sample'] = compose_cdm_derived_unit_dto_sequences($sob_dto, $compact_mode);
|
215
|
} else if($sob_dto->type == 'MediaSpecimen' && isset_not_empty($sob_dto->mediaSpecimen)) {
|
216
|
$render_array['media-specimens'] = cdm_sob_dto_media_table($sob_dto->mediaSpecimen, $sob_dto, 'Media Specimens');
|
217
|
}
|
218
|
}
|
219
|
if(isset_not_empty($sob_dto->determinedNames)){
|
220
|
$render_array['determinations'] = compose_cdm_sob_dto_determinations($sob_dto, $compact_mode);
|
221
|
}
|
222
|
if(isset_not_empty($sob_dto->listOfMedia)){
|
223
|
$render_array['media'] = cdm_sob_dto_media_table($sob_dto->listOfMedia, $sob_dto, 'Media');;
|
224
|
}
|
225
|
|
226
|
return $render_array;
|
227
|
}
|
228
|
/**
|
229
|
* Data rows with details for a SpecimenOrObservationDTO to be used in a table
|
230
|
* @param object $sob_dto
|
231
|
* the CDM SpecimenOrObservationDTO
|
232
|
* @param bool $compact_mode
|
233
|
* Currently unused,
|
234
|
*
|
235
|
* @return array
|
236
|
* The data rows
|
237
|
*/
|
238
|
function sob_dto_details_rows($sob_dto, $compact_mode = FALSE) {
|
239
|
|
240
|
$table_row_data = [];
|
241
|
|
242
|
if (isset_not_empty($sob_dto->recordBase)) {
|
243
|
$label = cdm_term_representation($sob_dto->recordBase);
|
244
|
if($label == 'Dna Sample'){
|
245
|
$label == 'DNA Sample';
|
246
|
}
|
247
|
$table_row_data[0] = cdm_sob_dto_table_row(
|
248
|
cdm_occurrence_field_name_label('recordBase'),
|
249
|
$label);
|
250
|
}
|
251
|
if (isset_not_empty($sob_dto->kindOfUnit)) {
|
252
|
$table_row_data[] = cdm_sob_dto_table_row(
|
253
|
cdm_occurrence_field_name_label('kindOfUnit'),
|
254
|
cdm_term_representation($sob_dto->kindOfUnit));
|
255
|
}
|
256
|
if (isset_not_empty($sob_dto->preferredStableUri)) {
|
257
|
$table_row_data[] = cdm_sob_dto_table_row(
|
258
|
cdm_occurrence_field_name_label('preferredStableUri'),
|
259
|
cdm_external_uri($sob_dto->preferredStableUri, false));
|
260
|
}
|
261
|
if (isset_not_empty($sob_dto->sex)) {
|
262
|
$table_row_data[] = cdm_sob_dto_table_row(
|
263
|
cdm_occurrence_field_name_label('sex'),
|
264
|
cdm_term_representation($sob_dto->sex));
|
265
|
}
|
266
|
if (isset_not_empty($sob_dto->lifeStage)) {
|
267
|
$table_row_data[] = cdm_sob_dto_table_row(
|
268
|
cdm_occurrence_field_name_label('lifeStage'),
|
269
|
cdm_term_representation($sob_dto->lifeStage));
|
270
|
}
|
271
|
|
272
|
return $table_row_data;
|
273
|
}
|
274
|
|
275
|
/**
|
276
|
* Compose a table of details for a DerivationEventDTO.
|
277
|
*
|
278
|
* compose_hook() implementation
|
279
|
*
|
280
|
* @param object $derivation_event_dto
|
281
|
* the CDM DerivationEventDTO
|
282
|
* @param bool $compact_mode
|
283
|
* Currently unused,
|
284
|
*
|
285
|
* @return array
|
286
|
* The render array for the DerivationEventDTO
|
287
|
*
|
288
|
* @ingroup compose
|
289
|
*/
|
290
|
function compose_cdm_derivation_event($derivation_event_dto, $compact_mode = FALSE){
|
291
|
|
292
|
$details_array = [];
|
293
|
// $markup = t("Derivation") . ': ';
|
294
|
$markup = ucfirst(cdm_term_representation($derivation_event_dto->eventType));
|
295
|
if(isset_not_empty($derivation_event_dto->actor)){
|
296
|
$details_array[] = $derivation_event_dto->actor;
|
297
|
}
|
298
|
if(isset_not_empty($derivation_event_dto->institute)){
|
299
|
$details_array[] = $derivation_event_dto->institute;
|
300
|
}
|
301
|
if(isset_not_empty($derivation_event_dto->timePeriod)){
|
302
|
$details_array[] = timePeriodToString($derivation_event_dto->timePeriod);
|
303
|
}
|
304
|
$details_markup = join(', ', $details_array);
|
305
|
if($details_markup){
|
306
|
$markup .= ': ' . $details_markup;
|
307
|
}
|
308
|
$render_array = [
|
309
|
'#type' => 'container',
|
310
|
'#attributes' => [
|
311
|
'class' => [
|
312
|
'derivation-event',
|
313
|
html_class_attribute_ref($derivation_event_dto)
|
314
|
],
|
315
|
'style' => [
|
316
|
'grid-column-start: span 2'
|
317
|
]
|
318
|
],
|
319
|
'content' => markup_to_render_array($markup)
|
320
|
];
|
321
|
return $render_array;
|
322
|
}
|
323
|
|
324
|
/**
|
325
|
* Compose a table of details for a FieldUnitDTO.
|
326
|
*
|
327
|
* The resulting DOM block level element will have a header line and details.
|
328
|
*
|
329
|
* compose_hook() implementation
|
330
|
*
|
331
|
* @param object $fu_dto
|
332
|
* the CDM FieldUnitDTO
|
333
|
* @param bool $compact_mode
|
334
|
* Currently unused,
|
335
|
*
|
336
|
* @return array
|
337
|
* The render array for the SpecimenOrObservationDTO
|
338
|
*
|
339
|
* @ingroup compose
|
340
|
*/
|
341
|
function compose_cdm_field_unit_dto_details($fu_dto, $compact_mode = FALSE) {
|
342
|
|
343
|
$table_row_data = sob_dto_details_rows($fu_dto, $compact_mode);
|
344
|
|
345
|
if (isset_not_empty($fu_dto->individualCount)) {
|
346
|
$table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('individualCount'), $fu_dto->individualCount);
|
347
|
}
|
348
|
if (isset_not_empty($fu_dto->definition)) {
|
349
|
$table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('definition'), $fu_dto->definition);
|
350
|
}
|
351
|
if (isset_not_empty($fu_dto->fieldNumber)) {
|
352
|
$table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('fieldNumber'), $fu_dto->fieldNumber);
|
353
|
}
|
354
|
if (isset_not_empty($fu_dto->primaryCollector)) {
|
355
|
$table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('primaryCollector'), $fu_dto->primaryCollector);
|
356
|
}
|
357
|
if (isset_not_empty($fu_dto->fieldNotes)) {
|
358
|
$table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('fieldNotes'), $fu_dto->fieldNotes);
|
359
|
}
|
360
|
|
361
|
$heading = $table_row_data[0]['data'][1];
|
362
|
unset($table_row_data[0]);
|
363
|
return cdm_sob_dto_table(t($heading), $table_row_data, $fu_dto, 2);
|
364
|
}
|
365
|
|
366
|
/**
|
367
|
* Compose details table for a DerivedUnitDTO.
|
368
|
*
|
369
|
* The resulting DOM block level element will have a header line and details.
|
370
|
*
|
371
|
* compose_hook() implementation
|
372
|
*
|
373
|
* @param object $du_dto
|
374
|
* the CDM DerivedUnitDTO
|
375
|
* @param bool $compact_mode
|
376
|
* Currently unused,
|
377
|
*
|
378
|
* @return array
|
379
|
* The render array for the DerivedUnitDTO
|
380
|
*
|
381
|
* @ingroup compose
|
382
|
*/
|
383
|
function compose_cdm_derived_unit_dto_storage_details($du_dto, $compact_mode = FALSE) {
|
384
|
|
385
|
$table_row_data = sob_dto_details_rows($du_dto, $compact_mode);
|
386
|
|
387
|
if (isset($du_dto->accessionNumber)) {
|
388
|
$table_row_data[] = cdm_sob_dto_table_row(
|
389
|
cdm_occurrence_field_name_label('accessionNumber'),
|
390
|
$du_dto->accessionNumber);
|
391
|
}
|
392
|
if (isset($du_dto->collection)) {
|
393
|
$table_row_data[] = cdm_sob_dto_table_row(
|
394
|
cdm_occurrence_field_name_label('collection'),
|
395
|
render_collection_dto($du_dto->collection));
|
396
|
}
|
397
|
if (isset($du_dto->storedUnder)) {
|
398
|
$taxon_name = cdm_ws_get(CDM_WS_PORTAL_NAME, array($du_dto->storedUnder->uuid));
|
399
|
$table_row_data[] = cdm_sob_dto_table_row(
|
400
|
cdm_occurrence_field_name_label('storedUnder'),
|
401
|
render_taxon_or_name($taxon_name, path_to_name($taxon_name->uuid)));
|
402
|
}
|
403
|
if (isset($du_dto->exsiccatum)) {
|
404
|
$table_row_data[] = cdm_sob_dto_table_row(
|
405
|
cdm_occurrence_field_name_label('exsiccatum'),
|
406
|
$du_dto->exsiccatum);
|
407
|
}
|
408
|
if (isset($du_dto->catalogNumber)) {
|
409
|
$table_row_data[] = cdm_sob_dto_table_row(
|
410
|
cdm_occurrence_field_name_label('catalogNumber'),
|
411
|
$du_dto->catalogNumber);
|
412
|
}
|
413
|
if (isset($du_dto->barcode)) {
|
414
|
$table_row_data[] = cdm_sob_dto_table_row(
|
415
|
cdm_occurrence_field_name_label('barcode'),
|
416
|
$du_dto->barcode);
|
417
|
}
|
418
|
if (isset($du_dto->preservationMethod)) {
|
419
|
$table_row_data[] = cdm_sob_dto_table_row(
|
420
|
cdm_occurrence_field_name_label('preservationMethod'),
|
421
|
$du_dto->preservationMethod);
|
422
|
}
|
423
|
|
424
|
/* TODO
|
425
|
|
426
|
@_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('medium'), $value->medium, NULL, 1);
|
427
|
@_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('temperature'), $value->temperature, NULL, 2);
|
428
|
@_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('definedMaterialOrMethod'), $value->definedMaterialOrMethod, NULL, 3);
|
429
|
|
430
|
*/
|
431
|
if (isset_not_empty($du_dto->characterData)) {
|
432
|
$table_row_data[] = cdm_sob_dto_table_row(
|
433
|
cdm_occurrence_field_name_label('characterData'),
|
434
|
icon_link(path_to_specimen($du_dto->uuid), '', FALSE), false);
|
435
|
}
|
436
|
|
437
|
$heading = $table_row_data[0]['data'][1];
|
438
|
unset($table_row_data[0]);
|
439
|
return cdm_sob_dto_table(t($heading), $table_row_data, $du_dto, 1);
|
440
|
}
|
441
|
|
442
|
/**
|
443
|
* Compose an render array from a CDM GatheringDTO.
|
444
|
*
|
445
|
* The resulting DOM block level element will have a header line and details.
|
446
|
*
|
447
|
* compose_hook() implementation
|
448
|
*
|
449
|
* @param object $gathering_dto
|
450
|
* the CDM GatheringDTO object
|
451
|
* @param bool $compact_mode
|
452
|
* Currently unused,
|
453
|
*
|
454
|
* @return array
|
455
|
* The render array for the GatheringDTO
|
456
|
*
|
457
|
* @ingroup compose
|
458
|
*/
|
459
|
function compose_cdm_gathering_dto_details($gathering_dto, $compact_mode = FALSE) {
|
460
|
|
461
|
$table_row_data = [];
|
462
|
if (isset_not_empty($gathering_dto->date)) {
|
463
|
$table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('date'),
|
464
|
partialToDate($gathering_dto->date));
|
465
|
}
|
466
|
if (isset_not_empty($gathering_dto->collector)) {
|
467
|
$table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('collector'),
|
468
|
$gathering_dto->collector);
|
469
|
}
|
470
|
if (isset_not_empty($gathering_dto->description)) {
|
471
|
$table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('description'),
|
472
|
$gathering_dto->description);
|
473
|
}
|
474
|
if (isset_not_empty($gathering_dto->locality)) {
|
475
|
$table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('locality'),
|
476
|
$gathering_dto->locality);
|
477
|
}
|
478
|
if (isset_not_empty($gathering_dto->country)) {
|
479
|
$table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('country'),
|
480
|
$gathering_dto->country);
|
481
|
}
|
482
|
if (isset_not_empty($gathering_dto->collectingMethod)) {
|
483
|
$table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('collectingMethod'),
|
484
|
$gathering_dto->collectingMethod);
|
485
|
}
|
486
|
if (isset($gathering_dto->exactLocation)) {
|
487
|
$table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('exactLocation'),
|
488
|
render_point($gathering_dto->exactLocation));
|
489
|
}
|
490
|
if (isset($gathering_dto->absoluteElevation)) {
|
491
|
$table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('absoluteElevation'),
|
492
|
statistical_values_from_gathering_event($gathering_dto, 'absoluteElevation'));
|
493
|
}
|
494
|
if (isset($gathering_dto->distanceToGround) && $gathering_dto->distanceToGround > 0) {
|
495
|
$table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('distanceToGround'),
|
496
|
statistical_values_from_gathering_event($gathering_dto, 'distanceToGround'));
|
497
|
}
|
498
|
if (isset($gathering_dto->distanceToWaterSurface) && $gathering_dto->distanceToWaterSurface > 0) {
|
499
|
$table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('distanceToWaterSurface'),
|
500
|
statistical_values_from_gathering_event($gathering_dto, 'distanceToWaterSurface'));
|
501
|
}
|
502
|
if (isset_not_empty($gathering_dto->collectingAreas)) {
|
503
|
$area_representations = [];
|
504
|
foreach ($gathering_dto->collectingAreas as $area) {
|
505
|
// $area_representations[] = l($area->representation_L10n, path_to_named_area($area->uuid));
|
506
|
$area_representations[] = $area;
|
507
|
}
|
508
|
if (!empty($area_representations)) {
|
509
|
$table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('collectingAreas'),
|
510
|
implode(', ', $area_representations)
|
511
|
);
|
512
|
}
|
513
|
}
|
514
|
|
515
|
return cdm_sob_dto_table(t("Gathering & Location"), $table_row_data, $gathering_dto, 1);
|
516
|
}
|
517
|
|
518
|
/**
|
519
|
* Compose an render array from the SpecimenOrObservationDTO.determinedNames.
|
520
|
*
|
521
|
* The resulting DOM block level element will have a header line and details.
|
522
|
*
|
523
|
* compose_hook() implementation
|
524
|
*
|
525
|
* @param object $sob_dto
|
526
|
* the CDM SpecimenOrObservationDTO
|
527
|
* @param bool $compact_mode
|
528
|
* Currently unused,
|
529
|
*
|
530
|
* @return array
|
531
|
* The render array for the SpecimenOrObservationDTO.determinedNames
|
532
|
*
|
533
|
* @ingroup compose
|
534
|
*/
|
535
|
function compose_cdm_sob_dto_determinations($sob_dto, $compact_mode = FALSE) {
|
536
|
|
537
|
$table_row_data = [];
|
538
|
|
539
|
foreach ($sob_dto->determinedNames as $name) {
|
540
|
$taxon_name = cdm_ws_get(CDM_WS_PORTAL_NAME, $name->uuid);
|
541
|
$table_row_data[] = cdm_sob_dto_table_row(NULL, render_taxon_or_name($taxon_name, url(path_to_name($taxon_name->uuid))));
|
542
|
}
|
543
|
|
544
|
$label = count($table_row_data) > 1 ? t("Identifications") : t("Identification");
|
545
|
return cdm_sob_dto_table($label, $table_row_data, $sob_dto, 1);
|
546
|
}
|
547
|
|
548
|
/**
|
549
|
* Compose an render array from the DerivedUnitDTO.specimenTypeDesignations.
|
550
|
*
|
551
|
* The resulting DOM block level element will have a header line and details.
|
552
|
*
|
553
|
* compose_hook() implementation
|
554
|
*
|
555
|
* @param object $unit_dto
|
556
|
* the CDM DerivedUnitDTO
|
557
|
* @param bool $compact_mode
|
558
|
* Currently unused,
|
559
|
*
|
560
|
* @return array
|
561
|
* The render array for the SpecimenOrObservationDTO.determinedNames
|
562
|
*
|
563
|
* @ingroup compose
|
564
|
*/
|
565
|
function compose_cdm_unit_dto_type_designations($unit_dto, $compact_mode = FALSE) {
|
566
|
|
567
|
$table_row_data = [];
|
568
|
|
569
|
if (isset_not_empty($unit_dto->specimenTypeDesignations)) {
|
570
|
$table_row_data[] = cdm_sob_dto_table_row(
|
571
|
NULL,
|
572
|
render_specimen_typedesignation_dto($unit_dto->specimenTypeDesignations));
|
573
|
}
|
574
|
|
575
|
return cdm_sob_dto_table(t('Type designations'), $table_row_data, $unit_dto, 5, 2);
|
576
|
}
|
577
|
|
578
|
/**
|
579
|
* @param $listOfMedia
|
580
|
* @param $sob_dto
|
581
|
* @param $heading
|
582
|
*
|
583
|
* @return array|null
|
584
|
*/
|
585
|
function cdm_sob_dto_media_table(array $listOfMedia, $sob_dto, $heading) {
|
586
|
$table_row_data = [];
|
587
|
$gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
|
588
|
$captionElements = array(
|
589
|
'title',
|
590
|
'#uri' => t('open media'),
|
591
|
);
|
592
|
$gallery_markup = compose_cdm_media_gallerie(array(
|
593
|
'mediaList' => $listOfMedia,
|
594
|
'galleryName' => $sob_dto->uuid,
|
595
|
'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
|
596
|
'cols' => $gallery_settings['cdm_dataportal_media_cols'],
|
597
|
'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
|
598
|
'captionElements' => $captionElements,
|
599
|
'mediaLinkType' => 'LIGHTBOX',
|
600
|
'alternativeMediaUri' => NULL,
|
601
|
'galleryLinkUri' => NULL,
|
602
|
'showCaption' => true
|
603
|
));
|
604
|
$table_row_data[] = cdm_sob_dto_table_row(NULL, $gallery_markup);
|
605
|
$grid_col_span = count($listOfMedia) > 1 ? 2 : NULL;
|
606
|
return cdm_sob_dto_table(t($heading), $table_row_data, $sob_dto, 20, $grid_col_span);
|
607
|
}
|
608
|
|
609
|
/**
|
610
|
* Compose an render array from the DerivedUnitDTO.sequences.
|
611
|
*
|
612
|
* The resulting DOM block level element will have a header line and details.
|
613
|
*
|
614
|
* compose_hook() implementation
|
615
|
*
|
616
|
* @param object $unit_dto
|
617
|
* the CDM DerivedUnitDTO
|
618
|
* @param bool $compact_mode
|
619
|
* Currently unused,
|
620
|
*
|
621
|
* @return array
|
622
|
* The render array for the DerivedUnitDTO.sequences.
|
623
|
*
|
624
|
* @ingroup compose
|
625
|
*
|
626
|
* TODO see #3347 (services and REST service controller for molecular classes implemented)
|
627
|
*/
|
628
|
function compose_cdm_derived_unit_dto_sequences($unit_dto, $compact_mode = FALSE) {
|
629
|
|
630
|
$table_row_data = [];
|
631
|
if(isset_not_empty($unit_dto->sequences)){
|
632
|
foreach ($unit_dto->sequences as $sequence) {
|
633
|
if (isset($sequence->geneticAccessionNumber)) {
|
634
|
$table_row_data[] = cdm_sob_dto_table_row(
|
635
|
cdm_occurrence_field_name_label('geneticAccessionNumber'),
|
636
|
$sequence->geneticAccessionNumber);
|
637
|
}
|
638
|
// TODO ....
|
639
|
}
|
640
|
}
|
641
|
|
642
|
/* TODO
|
643
|
case 'dnaQuality':
|
644
|
$sub_dl_groups = array();
|
645
|
|
646
|
@_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('purificationMethod'), $value->purificationMethod, NULL, 1);
|
647
|
@_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('ratioOfAbsorbance260_230'), $value->ratioOfAbsorbance260_230, NULL, 2);
|
648
|
@_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('ratioOfAbsorbance260_280'), $value->ratioOfAbsorbance260_280, NULL, 3);
|
649
|
@_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('concentration'), $value->concentration, NULL, 4);
|
650
|
@_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('concentrationUnit'), $value->concentrationUnit, NULL, 4);
|
651
|
@_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('qualityTerm'), $value->qualityTerm, NULL, 4);
|
652
|
@_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('qualityCheckDate'), $value->qualityCheckDate, NULL, 4);
|
653
|
|
654
|
if (is_array($sub_dl_groups) && sizeof($sub_dl_groups)>0) {
|
655
|
@_description_list_group_add($groups, cdm_occurrence_field_name_label($field),
|
656
|
array(
|
657
|
array('#markup' => $value->titleCache),
|
658
|
array('#theme' => 'description_list', '#groups' => $sub_dl_groups)
|
659
|
)
|
660
|
);
|
661
|
}
|
662
|
break;
|
663
|
*/
|
664
|
|
665
|
return cdm_sob_dto_table(t('Storage'), $table_row_data, $unit_dto, 1);
|
666
|
}
|
667
|
|
668
|
/**
|
669
|
* Creates a form array for showing details of SpecimenOrObservationDTO in a
|
670
|
* tabular form with heading.
|
671
|
*
|
672
|
* @param $table_heading
|
673
|
* @param array $table_row_data
|
674
|
* @param $sob_dto
|
675
|
* @param $weight
|
676
|
* The weight determining the order of the drupal render element
|
677
|
* @param $grid_col_span
|
678
|
* The number of grid colums the table should
|
679
|
*
|
680
|
* @return array|null
|
681
|
*/
|
682
|
function cdm_sob_dto_table($table_heading, array $table_row_data, $sob_dto, $weight = NULL, $grid_col_span = 1) {
|
683
|
|
684
|
if (count($table_row_data) > 0) {
|
685
|
$wrapper_style = '';
|
686
|
if($grid_col_span > 1){
|
687
|
$wrapper_style = ' style="grid-column-start: span ' . $grid_col_span. ';"';
|
688
|
}
|
689
|
$sob_table = [
|
690
|
'#theme' => 'table',
|
691
|
'#prefix' => '<div class="table-wrapper"' . $wrapper_style . '>',
|
692
|
'#suffix' => '</div>',
|
693
|
'#header' => [
|
694
|
[
|
695
|
'data' => $table_heading,
|
696
|
'colspan' => 2,
|
697
|
],
|
698
|
],
|
699
|
"#rows" => $table_row_data,
|
700
|
"#attributes" => [
|
701
|
"class" => [
|
702
|
'details-table',
|
703
|
'details-table-' . normalize_to_class_attribute($table_heading),
|
704
|
html_class_attribute_ref($sob_dto)
|
705
|
],
|
706
|
],
|
707
|
];
|
708
|
if ($weight) {
|
709
|
$sob_table['#weight'] = $weight;
|
710
|
}
|
711
|
return $sob_table;
|
712
|
}
|
713
|
return NULL;
|
714
|
}
|
715
|
|
716
|
function cdm_sob_dto_table_row($label, $value) {
|
717
|
if ($value) {
|
718
|
if($label) {
|
719
|
return [
|
720
|
'data' => [
|
721
|
[
|
722
|
'data' => str_replace(':', '', $label),
|
723
|
'class' => [
|
724
|
'label',
|
725
|
],
|
726
|
],
|
727
|
$value,
|
728
|
],
|
729
|
'no_striping' => TRUE,
|
730
|
];
|
731
|
} else {
|
732
|
// value spanning two columns
|
733
|
return [
|
734
|
'data' => [
|
735
|
[
|
736
|
'data' => $value,
|
737
|
'colspan' => 2,
|
738
|
]
|
739
|
],
|
740
|
'no_striping' => TRUE,
|
741
|
];
|
742
|
}
|
743
|
}
|
744
|
return NULL;
|
745
|
}
|
746
|
|
747
|
|
748
|
|
749
|
/**
|
750
|
* Compose an render array from a CDD SpecimenOrObservation entity.
|
751
|
*
|
752
|
* compose_hook() implementation
|
753
|
*
|
754
|
* @param object $sob_dto
|
755
|
* the CDM FieldUnit or DerivedUnit to compose
|
756
|
* the render array for.
|
757
|
* @param bool $isSpecimen_page
|
758
|
* @param array $derivatives
|
759
|
* the render array which contains the compositions of the derivatives
|
760
|
* of the supplied $specimenOrObservation
|
761
|
*
|
762
|
* @return array
|
763
|
* the supplied render array $derivatives to which the composition of the supplied
|
764
|
* $specimenOrObservation has been added to
|
765
|
*
|
766
|
* @throws \Exception
|
767
|
* @ingroup compose
|
768
|
*/
|
769
|
|
770
|
function compose_cdm_specimen_or_observation_new($sob_dto)
|
771
|
{
|
772
|
|
773
|
$render_array = [];
|
774
|
if (is_object($sob_dto)) {
|
775
|
|
776
|
/*** 95% no longer needed
|
777
|
if ($sob_dto->class == 'FieldUnit'){
|
778
|
// WARNING: adding a List<MediaDTO> as $specimen_or_observation->_derivedUnitMedia
|
779
|
$sob_dto->_derivedUnitMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array(
|
780
|
$sob_dto->uuid,
|
781
|
'fieldObjectMediaDTO',
|
782
|
));
|
783
|
}else{
|
784
|
// WARNING: adding a List<Media> as $specimen_or_observation->_derivedUnitMedia
|
785
|
$sob_dto->_derivedUnitMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array(
|
786
|
$sob_dto->uuid,
|
787
|
'derivedUnitMedia',
|
788
|
));
|
789
|
}
|
790
|
******/
|
791
|
|
792
|
RenderHints::setFootnoteListKey($sob_dto->type . '-' . $sob_dto->uuid);
|
793
|
|
794
|
$render_array['sob_details_grid'] = compose_cdm_specimen_or_observation_dto_details_grid($sob_dto);
|
795
|
|
796
|
/* TODO
|
797
|
case 'definition':
|
798
|
|
799
|
case 'annotations':
|
800
|
$dd_elements = array();
|
801
|
foreach ($value as $annotation) {
|
802
|
// TODO respect annotation type filter settings
|
803
|
$dd_elements[] = $annotation->text;
|
804
|
}
|
805
|
break;
|
806
|
|
807
|
case 'markers':
|
808
|
$dd_elements = array();
|
809
|
foreach ($value as $marker) {
|
810
|
$dd_elements[] = compose_cdm_marker($marker);
|
811
|
}
|
812
|
@_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
|
813
|
break;
|
814
|
|
815
|
@_description_list_group_add($groups, t('Notes:'), $dd_elements);
|
816
|
*
|
817
|
*/
|
818
|
|
819
|
|
820
|
|
821
|
/** TODO
|
822
|
|
823
|
|
824
|
case 'determinations':
|
825
|
$dd_elements = array();
|
826
|
$glue = ', ';
|
827
|
|
828
|
foreach ($value as $determinationEvent) {
|
829
|
$timeperiod_string = NULL;
|
830
|
if (isset($determinationEvent->timeperiod)) {
|
831
|
$timeperiod_string = timePeriodToString($determinationEvent->timeperiod);
|
832
|
}
|
833
|
$weight = isset($determinationEvent->preferred) && $determinationEvent->preferred == 1 ? '0' : ($timeperiod_string ? $timeperiod_string : '1');
|
834
|
// check key exists
|
835
|
while (array_key_exists($weight, $dd_elements)) {
|
836
|
$weight .= '0';
|
837
|
}
|
838
|
|
839
|
$taxon_name = '';
|
840
|
$name_link = '';
|
841
|
if ($determinationEvent->taxonName) {
|
842
|
$taxon_name = cdm_ws_get(CDM_WS_NAME, $determinationEvent->taxonName->uuid);
|
843
|
$taxon_name->taggedName = cdm_ws_get(CDM_WS_NAME, array($determinationEvent->taxonName->uuid, "taggedName"));
|
844
|
$name_link = path_to_name($determinationEvent->taxonName->uuid);
|
845
|
} else if ($determinationEvent->taxon) {
|
846
|
$taxon_name = cdm_ws_get(CDM_WS_TAXON . '/$0/name', $determinationEvent->taxon->uuid);
|
847
|
$name_link = path_to_taxon($determinationEvent->taxon->uuid);
|
848
|
}
|
849
|
if ($taxon_name) {
|
850
|
//$taxon_html = render_taxon_or_name($taxon_name, $name_link);
|
851
|
|
852
|
$taxon_html = l($taxon_name->titleCache, $name_link);
|
853
|
$dd_elements[$weight] = $taxon_html;
|
854
|
}
|
855
|
if (isset($determinationEvent->modifier)) {
|
856
|
$dd_elements[$weight] .= cdm_term_representation($determinationEvent->modifier);
|
857
|
}
|
858
|
if ($timeperiod_string) {
|
859
|
$dd_elements[$weight] .= $glue . $timeperiod_string;
|
860
|
}
|
861
|
if (isset($determinationEvent->actor->titleCache)) {
|
862
|
$dd_elements[$weight] .= $glue . $determinationEvent->actor->titleCache;
|
863
|
}
|
864
|
if (isset($determinationEvent->description)) {
|
865
|
$dd_elements[$weight] .= $glue . $determinationEvent->description;
|
866
|
}
|
867
|
}
|
868
|
ksort($dd_elements);
|
869
|
@_description_list_group_add($groups, cdm_occurrence_field_name_label('determinations'), $dd_elements);
|
870
|
break;
|
871
|
*/
|
872
|
|
873
|
/* TODO
|
874
|
|
875
|
case 'sources':
|
876
|
RenderHints::setAnnotationsAndSourceConfig([
|
877
|
'sources_as_content' => TRUE,
|
878
|
'link_to_name_used_in_source' => TRUE,
|
879
|
'link_to_reference' => FALSE,
|
880
|
'add_footnote_keys' => FALSE,
|
881
|
'bibliography_aware' => FALSE
|
882
|
]);
|
883
|
$annotations_and_sources = handle_annotations_and_sources($sob_dto);
|
884
|
if ($annotations_and_sources->hasSourceReferences()) {
|
885
|
@_description_list_group_add($groups, t('Sources') . ':', join(', ', $annotations_and_sources->getSourceReferences()), '', 12);
|
886
|
}
|
887
|
break;
|
888
|
*/
|
889
|
|
890
|
|
891
|
|
892
|
/* TODO Extensions
|
893
|
// TODO: filter by using visible_extensions_sorted()
|
894
|
// TODO: treat as top level element, see https://dev.e-taxonomy.eu/redmine/issues/2985#note-23
|
895
|
$extensions = cdm_ws_fetch_all(CDM_WS_PORTAL_OCCURRENCE . '/' . $sob_dto->uuid . '/extensions', array($sob_dto->uuid));
|
896
|
if ($extensions && count($extensions)) {
|
897
|
|
898
|
$extensions_render_array = compose_extensions($extensions);
|
899
|
@_description_list_group_add($groups, t('Extensions') . ':',
|
900
|
$extensions_render_array,
|
901
|
'', 100);
|
902
|
}
|
903
|
*/
|
904
|
|
905
|
|
906
|
|
907
|
|
908
|
|
909
|
|
910
|
} // END of $specimenOrObservation exists
|
911
|
|
912
|
return $render_array;
|
913
|
}
|
914
|
|