Project

General

Profile

Download (75 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
            $specimen_or_observation->_derivedUnitMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array(
363
                $specimen_or_observation->uuid,
364
                'fieldObjectMediaDTO',
365
            ));
366
        }else{
367
            $specimen_or_observation->_derivedUnitMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array(
368
                $specimen_or_observation->uuid,
369
                'derivedUnitMedia',
370
            ));
371
        }
372

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

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

    
389
        $title = $type_label . ': ' . $specimen_or_observation->titleCache;
390

    
391
        $groups = array();
392

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

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

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

    
413

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

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

    
430
                    case 'definition':
431
                        // TODO
432
                        break;
433

    
434
                    case 'preferredStableUri':
435

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

    
439
                    case 'specimenTypeDesignations':
440

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

    
451
                    case 'determinations':
452
                        $dd_elements = array();
453
                        $glue = ', ';
454

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

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

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

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

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

    
532
                        // $dd_elements[] = markup_to_render_array($gallery_html);
533

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

    
552

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

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

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

    
595
                        }
596
                        break;
597

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

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

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

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

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

    
639
                    case 'preservation':
640
                        $sub_dl_groups = array();
641

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

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

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

    
665
                    // TODO preservation
666
                    // TODO exsiccatum
667

    
668

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

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

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

    
732
                }
733

    
734
            }
735
        } // END of loop over $derivedUnitFacade fields
736

    
737
        // Extensions
738
        $extensions = cdm_ws_fetch_all(CDM_WS_PORTAL_OCCURRENCE . '/'  . $specimen_or_observation->uuid . '/extensions', array($specimen_or_observation->uuid));
739
        if ($extensions && count($extensions)) {
740

    
741
            $extensions_render_array = compose_extensions($extensions);
742
            @_description_list_group_add($groups, t('Extensions') . ':',
743
                $extensions_render_array,
744
                '', 100);
745
        }
746

    
747

    
748

    
749
        // template_preprocess_description_list() is not worting by weight so we do it right here
750
        uasort($groups, 'element_sort');
751

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

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

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

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

    
799

    
800

    
801

    
802
    } // END of $specimenOrObservation exists
803

    
804
    return $derivatives;
805
}
806

    
807

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

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

    
835
    $groups = array();
836

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

    
843
    foreach (get_object_vars($sequence) as $field => $value) {
844

    
845

    
846
        if (!in_array($field, $exclude_sequence_fields) && ($value && (!is_object($value) || isset($value->class)))) {
847
            switch ($field) {
848

    
849
                case 'geneticAccessionNumber';
850

    
851
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 2);
852
                    break;
853

    
854

    
855
                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.
856
                    if (isset($value->name)) {
857
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value->name, NULL, 3);
858
                    }
859
                    if (isset($value->description)) {
860
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field) . ' ' . t('description'), $value->description, NULL, 4);
861
                    }
862
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field) , $value, NULL, 4);
863
                    break;
864

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

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

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

    
902
                case 'citation':
903
                    @_description_list_group_add($groups,
904
                        cdm_occurrence_field_name_label($field),
905
                        theme('cdm_reference', array('reference' => $value, 'microReference' => $sequence->microReference)),
906
                        NULL,
907
                        8
908
                    );
909
                    break;
910

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

    
920
                case 'rights':
921
                    array_merge($groups, cdm_rights_as_dl_groups($value));
922
                    break;
923

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

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

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

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

    
960
                       _description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 20);
961
                    }
962
            }
963
        }
964
    }
965

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

    
982
    return $sequence_elements;
983
}
984

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

    
992
  $render_array_items = array();
993
  $items = array();
994

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

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

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

    
1027
function compose_compressed_specimen_derivate_table($field_unit_uuids) {
1028

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

    
1049
  $rowcount = 0;
1050
  $rows = array();
1051

    
1052
  foreach ($field_unit_uuids as $field_unit_uuid) {
1053

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

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

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

    
1149
  //add toggle functionality to derivate hierarchy table
1150
  drupal_add_js_rowToggle("#" . $tableId);
1151

    
1152
  return $derivateHierarchyTable;
1153
}
1154

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

    
1168
  $specimen_render_array_items = specimen_render_array_items($fieldunit_dtos);
1169

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

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

    
1224
        )
1225
      ),
1226
      'class' =>  array('detail_row')
1227
//                'class' =>  array(
1228
//                    'descriptionElement',
1229
//                    'descriptionElement_IndividualsAssociation'
1230
      //               ),
1231
    );
1232
    $rowcount++;
1233

    
1234
  }
1235
  drupal_add_js_rowToggle("#".$tableId);
1236

    
1237
  return $specimen_table;
1238
}
1239

    
1240

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

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

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

    
1284

    
1285
    if (is_object($specimen_or_observation)) {
1286

    
1287
        $type_label = $specimen_or_observation->recordBase;
1288
        RenderHints::setFootnoteListKey($type_label . '-' . $specimen_or_observation->uuid);
1289

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

    
1303
        if (isset($typeDesignation->typifiedNames)){
1304
            $title = $type_label . ' for: ' . $typeDesignation->typifiedNames;
1305
        }else{
1306
            $title = $type_label;
1307
        }
1308

    
1309
        $items['data'] = $title;
1310

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

    
1318
            if (!in_array($field, $exclude_occurrence_fields) && ($value && (!is_object($value) || isset($value->class)))) {
1319
                switch ($field) {
1320

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

    
1332
                    case 'preferredStableUri':
1333

    
1334
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), array(array('#markup' => cdm_external_uri($value, false))));
1335
                        break;
1336

    
1337
                    case 'specimenTypeDesignations':
1338
                        @_description_list_group_add(
1339
                            $groups,
1340
                            cdm_occurrence_field_name_label($field),
1341
                            array(
1342
                                '#markup' => theme('cdm_typedesignations', array('typeDesignations' => $value)),
1343
                            )
1344
                        );
1345
                        break;
1346

    
1347

    
1348

    
1349
                    case 'listOfMedia':
1350
                        $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
1351

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

    
1369
                         //@_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $gallery_html);
1370
                         break;
1371

    
1372

    
1373

    
1374
                    /* ---- DerivedUnitBase --- */
1375

    
1376

    
1377
                    case 'collectionDTO':
1378

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

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

    
1394
                        break;
1395

    
1396

    
1397

    
1398

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

    
1409
                    // TODO preservation
1410
                    // TODO exsiccatum
1411

    
1412

    
1413
                    /* ---- FieldObservation --- */
1414
                    case 'gatheringEvent':
1415

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

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

    
1469
                        break;
1470

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

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

    
1489

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

    
1500
                        }
1501

    
1502
                }
1503

    
1504

    
1505
            }
1506
        } // END of loop over $derivedUnitFacade fields
1507

    
1508

    
1509

    
1510
        // template_preprocess_description_list() is not worting by weight so we do it right here
1511
        uasort($groups, 'element_sort');
1512

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

    
1527
    return $output;
1528
}
1529

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

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

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

    
1583

    
1584
        $detail_html .= "<br>";
1585
        $detail_html .= $row_data["hsp_midline"];
1586

    
1587
        //$detail_html .= "<br>";
1588

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

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

    
1623
    drupal_add_js_rowToggle("#".$tableId);
1624

    
1625
    $render_array[$tableId] = $blast_result_table;
1626
    $out = drupal_render($render_array);
1627
   //$blast_result_page-> content = drupal_render($render_array);
1628
   return $out;
1629
}
1630

    
1631

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

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

    
1655
  if ($specimensOrObservations) {
1656

    
1657
    foreach ($specimensOrObservations as $specimenOrObservation) {
1658

    
1659
      $mediaList = array();
1660
      if (is_array($specimenOrObservation->_fieldObjectMedia)) {
1661
        $mediaList = array_merge($mediaList, $specimenOrObservation->_fieldObjectMedia);
1662
      }
1663
      if (is_array($specimenOrObservation->_derivedUnitMedia)) {
1664
        $mediaList = array_merge($mediaList, $specimenOrObservation->_derivedUnitMedia);
1665
      }
1666

    
1667

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

    
1684
      // --- Specimen entry as dynamic label:
1685
      //     -> Dynabox for the specimenOrObservation
1686
      $gallery_name = $specimenOrObservation->uuid;
1687

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

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

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

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

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

    
1758
  return $specimen_table;
1759
}
1760

    
1761

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

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

    
(6-6/11)