Project

General

Profile

Download (75.2 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/**
3
 * @file
4
 * Functions for dealing with CDM entities of type SpecimenOrOccurrences
5
 *
6
 * @copyright
7
 *   (C) 2007-2012 EDIT
8
 *   European Distributed Institute of Taxonomy
9
 *   http://www.e-taxonomy.eu
10
 *
11
 *   The contents of this module are subject to the Mozilla
12
 *   Public License Version 1.1.
13
 * @see http://www.mozilla.org/MPL/MPL-1.1.html
14
 *
15
 * @author
16
 *   - Andreas Kohlbecker <a.kohlbecker@BGBM.org>
17
 */
18

    
19

    
20
/**
21
 * Provides the HTML markup for a specimen page
22
 *
23
 * @param $specimen
24
 *
25
 * @return string
26
 *  The markup for a specimen page
27
 */
28
function render_cdm_specimen_page($specimen)
29
{
30

    
31
    $specimen_details = compose_cdm_specimen_or_observation($specimen, true);
32
    //$detail_html .= drupal_render($specimen_details);
33

    
34
    $specimen->_fieldObjectMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array(
35
        $specimen->uuid,
36
        'fieldObjectMediaDTO',
37
    ));
38
    $specimen->_derivedUnitMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array(
39
        $specimen->uuid,
40
        'derivedUnitMedia',
41
    ));
42
    $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
43
    $captionElements = array(
44
        'title',
45
        '#uri' => t('open media'),
46
    );
47
    if (isset($specimen->fieldObjectMediaDTO) ) {
48
        $gallery_html = compose_cdm_media_gallerie(array(
49
            'mediaList' => $specimen->fieldObjectMediaDTO,
50
            'galleryName' => $specimen->titleCache,
51
            'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
52
            'cols' => $gallery_settings['cdm_dataportal_media_cols'],
53
            'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
54
            'captionElements' => $captionElements,
55
            'mediaLinkType' => 'LIGHTBOX',
56
            'alternativeMediaUri' => NULL,
57
            'galleryLinkUri' => NULL,
58
        ));
59
        $specimen_details[] = markup_to_render_array($gallery_html);
60
    }
61

    
62
    if (isset($specimen->_derivedUnitMedia) ) {
63
        $gallery_html = compose_cdm_media_gallerie(array(
64
            'mediaList' => $specimen->_derivedUnitMedia,
65
            'galleryName' => $specimen->titleCache,
66
            'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
67
            'cols' => $gallery_settings['cdm_dataportal_media_cols'],
68
            'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
69
            'captionElements' => $captionElements,
70
            'mediaLinkType' => 'LIGHTBOX',
71
            'alternativeMediaUri' => NULL,
72
            'galleryLinkUri' => NULL,
73
        ));
74
        $specimen_details[] = markup_to_render_array($gallery_html);
75
    }
76

    
77
    $specimen_array = $specimen_details;
78
    $output = "";
79
    foreach($specimen_array as $value){
80
        $renderArray = array(
81
            '#theme' => 'item_list',
82
            '#items' => array($value),
83
            '#type' => 'ul');
84
        $output .= drupal_render($renderArray);
85
    }
86

    
87

    
88
    return $output;
89
}
90

    
91

    
92
/**
93
 * Provides the HTML markup for a specimen page
94
 *
95
 * @param $specimen
96
 *
97
 * @return string
98
 *  The markup for a specimen page
99
 */
100
function render_cdm_specimenDTO_page($specimen, $is_specimen_page = false)
101
{
102
    $detail_html = "";
103
    //link to specimen page
104
    $pathToSpecimen = path_to_specimen($specimen->uuid);
105
    if (!$is_specimen_page) {
106
        $specimenPageLink = l($specimen->accessionNumber, $pathToSpecimen);
107
        $detail_html .= "<strong>Specimen summary: $specimenPageLink</strong><br>";
108
    }
109

    
110

    
111
    if($is_specimen_page) {
112
        if($specimen->citation){
113
            $detail_html .= "<br>".$specimen->citation."<br>";
114

    
115
        }
116
    }
117
    if ($specimen->preferredStableUri) {
118
        $stableIdentifierLink = l($specimen->preferredStableUri, $specimen->preferredStableUri);
119
        $detail_html .= create_label("Preferred stable URI") . $stableIdentifierLink . "<br>";
120
    }
121
    if ($is_specimen_page) {
122
        // associated taxa
123
        if ($specimen->associatedTaxa) {
124
            $detail_html .= "<br>";
125
            $detail_html .= create_label("Associated with");
126
            if (sizeof($specimen->associatedTaxa) > 1) {
127
                $detail_html .= "<br>";
128
            }
129
            foreach ($specimen->associatedTaxa as $associatedTaxon) {
130
                $detail_html .= l($associatedTaxon->value, path_to_taxon($associatedTaxon->key, "specimens"));//$associatedTaxon->second."<br>";
131
            }
132
            $detail_html .= "<br>";
133
        }
134
    }
135
    // - type information
136
    $types = "";
137
    if (isset($specimen->types)) {
138
        //typed taxa
139
        foreach ($specimen->types as $typeStatus => $typedTaxa) {
140
            if($specimen->types){
141
                if(empty($typeStatus) || $typeStatus == "_empty_"|| $typeStatus == ""){
142
                    $detail_html .= "<i>Type for:</i> ";
143
                } else {
144
                    $detail_html .= "<i>".$typeStatus."</i> of ";
145
                }
146
                foreach($typedTaxa as $typedTaxon){
147
                    $detail_html .= $typedTaxon." ";
148

    
149
                }
150
            } else {
151
                $types .= $typeStatus . " ";
152

    
153
            }
154
        }
155
    }
156
    $derivateDataDTO = $specimen->derivateDataDTO;
157
    // - specimen scans
158
    $specimenScans = create_html_links($derivateDataDTO->specimenScans, true);
159
    // - molecular data
160
    $molecularData = "";
161
    if ($derivateDataDTO->molecularDataList) {
162
        foreach ($derivateDataDTO->molecularDataList as $molecular) {
163
            //provider link
164
            if (isset($molecular->providerLink)) {
165
                $molecularData .= create_html_link($molecular->providerLink, true);
166
            } else {
167
                $molecularData .= "[no provider]";
168
            }
169
            //contig link
170
            if (isset($molecular->contigFiles)) {
171
                $molecularData .= "[";
172
                if (sizeof($molecular->contigFiles) > 0) {
173
                    foreach ($molecular->contigFiles as $contigFile) {
174
                        if (isset($contigFile->contigLink)) {
175
                            if (isset($contigFile->contigLink->uri) and $contigFile->contigLink->uri != null) {
176
                                $molecularData .= create_html_link($contigFile->contigLink, true) . " ";
177
                            }
178
                        } else {
179
                            $molecularData .= "no contig ";
180
                        }
181
                        //primer links
182
                        if (isset($contigFile->primerLinks)) {
183
                            $molecularData .= create_html_links($contigFile->primerLinks, true);
184
                        }
185
                    }
186
                }
187
                $molecularData = rtrim($molecularData, " ");
188
                $molecularData .= "]";
189
            }
190
            //FIXME separate with comma (remove trailing comma)
191
        }
192
    }
193
    // - detail images
194
    $detailImages = create_html_links($derivateDataDTO->detailImages, true);
195

    
196
    if ($types) {
197
        $detail_html .= $is_specimen_page ? "<br>" : "";
198
        $detail_html .= create_label("Type(s)") . $types . "<br>";
199
    }
200
    if ($specimenScans and !$is_specimen_page) {
201
        $detail_html .= create_label("Specimen Scans") . $specimenScans . "<br>";
202
    }
203
    //specimen scan image gallery
204
    if ($is_specimen_page and isset($derivateDataDTO->specimenScanUuids) and !empty($derivateDataDTO->specimenScanUuids)) {
205
        $detail_html .= addImageGallery("Specimen scans", $derivateDataDTO->specimenScanUuids);
206
    }
207

    
208
    if ($molecularData) {
209
        $detail_html .= $is_specimen_page ? "<br>" : "";
210
        $detail_html .= create_label("Molecular Data") . $molecularData . "<br>";
211
    }
212

    
213
    if ($detailImages and !$is_specimen_page) {
214
        $detail_html .= create_label("Detail Images") . $detailImages . "<br>";
215
    }
216

    
217
    //detail image gallery
218
    if ($is_specimen_page and isset($derivateDataDTO->detailImageUuids) and !empty($derivateDataDTO->detailImageUuids)) {
219
        $detail_html .= addImageGallery("Detail Images", $derivateDataDTO->detailImageUuids);
220
    }
221

    
222
    //character data
223
    if ($specimen->characterData) {
224
        $detail_html .= $is_specimen_page ? "<br>" : "";
225
        $detail_html .= create_label("Character Data");
226
        if ($is_specimen_page) {
227
            $detail_html .= "<br>";
228
            foreach ($specimen->characterData as $characterStatePair) {
229
                $detail_html .= "<i>" . $characterStatePair->first . "</i>:" . $characterStatePair->second;
230
                $detail_html .= "<br>";
231
            }
232
        } else {
233
            $detail_html .= l("detail page", $pathToSpecimen);
234
            $detail_html .= "<br>";
235
        }
236
    }
237
    return $detail_html;
238
}
239

    
240
function addImageGallery($galleryName, $imageUuids)
241
{
242
    $images = array();
243
    foreach ($imageUuids as $uuid) {
244
        $images[] = cdm_ws_get(CDM_WS_PORTAL_MEDIA, $uuid);
245
    }
246

    
247
    $gallery_html = '';
248
    if (count($imageUuids) > 0) {
249
        $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
250
        $captionElements = array(
251
            'title',
252
            'rights',
253
        );
254
        $alternativeMediaUris = array();
255
        foreach ($images as $image) {
256
            $mediaUri = getMediaUri($image);
257
            if ($mediaUri) {
258
                $alternativeMediaUris[] = $mediaUri;
259
            } else {
260
                $alternativeMediaUris[] = path_to_media($image->uuid);
261
            }
262
        }
263

    
264

    
265

    
266
        $gallery_html = compose_cdm_media_gallerie(array(
267
            'mediaList' => $images,
268
            'galleryName' => $galleryName,
269
            'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
270
            'cols' => $gallery_settings['cdm_dataportal_media_cols'],
271
            'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
272
            'captionElements' => $captionElements,
273
            'mediaLinkType' => 'LIGHTBOX',
274
          // 'alternativeMediaUri' => $alternativeMediaUris,
275
            'alternativeMediaUri' => NULL,
276
            'galleryLinkUri' => NULL,
277
        ));
278
    }
279
    return "<br>" . create_label($galleryName) . "<br>" . $gallery_html;
280
}
281

    
282
function getMediaUri($media)
283
{
284
    if (isset($media->representations) && sizeof($media->representations) == 1
285
        && isset($media->representations[0]->parts) &&
286
        sizeof($media->representations[0]->parts) == 1) {
287
        return $media->representations[0]->parts[0]->uri;
288
    }
289
    return null;
290
}
291

    
292

    
293
/**
294
 * Formats the given string to a label for displaying key-object pairs in HTML
295
 * @return string
296
 */
297
function create_label($label)
298
{
299
    return "<span class='specimen_table_label'>" . $label . ": </span>";
300
}
301

    
302
/**
303
 * Compose an render array from a CDM DerivedUnitFacade object.
304
 *
305
 * compose_hook() implementation
306
 *
307
 * @param object $specimenOrObservation
308
 *   the CDM instance of type SpecimenOrObservation to compose
309
 *   the render array for
310
 * @param array $derivatives
311
 *   the render array which contains the compositions of the derivatives
312
 *   of the supplied $specimenOrObservation
313
 *
314
 * @return array
315
 *   the supplied render array $derivatives to which the composition of the supplied
316
 *   $specimenOrObservation has been added to
317
 *
318
 * @ingroup compose
319
 */
320

    
321
function compose_cdm_specimen_or_observation($specimen_or_observation, $isSpecimen_page = false, &$derivatives = null)
322
{
323
    $exclude_occurrence_fields = &drupal_static(__FUNCTION__);
324
    if (!isset($exclude_occurrence_fields)) {
325
        $exclude_occurrence_fields = array(
326

    
327
            'titleCache',
328
            'protectedTitleCache',
329
            'derivedUnitMedia',
330
            'created',
331
            'publish',
332
            'updated',
333
            'class',
334
            'uuid',
335
            ''
336
        );
337
    }
338
    if (variable_get('cdm_dataportal_compressed_specimen_derivate_table') || !$isSpecimen_page){
339
        $exclude_occurrence_fields[] = 'derivationEvents';
340
    }
341

    
342

    
343
    // only show uuid it the user is logged in
344
 //   if(user_is_logged_in() && ($a_idx = array_search('uuid', $exclude_occurrence_fields)) !== FALSE ) {
345
  //      unset($exclude_occurrence_fields[$a_idx]);
346
  //  }
347

    
348
    if (!isset($derivatives)) {
349
        $derivatives = array();
350
    }
351

    
352
    $descriptions = null;
353
    $derivedFrom = null;
354

    
355

    
356

    
357
    if (is_object($specimen_or_observation)) {
358

    
359
        // request again for deeper initialization
360
        $specimen_or_observation = cdm_ws_get("portal/" . CDM_WS_OCCURRENCE, $specimen_or_observation->uuid);
361
        if ($specimen_or_observation->class == 'FieldUnit'){
362
            // WARNING: adding a List<MediaDTO> as $specimen_or_observation->_derivedUnitMedia
363
            $specimen_or_observation->_derivedUnitMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array(
364
                $specimen_or_observation->uuid,
365
                'fieldObjectMediaDTO',
366
            ));
367
        }else{
368
            // WARNING: adding a List<Media> as $specimen_or_observation->_derivedUnitMedia
369
            $specimen_or_observation->_derivedUnitMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array(
370
                $specimen_or_observation->uuid,
371
                'derivedUnitMedia',
372
            ));
373
        }
374

    
375
        $type_label = $specimen_or_observation->class;
376
        RenderHints::setFootnoteListKey($type_label . '-' . $specimen_or_observation->uuid);
377

    
378
        // collect typeStatus as label
379
        if (isset($specimen_or_observation->specimenTypeDesignations)) {
380
            $type_status = array();
381
            foreach ($specimen_or_observation->specimenTypeDesignations as $typeDesignation) {
382
                if (isset($typeDesignation->typeStatus->representation_L10n)) {
383
                    $type_status[] = $typeDesignation->typeStatus->representation_L10n;
384
                }
385
            }
386
            if (count($type_status) > 0) {
387
                $type_label = implode(', ', $type_status);
388
            }
389
        }
390

    
391
        $title = $type_label . ': ' . $specimen_or_observation->titleCache;
392

    
393
        $groups = array();
394

    
395
        // --- add initialized fields
396
        foreach (get_object_vars($specimen_or_observation) as $field => $value) {
397
            if (!in_array($field, $exclude_occurrence_fields) && ($value && (!is_object($value) || isset($value->class)))) {
398
                switch ($field) {
399

    
400
                    /* ---- java.lang.Object --- */
401
                    case 'class':
402
                        if ($value != '' /* FieldUnit' */) {
403
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value);
404
                        }
405
                        break;
406

    
407
                    case 'markers':
408
                        $dd_elements = array();
409
                        foreach ($value as $marker) {
410
                            $dd_elements[] = compose_cdm_marker($marker);
411
                        }
412
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
413
                        break;
414

    
415

    
416
                    case 'annotations':
417
                        $dd_elements = array();
418
                        foreach ($value as $annotation) {
419
                            // TODO respect annotation type filter settings
420
                            $dd_elements[] = $annotation->text;
421
                        }
422
                        @_description_list_group_add($groups, t('Notes:'), $dd_elements);
423
                        break;
424

    
425
                    /* ---- SpecimenOrObservationBase --- */
426
                    case 'sex':
427
                    case 'lifeStage':
428
                    case 'kindOfUnit':
429
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value->representation_L10n);
430
                        break;
431

    
432
                    case 'definition':
433
                        // TODO
434
                        break;
435

    
436
                    case 'preferredStableUri':
437

    
438
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), array(array('#markup' => cdm_external_uri($value, false))));
439
                        break;
440

    
441
                    case 'specimenTypeDesignations':
442

    
443
                        //TODO: better display of details!!
444
                        @_description_list_group_add(
445
                            $groups,
446
                            cdm_occurrence_field_name_label($field),
447
                            array(
448
                                '#markup' => render_type_designations($value),
449
                            )
450
                        );
451
                        break;
452

    
453
                    case 'determinations':
454
                        $dd_elements = array();
455
                        $glue = ', ';
456

    
457
                        foreach ($value as $determinationEvent) {
458
                            $timeperiod_string = NULL;
459
                            if (isset($determinationEvent->timeperiod)) {
460
                                $timeperiod_string = timePeriodToString($determinationEvent->timeperiod);
461
                            }
462
                            $weight = isset($determinationEvent->preferred) && $determinationEvent->preferred == 1 ? '0' : ($timeperiod_string ? $timeperiod_string : '1');
463
                            // check key exists
464
                            while (array_key_exists($weight, $dd_elements)) {
465
                                $weight .= '0';
466
                            }
467

    
468
                            $taxon_name = '';
469
                            $name_link = '';
470
                            if ($determinationEvent->taxonName) {
471
                                $taxon_name = cdm_ws_get(CDM_WS_NAME, $determinationEvent->taxonName->uuid);
472
                                $taxon_name->taggedName = cdm_ws_get(CDM_WS_NAME, array($determinationEvent->taxonName->uuid, "taggedName"));
473
                                $name_link = path_to_name($determinationEvent->taxonName->uuid);
474
                            } else if ($determinationEvent->taxon) {
475
                                $taxon_name = cdm_ws_get(CDM_WS_TAXON . '/$0/name', $determinationEvent->taxon->uuid);
476
                                $name_link = path_to_taxon($determinationEvent->taxon->uuid);
477
                            }
478
                            if ($taxon_name) {
479
                                //$taxon_html = render_taxon_or_name($taxon_name, $name_link);
480

    
481
                                $taxon_html = l($taxon_name->titleCache, $name_link);
482
                                $dd_elements[$weight] = $taxon_html;
483
                            }
484
                            if (isset($determinationEvent->modifier)) {
485
                                $dd_elements[$weight] .= cdm_term_representation($determinationEvent->modifier);
486
                            }
487
                            if ($timeperiod_string) {
488
                                $dd_elements[$weight] .= $glue . $timeperiod_string;
489
                            }
490
                            if (isset($determinationEvent->actor->titleCache)) {
491
                                $dd_elements[$weight] .= $glue . $determinationEvent->actor->titleCache;
492
                            }
493
                            if (isset($determinationEvent->description)) {
494
                                $dd_elements[$weight] .= $glue . $determinationEvent->description;
495
                            }
496
                        }
497
                        ksort($dd_elements);
498
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('determinations'), $dd_elements);
499
                        break;
500

    
501
                    case 'descriptions':
502
                        $dd_elements = array();
503
                        foreach ($value as $description) {
504
                            $description = cdm_ws_get(CDM_WS_PORTAL_DESCRIPTION, $description->uuid);
505

    
506
                            if ($description->imageGallery == TRUE) {
507
                                continue;
508
                            }
509
                            $description_string = render_description_string(get_root_nodes_for_dataset($description));
510
                            $dd_elements[] = markup_to_render_array($description_string);
511
                        }
512
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
513
                        break;
514
                    case '_derivedUnitMedia':
515
                        if ($isSpecimen_page) {
516
                            $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
517
                            $captionElements = array(
518
                                '#uri' => t('open media'),
519
                            );
520
                            $gallery_html = compose_cdm_media_gallerie(array(
521
                                'mediaList' => $value, // WARNING: this is either a List<Media> or List<MediaDTO>, see above ~line 361
522
                                'galleryName' => $specimen_or_observation->titleCache,
523
                                'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
524
                                'cols' => $gallery_settings['cdm_dataportal_media_cols'],
525
                                'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
526
                                'captionElements' => $captionElements,
527
                                'mediaLinkType' => 'LIGHTBOX',
528
                                'alternativeMediaUri' => NULL,
529
                                'galleryLinkUri' => NULL,
530
                            ));
531
                            @_description_list_group_add($groups, "Detail Images:", markup_to_render_array($gallery_html), '', 20);
532
                        }
533

    
534
                        // $dd_elements[] = markup_to_render_array($gallery_html);
535

    
536
                        break;
537
                    case 'sources':
538
                        $annotations_and_sources = handle_annotations_and_sources(
539
                            $specimen_or_observation,
540
                            array(
541
                                'sources_as_content' => true,
542
                                'link_to_name_used_in_source' => 1,
543
                                'link_to_reference' => 0,
544
                                'add_footnote_keys' => 0
545
                            ),
546
                            NULL,
547
                            RenderHints::getFootnoteListKey()
548
                        );
549
                        if (!empty($annotations_and_sources['source_references'])) {
550
                            @_description_list_group_add($groups, t('Sources') . ':', join(', ', $annotations_and_sources['source_references']), '', 12);
551
                        }
552
                        break;
553

    
554

    
555
                    /* ---- DerivedUnitBase --- */
556
                    case 'derivedFrom':
557
                        $derivedFrom = $value;
558
                        if ($isSpecimen_page) {
559
                            foreach ($derivedFrom->originals as $original) {
560
                                $pathToSpecimen = path_to_specimen($original->uuid);
561
                                $description = "";
562
                                if (isset($derivedFrom->description) && $derivedFrom->description != '') {
563
                                    $description = $derivedFrom->description . ": ";
564
                                }
565

    
566
                                $originals[] = markup_to_render_array(l($description . $original->titleCache, $pathToSpecimen));
567
                                if ($original->class == 'FieldUnit') {
568
                                    $label = t('Field data');
569
                                } else {
570
                                    $label = t('Derived from');
571
                                }
572
                                @_description_list_group_add($groups, $label . ':',
573
                                    $originals,
574
                                    '', 13);
575
                            }
576
                        }
577
                        break;
578
                    case 'derivationEvents':
579
                        $derivationEvents = $value;
580
                        $derived_units = array();
581
                        if ($isSpecimen_page) {
582
                            foreach ($derivationEvents as $derivationEvent) {
583
                                foreach ($derivationEvent->derivatives as $derived_unit) {
584
                                    $pathToSpecimen = path_to_specimen($derived_unit->uuid);
585
                                    $description = "";
586
                                    if (isset($derived_unit->description) && $derived_unit->description != '') {
587
                                        $description = $derived_unit->description . ": ";
588
                                    }
589

    
590
                                    $derived_units[] = markup_to_render_array(l($description . $derived_unit->titleCache, $pathToSpecimen));
591
                                }
592
                            }
593
                            @_description_list_group_add($groups, t('Derivates') . ':',
594
                                $derived_units,
595
                                '', 100);
596

    
597
                        }
598
                        break;
599

    
600
                    case 'collection':
601
                        $sub_dl_groups = array();
602
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('code'), $value->code, NULL, 1);
603
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('codeStandard'), $value->codeStandard, NULL, 2);
604
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('institute'), $value->institute, NULL, 3);
605
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('townOrLocation'), $value->townOrLocation, NULL, 4);
606
                        // TODO "superCollection"
607
                        // TODO may have media
608

    
609
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),
610
                            array(
611
                                array('#markup' => $value->titleCache),
612
                                array('#theme' => 'description_list', '#groups' => $sub_dl_groups)
613
                            )
614
                        );
615
                        break;
616

    
617
                    case 'storedUnder':
618
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('storedUnder'), render_taxon_or_name($value));
619
                        break;
620
                    case 'dnaQuality':
621
                        $sub_dl_groups = array();
622

    
623
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('purificationMethod'), $value->purificationMethod, NULL, 1);
624
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('ratioOfAbsorbance260_230'), $value->ratioOfAbsorbance260_230, NULL, 2);
625
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('ratioOfAbsorbance260_280'), $value->ratioOfAbsorbance260_280, NULL, 3);
626
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('concentration'), $value->concentration, NULL, 4);
627
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('concentrationUnit'), $value->concentrationUnit, NULL, 4);
628
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('qualityTerm'), $value->qualityTerm, NULL, 4);
629
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('qualityCheckDate'), $value->qualityCheckDate, NULL, 4);
630

    
631
                        if (is_array($sub_dl_groups) && sizeof($sub_dl_groups)>0) {
632
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),
633
                                array(
634
                                    array('#markup' => $value->titleCache),
635
                                    array('#theme' => 'description_list', '#groups' => $sub_dl_groups)
636
                                )
637
                            );
638
                        }
639
                        break;
640

    
641
                    case 'preservation':
642
                        $sub_dl_groups = array();
643

    
644
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('medium'), $value->medium, NULL, 1);
645
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('temperature'), $value->temperature, NULL, 2);
646
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('definedMaterialOrMethod'), $value->definedMaterialOrMethod, NULL, 3);
647

    
648
                        if (is_array($sub_dl_groups) && sizeof($sub_dl_groups)>0) {
649
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),
650
                                array(
651
                                    array('#markup' => $value->titleCache),
652
                                    array('#theme' => 'description_list', '#groups' => $sub_dl_groups)
653
                                )
654
                            );
655
                        }
656
                        break;
657

    
658
                    /* ---- Specimen --- */
659
                    case 'sequences':
660
                        $dd_elements = array();
661
                        foreach ($value as $sequence) {
662
                            $dd_elements[] = compose_cdm_sequence($sequence);
663
                        }
664
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
665
                        break;
666

    
667
                    // TODO preservation
668
                    // TODO exsiccatum
669

    
670

    
671
                    /* ---- FieldObservation --- */
672
                    case 'gatheringEvent':
673
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collector'), $value->actor->titleCache, '', 1);
674
                        @_description_list_group_add($groups, t('Gathering date'), timePeriodToString($value->timeperiod), '', 2);
675
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('description'), $value->description, '', 3);
676
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('locality'), $value->locality->text, '', 10);
677
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('country'), $value->country->representation_L10n, '', 4);
678
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingMethod'), $value->collectingMethod,'',5);
679
                        if (isset($value->absoluteElevation)) {
680
                            $min_max_markup = statistical_values_from_gathering_event($value, 'absoluteElevation');
681
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('absoluteElevation'), $min_max_markup, '',6);
682
                        }
683
                        if (isset($value->distanceToGround)) {
684
                            $min_max_markup = statistical_values_from_gathering_event($value, 'distanceToGround');
685
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToGround'), $min_max_markup,'',7);
686
                        }
687
                        if (isset($value->distanceToWaterSurface)) {
688
                            $min_max_markup = statistical_values_from_gathering_event($value, 'distanceToWaterSurface');
689
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToWaterSurface'), $min_max_markup, '',8);
690
                        }
691
                        if (isset($value->collectingAreas) && count($value->collectingAreas) > 0) {
692
                            $area_representations = array();
693
                            foreach ($value->collectingAreas as $area) {
694
                                $area_representations[] = l($area->representation_L10n, path_to_named_area($area->uuid));
695
                            }
696
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingAreas'),
697
                                array(
698
                                    array('#markup' => implode(', ', $area_representations))
699
                                ),'',9
700
                            );
701
                        }
702
                        if (isset($value->exactLocation) && $value->exactLocation->sexagesimalString) {
703
                            $sub_dl_groups = array();
704
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('errorRadius'), $value->exactLocation->errorRadius, ' m', 1);
705
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('longitude'), round($value->exactLocation->longitude, 7), '°', 2);
706
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('latitude'), round($value->exactLocation->latitude, 7), '°', 3);
707
                            if (isset($value->exactLocation->referenceSystem)) {
708
                                @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('referenceSystem'), $value->exactLocation->referenceSystem->representation_L10n, '', 4);
709
                            }
710

    
711
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('exactLocation'),
712
                                array(
713
                                    array('#markup' => $value->exactLocation->sexagesimalString),
714
                                    array(
715
                                        '#theme' => 'description_list',
716
                                        '#groups' => $sub_dl_groups
717
                                    ),
718
                                ),'',11
719
                            );
720
                        }
721
                        break;
722

    
723
                    default:
724
                        if (is_object($value) || is_array($value)) {
725
                            drupal_set_message("Unhandled type in compose_cdm_specimen_or_observation() for field " . $field, "warning");
726
                        } else {
727
                            if ($field == 'RecordBase' && $value == 'DnaSample') {
728
                                _description_list_group_add($groups, cdm_occurrence_field_name_label($field), 'DNA Sample');
729
                            } else {
730
                                _description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value);
731
                            }
732
                        }
733

    
734
                }
735

    
736
            }
737
        } // END of loop over $derivedUnitFacade fields
738

    
739
        // Extensions
740
        // TODO: filter by using visible_extensions_sorted()
741
        $extensions = cdm_ws_fetch_all(CDM_WS_PORTAL_OCCURRENCE . '/'  . $specimen_or_observation->uuid . '/extensions', array($specimen_or_observation->uuid));
742
        if ($extensions && count($extensions)) {
743

    
744
            $extensions_render_array = compose_extensions($extensions);
745
            @_description_list_group_add($groups, t('Extensions') . ':',
746
                $extensions_render_array,
747
                '', 100);
748
        }
749

    
750

    
751

    
752
        // template_preprocess_description_list() is not worting by weight so we do it right here
753
        uasort($groups, 'element_sort');
754

    
755
        $occurrence_elements = array(
756
           // '#title' => $title,
757
            '#theme' => 'description_list',
758
            '#groups' => $groups,
759
            '#attributes' => array('class' => html_class_attribute_ref($specimen_or_observation)),
760
        );
761

    
762
        $derivatives[] = $occurrence_elements;
763
        // all footnotes which has been assembled so far (e.g. from typeDesignations) to here
764
//       $foonote_li_elements = render_footnotes(RenderHints::getFootnoteListKey(), 'span');
765
//        if (!empty($foonote_li_elements)) {
766
//            $derivatives[] =  array(
767
//                '#markup' =>  '<div class="footnotes">' . $foonote_li_elements . '</div>',
768
//            );
769
//        }
770

    
771
        // --- recurse into originals
772
        if (!isset($derivedFrom)  && !$isSpecimen_page) {
773
            $derivedFrom = cdm_ws_get(
774
                CDM_WS_OCCURRENCE,
775
                array($specimen_or_observation->uuid, 'derivedFrom')
776
            );
777
        }
778
        if (isset($derivedFrom) && !$isSpecimen_page) {
779
            if (isset($derivedFrom->originals)) {
780
                $derived_from_label = t('derived');
781
                $preposition = t('from');
782
                if(isset($derivedFrom->type)){
783
                    $derived_from_label = $derivedFrom->type->representation_L10n;
784
                    if($derivedFrom->type->uuid == UUID_DERIVATIONEVENTTYPE_ACCESSIONING){
785
                        $preposition = t('of');
786
                    }
787
                }
788
                if (count($groups) > 0) {
789
                    // TODO  annotations
790

    
791
                    // only display the derived from information when the derivative has any element which will be diplayed
792
                    $derivatives[] = array(
793
                        '#markup' => '<div class="derived_from">' . $derived_from_label . ' ' . $preposition . ': </div>',
794
                    );
795
                }
796
                foreach ($derivedFrom->originals as $original) {
797
                    compose_cdm_specimen_or_observation($original, $isSpecimen_page, $derivatives);
798
                }
799
            }
800
        }
801

    
802

    
803

    
804

    
805
    } // END of $specimenOrObservation exists
806

    
807
    return $derivatives;
808
}
809

    
810

    
811
/**
812
 * Compose an render array from a CDM Sequence object.
813
 *
814
 * compose_hook() implementation
815
 *
816
 * @param object $sequence
817
 *   CDM instance of type Sequence
818
 * @return array
819
 *   A render array containing the fields of the supplied $sequence
820
 *
821
 * @ingroup compose
822
 */
823
function compose_cdm_sequence($sequence, $isSpecimenPage = false)
824
{
825

    
826
    $exclude_sequence_fields = &drupal_static(__FUNCTION__);
827
    if (!isset($exclude_sequence_fields)) {
828
        $exclude_sequence_fields = array(
829
            'titleCache',
830
            'protectedTitleCache',
831
            'microReference',
832
            'created',
833
            'updated',
834
            'class',
835
        );
836
    }
837

    
838
    $groups = array();
839

    
840
    // -- retrieve additional data if neesscary
841
    // TODO below call disabled since sequences are not yet supported,
842
    //      see  #3347 (services and REST service controller for molecular classes implemented)
843
    //
844
    // cdm_load_annotations($sequence);
845

    
846
    foreach (get_object_vars($sequence) as $field => $value) {
847

    
848

    
849
        if (!in_array($field, $exclude_sequence_fields) && ($value && (!is_object($value) || isset($value->class)))) {
850
            switch ($field) {
851

    
852
                case 'geneticAccessionNumber';
853

    
854
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 2);
855
                    break;
856

    
857

    
858
                case 'dnaMarker': // FIXME 3.3 now dnaMarker (DefinedTerm)  if multiple amplifications where used to build this consensus sequence it may be the super set of the markers used in amplification.
859
                    if (isset($value->name)) {
860
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value->name, NULL, 3);
861
                    }
862
                    if (isset($value->description)) {
863
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field) . ' ' . t('description'), $value->description, NULL, 4);
864
                    }
865
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field) , $value, NULL, 4);
866
                    break;
867

    
868
                case 'consensusSequence':
869
                    // format in genbank style, force linebreaks after each 70 nucleotites
870
                    // see also http://stackoverflow.com/questions/499137/css-how-can-i-force-a-long-string-without-any-blank-to-be-wrapped-in-xul-and
871
                    if ($value->length > 0) {
872
                        @_description_list_group_add(
873
                            $groups,
874
                            cdm_occurrence_field_name_label($field),
875
                            array(
876
                                array(
877
                                    '#markup' => '<div class="sequence-length">' . $value->length . ' ' . t('pb') . '</div><div>' . wordwrap($value->string, 70, '</br>', TRUE) . '</div>',
878
                                    '#wrapper_attributes' => array('class' => 'dna-sequence')
879
                                )
880
                            ),
881
                            5);
882
                    }
883
                    break;
884

    
885
                case 'dnaSample': // FIXME 3.3 implement
886
                    break;
887
                case 'singleReads': // FIXME 3.3 implement
888
                    break;
889
                case 'contigFile': // FIXME 3.3 implement - Media
890
                    break;
891
                case 'pherograms': // FIXME 3.3 implement - Media
892
                    break;
893
                case 'haplotype': // FIXME 3.3 implement
894
                    break;
895
                case 'dateSequenced': // FIXME 3.3 now in SingelRead
896
                    @_description_list_group_add($groups, t('Sequencing date'), timePeriodToString($value), NULL, 6);
897
                    break;
898

    
899
                case 'barcode': // boolean
900
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value ? 'Yes' : 'No', NULL, 7);
901
                    break;
902
                case 'barcodeSequencePart': // FIXME 3.3 implement, compose sequence
903
                    break;
904

    
905
                case 'citation':
906
                    @_description_list_group_add($groups,
907
                        cdm_occurrence_field_name_label($field),
908
                        cdm_reference_markup($value, $sequence->microReference),
909
                        NULL,
910
                        8
911
                    );
912
                    break;
913

    
914
                case 'publishedIn':
915
                    @_description_list_group_add($groups,
916
                        cdm_occurrence_field_name_label($field),
917
                        theme('cdm_reference', array('reference' => $value)),
918
                        NULL,
919
                        7
920
                    );
921
                    break;
922

    
923
                case 'rights':
924
                    array_merge($groups, cdm_rights_as_dl_groups($value));
925
                    break;
926

    
927
                case 'annotations':
928
                    $dd_elements = array();
929
                    foreach ($value as $annotation) {
930
                        // TODO respect annotation type filter settings
931
                        $dd_elements[] = $annotation->text;
932
                    }
933
                    @_description_list_group_add($groups, t('Notes'), $dd_elements, NULL, 9);
934
                    break;
935

    
936
                case 'markers':
937
                    $dd_elements = array();
938
                    foreach ($value as $marker) {
939
                        $dd_elements[] = compose_cdm_marker($marker);
940
                    }
941
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements, NULL, 10);
942
                    break;
943

    
944
                case 'chromatograms':
945
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),
946
                        array(
947
                            '#markup' => compose_cdm_media_gallerie(array('medialist' => $value)),
948
                        ),
949
                        NULL,
950
                        11);
951
                    break;
952

    
953
                default:
954
                    if (is_object($value) || is_array($value)) {
955
                        drupal_set_message("Unhandled type in compose_cdm_sequence() for field " . $field, "warning");
956
                    } else {
957
                        if (!is_array($value) && strpos($value, 'http:') !== false ){
958
                            //make links for urls
959
                            $value = l($value, $value);
960
                            $value = markup_to_render_array($value);
961
                        }
962

    
963
                       _description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 20);
964
                    }
965
            }
966
        }
967
    }
968

    
969
    // template_preprocess_description_list() is not worting by weight so we do it right here
970
    uasort($groups, 'element_sort');
971
    if ($isSpecimenPage) {
972
        $sequence_elements = array(
973
            '#title' => $sequence->dnaMarker,
974
            '#theme' => 'description_list',
975
            '#groups' => $groups
976
        );
977
    } else{
978
        $sequence_elements = array(
979
            '#title' => $sequence->dnaMarker -> titleCache,
980
            '#theme' => 'description_list',
981
            '#groups' => $groups
982
        );
983
    }
984

    
985
    return $sequence_elements;
986
}
987

    
988
/**
989
 * Crates an array which can be used in render arrays to be passed to the theme_table() and theme_list().
990
 * @param array $fieldunit_dtos
991
 *     list of FieldUnitDTOs
992
 */
993
function specimen_render_array_items(array $fieldunit_dtos){
994

    
995
  $render_array_items = array();
996
  $items = array();
997

    
998
  //we need one more item to contain the items of one level (fieldunit, derivate data etc.)
999
  foreach ($fieldunit_dtos as &$fieldunit_dto) {
1000

    
1001
    $items['data'] = $fieldunit_dto->listLabel ;
1002
    $specimen = compose_cdm_specimen_or_observation_tree_entry($fieldunit_dto);
1003
    $children = array();
1004
    $child = array();
1005
    $child['data'] =$specimen;
1006
    // $children[] = create_specimen_array($specimenOrObservation->derivates);
1007
    if (isset($fieldunit_dto->derivates) && sizeof($fieldunit_dto->derivates) > 0){
1008
      $child['children']= specimen_render_array_items($fieldunit_dto->derivates);
1009
    }
1010
    $children[]=$child;
1011
    $items['children'] = $children;
1012
    $render_array_items[] = $items;
1013
  }
1014
  return $render_array_items;
1015
}
1016

    
1017
/**
1018
 * Creates the drupal render array for the table showing all derivatives which
1019
 * stem from a common gathering event.
1020
 *
1021
 * @param $field_unit_uuids array
1022
 *  An array of uuids for cdm FieldUnit entities.
1023
 *
1024
 * @return array
1025
 *  A drupal render array for a table
1026
 *
1027
 * @ingroup compose
1028
 */
1029

    
1030
function compose_compressed_specimen_derivate_table($field_unit_uuids) {
1031

    
1032
  // prepare font icons
1033
  $expand_icon = font_awesome_icon_markup(
1034
    'fa-plus-square-o',
1035
    array(
1036
      'alt' => 'Show details',
1037
      'class' => array('expand_icon')
1038
    )
1039
  );
1040
  $collapse_icon = font_awesome_icon_markup(
1041
    'fa-minus-square-o',
1042
    array(
1043
      'alt' => 'Show details',
1044
      'class' => array('collapse_icon')
1045
    )
1046
  );
1047
  $detail_image_icon = '<img title="Detail Image" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/detail_image_derivate-16x16-32.png' . '"/>';
1048
  $checked_box_icon = '<img src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/step_done.gif' . '"/>';
1049
  $sequence_icon = '<img title="Molecular Data" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/sequence_derivate-16x16-32.png' . '"/>';
1050
  $character_data_icon = '<img title="Character Data" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/character_data_derivate-16x16-32.png' . '"/>';
1051

    
1052
  $rowcount = 0;
1053
  $rows = array();
1054

    
1055
  foreach ($field_unit_uuids as $field_unit_uuid) {
1056

    
1057
    //get derivate hierarchy for the FieldUnit
1058
    $derivateHierarchy = cdm_ws_get(CDM_WS_PORTAL_OCCURRENCE, array($field_unit_uuid, 'derivateHierarchy'));
1059
    if ($derivateHierarchy) {
1060
      //summary row
1061
      $rows[] = array(
1062
        'data' => array(
1063
          array(
1064
            'data' => $expand_icon . $collapse_icon,
1065
            'class' => array('summary_row_cell', 'summary_row_icon', 'expand_column')
1066
          ),
1067
          array(
1068
            'data' => $derivateHierarchy->country,
1069
            'class' => array('summary_row_cell')
1070
          ),
1071
          array(
1072
            'data' => $derivateHierarchy->date,
1073
            'class' => array('summary_row_cell')
1074
          ),
1075
          array(
1076
            'data' => $derivateHierarchy->collectingString,
1077
            'class' => array('summary_row_cell')
1078
          ),
1079
          @array(
1080
            'data' => $derivateHierarchy->collection,
1081
            'class' => array('summary_row_cell')
1082
          ),
1083
          array(
1084
            'data' => $derivateHierarchy->hasType ? $checked_box_icon : "",
1085
            'class' => array('summary_row_cell', 'summary_row_icon')
1086
          ),
1087
          array(
1088
            'data' => $derivateHierarchy->hasSpecimenScan ? $checked_box_icon : "",
1089
            'class' => array('summary_row_cell', 'summary_row_icon')
1090
          ),
1091
          array(
1092
            'data' => ($derivateHierarchy->hasDna ? $sequence_icon : "") . " "
1093
              . ($derivateHierarchy->hasDetailImage ? $detail_image_icon : "") . " "
1094
              . ($derivateHierarchy->hasCharacterData ? $character_data_icon : ""),
1095
            'class' => array('summary_row_cell', 'summary_row_icon')
1096
          )
1097
        ),
1098
        'id' => 'derivate_summary' . $rowcount, // summary row id
1099
        'class' => array('summary_row'),
1100
      );
1101

    
1102
      //assemble field unit details
1103
      $detail_html = "";
1104
      // - citation
1105
      if ($derivateHierarchy->citation) {
1106
        $detail_html .= create_label("Citation") . $derivateHierarchy->citation . "<br>";
1107
      }
1108
      //assemble specimen details
1109
      if ($derivateHierarchy->derivates) {
1110
        foreach ($derivateHierarchy->derivates as $preservedSpecimenDTO) {
1111
          $detail_html .= "<br>";
1112
          $detail_html .= render_cdm_specimenDTO_page($preservedSpecimenDTO);
1113
        }
1114
      }
1115
      $detail_html .= "<br>";
1116
      //detail row resp. one BIG detail cell
1117
      $rows[] = array(
1118
        'data' => array(
1119
          array(
1120
            'data' => "", //empty first column
1121
            'class' => array('expand_column')
1122
          ),
1123
          array(
1124
            'data' => $detail_html,
1125
            'colspan' => 7,
1126
          ),
1127
        ),
1128
        'id' => 'derivate_details' . $rowcount,//details row ID
1129
        'class' => array('detail_row'),
1130
      );
1131
      $rowcount++;
1132
    }
1133
  }
1134

    
1135
  $tableId = "derivate_hierarchy_table";
1136
  $derivateHierarchyTable = array(
1137
    "#theme" => "table",
1138
    "#weight" => 2,
1139
    "#header" => array(
1140
      array(
1141
        'data' => "",
1142
        'class' => array('expand_column')
1143
      ),
1144
      "Country", "Date", "Collector + collecting number", "Herbaria", "Type", "Scan", "Derivatives"),
1145
    "#rows" => $rows,
1146
    "#attributes" => array(
1147
      "id" => $tableId,
1148
      "border" => 2
1149
    )
1150
  );
1151

    
1152
  //add toggle functionality to derivate hierarchy table
1153
  drupal_add_js_rowToggle("#" . $tableId);
1154

    
1155
  return $derivateHierarchyTable;
1156
}
1157

    
1158
/**
1159
 * Creates an array from a list of FieldUnitDTOs.
1160
 *
1161
 *
1162
 * @param object $fieldunit_dtos
1163
 *   list of FieldUnitDTOs
1164
 * @return array
1165
 *   An array containing the hierarchy of the field units corresponding to the taxon
1166
 *
1167
 * @ingroup compose
1168
 */
1169
function compose_specimen_table_top_down(array $fieldunit_dtos){
1170

    
1171
  $specimen_render_array_items = specimen_render_array_items($fieldunit_dtos);
1172

    
1173
    // add icons
1174
  $expand_icon = font_awesome_icon_markup(
1175
    'fa-plus-square-o',
1176
    array(
1177
      'alt' => 'Show details',
1178
      'class' => array('expand_icon')
1179
    )
1180
  );
1181
  $collapse_icon = font_awesome_icon_markup(
1182
    'fa-minus-square-o',
1183
    array(
1184
      'alt' => 'Show details',
1185
      'class' => array('collapse_icon')
1186
    )
1187
  );
1188
  $tableId = "specimen_tree_table";
1189
  $specimen_table = array(
1190
    '#theme' => 'table',
1191
    // prefix attributes and rows with '#' to let it pass toF the theme function,
1192
    // otherwise it is handled as child render array
1193
    '#attributes' => array(
1194
      'class' => 'specimens',
1195
      'id' => $tableId
1196
    ),
1197
    '#rows' => array(),
1198
  );
1199
  $rowcount = 0;
1200
  foreach($specimen_render_array_items as $value){
1201
    $renderArray = array(
1202
      '#theme' => 'item_list',
1203
      '#items' => $value['children'],
1204
      '#type' => 'ul');
1205
    $output = drupal_render($renderArray);
1206

    
1207
    $specimen_table['#rows'][] = array(
1208
      'data' =>array(
1209
        array(
1210
          'data' => $expand_icon . $collapse_icon,
1211
          'class' => array('summary_row_cell', 'summary_row_icon', 'expand_column')
1212
        ),
1213
        $value['data']
1214
      ),
1215
      'id' => 'label' . $rowcount, // summary row id
1216
      'class' => array('summary_row'),
1217
    );
1218
    $specimen_table['#rows'][] = array(
1219
      'data' =>  array(
1220
        array(
1221
          'data' => "", //empty first column
1222
          'class' => array('expand_column')
1223
        ),
1224
        array(
1225
          'data' => $output
1226

    
1227
        )
1228
      ),
1229
      'class' =>  array('detail_row')
1230
//                'class' =>  array(
1231
//                    'descriptionElement',
1232
//                    'descriptionElement_IndividualsAssociation'
1233
      //               ),
1234
    );
1235
    $rowcount++;
1236

    
1237
  }
1238
  drupal_add_js_rowToggle("#".$tableId);
1239

    
1240
  return $specimen_table;
1241
}
1242

    
1243

    
1244
/**
1245
 * Compose an render array from a CDM DerivedUnitFacade object.
1246
 *
1247
 * compose_hook() implementation
1248
 *
1249
 * @param object $specimenOrObservation
1250
 *   the CDM instance of type SpecimenOrObservation to compose
1251
 *   the render array for
1252
 * @param array $derivatives
1253
 *   the render array which contains the compositions of the derivatives
1254
 *   of the supplied $specimenOrObservation
1255
 *
1256
 * @return array
1257
 *   the supplied render array $derivatives to which the composition of the supplied
1258
 *   $specimenOrObservation has been added to
1259
 *
1260
 * @ingroup compose
1261
 */
1262

    
1263
function compose_cdm_specimen_or_observation_tree_entry($specimen_or_observation)
1264
{
1265
    $exclude_occurrence_fields = &drupal_static(__FUNCTION__);
1266
    if (!isset($exclude_occurrence_fields)) {
1267
        $exclude_occurrence_fields = array(
1268
            'type',
1269
            'taxonRelatedDerivedUnits',
1270
            'label',
1271
            'titleCache',
1272
            'listLabel',
1273
            'protectedTitleCache',
1274
            'class',
1275
            'uuid',
1276
            'derivates',
1277
            'collection'
1278
        );
1279
    }
1280
    $items = array();
1281

    
1282
    // only show uuid it the user is logged in
1283
    if (user_is_logged_in() && ($a_idx = array_search('uuid', $exclude_occurrence_fields)) !== FALSE) {
1284
      //  unset($exclude_occurrence_fields[$a_idx]);
1285
    }
1286

    
1287

    
1288
    if (is_object($specimen_or_observation)) {
1289

    
1290
        $type_label = $specimen_or_observation->recordBase;
1291
        RenderHints::setFootnoteListKey($type_label . '-' . $specimen_or_observation->uuid);
1292

    
1293
        // collect typeStatus as label
1294
        if (isset($specimen_or_observation->specimenTypeDesignations)) {
1295
            $type_status = array();
1296
            foreach ($specimen_or_observation->specimenTypeDesignations as $typeDesignation) {
1297
                if (isset($typeDesignation->typeStatus->representation_L10n)) {
1298
                    $type_status[] = $typeDesignation->typeStatus->representation_L10n;
1299
                }
1300
            }
1301
            if (count($type_status) > 0) {
1302
                $type_label = implode(', ', $type_status);
1303
          }
1304
        }
1305

    
1306
        if (isset($typeDesignation->typifiedNames)){
1307
            $title = $type_label . ' for: ' . $typeDesignation->typifiedNames;
1308
        }else{
1309
            $title = $type_label;
1310
        }
1311

    
1312
        $items['data'] = $title;
1313

    
1314
        $groups = array();
1315
        $items['children'] = $groups;
1316
        $children_items = array();
1317
        // --- add initialized fields
1318
        foreach (get_object_vars($specimen_or_observation) as $field => $value) {
1319
            $child_item = array();
1320

    
1321
            if (!in_array($field, $exclude_occurrence_fields) && ($value && (!is_object($value) || isset($value->class)))) {
1322
                switch ($field) {
1323

    
1324
                    /* ---- SpecimenOrObservationBase --- */
1325
                    case 'derivationEvent':
1326
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 1);
1327
                        break;
1328
                    case 'kindOfUnit':
1329
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 1);
1330
                        break;
1331
                    case 'accessionNumber':
1332
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 0);
1333
                        break;
1334

    
1335
                    case 'preferredStableUri':
1336

    
1337
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), array(array('#markup' => cdm_external_uri($value, false))));
1338
                        break;
1339

    
1340
                    case 'specimenTypeDesignations':
1341
                        @_description_list_group_add(
1342
                            $groups,
1343
                            cdm_occurrence_field_name_label($field),
1344
                            array(
1345
                                '#markup' => render_type_designations($value),
1346
                            )
1347
                        );
1348
                        break;
1349

    
1350

    
1351

    
1352
                    case 'listOfMedia':
1353
                        $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
1354

    
1355
                        $captionElements = array(
1356
                            'title',
1357
                            '#uri' => t('open media'),
1358
                        );
1359
                        $gallery_html = compose_cdm_media_gallerie(array(
1360
                            'mediaList' => $value,
1361
                            'galleryName' => $specimen_or_observation->uuid,
1362
                            'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
1363
                            'cols' => $gallery_settings['cdm_dataportal_media_cols'],
1364
                            'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
1365
                            'captionElements' => $captionElements,
1366
                            'mediaLinkType' => 'LIGHTBOX',
1367
                            'alternativeMediaUri' => NULL,
1368
                            'galleryLinkUri' => NULL,
1369
                            'showCaption' => true
1370
                        ));
1371

    
1372
                         //@_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $gallery_html);
1373
                         break;
1374

    
1375

    
1376

    
1377
                    /* ---- DerivedUnitBase --- */
1378

    
1379

    
1380
                    case 'collectionDTO':
1381

    
1382
                        $sub_dl_groups = array();
1383
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('code'), $value->code, NULL, 1);
1384
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('codeStandard'), $value->codeStandard, NULL, 2);
1385
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('institute'), $value->institute, NULL, 3);
1386
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('townOrLocation'), $value->townOrLocation, NULL, 4);
1387
                        // TODO "superCollection"
1388
                        // TODO may have media
1389

    
1390
                        @_description_list_group_add($groups, 'Collection',
1391
                            array(
1392
                                array('#markup' => $value->titleCache),
1393
                                array('#theme' => 'description_list', '#groups' => $sub_dl_groups)
1394
                            )
1395
                        );
1396

    
1397
                        break;
1398

    
1399

    
1400

    
1401

    
1402
                    /* ---- Specimen --- */
1403
                    case 'sequences':
1404
                        $dd_elements = array();
1405
                        foreach ($value as $sequence) {
1406
                            $dd_elements[] = compose_cdm_sequence($sequence, true);
1407
                            $dd_elements[] = "";
1408
                        }
1409
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements,'', 100);
1410
                        break;
1411

    
1412
                    // TODO preservation
1413
                    // TODO exsiccatum
1414

    
1415

    
1416
                    /* ---- FieldObservation --- */
1417
                    case 'gatheringEvent':
1418

    
1419
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collector'), $value->collector);
1420
                        @_description_list_group_add($groups, t('Gathering date'), timePeriodToString($value->timeperiod));
1421
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('description'), $value->description);
1422
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('locality'), $value->locality, '', 10);
1423
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('country'), $value->country);
1424
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingMethod'), $value->collectingMethod);
1425
                        if (isset($value->absoluteElevation)) {
1426
                            $min_max_markup = statistical_values_from_gathering_event($value, 'absoluteElevation');
1427
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('absoluteElevation'), $min_max_markup);
1428
                        }
1429
                        if (isset($value->distanceToGround) && $value->distanceToGround >0) {
1430
                            $min_max_markup = statistical_values_from_gathering_event($value, 'distanceToGround');
1431
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToGround'), $min_max_markup);
1432
                        }
1433
                        if (isset($value->distanceToWaterSurface) && $value->distanceToWaterSurface > 0) {
1434
                            $min_max_markup = statistical_values_from_gathering_event($value, 'distanceToWaterSurface');
1435
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToWaterSurface'), $min_max_markup);
1436
                        }
1437

    
1438
                        if (isset($value->collectingAreas)) {
1439
                            $area_representations = array();
1440
                            foreach ($value->collectingAreas as $area) {
1441
                               // $area_representations[] = l($area->representation_L10n, path_to_named_area($area->uuid));
1442
                                $area_representations[] = $area;
1443
                            }
1444
                            if (!empty($area_representations))
1445
                                @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingAreas'),
1446
                                    array(
1447
                                        array('#markup' => implode(', ', $area_representations))
1448
                                    )
1449
                                );
1450
                        }
1451
                        if (isset($value->exactLocation)  ) {
1452
                            $sub_dl_groups = array();
1453
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('errorRadius'), $value->exactLocation->errorRadius, ' m', 1);
1454
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('longitude'), round($value->exactLocation->longitude, 7), '°', 2);
1455
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('latitude'), round($value->exactLocation->latitude, 7), '°', 3);
1456
                            if (isset($value->exactLocation->referenceSystem)) {
1457
                                @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('referenceSystem'), $value->exactLocation->referenceSystem->representation_L10n, '', 4);
1458
                            }
1459
                            if ( isSet($value->exactLocation->sexagesimalString)){
1460
                                @_description_list_group_add($groups, cdm_occurrence_field_name_label('exactLocation'),
1461
                                    array(
1462
                                        array('#markup' => $value->exactLocation->sexagesimalString),
1463
                                        array(
1464
                                            '#theme' => 'description_list',
1465
                                            '#groups' => $sub_dl_groups
1466
                                        ),
1467
                                    ), '', 11
1468
                                );
1469
                            }
1470
                        }
1471

    
1472
                        break;
1473

    
1474
                    /* ---- DerivationEvent --- */
1475
                    case 'derivationEvents':
1476
                        //@_description_list_group_add($groups, t('Association type'), $value->description);
1477
                        break;
1478
                    case 'determinedNames':
1479
                        $dd_elements = array();
1480
                        foreach ($value as $name) {
1481
                            $taxon_name = cdm_ws_get(CDM_WS_NAME, $name->key);
1482
                            $taxon_name->taggedName = cdm_ws_get(CDM_WS_NAME, array($name->key, "taggedName"));
1483
                            $name_link = path_to_name($name->key);
1484

    
1485
                            //$taxon_html = render_taxon_or_name($taxon_name, $name_link);
1486
                            $taxon_html = l($taxon_name->titleCache, $name_link);
1487
                            $dd_elements[] = $taxon_html;
1488
                        }
1489
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label("Identification(s)"), $dd_elements,'', 100);
1490
                        break;
1491

    
1492

    
1493
                    default:
1494
                        if (is_object($value) || is_array($value)) {
1495
                            drupal_set_message("Unhandled type in compose_cdm_specimenOrObservation() for field " . $field, "warning");
1496
                        } else {
1497
                            if ($field == 'recordBase' && $value == 'Dna Sample'){
1498
                                _description_list_group_add($groups, cdm_occurrence_field_name_label($field), 'DNA Sample');
1499
                            }else{
1500
                                _description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value);
1501
                            }
1502

    
1503
                        }
1504

    
1505
                }
1506

    
1507

    
1508
            }
1509
        } // END of loop over $derivedUnitFacade fields
1510

    
1511

    
1512

    
1513
        // template_preprocess_description_list() is not worting by weight so we do it right here
1514
        uasort($groups, 'element_sort');
1515

    
1516
        $occurrence_elements = array(
1517
           // '#title' => $title,
1518
            '#theme' => 'description_list',
1519
            '#groups' => $groups,
1520
            '#attributes' => array('class' => html_class_attribute_ref($specimen_or_observation)),
1521
        );
1522
        $output = drupal_render($occurrence_elements);
1523
        if (isset($gallery_html)){
1524
            $output .= $gallery_html;
1525
        }
1526
        $pathToSpecimen = path_to_specimen($specimen_or_observation->uuid);
1527
        $output .=  l("Detail page", $pathToSpecimen);
1528
    } // END of $specimenOrObservation exists
1529

    
1530
    return $output;
1531
}
1532

    
1533
function compose_table_of_blast_result(array $data){
1534
   // get icon images
1535
  $expand_icon = font_awesome_icon_markup(
1536
      'fa-plus-square-o',
1537
      array(
1538
          'alt' => 'Show details',
1539
          'class' => array('expand_icon')
1540
      )
1541
  );
1542
  $collapse_icon = font_awesome_icon_markup(
1543
      'fa-minus-square-o',
1544
      array(
1545
          'alt' => 'Show details',
1546
          'class' => array('collapse_icon')
1547
      )
1548
  );
1549
  //$detail_image_icon = '<img title="Detail Image" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/detail_image_derivate-16x16-32.png' . '"/>';
1550
    $rowcount = 0;
1551
    $rows = array();
1552

    
1553
    foreach ($data as $row_data){
1554
        $pathToSpecimen = path_to_specimen_by_accession_number($row_data['id']);
1555
        $specimenPageLink = l($row_data['id'], $pathToSpecimen);
1556
        $ncbiLink = l($row_data['id'], 'https://www.ncbi.nlm.nih.gov/nuccore/'.$row_data['id'].'?report=graph');
1557
        $rows[] =  array(
1558
            'data' => array(
1559
                array(
1560
                    'data' => $expand_icon . $collapse_icon,
1561
                    'class' => array('summary_row_cell', 'summary_row_icon', 'expand_column')
1562
                ),
1563
                array(
1564
                    'data' => $row_data['def'],
1565
                ),
1566
                array(
1567
                    'data' => $specimenPageLink,
1568
                ),
1569
                array(
1570
                    'data' => $row_data['hsp_align_length'],
1571
                ),
1572
                array(
1573
                   'data' => $ncbiLink,
1574
                ),
1575
                array(
1576
                    'data' => $row_data['hsp_identity']/$row_data['hsp_align_length']*100,
1577
                )
1578
            ),
1579
            'id' => 'blast_summary' . $rowcount, // summary row id
1580
            'class' => array('summary_row'),
1581
        );
1582
        $detail_html = "";
1583

    
1584
        $detail_html .= create_label("Details") . $row_data["hsp_align_length"] . "<br>";
1585

    
1586

    
1587
        $detail_html .= "<br>";
1588
        $detail_html .= $row_data["hsp_midline"];
1589

    
1590
        //$detail_html .= "<br>";
1591

    
1592
        $rows[] = array(
1593
            'data' => array(
1594
                array(
1595
                    'data' => "", //empty first column
1596
                    'class' => array('expand_column')
1597
                ),
1598
                array(
1599
                    'data' => $detail_html,
1600
                    'colspan' => 5,
1601
                ),
1602
            ),
1603
            'id' => 'blast_detail' . $rowcount,//details row ID
1604
            'class' => array('detail_row'),
1605
        );
1606
        $rowcount++;
1607
    }
1608

    
1609
    $tableId = "blast_result_table";
1610
    $blast_result_table = array(
1611
        "#theme" => "table",
1612
        "#weight" => 2,
1613
        "#header" => array(
1614
            array(
1615
                'data' => "",
1616
                'class' => array('expand_column')
1617
            ),
1618
                        "Name", "Accession Number", "Align Length", "NCBI", "% Identity"),
1619
        "#rows" => $rows,
1620
        "#attributes" => array(
1621
            "id" => $tableId,
1622
            "border" => 2
1623
        )
1624
    );
1625

    
1626
    drupal_add_js_rowToggle("#".$tableId);
1627

    
1628
    $render_array[$tableId] = $blast_result_table;
1629
    $out = drupal_render($render_array);
1630
   //$blast_result_page-> content = drupal_render($render_array);
1631
   return $out;
1632
}
1633

    
1634

    
1635
/**
1636
 * Composes a BOTTOM-UP-SPECIMEN-TABLE
1637
 * @param $specimensOrObservations
1638
 * @return array
1639
 *  A drupal render array with the following keys:
1640
 *   - 'specimen_list'
1641
 *   - 'pager'
1642
 *
1643
 * @ingroup Compose
1644
 */
1645
function compose_specimens_table_bottom_up($specimensOrObservations)
1646
{
1647

    
1648
  // --- generate the specimen list as table
1649
  $specimen_table = array(
1650
    '#theme' => 'table',
1651
    '#weight' => 2,
1652
    // prefix attributes and rows with '#' to let it pass toF the theme function,
1653
    // otherwise it is handled as child render array
1654
    '#attributes' => array('class' => 'specimens'),
1655
    '#rows' => array(),
1656
  );
1657

    
1658
  if ($specimensOrObservations) {
1659

    
1660
    foreach ($specimensOrObservations as $specimenOrObservation) {
1661

    
1662
      $mediaList = array();
1663
      if (is_array($specimenOrObservation->_fieldObjectMedia)) {
1664
        $mediaList = array_merge($mediaList, $specimenOrObservation->_fieldObjectMedia);
1665
      }
1666
      if (is_array($specimenOrObservation->_derivedUnitMedia)) {
1667
        $mediaList = array_merge($mediaList, $specimenOrObservation->_derivedUnitMedia);
1668
      }
1669

    
1670

    
1671
      // typelabel will contain the typeStatus
1672
      $type_label = '';
1673
      $typeDesignationPager = cdm_ws_get(CDM_WS_OCCURRENCE . '/$0/specimenTypeDesignations', $specimenOrObservation->uuid);
1674
      if (isset($typeDesignationPager) and isset($typeDesignationPager->records)) {
1675
        $type_status = array();
1676
        foreach ($typeDesignationPager->records as $typeDesignation) {
1677
          if (isset($typeDesignation->typeStatus->representation_L10n)) {
1678
            $type_status[] = $typeDesignation->typeStatus->representation_L10n;
1679
          }
1680
        }
1681
        $type_label = implode(', ', $type_status);
1682
        if ($type_label) {
1683
          $type_label .= ': ';
1684
        }
1685
      }
1686

    
1687
      // --- Specimen entry as dynamic label:
1688
      //     -> Dynabox for the specimenOrObservation
1689
      $gallery_name = $specimenOrObservation->uuid;
1690

    
1691
      $derived_unit_ws_request = cdm_compose_url(CDM_WS_OCCURRENCE, array($specimenOrObservation->uuid));
1692
      // --- Render associated media.
1693
      $gallery_html = '';
1694
      if (count($mediaList) > 0) {
1695
        $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
1696
        $captionElements = array(
1697
          '#uri' => t('open media'),
1698
        );
1699

    
1700
        $gallery_html = compose_cdm_media_gallerie(array(
1701
          'mediaList' => $mediaList,
1702
          'galleryName' => $gallery_name,
1703
          'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
1704
          'cols' => $gallery_settings['cdm_dataportal_media_cols'],
1705
          'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
1706
          'captionElements' => $captionElements,
1707
          'mediaLinkType' => 'LIGHTBOX',
1708
          'alternativeMediaUri' => NULL,
1709
          'galleryLinkUri' => NULL,
1710
        ));
1711
      }
1712
      //here we should use the data we already have
1713
      $label_html = cdm_dynabox(
1714
        $specimenOrObservation->uuid,
1715
        $type_label . $specimenOrObservation->titleCache,
1716
        $derived_unit_ws_request,
1717
        'cdm_specimen_or_observation',
1718
        'Click for details',
1719
        array('div', 'div'),
1720
        array(),
1721
        null, // $content_element_selector
1722
        'function(){ jQuery(\'#media_gallery_' . $gallery_name . '\').hide(); }', // open_callback
1723
        'function(){ jQuery(\'#media_gallery_' . $gallery_name . '\').show(); }' // close_callback
1724
      );
1725

    
1726
      // --- Render associated media.
1727
      $gallery_html = '';
1728
      if (count($mediaList) > 0) {
1729
        $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
1730
        $captionElements = array(
1731
          '#uri' => t('open media'),
1732
        );
1733

    
1734
        $gallery_html = compose_cdm_media_gallerie(array(
1735
          'mediaList' => $mediaList,
1736
          'galleryName' => $gallery_name,
1737
          'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
1738
          'cols' => $gallery_settings['cdm_dataportal_media_cols'],
1739
          'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
1740
          'captionElements' => $captionElements,
1741
          'mediaLinkType' => 'LIGHTBOX',
1742
          'alternativeMediaUri' => NULL,
1743
          'galleryLinkUri' => NULL,
1744
        ));
1745
      }
1746

    
1747
      $specimen_table['#rows'][] = array(
1748
        // An array of table rows. Every row is an array of cells, or an associative array
1749
        'data' => array(
1750
          // Each cell can be either a string or an associative array
1751
          $label_html . $gallery_html
1752
        ),
1753
        'class' => array(
1754
          'descriptionElement',
1755
          'descriptionElement_IndividualsAssociation'
1756
        ),
1757
      );
1758
    }
1759
  }
1760

    
1761
  return $specimen_table;
1762
}
1763

    
1764

    
1765
/**
1766
 * Orders occurrences by date but types should be on top of the list.
1767
 *
1768
 * @param $specimensOrObservations_or_fieldUnitDTO
1769
 *
1770
 * @return array
1771
 */
1772
function order_specimens_or_observations_by_date_and_type($specimensOrObservations)
1773
{
1774
// order occurrences by date but types should be on top of the list
1775
  $type_specimens = array();
1776
  $other_occurrences = array();
1777
  foreach ($specimensOrObservations as &$occurrence) {
1778
    $typeDesignationsPager = cdm_ws_get(CDM_WS_OCCURRENCE . '/$0/specimenTypeDesignations', $occurrence->uuid);
1779
    if (isset($typeDesignationsPager->count) && $typeDesignationsPager->count > 0) {
1780
      $type_specimens[] = $occurrence;
1781
    } else {
1782
      $other_occurrences[] = $occurrence;
1783
    }
1784
  }
1785
  $specimensOrObservations = array_merge($type_specimens, $other_occurrences);
1786
  return $specimensOrObservations;
1787
}
1788

    
1789
/**
1790
 * Orders FieldUnitDTOs by date but types should be on top of the list.
1791
 *
1792
 * Delegates internally to order_specimens_or_observations_by_date_and_type()
1793
 *
1794
 * @param $fieldUnitDTOs
1795
 *
1796
 * @return array
1797
 */
1798
function order_fieldUnitDtos_by_date_and_type($fieldUnitDTOs)
1799
{
1800
  return order_specimens_or_observations_by_date_and_type($fieldUnitDTOs);
1801
}
1802

    
(8-8/14)