Project

General

Profile

Download (25.7 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
  @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('medium'), $value->medium, NULL, 1);
300
  @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('temperature'), $value->temperature, NULL, 2);
301
  @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('definedMaterialOrMethod'), $value->definedMaterialOrMethod, NULL, 3);
302
  */
303
  if (isset_not_empty($du_dto->characterData)) {
304
    $table_row_data[] = cdm_sob_dto_table_row(
305
      cdm_occurrence_field_name_label('characterData'),
306
      icon_link(path_to_specimen($du_dto->uuid), '', FALSE), false);
307
  }
308

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

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

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

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

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

    
409
  $table_row_data = [];
410

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

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

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

    
464
  $table_row_data = [];
465

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

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

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

    
482
  $table_row_data = [];
483

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

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

    
492
function compose_cdm_sob_dto_markers($sob_dto, $markers) {
493

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

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

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

    
522
  $table_row_data = [];
523

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

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

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

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

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

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

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

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

    
620
  return cdm_sob_dto_table(t('Storage'), $table_row_data, $unit_dto, 1);
621
}
622

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

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

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

    
702

    
703

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

    
722
  $render_array = [];
723
  if (is_object($sob_dto)) {
724

    
725
    RenderHints::pushToRenderStack('specimen_or_observation');
726
    $footnote_list_key = $sob_dto->type . '-' . $sob_dto->uuid;
727
    RenderHints::setFootnoteListKey($footnote_list_key);
728

    
729
    $render_array['sob_details_grid'] = [
730
      '#type' => 'container',
731
      '#attributes' => [
732
        'class' => 'derived-unit-details-grid'
733
      ],
734
      'children' => compose_cdm_specimen_or_observation_dto_details_grid($sob_dto, true)
735
    ];;
736

    
737
    $derivation_tree_roots = cdm_ws_get(CDM_WS_OCCURRENCE_ROOT_UNIT_DTOS, [$sob_dto->uuid]);
738
    $render_array['derivation_tree_header'] = markup_to_render_array("<h3>Derivation tree</h3>");
739
    $derivationTreeComposer = new DerivationTreeComposer($derivation_tree_roots);
740
    $derivationTreeComposer->setWithDetails(false);
741
    $derivationTreeComposer->setFocusedUnitUuid($sob_dto->uuid);
742
    $render_array['derivation_tree'] = $derivationTreeComposer->compose();
743

    
744
    /*   TODO Extensions
745
    // TODO: filter by using visible_extensions_sorted()
746
    // TODO: treat as top level element, see https://dev.e-taxonomy.eu/redmine/issues/2985#note-23
747
    $extensions = cdm_ws_fetch_all(CDM_WS_PORTAL_OCCURRENCE . '/'  . $sob_dto->uuid . '/extensions', array($sob_dto->uuid));
748
    if ($extensions && count($extensions)) {
749

    
750
      $extensions_render_array = compose_extensions($extensions);
751
      @_description_list_group_add($groups, t('Extensions') . ':',
752
        $extensions_render_array,
753
        '', 100);
754
    }
755
    */
756

    
757
    $render_array['footnotes'] = markup_to_render_array(render_footnotes($footnote_list_key));
758

    
759

    
760
  } // END of $specimenOrObservation exists
761

    
762
  return $render_array;
763
}
764

    
(9-9/15)