Project

General

Profile

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

    
53
  $derivation_tree = derived_units_tree($root_unit_dtos);
54

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

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

    
60
  return $render_array;
61
}
62

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

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

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

    
109
  return $root_items;
110
}
111

    
112
/**
113
 * @param array $unit_dtos
114
 *
115
 * @return array
116
 */
117
function derived_units_sub_tree(array $unit_dtos) {
118

    
119
  $list_items = derived_units_as_list_items($unit_dtos);
120

    
121
  $derivation_tree = [
122
    '#theme' => 'item_list',
123
    '#type' => 'ul',
124
    '#attributes' => [
125
      'class' => CDM_SPECIMEN_LIST_VIEW_MODE_OPTION_DERIVATE_TREE . ' derived-unit-sub-tree',
126
    ],
127
    '#items' => $list_items,
128
  ];
129
  return $derivation_tree;
130
}
131

    
132
/**
133
 * Creates render array items for FieldUnitDTO or DerivedUnitDTO.
134
 *
135
 * @param array $root_unit_dtos
136
 *     list of SpecimenOrObservationDTOs
137
 *
138
 * @return array
139
 *    An array which can be used in render arrays to be passed to the
140
 * theme_table() and theme_list().
141
 */
142
function derived_units_as_list_items(array $root_unit_dtos) {
143

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

    
162
  return $list_items;
163
}
164

    
165
/**
166
 * @param $sob_dto
167
 *
168
 * @return string
169
 */
170
function derived_units_tree_node_header($sob_dto) {
171
  $link =  cdm_internal_link(path_to_specimen($sob_dto->uuid), null);
172
  return '<div class="unit-header"><div class="unit-label">' . $sob_dto->label . '<span class="page-link">' . $link . '</span></div></div>';
173
}
174

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

    
232
  return $render_array;
233
}
234
/**
235
 * Data rows with details for a SpecimenOrObservationDTO to be used in a table
236
 * @param object $sob_dto
237
 *   the CDM SpecimenOrObservationDTO
238
 * @param bool $compact_mode
239
 *   Currently unused,
240
 *
241
 * @return array
242
 *  The data rows
243
 */
244
function sob_dto_details_rows($sob_dto, $compact_mode = FALSE) {
245

    
246
  $table_row_data = [];
247

    
248
  if (isset_not_empty($sob_dto->recordBase)) {
249
    $label = cdm_term_representation($sob_dto->recordBase);
250
    if($label == 'Dna Sample'){
251
      $label == 'DNA Sample';
252
    }
253
    $table_row_data[0] = cdm_sob_dto_table_row(
254
      cdm_occurrence_field_name_label('recordBase'),
255
      $label);
256
  }
257
  if (isset_not_empty($sob_dto->kindOfUnit)) {
258
    $table_row_data[] = cdm_sob_dto_table_row(
259
      cdm_occurrence_field_name_label('kindOfUnit'),
260
      cdm_term_representation($sob_dto->kindOfUnit));
261
  }
262
  if (isset_not_empty($sob_dto->preferredStableUri)) {
263
    $table_row_data[] = cdm_sob_dto_table_row(
264
      cdm_occurrence_field_name_label('preferredStableUri'),
265
      cdm_external_uri($sob_dto->preferredStableUri, false));
266
  }
267
  if (isset_not_empty($sob_dto->sex)) {
268
    $table_row_data[] = cdm_sob_dto_table_row(
269
      cdm_occurrence_field_name_label('sex'),
270
      cdm_term_representation($sob_dto->sex));
271
  }
272
  if (isset_not_empty($sob_dto->lifeStage)) {
273
    $table_row_data[] = cdm_sob_dto_table_row(
274
      cdm_occurrence_field_name_label('lifeStage'),
275
      cdm_term_representation($sob_dto->lifeStage));
276
  }
277

    
278
  return $table_row_data;
279
}
280

    
281

    
282
/**
283
 * Compose a table of details for a FieldUnitDTO.
284
 *
285
 * The resulting DOM block level element will have a header line and details.
286
 *
287
 * compose_hook() implementation
288
 *
289
 * @param object $fu_dto
290
 *   the CDM FieldUnitDTO
291
 * @param bool $compact_mode
292
 *   Currently unused,
293
 *
294
 * @return array
295
 *  The render array for the SpecimenOrObservationDTO
296
 *
297
 * @ingroup compose
298
 */
299
function compose_cdm_field_unit_dto_details($fu_dto, $compact_mode = FALSE) {
300

    
301
  $table_row_data = sob_dto_details_rows($fu_dto, $compact_mode);
302

    
303
  if (isset_not_empty($fu_dto->individualCount)) {
304
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('individualCount'), $fu_dto->individualCount);
305
  }
306
  if (isset_not_empty($fu_dto->definition)) {
307
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('definition'), $fu_dto->definition);
308
  }
309
  if (isset_not_empty($fu_dto->fieldNumber)) {
310
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('fieldNumber'), $fu_dto->fieldNumber);
311
  }
312
  if (isset_not_empty($fu_dto->primaryCollector)) {
313
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('primaryCollector'), $fu_dto->primaryCollector);
314
  }
315
  if (isset_not_empty($fu_dto->fieldNotes)) {
316
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('fieldNotes'), $fu_dto->fieldNotes);
317
  }
318

    
319
  $heading = $table_row_data[0]['data'][1];
320
  unset($table_row_data[0]);
321
  return cdm_sob_dto_table(t($heading), $table_row_data, $fu_dto, 2);
322
}
323

    
324
/**
325
 * Compose details table for a DerivedUnitDTO.
326
 *
327
 * The resulting DOM block level element will have a header line and details.
328
 *
329
 * compose_hook() implementation
330
 *
331
 * @param object $du_dto
332
 *   the CDM DerivedUnitDTO
333
 * @param bool $compact_mode
334
 *   Currently unused,
335
 *
336
 * @return array
337
 *  The render array for the DerivedUnitDTO
338
 *
339
 * @ingroup compose
340
 */
341
function compose_cdm_derived_unit_dto_storage_details($du_dto, $compact_mode = FALSE) {
342

    
343
  $table_row_data = sob_dto_details_rows($du_dto, $compact_mode);
344

    
345
  if (isset($du_dto->accessionNumber)) {
346
    $table_row_data[] = cdm_sob_dto_table_row(
347
      cdm_occurrence_field_name_label('accessionNumber'),
348
      $du_dto->accessionNumber);
349
  }
350
  if (isset($du_dto->collection)) {
351
    $table_row_data[] = cdm_sob_dto_table_row(
352
      cdm_occurrence_field_name_label('collection'),
353
      render_collection_dto($du_dto->collection));
354
  }
355
  if (isset($du_dto->storedUnder)) {
356
    $taxon_name = cdm_ws_get(CDM_WS_PORTAL_NAME, array($du_dto->storedUnder->uuid));
357
    $table_row_data[] = cdm_sob_dto_table_row(
358
      cdm_occurrence_field_name_label('storedUnder'),
359
      render_taxon_or_name($taxon_name, path_to_name($taxon_name->uuid)));
360
  }
361
  if (isset_not_empty($du_dto->characterData)) {
362
    $table_row_data[] = cdm_sob_dto_table_row(
363
      cdm_occurrence_field_name_label('characterData'),
364
      icon_link(path_to_specimen($du_dto->uuid), '', FALSE), false);
365
  }
366

    
367
  $heading = $table_row_data[0]['data'][1];
368
  unset($table_row_data[0]);
369
  return cdm_sob_dto_table(t($heading), $table_row_data, $du_dto, 1);
370
}
371

    
372
/**
373
 * Compose an render array from a CDM GatheringDTO.
374
 *
375
 * The resulting DOM block level element will have a header line and details.
376
 *
377
 * compose_hook() implementation
378
 *
379
 * @param object $gathering_dto
380
 *   the CDM GatheringDTO object
381
 * @param bool $compact_mode
382
 *   Currently unused,
383
 *
384
 * @return array
385
 *  The render array for the GatheringDTO
386
 *
387
 * @ingroup compose
388
 */
389
function compose_cdm_gathering_dto_details($gathering_dto, $compact_mode = FALSE) {
390

    
391
  $table_row_data = [];
392
  if (isset_not_empty($gathering_dto->date)) {
393
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('date'),
394
      partialToDate($gathering_dto->date));
395
  }
396
  if (isset_not_empty($gathering_dto->collector)) {
397
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('collector'),
398
      $gathering_dto->collector);
399
  }
400
  if (isset_not_empty($gathering_dto->description)) {
401
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('description'),
402
      $gathering_dto->description);
403
  }
404
  if (isset_not_empty($gathering_dto->locality)) {
405
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('locality'),
406
      $gathering_dto->locality);
407
  }
408
  if (isset_not_empty($gathering_dto->country)) {
409
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('country'),
410
      $gathering_dto->country);
411
  }
412
  if (isset_not_empty($gathering_dto->collectingMethod)) {
413
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('collectingMethod'),
414
      $gathering_dto->collectingMethod);
415
  }
416
  if (isset($gathering_dto->exactLocation)) {
417
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('exactLocation'),
418
      render_point($gathering_dto->exactLocation));
419
  }
420
  if (isset($gathering_dto->absoluteElevation)) {
421
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('absoluteElevation'),
422
      statistical_values_from_gathering_event($gathering_dto, 'absoluteElevation'));
423
  }
424
  if (isset($gathering_dto->distanceToGround) && $gathering_dto->distanceToGround > 0) {
425
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('distanceToGround'),
426
      statistical_values_from_gathering_event($gathering_dto, 'distanceToGround'));
427
  }
428
  if (isset($gathering_dto->distanceToWaterSurface) && $gathering_dto->distanceToWaterSurface > 0) {
429
    $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('distanceToWaterSurface'),
430
      statistical_values_from_gathering_event($gathering_dto, 'distanceToWaterSurface'));
431
  }
432
  if (isset_not_empty($gathering_dto->collectingAreas)) {
433
    $area_representations = [];
434
    foreach ($gathering_dto->collectingAreas as $area) {
435
      // $area_representations[] = l($area->representation_L10n, path_to_named_area($area->uuid));
436
      $area_representations[] = $area;
437
    }
438
    if (!empty($area_representations)) {
439
      $table_row_data[] = cdm_sob_dto_table_row(cdm_occurrence_field_name_label('collectingAreas'),
440
        implode(', ', $area_representations)
441
      );
442
    }
443
  }
444

    
445
  return cdm_sob_dto_table(t("Gathering & Location"), $table_row_data, $gathering_dto, 1);
446
}
447

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

    
467
  $table_row_data = [];
468

    
469
  foreach ($sob_dto->determinedNames as $name) {
470
    $taxon_name = cdm_ws_get(CDM_WS_PORTAL_NAME, $name->uuid);
471
    $table_row_data[] = cdm_sob_dto_table_row(NULL, render_taxon_or_name($taxon_name, url(path_to_name($taxon_name->uuid))));
472
  }
473

    
474
  $label = count($table_row_data) > 1 ? t("Identifications") : t("Identification");
475
  return cdm_sob_dto_table($label, $table_row_data, $sob_dto, 1);
476
}
477

    
478
/**
479
 * Compose an render array from the DerivedUnitDTO.specimenTypeDesignations.
480
 *
481
 * The resulting DOM block level element will have a header line and details.
482
 *
483
 * compose_hook() implementation
484
 *
485
 * @param object $unit_dto
486
 *   the CDM DerivedUnitDTO
487
 * @param bool $compact_mode
488
 *   Currently unused,
489
 *
490
 * @return array
491
 *  The render array for the SpecimenOrObservationDTO.determinedNames
492
 *
493
 * @ingroup compose
494
 */
495
function compose_cdm_unit_dto_type_designations($unit_dto, $compact_mode = FALSE) {
496

    
497
  $table_row_data = [];
498

    
499
  if (isset_not_empty($unit_dto->specimenTypeDesignations)) {
500
    $table_row_data[] = cdm_sob_dto_table_row(
501
      NULL,
502
      render_specimen_typedesignation_dto($unit_dto->specimenTypeDesignations));
503
  }
504

    
505
  return cdm_sob_dto_table(t('Type designations'), $table_row_data, $unit_dto, 5, 2);
506
}
507

    
508
/**
509
 * @param $listOfMedia
510
 * @param $sob_dto
511
 * @param $heading
512
 *
513
 * @return array|null
514
 */
515
function cdm_sob_dto_media_table(array $listOfMedia, $sob_dto, $heading) {
516
  $table_row_data = [];
517
  $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
518
  $captionElements = array(
519
    'title',
520
    '#uri' => t('open media'),
521
  );
522
  $gallery_markup = compose_cdm_media_gallerie(array(
523
    'mediaList' => $listOfMedia,
524
    'galleryName' => $sob_dto->uuid,
525
    'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
526
    'cols' => $gallery_settings['cdm_dataportal_media_cols'],
527
    'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
528
    'captionElements' => $captionElements,
529
    'mediaLinkType' => 'LIGHTBOX',
530
    'alternativeMediaUri' => NULL,
531
    'galleryLinkUri' => NULL,
532
    'showCaption' => true
533
  ));
534
  $table_row_data[] = cdm_sob_dto_table_row(NULL, $gallery_markup);
535
  $grid_col_span = count($listOfMedia) > 1 ? 2 : NULL;
536
  return cdm_sob_dto_table(t($heading), $table_row_data, $sob_dto, 20, $grid_col_span);
537
}
538

    
539
/**
540
 * Compose an render array from the DerivedUnitDTO.sequences.
541
 *
542
 * The resulting DOM block level element will have a header line and details.
543
 *
544
 * compose_hook() implementation
545
 *
546
 * @param object $unit_dto
547
 *   the CDM DerivedUnitDTO
548
 * @param bool $compact_mode
549
 *   Currently unused,
550
 *
551
 * @return array
552
 *  The render array for the DerivedUnitDTO.sequences.
553
 *
554
 * @ingroup compose
555
 *
556
 * TODO see  #3347 (services and REST service controller for molecular classes implemented)
557
 */
558
function compose_cdm_derived_unit_dto_sequences($unit_dto, $compact_mode = FALSE) {
559

    
560
  $table_row_data = [];
561
  if(isset_not_empty($unit_dto->sequences)){
562
    foreach ($unit_dto->sequences as $sequence) {
563
      if (isset($sequence->geneticAccessionNumber)) {
564
        $table_row_data[] = cdm_sob_dto_table_row(
565
          cdm_occurrence_field_name_label('geneticAccessionNumber'),
566
          $sequence->geneticAccessionNumber);
567
      }
568
      // TODO ....
569
    }
570
  }
571

    
572
  return cdm_sob_dto_table(t('Storage'), $table_row_data, $unit_dto, 1);
573
}
574

    
575
/**
576
 * Creates a form array for showing details of SpecimenOrObservationDTO in a
577
 * tabular form with heading.
578
 *
579
 * @param $table_heading
580
 * @param array $table_row_data
581
 * @param $sob_dto
582
 * @param $weight
583
 *  The weight determining the order of the drupal render element
584
 * @param $grid_col_span
585
 *  The number of grid colums the table should
586
 *
587
 * @return array|null
588
 */
589
function cdm_sob_dto_table($table_heading, array $table_row_data, $sob_dto, $weight = NULL, $grid_col_span = 1) {
590

    
591
  if (count($table_row_data) > 0) {
592
    $wrapper_style = '';
593
    if($grid_col_span > 1){
594
      $wrapper_style = ' style="grid-column-start: span ' . $grid_col_span. ';"';
595
    }
596
    $sob_table = [
597
      '#theme' => 'table',
598
      '#prefix' => '<div class="table-wrapper"' . $wrapper_style . '>',
599
      '#suffix' => '</div>',
600
      '#header' => [
601
        [
602
          'data' => $table_heading,
603
          'colspan' => 2,
604
        ],
605
      ],
606
      "#rows" => $table_row_data,
607
      "#attributes" => [
608
        "class" => [
609
          'specimen-or-observation-details',
610
          html_class_attribute_ref($sob_dto)
611
        ],
612
      ],
613
    ];
614
    if ($weight) {
615
      $sob_table['#weight'] = $weight;
616
    }
617
    return $sob_table;
618
  }
619
  return NULL;
620
}
621

    
622
function cdm_sob_dto_table_row($label, $value) {
623
  if ($value) {
624
    if($label) {
625
      return [
626
        'data' => [
627
          [
628
            'data' => str_replace(':', '', $label),
629
            'class' => [
630
              'label',
631
            ],
632
          ],
633
          $value,
634
        ],
635
        'no_striping' => TRUE,
636
      ];
637
    } else {
638
      // value spanning two columns
639
      return [
640
        'data' => [
641
          [
642
            'data' => $value,
643
            'colspan' => 2,
644
          ]
645
        ],
646
        'no_striping' => TRUE,
647
      ];
648
    }
649
  }
650
  return NULL;
651
}
(9-9/15)