Project

General

Profile

Download (54 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
        '#uri' => t('open media'),
45
    );
46
    if (isset($specimen->fieldObjectMediaDTO) ) {
47
        $gallery_html = compose_cdm_media_gallerie(array(
48
            'mediaList' => $specimen->fieldObjectMediaDTO,
49
            'galleryName' => $specimen->titleCache,
50
            'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
51
            'cols' => $gallery_settings['cdm_dataportal_media_cols'],
52
            'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
53
            'captionElements' => $captionElements,
54
            'mediaLinkType' => 'LIGHTBOX',
55
            'alternativeMediaUri' => NULL,
56
            'galleryLinkUri' => NULL,
57
        ));
58
        $specimen_details[] = markup_to_render_array($gallery_html);
59
    }
60

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

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

    
86

    
87
    return $output;
88
}
89

    
90

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

    
109

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

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

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

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

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

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

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

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

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

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

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

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

    
278
function getMediaUri($media)
279
{
280
    if (isset($media->representations) && sizeof($media->representations) == 1
281
        && isset($media->representations[0]->parts) &&
282
        sizeof($media->representations[0]->parts) == 1) {
283
        return $media->representations[0]->parts[0]->uri;
284
    }
285
    return null;
286
}
287

    
288

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

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

    
317
function compose_cdm_specimen_or_observation($specimen_or_observation, $isSpecimen_page = false, &$derivatives = null)
318
{
319
    $exclude_occurrence_fields = &drupal_static(__FUNCTION__);
320
    if (!isset($exclude_occurrence_fields)) {
321
        $exclude_occurrence_fields = array(
322

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

    
338

    
339
    // only show uuid it the user is logged in
340
    if(user_is_logged_in() && ($a_idx = array_search('uuid', $exclude_occurrence_fields)) !== FALSE ) {
341
        unset($exclude_occurrence_fields[$a_idx]);
342
    }
343

    
344
    if (!isset($derivatives)) {
345
        $derivatives = array();
346
    }
347

    
348
    $descriptions = null;
349
    $derivedFrom = null;
350

    
351

    
352

    
353
    if (is_object($specimen_or_observation)) {
354

    
355
        // request again for deeper initialization
356
        $specimen_or_observation = cdm_ws_get("portal/" . CDM_WS_OCCURRENCE, $specimen_or_observation->uuid);
357
        if ($specimen_or_observation->class == 'FieldUnit'){
358
            $specimen_or_observation->_derivedUnitMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array(
359
                $specimen_or_observation->uuid,
360
                'fieldObjectMediaDTO',
361
            ));
362
        }else{
363
            $specimen_or_observation->_derivedUnitMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array(
364
                $specimen_or_observation->uuid,
365
                'derivedUnitMedia',
366
            ));
367
        }
368

    
369
        $type_label = $specimen_or_observation->class;
370
        RenderHints::setFootnoteListKey($type_label . '-' . $specimen_or_observation->uuid);
371

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

    
385
        $title = $type_label . ': ' . $specimen_or_observation->titleCache;
386

    
387
        $groups = array();
388

    
389
        // --- add initialized fields
390
        foreach (get_object_vars($specimen_or_observation) as $field => $value) {
391
            if (!in_array($field, $exclude_occurrence_fields) && ($value && (!is_object($value) || isset($value->class)))) {
392
                switch ($field) {
393

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

    
401
                    case 'markers':
402
                        $dd_elements = array();
403
                        foreach ($value as $marker) {
404
                            $dd_elements[] = compose_cdm_marker($marker);
405
                        }
406
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
407
                        break;
408

    
409

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

    
419
                    /* ---- SpecimenOrObservationBase --- */
420
                    case 'sex':
421
                    case 'lifeStage':
422
                    case 'kindOfUnit':
423
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value->representation_L10n);
424
                        break;
425

    
426
                    case 'definition':
427
                        // TODO
428
                        break;
429

    
430
                    case 'preferredStableUri':
431

    
432
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), array(array('#markup' => cdm_external_uri($value, false))));
433
                        break;
434

    
435
                    case 'specimenTypeDesignations':
436

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

    
447
                    case 'determinations':
448
                        $dd_elements = array();
449
                        $glue = ', ';
450

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

    
462
                            $taxon_name = '';
463
                            $name_link = '';
464
                            if ($determinationEvent->taxonName) {
465
                                $taxon_name = $determinationEvent->taxonName;
466
                            } else if ($determinationEvent->taxon) {
467
                                $taxon_name = cdm_ws_get(CDM_WS_TAXON . '/$0/name', $determinationEvent->taxon->uuid);
468
                                $name_link = path_to_taxon($determinationEvent->taxon->uuid);
469
                            }
470
                            if ($taxon_name) {
471
                                $taxon_html = render_taxon_or_name($taxon_name, $name_link);
472
                                $dd_elements[$weight] = $taxon_html;
473
                            }
474
                            if (isset($determinationEvent->modifier)) {
475
                                $dd_elements[$weight] .= cdm_term_representation($determinationEvent->modifier);
476
                            }
477
                            if ($timeperiod_string) {
478
                                $dd_elements[$weight] .= $glue . $timeperiod_string;
479
                            }
480
                            if (isset($determinationEvent->actor->titleCache)) {
481
                                $dd_elements[$weight] .= $glue . $determinationEvent->actor->titleCache;
482
                            }
483
                            if (isset($determinationEvent->description)) {
484
                                $dd_elements[$weight] .= $glue . $determinationEvent->description;
485
                            }
486
                        }
487
                        ksort($dd_elements);
488
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('determinations'), $dd_elements);
489
                        break;
490

    
491
                    case 'descriptions':
492
                        $occurrence_featureTree = cdm_get_occurrence_featureTree();
493
                        $dd_elements = array();
494

    
495
                        foreach ($value as $description) {
496
                            $description = cdm_ws_get(CDM_WS_PORTAL_DESCRIPTION, $description->uuid);
497

    
498
                        if($description->imageGallery == TRUE) {
499
                            continue;
500
                        }
501
                            $elements_by_feature = _mergeFeatureTreeDescriptions($occurrence_featureTree->root->childNodes, $description->elements);
502
                            $description_render_elements = _block_get_renderable_array(make_feature_block_list($elements_by_feature, null));
503
                            $dd_elements[] = $description_render_elements;
504
                        }
505

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

    
528
                       // $dd_elements[] = markup_to_render_array($gallery_html);
529

    
530
                        break;
531
                    case 'sources':
532
                        $dd_elements = array();
533
                        foreach ($value as $identifiable_source) {
534
                            $dd_elements[] = theme('cdm_OriginalSource', array('source' => $identifiable_source));
535
                        }
536
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
537
                        break;
538

    
539

    
540
                    /* ---- DerivedUnitBase --- */
541
                    case 'derivedFrom':
542
                        $derivedFrom = $value;
543
                        if ($isSpecimen_page) {
544
                            foreach ($derivedFrom->originals as $original) {
545
                                $pathToSpecimen = path_to_specimen($original->uuid);
546
                                $description = "";
547
                                if (isset( $derivedFrom->description) && $derivedFrom->description != ''){
548
                                    $description = $derivedFrom->description . ": ";
549
                                }
550

    
551
                                $originals[] = markup_to_render_array(l($description . $original->titleCache, $pathToSpecimen, array('attributes' => array('target' => '_blank'))));
552
                                @_description_list_group_add($groups, t('Originals') . ':',
553
                                    $originals,
554
                                    '', 1);
555
                            }
556
                        }
557
                        break;
558
                    case 'derivationEvents':
559
                        $derivationEvents = $value;
560
                        $derived_units = array();
561
                        if ($isSpecimen_page) {
562
                            foreach ($derivationEvents as $derivationEvent) {
563
                                foreach ($derivationEvent->derivatives as $derived_unit) {
564
                                    $pathToSpecimen = path_to_specimen($derived_unit->uuid);
565
                                    $description = "";
566
                                    if (isset($derived_unit->description) && $derived_unit->description != '') {
567
                                        $description = $derived_unit->description . ": ";
568
                                    }
569

    
570
                                    $derived_units[] = markup_to_render_array(l($description . $derived_unit->titleCache, $pathToSpecimen, array('attributes' => array('target' => '_blank'))));
571
                                 }
572
                            } @_description_list_group_add($groups, t('Derivates') . ':',
573
                                $derived_units,
574
                                    '', 100);
575

    
576
                        }
577
                        break;
578

    
579
                    case 'collection':
580
                        $sub_dl_groups = array();
581
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('code'), $value->code, NULL, 1);
582
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('codeStandard'), $value->codeStandard, NULL, 2);
583
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('institute'), $value->institute, NULL, 3);
584
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('townOrLocation'), $value->townOrLocation, NULL, 4);
585
                        // TODO "superCollection"
586
                        // TODO may have media
587

    
588
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),
589
                            array(
590
                                array('#markup' => $value->titleCache),
591
                                array('#theme' => 'description_list', '#groups' => $sub_dl_groups)
592
                            )
593
                        );
594
                        break;
595

    
596
                    case 'storedUnder':
597
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('storedUnder'), render_taxon_or_name($value));
598
                        break;
599

    
600

    
601
                    /* ---- Specimen --- */
602
                    case 'sequences':
603
                        $dd_elements = array();
604
                        foreach ($value as $sequence) {
605
                            $dd_elements[] = compose_cdm_sequence($sequence);
606
                        }
607
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
608
                        break;
609

    
610
                    // TODO preservation
611
                    // TODO exsiccatum
612

    
613

    
614
                    /* ---- FieldObservation --- */
615
                    case 'gatheringEvent':
616
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collector'), $value->actor->titleCache);
617
                        @_description_list_group_add($groups, t('Gathering time'), timePeriodToString($value->timeperiod));
618
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('description'), $value->description);
619
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('locality'), $value->locality->text);
620
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('country'), $value->country->representation_L10n);
621
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingMethod'), $value->collectingMethod);
622
                        if (isset($value->absoluteElevation)) {
623
                            $min_max_markup = min_max_measure($value, 'absoluteElevation');
624
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('absoluteElevation'), $min_max_markup);
625
                        }
626
                        if (isset($value->distanceToGround)) {
627
                            $min_max_markup = min_max_measure($value, 'distanceToGround');
628
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToGround'), $min_max_markup);
629
                        }
630
                        if (isset($value->distanceToWaterSurface)) {
631
                            $min_max_markup = min_max_measure($value, 'distanceToWaterSurface');
632
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToWaterSurface'), $min_max_markup);
633
                        }
634

    
635
            if (isset($value->collectingAreas) && count($value->collectingAreas) > 0) {
636
                            $area_representations = array();
637
                            foreach ($value->collectingAreas as $area) {
638
                                $area_representations[] = l($area->representation_L10n, path_to_named_area($area->uuid));
639
                            }
640
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingAreas'),
641
                                array(
642
                                    array('#markup' => implode(', ', $area_representations))
643
                                )
644
                            );
645
                        }
646
                        if (isset($value->exactLocation) && $value->exactLocation->sexagesimalString) {
647
                            $sub_dl_groups = array();
648
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('errorRadius'), $value->exactLocation->errorRadius, ' m', 1);
649
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('longitude'), round($value->exactLocation->longitude, 7), '°', 2);
650
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('latitude'), round($value->exactLocation->latitude, 7), '°', 3);
651
                            if (isset($value->exactLocation->referenceSystem)) {
652
                                @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('referenceSystem'), $value->exactLocation->referenceSystem->representation_L10n, '', 4);
653
                            }
654

    
655
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('exactLocation'),
656
                                array(
657
                                    array('#markup' => $value->exactLocation->sexagesimalString),
658
                                    array(
659
                                        '#theme' => 'description_list',
660
                                        '#groups' => $sub_dl_groups
661
                                    ),
662
                                )
663
                            );
664
                        }
665
                        break;
666

    
667
                    default:
668
                        if (is_object($value) || is_array($value)) {
669
                            drupal_set_message("Unhandled type in compose_cdm_specimen_or_observation() for field " . $field, "warning");
670
                        } else {
671
                            _description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value);
672
                        }
673

    
674
                }
675

    
676
            }
677
        } // END of loop over $derivedUnitFacade fields
678

    
679
        // Extensions
680
        $extensions = cdm_ws_fetch_all(CDM_WS_PORTAL_OCCURRENCE . '/'  . $specimen_or_observation->uuid . '/extensions', array($specimen_or_observation->uuid));
681
        if ($extensions && count($extensions)) {
682

    
683
            $extensions_render_array = compose_extensions($extensions);
684
            @_description_list_group_add($groups, t('Extensions') . ':',
685
                $extensions_render_array,
686
                '', 100);
687
        }
688

    
689

    
690

    
691
        // template_preprocess_description_list() is not worting by weight so we do it right here
692
        uasort($groups, 'element_sort');
693

    
694
        $occurrence_elements = array(
695
            '#title' => $title,
696
            '#theme' => 'description_list',
697
            '#groups' => $groups,
698
            '#attributes' => array('class' => html_class_attribute_ref($specimen_or_observation)),
699
        );
700

    
701
        $derivatives[] = $occurrence_elements;
702
        // all footnotes which has been assembled so far (e.g. from typeDesignations) to here
703
        $foonote_li_elements = theme('cdm_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey(), 'enclosingTag' => 'span'));
704
        if (!empty($foonote_li_elements)) {
705
            $derivatives[] =  array(
706
                '#markup' =>  '<div class="footnotes">' . $foonote_li_elements . '</div>',
707
            );
708
        }
709

    
710
        // --- recurse into originals
711
        if (!isset($derivedFrom)  && !$isSpecimen_page) {
712
            $derivedFrom = cdm_ws_get(
713
                CDM_WS_OCCURRENCE,
714
                array($specimen_or_observation->uuid, 'derivedFrom')
715
            );
716
        }
717
        if (isset($derivedFrom) && !$isSpecimen_page) {
718
            if (isset($derivedFrom->originals)) {
719
                $derived_from_label = t('derived');
720
                $preposition = t('from');
721
                if(isset($derivedFrom->type)){
722
                    $derived_from_label = $derivedFrom->type->representation_L10n;
723
                    if($derivedFrom->type->uuid == UUID_DERIVATIONEVENTTYPE_ACCESSIONING){
724
                        $preposition = t('of');
725
                    }
726
                }
727
                if (count($groups) > 0) {
728
                    // TODO  annotations
729

    
730
                    // only display the derived from information when the derivative has any element which will be diplayed
731
                    $derivatives[] = array(
732
                        '#markup' => '<div class="derived_from">' . $derived_from_label . ' ' . $preposition . ': </div>',
733
                    );
734
                }
735
                foreach ($derivedFrom->originals as $original) {
736
                    compose_cdm_specimen_or_observation($original, $isSpecimen_page, $derivatives);
737
                }
738
            }
739
        }
740

    
741

    
742

    
743

    
744
    } // END of $specimenOrObservation exists
745

    
746
    return $derivatives;
747
}
748

    
749

    
750
/**
751
 * Compose an render array from a CDM Sequence object.
752
 *
753
 * compose_hook() implementation
754
 *
755
 * @param object $sequence
756
 *   CDM instance of type Sequence
757
 * @return array
758
 *   A render array containing the fields of the supplied $sequence
759
 *
760
 * @ingroup compose
761
 */
762
function compose_cdm_sequence($sequence, $isSpecimenPage = false)
763
{
764

    
765
    $exclude_sequence_fields = &drupal_static(__FUNCTION__);
766
    if (!isset($exclude_sequence_fields)) {
767
        $exclude_sequence_fields = array(
768
            'titleCache',
769
            'protectedTitleCache',
770
            'microReference',
771
            'created',
772
            'updated',
773
            'class',
774
        );
775
    }
776

    
777
    $groups = array();
778

    
779
    // -- retrieve additional data if neesscary
780
    // TODO below call disabled since sequences are not yet supported,
781
    //      see  #3347 (services and REST service controller for molecular classes implemented)
782
    //
783
    // cdm_load_annotations($sequence);
784

    
785
    foreach (get_object_vars($sequence) as $field => $value) {
786

    
787

    
788
        if (!in_array($field, $exclude_sequence_fields) && ($value && (!is_object($value) || isset($value->class)))) {
789
            switch ($field) {
790

    
791
                case 'geneticAccessionNumber';
792

    
793
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 2);
794
                    break;
795

    
796

    
797
                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.
798
                    if (isset($value->name)) {
799
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value->name, NULL, 3);
800
                    }
801
                    if (isset($value->description)) {
802
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field) . ' ' . t('description'), $value->description, NULL, 4);
803
                    }
804
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field) , $value, NULL, 4);
805
                    break;
806

    
807
                case 'consensusSequence':
808
                    // format in genbank style, force linebreaks after each 70 nucleotites
809
                    // see also http://stackoverflow.com/questions/499137/css-how-can-i-force-a-long-string-without-any-blank-to-be-wrapped-in-xul-and
810
                    if ($value->length > 0) {
811
                        @_description_list_group_add(
812
                            $groups,
813
                            cdm_occurrence_field_name_label($field),
814
                            array(
815
                                array(
816
                                    '#markup' => '<div class="sequence-length">' . $value->length . ' ' . t('pb') . '</div><div>' . wordwrap($value->string, 70, '</br>', TRUE) . '</div>',
817
                                    '#wrapper_attributes' => array('class' => 'dna-sequence')
818
                                )
819
                            ),
820
                            5);
821
                    }
822
                    break;
823

    
824
                case 'dnaSample': // FIXME 3.3 implement
825
                    break;
826
                case 'singleReads': // FIXME 3.3 implement
827
                    break;
828
                case 'contigFile': // FIXME 3.3 implement - Media
829
                    break;
830
                case 'pherograms': // FIXME 3.3 implement - Media
831
                    break;
832
                case 'haplotype': // FIXME 3.3 implement
833
                    break;
834
                case 'dateSequenced': // FIXME 3.3 now in SingelRead
835
                    @_description_list_group_add($groups, t('Sequencing date'), timePeriodToString($value), NULL, 6);
836
                    break;
837

    
838
                case 'barcode': // boolean
839
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value ? 'Yes' : 'No', NULL, 7);
840
                    break;
841
                case 'barcodeSequencePart': // FIXME 3.3 implement, compose sequence
842
                    break;
843

    
844
                case 'citation':
845
                    @_description_list_group_add($groups,
846
                        cdm_occurrence_field_name_label($field),
847
                        theme('cdm_reference', array('reference' => $value, 'microReference' => $sequence->microReference)),
848
                        NULL,
849
                        8
850
                    );
851
                    break;
852

    
853
                case 'publishedIn':
854
                    @_description_list_group_add($groups,
855
                        cdm_occurrence_field_name_label($field),
856
                        theme('cdm_reference', array('reference' => $value)),
857
                        NULL,
858
                        7
859
                    );
860
                    break;
861

    
862
                case 'rights':
863
                    array_merge($groups, cdm_rights_as_dl_groups($value));
864
                    break;
865

    
866
                case 'annotations':
867
                    $dd_elements = array();
868
                    foreach ($value as $annotation) {
869
                        // TODO respect annotation type filter settings
870
                        $dd_elements[] = $annotation->text;
871
                    }
872
                    @_description_list_group_add($groups, t('Notes'), $dd_elements, NULL, 9);
873
                    break;
874

    
875
                case 'markers':
876
                    $dd_elements = array();
877
                    foreach ($value as $marker) {
878
                        $dd_elements[] = compose_cdm_marker($marker);
879
                    }
880
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements, NULL, 10);
881
                    break;
882

    
883
                case 'chromatograms':
884
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),
885
                        array(
886
                            '#markup' => compose_cdm_media_gallerie(array('medialist' => $value)),
887
                        ),
888
                        NULL,
889
                        11);
890
                    break;
891

    
892
                default:
893
                    if (is_object($value) || is_array($value)) {
894
                        drupal_set_message("Unhandled type in compose_cdm_sequence() for field " . $field, "warning");
895
                    } else {
896
                        if (!is_array($value) && strpos($value, 'http:') !== false ){
897
                            //make links for urls
898
                            $value = l($value, $value, array('attributes' => array('target' => '_blank')));
899
                            $value = markup_to_render_array($value);
900
                        }
901

    
902
                       _description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 20);
903
                    }
904
            }
905
        }
906
    }
907

    
908
    // template_preprocess_description_list() is not worting by weight so we do it right here
909
    uasort($groups, 'element_sort');
910
    if ($isSpecimenPage) {
911
        $sequence_elements = array(
912
            '#title' => $sequence->dnaMarker,
913
            '#theme' => 'description_list',
914
            '#groups' => $groups
915
        );
916
    } else{
917
        $sequence_elements = array(
918
            '#title' => $sequence->dnaMarker -> titleCache,
919
            '#theme' => 'description_list',
920
            '#groups' => $groups
921
        );
922
    }
923

    
924
    return $sequence_elements;
925
}
926
/**
927
 * Creates an array from a list of FieldUnitDTOs.
928
 *
929
 *
930
 * @param object $specimenOrObservations
931
 *   list of FieldUnitDTOs
932
 * @return array
933
 *   An array containing the hierarchy of the field units corresponding to the taxon
934
 *
935
 * @ingroup compose
936
 */
937
function compose_specimen_array(array $specimenOrObservations){
938
    $items_specimen = array();
939
    $items = array();
940

    
941
    //we need one more item to contain the items of one level (fieldunit, derivate data etc.)
942
    foreach ($specimenOrObservations as &$specimenOrObservation) {
943

    
944
        $items['data'] = $specimenOrObservation->listLabel ;
945
        $specimen = compose_cdm_specimen_or_observation_tree_entry($specimenOrObservation);
946
        $children = array();
947
        $child = array();
948
        $child['data'] =$specimen;
949
       // $children[] = create_specimen_array($specimenOrObservation->derivates);
950
       if (isset($specimenOrObservation->derivates) && sizeof($specimenOrObservation->derivates) > 0){
951
           $child['children']= compose_specimen_array($specimenOrObservation->derivates);
952
       }
953
       $children[]=$child;
954
       $items['children'] = $children;
955
       $items_specimen[] = $items;
956
    }
957
    return $items_specimen;
958
}
959

    
960

    
961
/**
962
 * Compose an render array from a CDM DerivedUnitFacade object.
963
 *
964
 * compose_hook() implementation
965
 *
966
 * @param object $specimenOrObservation
967
 *   the CDM instance of type SpecimenOrObservation to compose
968
 *   the render array for
969
 * @param array $derivatives
970
 *   the render array which contains the compositions of the derivatives
971
 *   of the supplied $specimenOrObservation
972
 *
973
 * @return array
974
 *   the supplied render array $derivatives to which the composition of the supplied
975
 *   $specimenOrObservation has been added to
976
 *
977
 * @ingroup compose
978
 */
979

    
980
function compose_cdm_specimen_or_observation_tree_entry($specimen_or_observation)
981
{
982
    $exclude_occurrence_fields = &drupal_static(__FUNCTION__);
983
    if (!isset($exclude_occurrence_fields)) {
984
        $exclude_occurrence_fields = array(
985
            'type',
986
            'taxonRelatedDerivedUnits',
987
            'label',
988
            'titleCache',
989
            'listLabel',
990
            'protectedTitleCache',
991
            'class',
992
            'uuid',
993
            'derivates',
994
            'collection'
995
        );
996
    }
997
    $items = array();
998

    
999
    // only show uuid it the user is logged in
1000
    if (user_is_logged_in() && ($a_idx = array_search('uuid', $exclude_occurrence_fields)) !== FALSE) {
1001
      //  unset($exclude_occurrence_fields[$a_idx]);
1002
    }
1003

    
1004

    
1005
    if (is_object($specimen_or_observation)) {
1006

    
1007
        $type_label = $specimen_or_observation->recordBase;
1008
        RenderHints::setFootnoteListKey($type_label . '-' . $specimen_or_observation->uuid);
1009

    
1010
        // collect typeStatus as label
1011
        if (isset($specimen_or_observation->specimenTypeDesignations)) {
1012
            $type_status = array();
1013
            foreach ($specimen_or_observation->specimenTypeDesignations as $typeDesignation) {
1014
                if (isset($typeDesignation->typeStatus->representation_L10n)) {
1015
                    $type_status[] = $typeDesignation->typeStatus->representation_L10n;
1016
                }
1017
            }
1018
            if (count($type_status) > 0) {
1019
                $type_label = implode(', ', $type_status);
1020
            }
1021
        }
1022

    
1023
        $title = $type_label . ': ' . $specimen_or_observation->titleCache;
1024
        $items['data'] = $title;
1025

    
1026
        $groups = array();
1027
        $items['children'] = $groups;
1028
        $children_items = array();
1029
        // --- add initialized fields
1030
        foreach (get_object_vars($specimen_or_observation) as $field => $value) {
1031
            $child_item = array();
1032

    
1033
            if (!in_array($field, $exclude_occurrence_fields) && ($value && (!is_object($value) || isset($value->class)))) {
1034
                switch ($field) {
1035

    
1036
                    /* ---- SpecimenOrObservationBase --- */
1037
                    case 'derivationEvent':
1038
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 1);
1039
                        break;
1040
                    case 'kindOfUnit':
1041
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 1);
1042
                        break;
1043

    
1044

    
1045
                    case 'preferredStableUri':
1046

    
1047
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), array(array('#markup' => cdm_external_uri($value, false))));
1048
                        break;
1049

    
1050
                    case 'specimenTypeDesignations':
1051
                        @_description_list_group_add(
1052
                            $groups,
1053
                            cdm_occurrence_field_name_label($field),
1054
                            array(
1055
                                '#markup' => theme('cdm_typedesignations', array('typeDesignations' => $value)),
1056
                            )
1057
                        );
1058
                        break;
1059

    
1060

    
1061

    
1062
                    case 'listOfMedia':
1063
                        $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
1064
                        $captionElements = array(
1065
                            '#uri' => t('open media'),
1066
                        );
1067
                        $gallery_html = compose_cdm_media_gallerie(array(
1068
                            'mediaList' => $value,
1069
                            'galleryName' => $specimen_or_observation->label,
1070
                            'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
1071
                            'cols' => $gallery_settings['cdm_dataportal_media_cols'],
1072
                            'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
1073
                            'captionElements' => $captionElements,
1074
                            'mediaLinkType' => 'LIGHTBOX',
1075
                            'alternativeMediaUri' => NULL,
1076
                            'galleryLinkUri' => NULL,
1077
                        ));
1078

    
1079
                         //@_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $gallery_html);
1080
                         break;
1081

    
1082

    
1083

    
1084
                    /* ---- DerivedUnitBase --- */
1085

    
1086

    
1087
                    case 'collectionDTO':
1088

    
1089
                        $sub_dl_groups = array();
1090
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('code'), $value->code, NULL, 1);
1091
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('codeStandard'), $value->codeStandard, NULL, 2);
1092
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('institute'), $value->institute, NULL, 3);
1093
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('townOrLocation'), $value->townOrLocation, NULL, 4);
1094
                        // TODO "superCollection"
1095
                        // TODO may have media
1096

    
1097
                        @_description_list_group_add($groups, 'Collection',
1098
                            array(
1099
                                array('#markup' => $value->titleCache),
1100
                                array('#theme' => 'description_list', '#groups' => $sub_dl_groups)
1101
                            )
1102
                        );
1103

    
1104
                        break;
1105

    
1106

    
1107

    
1108

    
1109
                    /* ---- Specimen --- */
1110
                    case 'sequences':
1111
                        $dd_elements = array();
1112
                        foreach ($value as $sequence) {
1113
                            $dd_elements[] = compose_cdm_sequence($sequence, true);
1114
                            $dd_elements[] = "";
1115
                        }
1116
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements,'', 100);
1117
                        break;
1118

    
1119
                    // TODO preservation
1120
                    // TODO exsiccatum
1121

    
1122

    
1123
                    /* ---- FieldObservation --- */
1124
                    case 'gatheringEvent':
1125

    
1126
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collector'), $value->collector);
1127
                        @_description_list_group_add($groups, t('Gathering time'), timePeriodToString($value->timeperiod));
1128
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('description'), $value->description);
1129
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('locality'), $value->locality);
1130
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('country'), $value->country);
1131
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingMethod'), $value->collectingMethod);
1132
                        if (isset($value->absoluteElevation)) {
1133
                            $min_max_markup = min_max_measure($value, 'absoluteElevation');
1134
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('absoluteElevation'), $min_max_markup);
1135
                        }
1136
                        if (isset($value->distanceToGround) && $value->distanceToGround >0) {
1137
                            $min_max_markup = min_max_measure($value, 'distanceToGround');
1138
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToGround'), $min_max_markup);
1139
                        }
1140
                        if (isset($value->distanceToWaterSurface) && $value->distanceToWaterSurface > 0) {
1141
                            $min_max_markup = min_max_measure($value, 'distanceToWaterSurface');
1142
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToWaterSurface'), $min_max_markup);
1143
                        }
1144

    
1145
                        if (isset($value->collectingAreas)) {
1146
                            $area_representations = array();
1147
                            foreach ($value->collectingAreas as $area) {
1148
                               // $area_representations[] = l($area->representation_L10n, path_to_named_area($area->uuid));
1149
                                $area_representations[] = $area;
1150
                            }
1151
                            if (!empty($area_representations))
1152
                                @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingAreas'),
1153
                                    array(
1154
                                        array('#markup' => implode(', ', $area_representations))
1155
                                    )
1156
                                );
1157
                        }
1158
                        if (isset($value->exactLocation)  ) {
1159
                            $sub_dl_groups = array();
1160
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('errorRadius'), $value->exactLocation->errorRadius, ' m', 1);
1161
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('longitude'), round($value->exactLocation->longitude, 7), '°', 2);
1162
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('latitude'), round($value->exactLocation->latitude, 7), '°', 3);
1163
                            if (isset($value->exactLocation->referenceSystem)) {
1164
                                @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('referenceSystem'), $value->exactLocation->referenceSystem->representation_L10n, '', 4);
1165
                            }
1166
                            if ( isSet($value->exactLocation->sexagesimalString)){
1167
                                @_description_list_group_add($groups, cdm_occurrence_field_name_label('exactLocation'),
1168
                                    array(
1169
                                        array('#markup' => $value->exactLocation->sexagesimalString),
1170
                                        array(
1171
                                            '#theme' => 'description_list',
1172
                                            '#groups' => $sub_dl_groups
1173
                                        ),
1174
                                    )
1175
                                );
1176
                            }
1177
                        }
1178

    
1179
                        break;
1180

    
1181
                    /* ---- DerivationEvent --- */
1182
                    case 'derivationEvents':
1183
                        //@_description_list_group_add($groups, t('Association type'), $value->description);
1184
                        break;
1185

    
1186

    
1187
                    default:
1188
                        if (is_object($value) || is_array($value)) {
1189
                            drupal_set_message("Unhandled type in compose_cdm_specimenOrObservation() for field " . $field, "warning");
1190
                        } else {
1191
                            _description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value);
1192
                        }
1193

    
1194
                }
1195

    
1196

    
1197
            }
1198
        } // END of loop over $derivedUnitFacade fields
1199

    
1200

    
1201

    
1202
        // template_preprocess_description_list() is not worting by weight so we do it right here
1203
        uasort($groups, 'element_sort');
1204

    
1205
        $occurrence_elements = array(
1206
           // '#title' => $title,
1207
            '#theme' => 'description_list',
1208
            '#groups' => $groups,
1209
            '#attributes' => array('class' => html_class_attribute_ref($specimen_or_observation)),
1210
        );
1211
        $output = drupal_render($occurrence_elements);
1212
        if (isset($gallery_html)){
1213
            $output .= $gallery_html;
1214
        }
1215
        $pathToSpecimen = path_to_specimen($specimen_or_observation->uuid);
1216
        $output .=  l("detail page", $pathToSpecimen, array('attributes' => array('target' => '_blank')));
1217
    } // END of $specimenOrObservation exists
1218

    
1219
    return $output;
1220
}
1221

    
(6-6/10)