Project

General

Profile

Download (23.3 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
/**
23
 * Composes the view on specimens and occurrences as derivate tree
24
 * starting from the field unit including all derivatives.
25
 *
26
 * @param array $root_unit_dtos
27
 *   list of SpecimenOrObservationDTOs
28
 *
29
 * @return array
30
 *   The Drupal render array
31
 *
32
 * @ingroup compose
33
 * @see CDM_SPECIMEN_LIST_VIEW_MODE_OPTION_DERIVATE_TREE
34
 *
35
 */
36
function compose_specimen_table_top_down_new(array $root_unit_dtos) {
37
  // add icons
38
  $expand_icon = font_awesome_icon_markup(
39
    'fa-plus-square-o',
40
    [
41
      'alt' => 'Show details',
42
      'class' => ['expand_icon'],
43
    ]
44
  );
45
  $collapse_icon = font_awesome_icon_markup(
46
    'fa-minus-square-o',
47
    [
48
      'alt' => 'Show details',
49
      'class' => ['collapse_icon'],
50
    ]
51
  );
52

    
53
  $derivation_tree = derived_units_tree($root_unit_dtos);
54

    
55
  $render_array = [];
56
  $render_array['derived-unit-tree'] = $derivation_tree;
57

    
58
  _add_js_derivation_tree('.derived-unit-tree');
59

    
60
  return $render_array;
61
}
62

    
63
/**
64
 * Creates the root levels and trees for all subordinate derivatives.
65
 *
66
 * See derived_units_sub_tree()
67
 *
68
 * @param array $root_unit_dtos
69
 *     list of SpecimenOrObservationDTOs
70
 *
71
 * @return array
72
 *    An array which can be used in render arrays to be passed to the
73
 * theme_table() and theme_list().
74
 */
75
function derived_units_tree(array $root_unit_dtos) {
76

    
77
  RenderHints::pushToRenderStack('derived-unit-tree');
78
  RenderHints::setFootnoteListKey('derived-unit-tree');
79

    
80
  $root_items = [];
81
  //we need one more item to contain the items of one level (fieldunit, derivate data etc.)
82
  foreach ($root_unit_dtos as &$sob_dto) {
83
    $field_unit_dto_render_array = compose_cdm_specimen_or_observation_dto_details_grid($sob_dto);
84
    $root_item = [
85
      '#prefix' => '<div class="derived-unit-tree">',
86
      '#suffix' => '</div>',
87
      '#type' => 'container',
88
      '#attributes' => [
89
        'class' => [
90
          'derived-unit-item derived-unit-tree-root',
91
          html_class_attribute_ref($sob_dto),
92
        ],
93
      ],
94
      'div-container' => [
95
        'root-item-and-sub-tree' => [
96
          markup_to_render_array(derived_units_tree_node_header($sob_dto)
97
            . '<div class="unit-content-wrapper">' // allows to apply the borders between .derived-unit-tree-root and .unit-content
98
            . '<div class="unit-content">' . drupal_render($field_unit_dto_render_array) . '</div>'
99
            . '</div>'),
100
        ],
101
      ],
102

    
103
    ];
104
    if (isset($sob_dto->derivatives) && sizeof($sob_dto->derivatives) > 0) {
105
      usort($sob_dto->derivatives, 'compare_specimen_or_observation_dtos');
106
      // children are displayed in a nested list.
107
      $root_item['div-container']['root-item-and-sub-tree'][] = derived_units_sub_tree($sob_dto->derivatives);
108
    }
109
    $root_items[] = $root_item;
110
  }
111

    
112
  $root_items['footnotes'] = markup_to_render_array(render_footnotes());
113
  RenderHints::popFromRenderStack();
114

    
115
  return $root_items;
116
}
117

    
118
/**
119
 * @param array $unit_dtos
120
 *
121
 * @return array
122
 */
123
function derived_units_sub_tree(array $unit_dtos) {
124

    
125
  $list_items = derived_units_as_list_items($unit_dtos);
126

    
127
  $derivation_tree = [
128
    '#theme' => 'item_list',
129
    '#type' => 'ul',
130
    '#attributes' => [
131
      // NOTE: class attribute "derived-unit-item" is important for consistency with subordinate <ul> elements produced by the drupal theme function
132
      'class' => CDM_SPECIMEN_LIST_VIEW_MODE_OPTION_DERIVATE_TREE . ' derived-unit-item derived-unit-sub-tree',
133
    ],
134
    '#items' => $list_items,
135
  ];
136
  return $derivation_tree;
137
}
138

    
139
/**
140
 * Creates render array items for FieldUnitDTO or DerivedUnitDTO.
141
 *
142
 * @param array $root_unit_dtos
143
 *     list of SpecimenOrObservationDTOs
144
 *
145
 * @return array
146
 *    An array which can be used in render arrays to be passed to the
147
 * theme_table() and theme_list().
148
 */
149
function derived_units_as_list_items(array $root_unit_dtos) {
150

    
151
  $list_items = [];
152
  //we need one more item to contain the items of one level (fieldunit, derivate data etc.)
153
  foreach ($root_unit_dtos as &$sob_dto) {
154
    $item = [];
155
    $item['class'] = ['derived-unit-item ', html_class_attribute_ref($sob_dto)];
156
    // data" element of the array is used as the contents of the list item
157
    $item['data'] = [];
158
    $units_render_array = compose_cdm_specimen_or_observation_dto_details_grid($sob_dto);
159
    $item['data'] = derived_units_tree_node_header($sob_dto)
160
      . '<div class="unit-content derived-unit-details-grid">' . drupal_render($units_render_array) . '</div>';
161
    if (isset($sob_dto->derivatives) && sizeof($sob_dto->derivatives) > 0) {
162
      usort($sob_dto->derivatives, 'compare_specimen_or_observation_dtos');
163
      // children are displayed in a nested list.
164
      $item['children'] = derived_units_as_list_items($sob_dto->derivatives);
165
    }
166
    $list_items[] = $item;
167
  }
168

    
169
  return $list_items;
170
}
171

    
172
/**
173
 * @param $sob_dto
174
 *
175
 * @return string
176
 */
177
function derived_units_tree_node_header($sob_dto) {
178
  $link =  cdm_internal_link(path_to_specimen($sob_dto->uuid), null);
179
  return '<div class="unit-header"><div class="unit-label">' . $sob_dto->label . '<span class="page-link">' . $link . '</span></div></div>';
180
}
181

    
182
/**
183
 * Compose grid of details tabled for a CDM SpecimenOrObservationDTO
184
 *
185
 * The resulting render array will contain separate DOM block level elements
186
 * with header line for the various kind of information like, location,
187
 * gathering, specimen/observation, DNA, etc.
188
 *
189
 *
190
 * Subordinate derivatives will not be included. For showing the derivation
191
 * hierarchy see methods like derived_units_sub_tree()
192
 *
193
 * compose_hook() implementation
194
 *
195
 * @param object $sob_dto
196
 *   the CDM FieldUnitDTO or DerivedUnitDTO to compose
197
 *   the render array for.
198
 * @param bool $compact_mode
199
 *   Currently unused, but added for compatibility with
200
 *   compose_cdm_specimen_or_observation($specimen_or_observation,
201
 *   $isSpecimen_page = false, &$derivatives = null)
202
 * @param array $derivatives
203
 *   the render array which contains the compositions of the derivatives
204
 *   of the supplied $specimenOrObservation
205
 *
206
 * @return array
207
 *  The render array for the SpecimenOrObservationDTO
208
 *
209
 * @ingroup compose
210
 */
211
function compose_cdm_specimen_or_observation_dto_details_grid($sob_dto, $compact_mode = FALSE, &$derivatives = NULL) {
212
  $render_array = [];
213
  if (!$sob_dto) {
214
    return $render_array;
215
  }
216
  if ($sob_dto->type == 'FieldUnit') {
217
    $render_array['field-unit'] = compose_cdm_field_unit_dto_details($sob_dto, $compact_mode);
218
    if (isset($sob_dto->gatheringEvent)) {
219
      $render_array['gathering'] = compose_cdm_gathering_dto_details($sob_dto->gatheringEvent, $compact_mode);
220
    }
221
  } else {
222
    if(isset($sob_dto->derivationEvent)){
223
      $render_array['derivation-event'] = compose_cdm_derivation_event($sob_dto->derivationEvent);
224
    }
225
    $render_array['storage'] = compose_cdm_derived_unit_dto_storage_details($sob_dto, $compact_mode);
226
    $render_array['type-designations'] = compose_cdm_unit_dto_type_designations($sob_dto, $compact_mode);
227
    if($sob_dto->type == 'DnaSample'){
228
      // FIXME:
229
      $render_array['dna-sample'] = compose_cdm_derived_unit_dto_sequences($sob_dto, $compact_mode);
230
    } else if($sob_dto->type == 'MediaSpecimen' && isset_not_empty($sob_dto->mediaSpecimen)) {
231
      $render_array['media-specimens'] = cdm_sob_dto_media_table($sob_dto->mediaSpecimen, $sob_dto, 'Media Specimens');
232
    }
233
  }
234
  if(isset_not_empty($sob_dto->determinedNames)){
235
    $render_array['determinations'] = compose_cdm_sob_dto_determinations($sob_dto, $compact_mode);
236
  }
237
  if(isset_not_empty($sob_dto->listOfMedia)){
238
    $render_array['media'] = cdm_sob_dto_media_table($sob_dto->listOfMedia, $sob_dto, 'Media');;
239
  }
240

    
241
  return $render_array;
242
}
243
/**
244
 * Data rows with details for a SpecimenOrObservationDTO to be used in a table
245
 * @param object $sob_dto
246
 *   the CDM SpecimenOrObservationDTO
247
 * @param bool $compact_mode
248
 *   Currently unused,
249
 *
250
 * @return array
251
 *  The data rows
252
 */
253
function sob_dto_details_rows($sob_dto, $compact_mode = FALSE) {
254

    
255
  $table_row_data = [];
256

    
257
  if (isset_not_empty($sob_dto->recordBase)) {
258
    $label = cdm_term_representation($sob_dto->recordBase);
259
    if($label == 'Dna Sample'){
260
      $label == 'DNA Sample';
261
    }
262
    $table_row_data[0] = cdm_sob_dto_table_row(
263
      cdm_occurrence_field_name_label('recordBase'),
264
      $label);
265
  }
266
  if (isset_not_empty($sob_dto->kindOfUnit)) {
267
    $table_row_data[] = cdm_sob_dto_table_row(
268
      cdm_occurrence_field_name_label('kindOfUnit'),
269
      cdm_term_representation($sob_dto->kindOfUnit));
270
  }
271
  if (isset_not_empty($sob_dto->preferredStableUri)) {
272
    $table_row_data[] = cdm_sob_dto_table_row(
273
      cdm_occurrence_field_name_label('preferredStableUri'),
274
      cdm_external_uri($sob_dto->preferredStableUri, false));
275
  }
276
  if (isset_not_empty($sob_dto->sex)) {
277
    $table_row_data[] = cdm_sob_dto_table_row(
278
      cdm_occurrence_field_name_label('sex'),
279
      cdm_term_representation($sob_dto->sex));
280
  }
281
  if (isset_not_empty($sob_dto->lifeStage)) {
282
    $table_row_data[] = cdm_sob_dto_table_row(
283
      cdm_occurrence_field_name_label('lifeStage'),
284
      cdm_term_representation($sob_dto->lifeStage));
285
  }
286

    
287
  return $table_row_data;
288
}
289

    
290
/**
291
 * Compose a table of details for a DerivationEventDTO.
292
 *
293
 * compose_hook() implementation
294
 *
295
 * @param object $derivation_event_dto
296
 *   the CDM DerivationEventDTO
297
 * @param bool $compact_mode
298
 *   Currently unused,
299
 *
300
 * @return array
301
 *  The render array for the DerivationEventDTO
302
 *
303
 * @ingroup compose
304
 */
305
function compose_cdm_derivation_event($derivation_event_dto, $compact_mode = FALSE){
306

    
307
  $details_array = [];
308
  // $markup = t("Derivation") . ': ';
309
  $markup = ucfirst(cdm_term_representation($derivation_event_dto->eventType));
310
  if(isset_not_empty($derivation_event_dto->actor)){
311
    $details_array[] = $derivation_event_dto->actor;
312
  }
313
  if(isset_not_empty($derivation_event_dto->institute)){
314
    $details_array[] = $derivation_event_dto->institute;
315
  }
316
  if(isset_not_empty($derivation_event_dto->timePeriod)){
317
    $details_array[] = timePeriodToString($derivation_event_dto->timePeriod);
318
  }
319
  $details_markup = join(', ', $details_array);
320
  if($details_markup){
321
    $markup .= ': ' . $details_markup;
322
  }
323
  $render_array = [
324
    '#type' => 'container',
325
    '#attributes' => [
326
      'class' => [
327
        'derivation-event',
328
        html_class_attribute_ref($derivation_event_dto)
329
      ],
330
      'style' => [
331
        'grid-column-start: span 2'
332
      ]
333
    ],
334
    'content' => markup_to_render_array($markup)
335
  ];
336
  return $render_array;
337
}
338

    
339
/**
340
 * Compose a table of details for a FieldUnitDTO.
341
 *
342
 * The resulting DOM block level element will have a header line and details.
343
 *
344
 * compose_hook() implementation
345
 *
346
 * @param object $fu_dto
347
 *   the CDM FieldUnitDTO
348
 * @param bool $compact_mode
349
 *   Currently unused,
350
 *
351
 * @return array
352
 *  The render array for the SpecimenOrObservationDTO
353
 *
354
 * @ingroup compose
355
 */
356
function compose_cdm_field_unit_dto_details($fu_dto, $compact_mode = FALSE) {
357

    
358
  $table_row_data = sob_dto_details_rows($fu_dto, $compact_mode);
359

    
360
  if (isset_not_empty($fu_dto->individualCount)) {
361
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('individualCount'), $fu_dto->individualCount);
362
  }
363
  if (isset_not_empty($fu_dto->definition)) {
364
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('definition'), $fu_dto->definition);
365
  }
366
  if (isset_not_empty($fu_dto->fieldNumber)) {
367
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('fieldNumber'), $fu_dto->fieldNumber);
368
  }
369
  if (isset_not_empty($fu_dto->primaryCollector)) {
370
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('primaryCollector'), $fu_dto->primaryCollector);
371
  }
372
  if (isset_not_empty($fu_dto->fieldNotes)) {
373
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('fieldNotes'), $fu_dto->fieldNotes);
374
  }
375

    
376
  $heading = $table_row_data[0]['data'][1];
377
  unset($table_row_data[0]);
378
  return cdm_sob_dto_table(t($heading), $table_row_data, $fu_dto, 2);
379
}
380

    
381
/**
382
 * Compose details table for a DerivedUnitDTO.
383
 *
384
 * The resulting DOM block level element will have a header line and details.
385
 *
386
 * compose_hook() implementation
387
 *
388
 * @param object $du_dto
389
 *   the CDM DerivedUnitDTO
390
 * @param bool $compact_mode
391
 *   Currently unused,
392
 *
393
 * @return array
394
 *  The render array for the DerivedUnitDTO
395
 *
396
 * @ingroup compose
397
 */
398
function  compose_cdm_derived_unit_dto_storage_details($du_dto, $compact_mode = FALSE) {
399

    
400
  $table_row_data = sob_dto_details_rows($du_dto, $compact_mode);
401

    
402
  if (isset($du_dto->accessionNumber)) {
403
    $table_row_data[] = cdm_sob_dto_table_row(
404
      cdm_occurrence_field_name_label('accessionNumber'),
405
      $du_dto->accessionNumber);
406
  }
407
  if (isset($du_dto->collection)) {
408
    $table_row_data[] = cdm_sob_dto_table_row(
409
      cdm_occurrence_field_name_label('collection'),
410
      render_collection_dto($du_dto->collection));
411
  }
412
  if (isset($du_dto->storedUnder)) {
413
    $taxon_name = cdm_ws_get(CDM_WS_PORTAL_NAME, array($du_dto->storedUnder->uuid));
414
    $table_row_data[] = cdm_sob_dto_table_row(
415
      cdm_occurrence_field_name_label('storedUnder'),
416
      render_taxon_or_name($taxon_name, path_to_name($taxon_name->uuid)));
417
  }
418
  if (isset($du_dto->exsiccatum)) {
419
    $table_row_data[] = cdm_sob_dto_table_row(
420
      cdm_occurrence_field_name_label('exsiccatum'),
421
      $du_dto->exsiccatum);
422
  }
423
  if (isset($du_dto->catalogNumber)) {
424
    $table_row_data[] = cdm_sob_dto_table_row(
425
      cdm_occurrence_field_name_label('catalogNumber'),
426
      $du_dto->catalogNumber);
427
  }
428
  if (isset($du_dto->barcode)) {
429
    $table_row_data[] = cdm_sob_dto_table_row(
430
      cdm_occurrence_field_name_label('barcode'),
431
      $du_dto->barcode);
432
  }
433
  if (isset($du_dto->preservationMethod)) {
434
    $table_row_data[] = cdm_sob_dto_table_row(
435
      cdm_occurrence_field_name_label('preservationMethod'),
436
      $du_dto->preservationMethod);
437
  }
438
  if (isset_not_empty($du_dto->characterData)) {
439
    $table_row_data[] = cdm_sob_dto_table_row(
440
      cdm_occurrence_field_name_label('characterData'),
441
      icon_link(path_to_specimen($du_dto->uuid), '', FALSE), false);
442
  }
443

    
444
  $heading = $table_row_data[0]['data'][1];
445
  unset($table_row_data[0]);
446
  return cdm_sob_dto_table(t($heading), $table_row_data, $du_dto, 1);
447
}
448

    
449
/**
450
 * Compose an render array from a CDM GatheringDTO.
451
 *
452
 * The resulting DOM block level element will have a header line and details.
453
 *
454
 * compose_hook() implementation
455
 *
456
 * @param object $gathering_dto
457
 *   the CDM GatheringDTO object
458
 * @param bool $compact_mode
459
 *   Currently unused,
460
 *
461
 * @return array
462
 *  The render array for the GatheringDTO
463
 *
464
 * @ingroup compose
465
 */
466
function compose_cdm_gathering_dto_details($gathering_dto, $compact_mode = FALSE) {
467

    
468
  $table_row_data = [];
469
  if (isset_not_empty($gathering_dto->date)) {
470
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('date'),
471
      partialToDate($gathering_dto->date));
472
  }
473
  if (isset_not_empty($gathering_dto->collector)) {
474
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('collector'),
475
      $gathering_dto->collector);
476
  }
477
  if (isset_not_empty($gathering_dto->description)) {
478
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('description'),
479
      $gathering_dto->description);
480
  }
481
  if (isset_not_empty($gathering_dto->locality)) {
482
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('locality'),
483
      $gathering_dto->locality);
484
  }
485
  if (isset_not_empty($gathering_dto->country)) {
486
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('country'),
487
      $gathering_dto->country);
488
  }
489
  if (isset_not_empty($gathering_dto->collectingMethod)) {
490
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('collectingMethod'),
491
      $gathering_dto->collectingMethod);
492
  }
493
  if (isset($gathering_dto->exactLocation)) {
494
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('exactLocation'),
495
      render_point($gathering_dto->exactLocation));
496
  }
497
  if (isset($gathering_dto->absoluteElevation)) {
498
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('absoluteElevation'),
499
      statistical_values_from_gathering_event($gathering_dto, 'absoluteElevation'));
500
  }
501
  if (isset($gathering_dto->distanceToGround) && $gathering_dto->distanceToGround > 0) {
502
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('distanceToGround'),
503
      statistical_values_from_gathering_event($gathering_dto, 'distanceToGround'));
504
  }
505
  if (isset($gathering_dto->distanceToWaterSurface) && $gathering_dto->distanceToWaterSurface > 0) {
506
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('distanceToWaterSurface'),
507
      statistical_values_from_gathering_event($gathering_dto, 'distanceToWaterSurface'));
508
  }
509
  if (isset_not_empty($gathering_dto->collectingAreas)) {
510
    $area_representations = [];
511
    foreach ($gathering_dto->collectingAreas as $area) {
512
      // $area_representations[] = l($area->representation_L10n, path_to_named_area($area->uuid));
513
      $area_representations[] = $area;
514
    }
515
    if (!empty($area_representations)) {
516
      $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('collectingAreas'),
517
        implode(', ', $area_representations)
518
      );
519
    }
520
  }
521

    
522
  return cdm_sob_dto_table(t("Gathering & Location"), $table_row_data, $gathering_dto, 1);
523
}
524

    
525
/**
526
 * Compose an render array from the SpecimenOrObservationDTO.determinedNames.
527
 *
528
 * The resulting DOM block level element will have a header line and details.
529
 *
530
 * compose_hook() implementation
531
 *
532
 * @param object $sob_dto
533
 *   the CDM SpecimenOrObservationDTO
534
 * @param bool $compact_mode
535
 *   Currently unused,
536
 *
537
 * @return array
538
 *  The render array for the SpecimenOrObservationDTO.determinedNames
539
 *
540
 * @ingroup compose
541
 */
542
function compose_cdm_sob_dto_determinations($sob_dto, $compact_mode = FALSE) {
543

    
544
  $table_row_data = [];
545

    
546
  foreach ($sob_dto->determinedNames as $name) {
547
    $taxon_name = cdm_ws_get(CDM_WS_PORTAL_NAME, $name->uuid);
548
    $table_row_data[] = cdm_sob_dto_table_row(NULL, render_taxon_or_name($taxon_name, url(path_to_name($taxon_name->uuid))));
549
  }
550

    
551
  $label = count($table_row_data) > 1 ? t("Identifications") : t("Identification");
552
  return cdm_sob_dto_table($label, $table_row_data, $sob_dto, 1);
553
}
554

    
555
/**
556
 * Compose an render array from the DerivedUnitDTO.specimenTypeDesignations.
557
 *
558
 * The resulting DOM block level element will have a header line and details.
559
 *
560
 * compose_hook() implementation
561
 *
562
 * @param object $unit_dto
563
 *   the CDM DerivedUnitDTO
564
 * @param bool $compact_mode
565
 *   Currently unused,
566
 *
567
 * @return array
568
 *  The render array for the SpecimenOrObservationDTO.determinedNames
569
 *
570
 * @ingroup compose
571
 */
572
function compose_cdm_unit_dto_type_designations($unit_dto, $compact_mode = FALSE) {
573

    
574
  $table_row_data = [];
575

    
576
  if (isset_not_empty($unit_dto->specimenTypeDesignations)) {
577
    $table_row_data[] = cdm_sob_dto_table_row(
578
      NULL,
579
      render_specimen_typedesignation_dto($unit_dto->specimenTypeDesignations));
580
  }
581

    
582
  return cdm_sob_dto_table(t('Type designations'), $table_row_data, $unit_dto, 5, 2);
583
}
584

    
585
/**
586
 * @param $listOfMedia
587
 * @param $sob_dto
588
 * @param $heading
589
 *
590
 * @return array|null
591
 */
592
function cdm_sob_dto_media_table(array $listOfMedia, $sob_dto, $heading) {
593
  $table_row_data = [];
594
  $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
595
  $captionElements = array(
596
    'title',
597
    '#uri' => t('open media'),
598
  );
599
  $gallery_markup = compose_cdm_media_gallerie(array(
600
    'mediaList' => $listOfMedia,
601
    'galleryName' => $sob_dto->uuid,
602
    'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
603
    'cols' => $gallery_settings['cdm_dataportal_media_cols'],
604
    'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
605
    'captionElements' => $captionElements,
606
    'mediaLinkType' => 'LIGHTBOX',
607
    'alternativeMediaUri' => NULL,
608
    'galleryLinkUri' => NULL,
609
    'showCaption' => true
610
  ));
611
  $table_row_data[] = cdm_sob_dto_table_row(NULL, $gallery_markup);
612
  $grid_col_span = count($listOfMedia) > 1 ? 2 : NULL;
613
  return cdm_sob_dto_table(t($heading), $table_row_data, $sob_dto, 20, $grid_col_span);
614
}
615

    
616
/**
617
 * Compose an render array from the DerivedUnitDTO.sequences.
618
 *
619
 * The resulting DOM block level element will have a header line and details.
620
 *
621
 * compose_hook() implementation
622
 *
623
 * @param object $unit_dto
624
 *   the CDM DerivedUnitDTO
625
 * @param bool $compact_mode
626
 *   Currently unused,
627
 *
628
 * @return array
629
 *  The render array for the DerivedUnitDTO.sequences.
630
 *
631
 * @ingroup compose
632
 *
633
 * TODO see  #3347 (services and REST service controller for molecular classes implemented)
634
 */
635
function compose_cdm_derived_unit_dto_sequences($unit_dto, $compact_mode = FALSE) {
636

    
637
  $table_row_data = [];
638
  if(isset_not_empty($unit_dto->sequences)){
639
    foreach ($unit_dto->sequences as $sequence) {
640
      if (isset($sequence->geneticAccessionNumber)) {
641
        $table_row_data[] = cdm_sob_dto_table_row(
642
          cdm_occurrence_field_name_label('geneticAccessionNumber'),
643
          $sequence->geneticAccessionNumber);
644
      }
645
      // TODO ....
646
    }
647
  }
648

    
649
  return cdm_sob_dto_table(t('Storage'), $table_row_data, $unit_dto, 1);
650
}
651

    
652
/**
653
 * Creates a form array for showing details of SpecimenOrObservationDTO in a
654
 * tabular form with heading.
655
 *
656
 * @param $table_heading
657
 * @param array $table_row_data
658
 * @param $sob_dto
659
 * @param $weight
660
 *  The weight determining the order of the drupal render element
661
 * @param $grid_col_span
662
 *  The number of grid colums the table should
663
 *
664
 * @return array|null
665
 */
666
function cdm_sob_dto_table($table_heading, array $table_row_data, $sob_dto, $weight = NULL, $grid_col_span = 1) {
667

    
668
  if (count($table_row_data) > 0) {
669
    $wrapper_style = '';
670
    if($grid_col_span > 1){
671
      $wrapper_style = ' style="grid-column-start: span ' . $grid_col_span. ';"';
672
    }
673
    $sob_table = [
674
      '#theme' => 'table',
675
      '#prefix' => '<div class="table-wrapper"' . $wrapper_style . '>',
676
      '#suffix' => '</div>',
677
      '#header' => [
678
        [
679
          'data' => $table_heading,
680
          'colspan' => 2,
681
        ],
682
      ],
683
      "#rows" => $table_row_data,
684
      "#attributes" => [
685
        "class" => [
686
          'details-table',
687
          'details-table-' . normalize_to_class_attribute($table_heading),
688
          html_class_attribute_ref($sob_dto)
689
        ],
690
      ],
691
    ];
692
    if ($weight) {
693
      $sob_table['#weight'] = $weight;
694
    }
695
    return $sob_table;
696
  }
697
  return NULL;
698
}
699

    
700
function cdm_sob_dto_table_row($label, $value) {
701
  if ($value) {
702
    if($label) {
703
      return [
704
        'data' => [
705
          [
706
            'data' => str_replace(':', '', $label),
707
            'class' => [
708
              'label',
709
            ],
710
          ],
711
          $value,
712
        ],
713
        'no_striping' => TRUE,
714
      ];
715
    } else {
716
      // value spanning two columns
717
      return [
718
        'data' => [
719
          [
720
            'data' => $value,
721
            'colspan' => 2,
722
          ]
723
        ],
724
        'no_striping' => TRUE,
725
      ];
726
    }
727
  }
728
  return NULL;
729
}
(9-9/15)