Project

General

Profile

Download (26.8 KB) Statistics
| Branch: | Tag: | Revision:
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
 * Compose grid of details tabled for a CDM SpecimenOrObservationDTO
23
 *
24
 * The resulting render array will contain separate DOM block level elements
25
 * with header line for the various kind of information like, location,
26
 * gathering, specimen/observation, DNA, etc.
27
 *
28
 *
29
 * Subordinate derivatives will not be included. For showing the derivation
30
 * hierarchy see methods like derived_units_sub_tree()
31
 *
32
 * compose_hook() implementation
33
 *
34
 * @param object $sob_dto
35
 *   the CDM FieldUnitDTO or DerivedUnitDTO to compose
36
 *   the render array for.
37
 * @param bool $full_details
38
 *  Activates the display of additional data like: annotations, markers, ...
39
 *
40
 * @return array
41
 *  The render array for the SpecimenOrObservationDTO
42
 *
43
 * @ingroup compose
44
 */
45
function compose_cdm_specimen_or_observation_dto_details_grid($sob_dto, $full_details = FALSE) {
46
  $render_array = [];
47
  if (!$sob_dto) {
48
    return $render_array;
49
  }
50
  if ($sob_dto->type == 'FieldUnit') {
51
    $render_array['field-unit'] = compose_cdm_field_unit_dto_details($sob_dto, $full_details);
52
    if (isset($sob_dto->gatheringEvent)) {
53
      $render_array['gathering'] = compose_cdm_gathering_dto_details($sob_dto->gatheringEvent, $full_details);
54
    }
55
  } else {
56
    if(isset($sob_dto->derivationEvent)){
57
      $render_array['derivation-event'] = compose_cdm_derivation_event($sob_dto->derivationEvent);
58
    }
59
    $render_array['storage'] = compose_cdm_derived_unit_dto_storage_details($sob_dto, $full_details);
60
    $render_array['type-designations'] = compose_cdm_unit_dto_type_designations($sob_dto, $full_details);
61
    if($sob_dto->type == 'DnaSample'){
62
      // FIXME:
63
      $render_array['dna-sample'] = compose_cdm_derived_unit_dto_sequences($sob_dto, $full_details);
64
    } else if($sob_dto->type == 'MediaSpecimen' && isset_not_empty($sob_dto->mediaSpecimen)) {
65
      $render_array['media-specimens'] = cdm_sob_dto_media_table($sob_dto->mediaSpecimen, $sob_dto, 'Media Specimens');
66
    }
67
  }
68
  if(isset_not_empty($sob_dto->determinedNames)){
69
    $render_array['determinations'] = compose_cdm_sob_dto_determinations($sob_dto, $full_details);
70
  }
71
  if(isset_not_empty($sob_dto->listOfMedia)){
72
    $render_array['media'] = cdm_sob_dto_media_table($sob_dto->listOfMedia, $sob_dto, 'Media');;
73
  }
74

    
75
  if($full_details){
76
    // Annotations and Sources
77
    RenderHints::setAnnotationsAndSourceConfig([
78
      'sources_as_content' => TRUE,
79
      'annotations_as_content' => TRUE,
80
      'link_to_name_used_in_source' => TRUE,
81
      'link_to_reference' => FALSE,
82
      'add_footnote_keys' => FALSE,
83
      'bibliography_aware' => FALSE
84
    ]);
85
    $annotations_and_sources = handle_annotations_and_sources($sob_dto);
86
    if ($annotations_and_sources->hasSourceReferences()) {
87
      $render_array['sources'] = compose_cdm_sob_dto_sources($sob_dto, $annotations_and_sources);
88
    }
89

    
90
    if(count($annotations_and_sources->getAnnotations()) > 0){
91
      $render_array['annotations'] = compose_cdm_sob_dto_annotations($sob_dto, $annotations_and_sources);
92
    }
93
      // Markers
94
    $markers = cdm_ws_get(CDM_WS_PORTAL_OCCURRENCE, [$sob_dto->uuid, 'markers']);
95
    if(isset_not_empty($markers->records)){
96
      $render_array['markers'] = compose_cdm_sob_dto_markers($sob_dto, $markers);
97
    }
98
  }
99

    
100
  return $render_array;
101
}
102
/**
103
 * Data rows with details for a SpecimenOrObservationDTO to be used in a table
104
 * @param object $sob_dto
105
 *   the CDM SpecimenOrObservationDTO
106
 * @param bool $full_details
107
 *   Currently unused,
108
 *
109
 * @return array
110
 *  The data rows
111
 */
112
function sob_dto_details_rows($sob_dto, $full_details = FALSE) {
113

    
114
  $table_row_data = [];
115

    
116
  if (isset_not_empty($sob_dto->recordBase)) {
117
    $label = cdm_term_representation($sob_dto->recordBase);
118
    if($label == 'Dna Sample'){
119
      $label == 'DNA Sample';
120
    }
121
    $table_row_data[0] = cdm_sob_dto_table_row(
122
      cdm_occurrence_field_name_label('recordBase'),
123
      $label);
124
  }
125
  if (isset_not_empty($sob_dto->kindOfUnit)) {
126
    $table_row_data[] = cdm_sob_dto_table_row(
127
      cdm_occurrence_field_name_label('kindOfUnit'),
128
      cdm_term_representation($sob_dto->kindOfUnit));
129
  }
130
  if (isset_not_empty($sob_dto->preferredStableUri)) {
131
    $table_row_data[] = cdm_sob_dto_table_row(
132
      cdm_occurrence_field_name_label('preferredStableUri'),
133
      cdm_external_uri($sob_dto->preferredStableUri, false));
134
  }
135
  if (isset_not_empty($sob_dto->sex)) {
136
    $table_row_data[] = cdm_sob_dto_table_row(
137
      cdm_occurrence_field_name_label('sex'),
138
      cdm_term_representation($sob_dto->sex));
139
  }
140
  if (isset_not_empty($sob_dto->lifeStage)) {
141
    $table_row_data[] = cdm_sob_dto_table_row(
142
      cdm_occurrence_field_name_label('lifeStage'),
143
      cdm_term_representation($sob_dto->lifeStage));
144
  }
145

    
146
  return $table_row_data;
147
}
148

    
149
/**
150
 * Compose a table of details for a DerivationEventDTO.
151
 *
152
 * compose_hook() implementation
153
 *
154
 * @param object $derivation_event_dto
155
 *   the CDM DerivationEventDTO
156
 * @param bool $full_details
157
 *   Currently unused,
158
 *
159
 * @return array
160
 *  The render array for the DerivationEventDTO
161
 *
162
 * @ingroup compose
163
 */
164
function compose_cdm_derivation_event($derivation_event_dto, $full_details = FALSE){
165

    
166
  $details_array = [];
167
  // $markup = t("Derivation") . ': ';
168
  $markup = ucfirst(cdm_term_representation($derivation_event_dto->eventType));
169
  if(isset_not_empty($derivation_event_dto->actor)){
170
    $details_array[] = $derivation_event_dto->actor;
171
  }
172
  if(isset_not_empty($derivation_event_dto->institute)){
173
    $details_array[] = $derivation_event_dto->institute;
174
  }
175
  if(isset_not_empty($derivation_event_dto->timePeriod)){
176
    $details_array[] = timePeriodToString($derivation_event_dto->timePeriod);
177
  }
178
  $details_markup = join(', ', $details_array);
179
  if($details_markup){
180
    $markup .= ': ' . $details_markup;
181
  }
182
  $render_array = [
183
    '#type' => 'container',
184
    '#attributes' => [
185
      'class' => [
186
        'derivation-event',
187
        html_class_attribute_ref($derivation_event_dto)
188
      ],
189
      'style' => [
190
        'grid-column-start: span 2'
191
      ]
192
    ],
193
    'content' => markup_to_render_array($markup)
194
  ];
195
  return $render_array;
196
}
197

    
198
/**
199
 * Compose a table of details for a FieldUnitDTO.
200
 *
201
 * The resulting DOM block level element will have a header line and details.
202
 *
203
 * compose_hook() implementation
204
 *
205
 * @param object $fu_dto
206
 *   the CDM FieldUnitDTO
207
 * @param bool $full_details
208
 *   Currently unused,
209
 *
210
 * @return array
211
 *  The render array for the SpecimenOrObservationDTO
212
 *
213
 * @ingroup compose
214
 */
215
function compose_cdm_field_unit_dto_details($fu_dto, $full_details = FALSE) {
216

    
217
  $table_row_data = sob_dto_details_rows($fu_dto, $full_details);
218

    
219
  if (isset_not_empty($fu_dto->individualCount)) {
220
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('individualCount'), $fu_dto->individualCount);
221
  }
222
  if (isset_not_empty($fu_dto->definition)) {
223
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('definition'), $fu_dto->definition);
224
  }
225
  if (isset_not_empty($fu_dto->fieldNumber)) {
226
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('fieldNumber'), $fu_dto->fieldNumber);
227
  }
228
  if (isset_not_empty($fu_dto->primaryCollector)) {
229
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('primaryCollector'), $fu_dto->primaryCollector);
230
  }
231
  if (isset_not_empty($fu_dto->fieldNotes)) {
232
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('fieldNotes'), $fu_dto->fieldNotes);
233
  }
234

    
235
  $heading = $table_row_data[0]['data'][1];
236
  unset($table_row_data[0]);
237
  return cdm_sob_dto_table(t($heading), $table_row_data, $fu_dto, 2);
238
}
239

    
240
/**
241
 * Compose details table for a DerivedUnitDTO.
242
 *
243
 * The resulting DOM block level element will have a header line and details.
244
 *
245
 * compose_hook() implementation
246
 *
247
 * @param object $du_dto
248
 *   the CDM DerivedUnitDTO
249
 * @param bool $full_details
250
 *   Currently unused,
251
 *
252
 * @return array
253
 *  The render array for the DerivedUnitDTO
254
 *
255
 * @ingroup compose
256
 */
257
function  compose_cdm_derived_unit_dto_storage_details($du_dto, $full_details = FALSE) {
258

    
259
  $table_row_data = sob_dto_details_rows($du_dto, $full_details);
260

    
261
  if (isset($du_dto->accessionNumber)) {
262
    $table_row_data[] = cdm_sob_dto_table_row(
263
      cdm_occurrence_field_name_label('accessionNumber'),
264
      $du_dto->accessionNumber);
265
  }
266
  if (isset($du_dto->collection)) {
267
    $table_row_data[] = cdm_sob_dto_table_row(
268
      cdm_occurrence_field_name_label('collection'),
269
      render_collection_dto($du_dto->collection));
270
  }
271
  if (isset($du_dto->storedUnder)) {
272
    $taxon_name = cdm_ws_get(CDM_WS_PORTAL_NAME, array($du_dto->storedUnder->uuid));
273
    $table_row_data[] = cdm_sob_dto_table_row(
274
      cdm_occurrence_field_name_label('storedUnder'),
275
      render_taxon_or_name($taxon_name, path_to_name($taxon_name->uuid)));
276
  }
277
  if (isset($du_dto->exsiccatum)) {
278
    $table_row_data[] = cdm_sob_dto_table_row(
279
      cdm_occurrence_field_name_label('exsiccatum'),
280
      $du_dto->exsiccatum);
281
  }
282
  if (isset($du_dto->catalogNumber)) {
283
    $table_row_data[] = cdm_sob_dto_table_row(
284
      cdm_occurrence_field_name_label('catalogNumber'),
285
      $du_dto->catalogNumber);
286
  }
287
  if (isset($du_dto->barcode)) {
288
    $table_row_data[] = cdm_sob_dto_table_row(
289
      cdm_occurrence_field_name_label('barcode'),
290
      $du_dto->barcode);
291
  }
292
  if (isset($du_dto->preservationMethod)) {
293
    $table_row_data[] = cdm_sob_dto_table_row(
294
      cdm_occurrence_field_name_label('preservationMethod'),
295
      $du_dto->preservationMethod);
296
  }
297

    
298
  /* TODO
299

    
300
            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('medium'), $value->medium, NULL, 1);
301
            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('temperature'), $value->temperature, NULL, 2);
302
            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('definedMaterialOrMethod'), $value->definedMaterialOrMethod, NULL, 3);
303

    
304
  */
305
  if (isset_not_empty($du_dto->characterData)) {
306
    $table_row_data[] = cdm_sob_dto_table_row(
307
      cdm_occurrence_field_name_label('characterData'),
308
      icon_link(path_to_specimen($du_dto->uuid), '', FALSE), false);
309
  }
310

    
311
  $heading = $table_row_data[0]['data'][1];
312
  unset($table_row_data[0]);
313
  return cdm_sob_dto_table(t($heading), $table_row_data, $du_dto, 1);
314
}
315

    
316
/**
317
 * Compose an render array from a CDM GatheringDTO.
318
 *
319
 * The resulting DOM block level element will have a header line and details.
320
 *
321
 * compose_hook() implementation
322
 *
323
 * @param object $gathering_dto
324
 *   the CDM GatheringDTO object
325
 * @param bool $full_details
326
 *   Currently unused,
327
 *
328
 * @return array
329
 *  The render array for the GatheringDTO
330
 *
331
 * @ingroup compose
332
 */
333
function compose_cdm_gathering_dto_details($gathering_dto, $full_details = FALSE) {
334

    
335
  $table_row_data = [];
336
  if (isset_not_empty($gathering_dto->date)) {
337
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('date'),
338
      partialToDate($gathering_dto->date));
339
  }
340
  if (isset_not_empty($gathering_dto->collector)) {
341
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('collector'),
342
      $gathering_dto->collector);
343
  }
344
  if (isset_not_empty($gathering_dto->description)) {
345
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('description'),
346
      $gathering_dto->description);
347
  }
348
  if (isset_not_empty($gathering_dto->locality)) {
349
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('locality'),
350
      $gathering_dto->locality);
351
  }
352
  if (isset_not_empty($gathering_dto->country)) {
353
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('country'),
354
      $gathering_dto->country);
355
  }
356
  if (isset_not_empty($gathering_dto->collectingMethod)) {
357
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('collectingMethod'),
358
      $gathering_dto->collectingMethod);
359
  }
360
  if (isset($gathering_dto->exactLocation)) {
361
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('exactLocation'),
362
      render_point($gathering_dto->exactLocation));
363
  }
364
  if (isset($gathering_dto->absoluteElevation)) {
365
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('absoluteElevation'),
366
      statistical_values_from_gathering_event($gathering_dto, 'absoluteElevation'));
367
  }
368
  if (isset($gathering_dto->distanceToGround) && $gathering_dto->distanceToGround > 0) {
369
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('distanceToGround'),
370
      statistical_values_from_gathering_event($gathering_dto, 'distanceToGround'));
371
  }
372
  if (isset($gathering_dto->distanceToWaterSurface) && $gathering_dto->distanceToWaterSurface > 0) {
373
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('distanceToWaterSurface'),
374
      statistical_values_from_gathering_event($gathering_dto, 'distanceToWaterSurface'));
375
  }
376
  if (isset_not_empty($gathering_dto->collectingAreas)) {
377
    $area_representations = [];
378
    foreach ($gathering_dto->collectingAreas as $area) {
379
      // $area_representations[] = l($area->representation_L10n, path_to_named_area($area->uuid));
380
      $area_representations[] = $area;
381
    }
382
    if (!empty($area_representations)) {
383
      $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('collectingAreas'),
384
        implode(', ', $area_representations)
385
      );
386
    }
387
  }
388

    
389
  return cdm_sob_dto_table(t("Gathering & Location"), $table_row_data, $gathering_dto, 1);
390
}
391

    
392
/**
393
 * Compose an render array from the SpecimenOrObservationDTO.determinedNames.
394
 *
395
 * The resulting DOM block level element will have a header line and details.
396
 *
397
 * compose_hook() implementation
398
 *
399
 * @param object $sob_dto
400
 *   the CDM SpecimenOrObservationDTO
401
 * @param bool $full_details
402
 *   Currently unused,
403
 *
404
 * @return array
405
 *  The render array for the SpecimenOrObservationDTO.determinedNames
406
 *
407
 * @ingroup compose
408
 */
409
function compose_cdm_sob_dto_determinations($sob_dto, $full_details = FALSE) {
410

    
411
  $table_row_data = [];
412

    
413
  foreach ($sob_dto->determinations as $det_event) {
414
    // FIXME use $det_event->determination->taggedText instead of loading the entity
415
    if($det_event->determination->type == "TaxonName") {
416
      $link_path = path_to_name($det_event->determination->uuid);
417
      $taxon_or_name = cdm_ws_get(CDM_WS_PORTAL_NAME, [$det_event->determination->uuid]);
418
    } else {
419
      $link_path = path_to_taxon($det_event->determination->uuid);
420
      $taxon_or_name = cdm_ws_get(CDM_WS_PORTAL_TAXON, [$det_event->determination->uuid]);
421
    }
422
    $timeperiod_string = NULL;
423
    if (isset($det_eventEvent->timeperiod)) {
424
      $timeperiod_string = timePeriodToString($det_event->timeperiod);
425
    }
426
    $markup = $det_event->determination->taggedText;
427
    if (isset($determinationEvent->modifier)) {
428
      $markup .= cdm_term_representation($determinationEvent->modifier);
429
    }
430
    if ($timeperiod_string) {
431
      $markup .= ' ' . $timeperiod_string;
432
    }
433
    if (isset($determinationEvent->actor->titleCache)) {
434
      $markup .= ' ' . $determinationEvent->actor->titleCache;
435
    }
436
    // FXIME not yet supported by the DTO!
437
    if (isset($determinationEvent->description)) {
438
      $markup .= ' ' . $determinationEvent->description;
439
    }
440
    $row = cdm_sob_dto_table_row(NULL, render_taxon_or_name($taxon_or_name, $link_path));
441
    $row['#weight'] = isset_numerical($det_event->isPreferred) ? '0' : ($timeperiod_string ? $timeperiod_string : '1');
442
    $table_row_data[] = $row;
443
  }
444

    
445
  $label = count($table_row_data) > 1 ? t("Identifications") : t("Identification");
446
  return cdm_sob_dto_table($label, $table_row_data, $sob_dto, 1);
447
}
448

    
449
/**
450
 * Compose an render array from the SpecimenOrObservationDTO.determinedNames.
451
 *
452
 * The resulting DOM block level element will have a header line and details.
453
 *
454
 * compose_hook() implementation
455
 *
456
 * @param \AnnotationsAndSources $annotations_and_sources
457
 *   see
458
 *
459
 * @return array
460
 *  The render array for the SpecimenOrObservationDTO.determinedNames
461
 *
462
 * @ingroup compose
463
 */
464
function compose_cdm_sob_dto_sources($sob_dto, $annotations_and_sources) {
465

    
466
  $table_row_data = [];
467

    
468
  foreach ($annotations_and_sources->getSourceReferences() as $source_ref) {
469
    $table_row_data[] = cdm_sob_dto_table_row(NULL, $source_ref);
470
  }
471

    
472
  $label = count($table_row_data) > 1 ? t("Sources") : t("Source");
473
  return cdm_sob_dto_table($label, $table_row_data, $sob_dto, 1);
474
}
475

    
476
/**
477
 * @param $sob_dto
478
 * @param \AnnotationsAndSources $annotations_and_sources
479
 *
480
 * @return array|null
481
 */
482
function compose_cdm_sob_dto_annotations($sob_dto, $annotations_and_sources) {
483

    
484
  $table_row_data = [];
485

    
486
  foreach ($annotations_and_sources->getAnnotations() as $annotation_text) {
487
    $table_row_data[] = cdm_sob_dto_table_row(NULL, $annotation_text);
488
  }
489

    
490
  $label = count($table_row_data) > 1 ? t("Annotations") : t("Annotation");
491
  return cdm_sob_dto_table($label, $table_row_data, $sob_dto, 1);
492
}
493

    
494
function compose_cdm_sob_dto_markers($sob_dto, $markers) {
495

    
496
  $table_row_data = [];
497
  foreach ($markers->records as $marker) {
498
    $table_row_data[] = cdm_sob_dto_table_row($marker->markerType->representation_L10n, ($marker->flag !== TRUE ? t('yes') : t('no')));
499
  }
500

    
501
  $label = count($table_row_data) > 1 ? t("Markers") : t("Marker");
502
  return cdm_sob_dto_table($label, $table_row_data, $sob_dto, 1);
503
}
504

    
505
/**
506
 * Compose an render array from the DerivedUnitDTO.specimenTypeDesignations.
507
 *
508
 * The resulting DOM block level element will have a header line and details.
509
 *
510
 * compose_hook() implementation
511
 *
512
 * @param object $unit_dto
513
 *   the CDM DerivedUnitDTO
514
 * @param bool $full_details
515
 *   Currently unused,
516
 *
517
 * @return array
518
 *  The render array for the SpecimenOrObservationDTO.determinedNames
519
 *
520
 * @ingroup compose
521
 */
522
function compose_cdm_unit_dto_type_designations($unit_dto, $full_details = FALSE) {
523

    
524
  $table_row_data = [];
525

    
526
  if (isset_not_empty($unit_dto->specimenTypeDesignations)) {
527
    $table_row_data[] = cdm_sob_dto_table_row(
528
      NULL,
529
      render_specimen_typedesignation_dto($unit_dto->specimenTypeDesignations));
530
  }
531

    
532
  return cdm_sob_dto_table(t('Type designations'), $table_row_data, $unit_dto, 5, 2);
533
}
534

    
535
/**
536
 * @param $listOfMedia
537
 * @param $sob_dto
538
 * @param $heading
539
 *
540
 * @return array|null
541
 */
542
function cdm_sob_dto_media_table(array $listOfMedia, $sob_dto, $heading) {
543
  $table_row_data = [];
544
  $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
545
  $captionElements = array(
546
    'title',
547
    '#uri' => t('open media'),
548
  );
549
  $gallery_markup = compose_cdm_media_gallerie(array(
550
    'mediaList' => $listOfMedia,
551
    'galleryName' => $sob_dto->uuid,
552
    'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
553
    'cols' => $gallery_settings['cdm_dataportal_media_cols'],
554
    'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
555
    'captionElements' => $captionElements,
556
    'mediaLinkType' => 'LIGHTBOX',
557
    'alternativeMediaUri' => NULL,
558
    'galleryLinkUri' => NULL,
559
    'showCaption' => true
560
  ));
561
  $table_row_data[] = cdm_sob_dto_table_row(NULL, $gallery_markup);
562
  $grid_col_span = count($listOfMedia) > 1 ? 2 : NULL;
563
  return cdm_sob_dto_table(t($heading), $table_row_data, $sob_dto, 20, $grid_col_span);
564
}
565

    
566
/**
567
 * Compose an render array from the DerivedUnitDTO.sequences.
568
 *
569
 * The resulting DOM block level element will have a header line and details.
570
 *
571
 * compose_hook() implementation
572
 *
573
 * @param object $unit_dto
574
 *   the CDM DerivedUnitDTO
575
 * @param bool $full_details
576
 *   Currently unused,
577
 *
578
 * @return array
579
 *  The render array for the DerivedUnitDTO.sequences.
580
 *
581
 * @ingroup compose
582
 *
583
 * TODO see  #3347 (services and REST service controller for molecular classes implemented)
584
 */
585
function compose_cdm_derived_unit_dto_sequences($unit_dto, $full_details = FALSE) {
586

    
587
  $table_row_data = [];
588
  if(isset_not_empty($unit_dto->sequences)){
589
    foreach ($unit_dto->sequences as $sequence) {
590
      if (isset($sequence->geneticAccessionNumber)) {
591
        $table_row_data[] = cdm_sob_dto_table_row(
592
          cdm_occurrence_field_name_label('geneticAccessionNumber'),
593
          $sequence->geneticAccessionNumber);
594
      }
595
      // TODO ....
596
    }
597
  }
598

    
599
  /* TODO
600
case 'dnaQuality':
601
            $sub_dl_groups = array();
602

    
603
            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('purificationMethod'), $value->purificationMethod, NULL, 1);
604
            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('ratioOfAbsorbance260_230'), $value->ratioOfAbsorbance260_230, NULL, 2);
605
            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('ratioOfAbsorbance260_280'), $value->ratioOfAbsorbance260_280, NULL, 3);
606
            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('concentration'), $value->concentration, NULL, 4);
607
            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('concentrationUnit'), $value->concentrationUnit, NULL, 4);
608
            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('qualityTerm'), $value->qualityTerm, NULL, 4);
609
            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('qualityCheckDate'), $value->qualityCheckDate, NULL, 4);
610

    
611
            if (is_array($sub_dl_groups) && sizeof($sub_dl_groups)>0) {
612
              @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),
613
                array(
614
                  array('#markup' => $value->titleCache),
615
                  array('#theme' => 'description_list', '#groups' => $sub_dl_groups)
616
                )
617
              );
618
            }
619
            break;
620
*/
621

    
622
  return cdm_sob_dto_table(t('Storage'), $table_row_data, $unit_dto, 1);
623
}
624

    
625
/**
626
 * Creates a form array for showing details of SpecimenOrObservationDTO in a
627
 * tabular form with heading.
628
 *
629
 * @param $table_heading
630
 * @param array $table_row_data
631
 * @param $sob_dto
632
 * @param $weight
633
 *  The weight determining the order of the drupal render element
634
 * @param $grid_col_span
635
 *  The number of grid colums the table should
636
 *
637
 * @return array|null
638
 */
639
function cdm_sob_dto_table($table_heading, array $table_row_data, $sob_dto, $weight = NULL, $grid_col_span = 1) {
640

    
641
  if (count($table_row_data) > 0) {
642
    $wrapper_style = '';
643
    if($grid_col_span > 1){
644
      $wrapper_style = ' style="grid-column-start: span ' . $grid_col_span. ';"';
645
    }
646
    $sob_table = [
647
      '#theme' => 'table',
648
      '#prefix' => '<div class="table-wrapper"' . $wrapper_style . '>',
649
      '#suffix' => '</div>',
650
      '#header' => [
651
        [
652
          'data' => $table_heading,
653
          'colspan' => 2,
654
        ],
655
      ],
656
      "#rows" => $table_row_data,
657
      "#attributes" => [
658
        "class" => [
659
          'details-table',
660
          'details-table-' . normalize_to_class_attribute($table_heading),
661
          html_class_attribute_ref($sob_dto)
662
        ],
663
      ],
664
    ];
665
    if ($weight) {
666
      $sob_table['#weight'] = $weight;
667
    }
668
    return $sob_table;
669
  }
670
  return NULL;
671
}
672

    
673
function cdm_sob_dto_table_row($label, $value) {
674
  if ($value) {
675
    if($label) {
676
      return [
677
        'data' => [
678
          [
679
            'data' => str_replace(':', '', $label),
680
            'class' => [
681
              'label',
682
            ],
683
          ],
684
          $value,
685
        ],
686
        'no_striping' => TRUE,
687
      ];
688
    } else {
689
      // value spanning two columns
690
      return [
691
        'data' => [
692
          [
693
            'data' => $value,
694
            'colspan' => 2,
695
          ]
696
        ],
697
        'no_striping' => TRUE,
698
      ];
699
    }
700
  }
701
  return NULL;
702
}
703

    
704

    
705

    
706
/**
707
 * Compose an render array from a CDD SpecimenOrObservation entity.
708
 *
709
 * compose_hook() implementation
710
 *
711
 * @param object $sob_dto
712
 *   the CDM FieldUnit or DerivedUnit to compose
713
 *   the render array for.
714
 *
715
 * @return array
716
 *   the supplied render array $derivatives to which the composition of the supplied
717
 *   $specimenOrObservation has been added to
718
 *
719
 * @ingroup compose
720
 */
721
function compose_cdm_specimen_or_observation_new($sob_dto)
722
{
723

    
724
  $render_array = [];
725
  if (is_object($sob_dto)) {
726

    
727
    /*** 95% no longer needed
728
    if ($sob_dto->class == 'FieldUnit'){
729
      // WARNING: adding a List<MediaDTO> as $specimen_or_observation->_derivedUnitMedia
730
      $sob_dto->_derivedUnitMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array(
731
        $sob_dto->uuid,
732
        'fieldObjectMediaDTO',
733
      ));
734
    }else{
735
      // WARNING: adding a List<Media> as $specimen_or_observation->_derivedUnitMedia
736
      $sob_dto->_derivedUnitMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array(
737
        $sob_dto->uuid,
738
        'derivedUnitMedia',
739
      ));
740
    }
741
    ******/
742

    
743
    RenderHints::pushToRenderStack('specimen_or_observation');
744
    $footnote_list_key = $sob_dto->type . '-' . $sob_dto->uuid;
745
    RenderHints::setFootnoteListKey($footnote_list_key);
746

    
747
    $render_array['sob_details_grid'] = [
748
      '#type' => 'container',
749
      '#attributes' => [
750
        'class' => 'derived-unit-details-grid'
751
      ],
752
      'children' => compose_cdm_specimen_or_observation_dto_details_grid($sob_dto, true)
753
    ];;
754

    
755
    $derivation_tree_roots = cdm_ws_get(CDM_WS_OCCURRENCE_FIELD_UNIT_DTOS, [$sob_dto->uuid]);
756
    $render_array['derivation_tree_header'] = markup_to_render_array("<h3>Derivation tree</h3>");
757
    $derivationTreeComposer = new DerivationTreeComposer($derivation_tree_roots);
758
    $derivationTreeComposer->setWithDetails(false);
759
    $derivationTreeComposer->setFocusedUnitUuid($sob_dto->uuid);
760
    $render_array['derivation_tree'] = $derivationTreeComposer->compose();
761

    
762
      /* TODO
763
      case 'definition':
764

    
765
      case 'annotations':
766
      $dd_elements = array();
767
      foreach ($value as $annotation) {
768
        // TODO respect annotation type filter settings
769
        $dd_elements[] = $annotation->text;
770
      }
771
      break;
772

    
773

    
774

    
775
    /** TODO
776

    
777

    
778
    case 'determinations':
779
      $dd_elements = array();
780
      $glue = ', ';
781

    
782
      foreach ($value as $determinationEvent) {
783

    
784
      break;
785
     */
786

    
787
    /*   TODO Extensions
788
    // TODO: filter by using visible_extensions_sorted()
789
    // TODO: treat as top level element, see https://dev.e-taxonomy.eu/redmine/issues/2985#note-23
790
    $extensions = cdm_ws_fetch_all(CDM_WS_PORTAL_OCCURRENCE . '/'  . $sob_dto->uuid . '/extensions', array($sob_dto->uuid));
791
    if ($extensions && count($extensions)) {
792

    
793
      $extensions_render_array = compose_extensions($extensions);
794
      @_description_list_group_add($groups, t('Extensions') . ':',
795
        $extensions_render_array,
796
        '', 100);
797
    }
798
    */
799

    
800
    $render_array['footnotes'] = markup_to_render_array(render_footnotes($footnote_list_key));
801

    
802

    
803
  } // END of $specimenOrObservation exists
804

    
805
  return $render_array;
806
}
807

    
(9-9/15)