Project

General

Profile

Download (53.9 KB) Statistics
| Branch: | Tag: | Revision:
1 c70b93c3 Andreas Kohlbecker
<?php
2 f19f47fa Andreas Kohlbecker
/**
3
 * @file
4 bff67f14 Patric Plitzner
 * Functions for dealing with CDM entities of type SpecimenOrOccurrences
5 f19f47fa Andreas Kohlbecker
 *
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 c70b93c3 Andreas Kohlbecker
 */
18
19 b810158e Patric Plitzner
20
/**
21 30845bda Andreas Kohlbecker
 * Provides the HTML markup for a specimen page
22
 *
23
 * @param $specimen
24
 *
25 b810158e Patric Plitzner
 * @return string
26 30845bda Andreas Kohlbecker
 *  The markup for a specimen page
27 b810158e Patric Plitzner
 */
28 30845bda Andreas Kohlbecker
function render_cdm_specimen_page($specimen, $is_specimen_page = false)
29 b810158e Patric Plitzner
{
30
    $detail_html = "";
31
    //link to specimen page
32 30845bda Andreas Kohlbecker
    $pathToSpecimen = path_to_specimen($specimen->uuid);
33
    if (!$is_specimen_page) {
34
        $specimenPageLink = l($specimen->accessionNumber, $pathToSpecimen, array('attributes' => array('target' => '_blank')));
35 a7a302a0 Patric Plitzner
        $detail_html .= "<strong>$specimenPageLink</strong><br>";
36
    }
37
38 c10f70e4 Katja Luther
    if ($is_specimen_page) {
39
        if ($specimen->citation) {
40
            $detail_html .= "<br>" . create_label("Citation") . $specimen->citation . "<br>";
41 fdc85125 Patric Plitzner
        }
42 b810158e Patric Plitzner
    }
43 c10f70e4 Katja Luther
    if ($specimen->preferredStableUri) {
44
        $stableIdentifierLink = l($specimen->preferredStableUri, $specimen->preferredStableUri, array('attributes' => array('target' => '_blank')));
45 907cc9b4 Patrick Plitzner
        $detail_html .= create_label("Preferred stable URI") . $stableIdentifierLink . "<br>";
46 1cefb4e5 Patrick Plitzner
    }
47 c10f70e4 Katja Luther
    if ($is_specimen_page) {
48 fdc85125 Patric Plitzner
        // associated taxa
49 c10f70e4 Katja Luther
        if ($specimen->associatedTaxa) {
50 3dd58832 Patric Plitzner
            $detail_html .= "<br>";
51 c10f70e4 Katja Luther
            $detail_html .= create_label("Associated with");
52
            if (sizeof($specimen->associatedTaxa) > 1) {
53
                $detail_html .= "<br>";
54
            }
55
            foreach ($specimen->associatedTaxa as $associatedTaxon) {
56
                $detail_html .= l($associatedTaxon->second, path_to_taxon($associatedTaxon->first, "specimens"));//$associatedTaxon->second."<br>";
57
            }
58 fa09fe7d Patrick Plitzner
            $detail_html .= "<br>";
59 fdc85125 Patric Plitzner
        }
60 b810158e Patric Plitzner
    }
61 c10f70e4 Katja Luther
    // - type information
62 b810158e Patric Plitzner
    $types = "";
63 30845bda Andreas Kohlbecker
    if (isset($specimen->types)) {
64 56d58f9b Patric Plitzner
        //typed taxa
65 30845bda Andreas Kohlbecker
        foreach ($specimen->types as $typeStatus => $typedTaxa) {
66 c10f70e4 Katja Luther
            if ($is_specimen_page) {
67
                if ($specimen->types) {
68
                    $detail_html .= "<i>" . $typeStatus . "</i>: ";
69
                    foreach ($typedTaxa as $typedTaxon) {
70
                        $detail_html .= $typedTaxon . " ";
71
                    }
72
                    $detail_html .= "<br>";
73
                }
74
            } else {
75
                $types .= $typeStatus . " ";
76
77 fdc85125 Patric Plitzner
            }
78 b810158e Patric Plitzner
        }
79
    }
80 30845bda Andreas Kohlbecker
    $derivateDataDTO = $specimen->derivateDataDTO;
81 b810158e Patric Plitzner
    // - specimen scans
82 65a4de51 Patrick Plitzner
    $specimenScans = create_html_links($derivateDataDTO->specimenScans, true);
83 b810158e Patric Plitzner
    // - molecular data
84
    $molecularData = "";
85
    if ($derivateDataDTO->molecularDataList) {
86
        foreach ($derivateDataDTO->molecularDataList as $molecular) {
87
            //provider link
88
            if (isset($molecular->providerLink)) {
89 65a4de51 Patrick Plitzner
                $molecularData .= create_html_link($molecular->providerLink, true);
90 2c23b054 Patrick Plitzner
            } else {
91
                $molecularData .= "[no provider]";
92 b810158e Patric Plitzner
            }
93
            //contig link
94 2c23b054 Patrick Plitzner
            if (isset($molecular->contigFiles)) {
95 b810158e Patric Plitzner
                $molecularData .= "[";
96 2c23b054 Patrick Plitzner
                if (sizeof($molecular->contigFiles) > 0) {
97 b810158e Patric Plitzner
                    foreach ($molecular->contigFiles as $contigFile) {
98 2c23b054 Patrick Plitzner
                        if (isset($contigFile->contigLink)) {
99
                            if (isset($contigFile->contigLink->uri) and $contigFile->contigLink->uri != null) {
100
                                $molecularData .= create_html_link($contigFile->contigLink, true) . " ";
101 37ab3ddc Patric Plitzner
                            }
102 c10f70e4 Katja Luther
                        } else {
103 2c23b054 Patrick Plitzner
                            $molecularData .= "no contig ";
104
                        }
105
                        //primer links
106 c10f70e4 Katja Luther
                        if (isset($contigFile->primerLinks)) {
107 65a4de51 Patrick Plitzner
                            $molecularData .= create_html_links($contigFile->primerLinks, true);
108 b810158e Patric Plitzner
                        }
109
                    }
110
                }
111 5eafa5ff Patric Plitzner
                $molecularData = rtrim($molecularData, " ");
112 b810158e Patric Plitzner
                $molecularData .= "]";
113
            }
114
            //FIXME separate with comma (remove trailing comma)
115
        }
116
    }
117
    // - detail images
118 65a4de51 Patrick Plitzner
    $detailImages = create_html_links($derivateDataDTO->detailImages, true);
119 b810158e Patric Plitzner
120
    if ($types) {
121 c10f70e4 Katja Luther
        $detail_html .= $is_specimen_page ? "<br>" : "";
122 a0bbccce Patrick Plitzner
        $detail_html .= create_label("Type(s)") . $types . "<br>";
123 b810158e Patric Plitzner
    }
124 30845bda Andreas Kohlbecker
    if ($specimenScans and !$is_specimen_page) {
125 3dd58832 Patric Plitzner
        $detail_html .= create_label("Specimen Scans") . $specimenScans . "<br>";
126 b810158e Patric Plitzner
    }
127 8d9d64a5 Patric Plitzner
    //specimen scan image gallery
128 c10f70e4 Katja Luther
    if ($is_specimen_page and isset($derivateDataDTO->specimenScanUuids) and !empty($derivateDataDTO->specimenScanUuids)) {
129 8d9d64a5 Patric Plitzner
        $detail_html .= addImageGallery("Specimen scans", $derivateDataDTO->specimenScanUuids);
130
    }
131
132 b810158e Patric Plitzner
    if ($molecularData) {
133 c10f70e4 Katja Luther
        $detail_html .= $is_specimen_page ? "<br>" : "";
134 3dd58832 Patric Plitzner
        $detail_html .= create_label("Molecular Data") . $molecularData . "<br>";
135 b810158e Patric Plitzner
    }
136 8d9d64a5 Patric Plitzner
137 30845bda Andreas Kohlbecker
    if ($detailImages and !$is_specimen_page) {
138 3dd58832 Patric Plitzner
        $detail_html .= create_label("Detail Images") . $detailImages . "<br>";
139 b810158e Patric Plitzner
    }
140
141 8d9d64a5 Patric Plitzner
    //detail image gallery
142 c10f70e4 Katja Luther
    if ($is_specimen_page and isset($derivateDataDTO->detailImageUuids) and !empty($derivateDataDTO->detailImageUuids)) {
143 8d9d64a5 Patric Plitzner
        $detail_html .= addImageGallery("Detail Images", $derivateDataDTO->detailImageUuids);
144
    }
145
146 b810158e Patric Plitzner
    //character data
147 30845bda Andreas Kohlbecker
    if ($specimen->characterData) {
148 c10f70e4 Katja Luther
        $detail_html .= $is_specimen_page ? "<br>" : "";
149 a442acb8 Patric Plitzner
        $detail_html .= create_label("Character Data");
150 c10f70e4 Katja Luther
        if ($is_specimen_page) {
151 b810158e Patric Plitzner
            $detail_html .= "<br>";
152 30845bda Andreas Kohlbecker
            foreach ($specimen->characterData as $characterStatePair) {
153 a442acb8 Patric Plitzner
                $detail_html .= "<i>" . $characterStatePair->first . "</i>:" . $characterStatePair->second;
154
                $detail_html .= "<br>";
155
            }
156 c10f70e4 Katja Luther
        } else {
157
            $detail_html .= l("detail page", $pathToSpecimen, array('attributes' => array('target' => '_blank')));
158 216abf0b Patric Plitzner
            $detail_html .= "<br>";
159 b810158e Patric Plitzner
        }
160
    }
161 8d9d64a5 Patric Plitzner
    return $detail_html;
162
}
163 8c1d6d72 Patric Plitzner
164 c10f70e4 Katja Luther
function addImageGallery($galleryName, $imageUuids)
165
{
166 b5c89485 Patric Plitzner
    $images = array();
167 8d9d64a5 Patric Plitzner
    foreach ($imageUuids as $uuid) {
168
        $images[] = cdm_ws_get(CDM_WS_PORTAL_MEDIA, $uuid);
169 8c1d6d72 Patric Plitzner
    }
170 7cf177d0 Patrick Plitzner
171
    $gallery_html = '';
172
    if (count($imageUuids) > 0) {
173
        $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
174
        $captionElements = array(
175
            'title',
176
            'rights',
177
        );
178
        $alternativeMediaUris = array();
179 c10f70e4 Katja Luther
        foreach ($images as $image) {
180
            $mediaUri = getMediaUri($image);
181
            if ($mediaUri) {
182
                $alternativeMediaUris[] = $mediaUri;
183
            } else {
184
                $alternativeMediaUris[] = path_to_media($image->uuid);
185
            }
186 7cf177d0 Patrick Plitzner
        }
187
188 a9815578 Andreas Kohlbecker
        $gallery_html = compose_cdm_media_gallerie(array(
189 7cf177d0 Patrick Plitzner
            'mediaList' => $images,
190
            'galleryName' => $galleryName,
191
            'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
192
            'cols' => $gallery_settings['cdm_dataportal_media_cols'],
193
            'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
194
            'captionElements' => $captionElements,
195
            'mediaLinkType' => 'LIGHTBOX',
196
            'alternativeMediaUri' => $alternativeMediaUris,
197
            'galleryLinkUri' => NULL,
198
        ));
199
    }
200 c10f70e4 Katja Luther
    return "<br>" . create_label($galleryName) . "<br>" . $gallery_html;
201 b810158e Patric Plitzner
}
202
203 c10f70e4 Katja Luther
function getMediaUri($media)
204
{
205
    if (isset($media->representations) && sizeof($media->representations) == 1
206
        && isset($media->representations[0]->parts) &&
207
        sizeof($media->representations[0]->parts) == 1) {
208
        return $media->representations[0]->parts[0]->uri;
209
    }
210
    return null;
211 e2eaa6c7 Patrick Plitzner
}
212
213 8d9d64a5 Patric Plitzner
214 3dd58832 Patric Plitzner
/**
215 5a079dbf Andreas Kohlbecker
 * Formats the given string to a label for displaying key-object pairs in HTML
216 3dd58832 Patric Plitzner
 * @return string
217
 */
218
function create_label($label)
219
{
220 c10f70e4 Katja Luther
    return "<span class='specimen_table_label'>" . $label . ": </span>";
221 3dd58832 Patric Plitzner
}
222
223 f19f47fa Andreas Kohlbecker
/**
224
 * Compose an render array from a CDM DerivedUnitFacade object.
225
 *
226
 * compose_hook() implementation
227 235fc94b Andreas Kohlbecker
 *
228
 * @param object $specimenOrObservation
229
 *   the CDM instance of type SpecimenOrObservation to compose
230
 *   the render array for
231
 * @param array $derivatives
232
 *   the render array which contains the compositions of the derivatives
233
 *   of the supplied $specimenOrObservation
234
 *
235
 * @return array
236
 *   the supplied render array $derivatives to which the composition of the supplied
237
 *   $specimenOrObservation has been added to
238 5b26b91a Andreas Kohlbecker
 *
239
 * @ingroup compose
240 f19f47fa Andreas Kohlbecker
 */
241
242 98262d29 Katja Luther
function compose_cdm_specimen_or_observation($specimenOrObservation, &$derivatives = null)
243
{
244 c10f70e4 Katja Luther
    $exclude_occurrence_fields = &drupal_static(__FUNCTION__);
245
    if (!isset($exclude_occurrence_fields)) {
246
        $exclude_occurrence_fields = array(
247 fc169e34 Katja Luther
            'derivationEvent',
248
            'taxonRelatedDerivedUnits',
249 c10f70e4 Katja Luther
            'titleCache',
250
            'protectedTitleCache',
251
            'derivedUnitMedia',
252
            'created',
253
            'publish',
254
            'updated',
255
            'class',
256
            'uuid',
257 fc169e34 Katja Luther
            'collectionDTO'
258 c10f70e4 Katja Luther
        );
259
    }
260 f846e7e7 Andreas Kohlbecker
261 9b9037f3 Andreas Kohlbecker
262 c10f70e4 Katja Luther
    // only show uuid it the user is logged in
263
    if (user_is_logged_in() && ($a_idx = array_search('uuid', $exclude_occurrence_fields)) !== FALSE) {
264
        unset($exclude_occurrence_fields[$a_idx]);
265
    }
266 15b7c460 Andreas Kohlbecker
267 c10f70e4 Katja Luther
    if (!isset($derivatives)) {
268
        $derivatives = array();
269
    }
270 15b7c460 Andreas Kohlbecker
271 c10f70e4 Katja Luther
    $descriptions = null;
272
    $derivedFrom = null;
273
    $derivates = null;
274
275
    if (is_object($specimenOrObservation)) {
276
277
        // request again for deeper initialization
278
      //  $specimenOrObservation = cdm_ws_get("portal/" . CDM_WS_OCCURRENCE, $specimenOrObservation->uuid);
279
280
281
        $type_label = $specimenOrObservation->recordBase;
282
        RenderHints::setFootnoteListKey($type_label . '-' . $specimenOrObservation->uuid);
283
284
        // collect typeStatus as label
285
        if (isset($specimenOrObservation->specimenTypeDesignations)) {
286
            $type_status = array();
287
            foreach ($specimenOrObservation->specimenTypeDesignations as $typeDesignation) {
288
                if (isset($typeDesignation->typeStatus->representation_L10n)) {
289
                    $type_status[] = $typeDesignation->typeStatus->representation_L10n;
290
                }
291
            }
292
            if (count($type_status) > 0) {
293
                $type_label = implode(', ', $type_status);
294
            }
295 9b9037f3 Andreas Kohlbecker
        }
296
297 c10f70e4 Katja Luther
        $title = $type_label . ': ' . $specimenOrObservation->titleCache;
298
299
        $groups = array();
300
        // --- add initialized fields
301
        foreach (get_object_vars($specimenOrObservation) as $field => $value) {
302
            if (!in_array($field, $exclude_occurrence_fields) && ($value && (!is_object($value) || isset($value->class)))) {
303
                switch ($field) {
304
//            case 'recordBasis':
305
//                if ($value != '' /* FieldUnit' */) {
306
//                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value);
307
//                }
308
//                break;
309
                    /* ---- java.lang.Object --- */
310
                    case 'class':
311
                        if ($value != '' /* FieldUnit' */) {
312
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value);
313
                        }
314
                        break;
315 6fbdb943 Andreas Kohlbecker
316 c10f70e4 Katja Luther
                    case 'markers':
317
                        $dd_elements = array();
318
                        foreach ($value as $marker) {
319
                            $dd_elements[] = compose_cdm_marker($marker);
320
                        }
321
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
322
                        break;
323 4ae6064e Andreas Kohlbecker
324 f19f47fa Andreas Kohlbecker
325 c10f70e4 Katja Luther
                    case 'annotations':
326
                        $dd_elements = array();
327
                        foreach ($value as $annotation) {
328
                            // TODO respect annotation type filter settings
329
                            $dd_elements[] = $annotation->text;
330
                        }
331
                        @_description_list_group_add($groups, t('Notes'), $dd_elements);
332
                        break;
333
334
                    /* ---- SpecimenOrObservationBase --- */
335
                    case 'sex':
336
                    case 'lifeStage':
337
                    case 'kindOfUnit':
338
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value->representation_L10n, NULL, 1);
339
                        break;
340
341
                    case 'definition':
342
                        // TODO
343
                        break;
344
345
                    case 'preferredStableUri':
346
347
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), array(array('#markup' => cdm_external_uri($value, false))));
348
                        break;
349
350
                    case 'specimenTypeDesignations':
351
                        @_description_list_group_add(
352
                            $groups,
353
                            cdm_occurrence_field_name_label($field),
354
                            array(
355
                                '#markup' => theme('cdm_typedesignations', array('typeDesignations' => $value)),
356
                            )
357
                        );
358
                        break;
359
360
                    case 'determinations':
361
                        $dd_elements = array();
362
                        $glue = ', ';
363
364
                        foreach ($value as $determinationEvent) {
365
                            $timeperiod_string = NULL;
366
                            if (isset($determinationEvent->timeperiod)) {
367
                                $timeperiod_string = timePeriodToString($determinationEvent->timeperiod);
368
                            }
369
                            $weight = isset($determinationEvent->preferred) && $determinationEvent->preferred == 1 ? '0' : ($timeperiod_string ? $timeperiod_string : '1');
370
                            // check key exists
371
                            while (array_key_exists($weight, $dd_elements)) {
372
                                $weight .= '0';
373
                            }
374 4ae6064e Andreas Kohlbecker
375 c10f70e4 Katja Luther
                            $taxon_name = '';
376
                            $name_link = '';
377
                            if ($determinationEvent->taxonName) {
378
                                $taxon_name = $determinationEvent->taxonName;
379
                            } else if ($determinationEvent->taxon) {
380
                                $taxon_name = cdm_ws_get(CDM_WS_TAXON . '/$0/name', $determinationEvent->taxon->uuid);
381
                                $name_link = path_to_taxon($determinationEvent->taxon->uuid);
382
                            }
383
                            if ($taxon_name) {
384
                                $taxon_html = render_taxon_or_name($taxon_name, $name_link);
385
                                $dd_elements[$weight] = $taxon_html;
386
                            }
387
                            if (isset($determinationEvent->modifier)) {
388
                                $dd_elements[$weight] .= cdm_term_representation($determinationEvent->modifier);
389
                            }
390
                            if ($timeperiod_string) {
391
                                $dd_elements[$weight] .= $glue . $timeperiod_string;
392
                            }
393
                            if (isset($determinationEvent->actor->titleCache)) {
394
                                $dd_elements[$weight] .= $glue . $determinationEvent->actor->titleCache;
395
                            }
396
                            if (isset($determinationEvent->description)) {
397
                                $dd_elements[$weight] .= $glue . $determinationEvent->description;
398
                            }
399
                        }
400
                        ksort($dd_elements);
401
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('determinations'), $dd_elements);
402
                        break;
403 f846e7e7 Andreas Kohlbecker
404 c10f70e4 Katja Luther
                    case 'descriptions':
405
                        $occurrence_featureTree = cdm_get_occurrence_featureTree();
406
                        $dd_elements = array();
407 bfb2b81a Andreas Kohlbecker
408 c10f70e4 Katja Luther
                        foreach ($value as $description) {
409
                            $description = cdm_ws_get(CDM_WS_PORTAL_DESCRIPTION, $description->uuid);
410 a67e7364 Andreas Kohlbecker
//               if($description->imageGallery == TRUE) {
411
//                 continue;
412
//               }
413 c10f70e4 Katja Luther
                            $elements_by_feature = _mergeFeatureTreeDescriptions($occurrence_featureTree->root->childNodes, $description->elements);
414
                            $description_render_elements = _block_get_renderable_array(make_feature_block_list($elements_by_feature, null));
415
                            $dd_elements[] = $description_render_elements;
416
                            if ($description->isImageGallery) {
417
                                $mediaList = array();
418
                                if (is_array($description->elements)) {
419
                                    $mediaList = $description->elements;
420
                                }
421
                                $gallery_html = '';
422
                                if (count($mediaList) > 0) {
423
                                    $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
424
                                    $captionElements = array(
425
                                        '#uri' => t('open media'),
426
                                    );
427
428
                                    $gallery_html = compose_cdm_media_gallerie(array(
429
                                        'mediaList' => $mediaList,
430
                                        'galleryName' => $gallery_name,
431
                                        'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
432
                                        'cols' => $gallery_settings['cdm_dataportal_media_cols'],
433
                                        'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
434
                                        'captionElements' => $captionElements,
435
                                        'mediaLinkType' => 'LIGHTBOX',
436
                                        'alternativeMediaUri' => NULL,
437
                                        'galleryLinkUri' => NULL,
438
                                    ));
439
                                }
440 bfb2b81a Andreas Kohlbecker
441 c10f70e4 Katja Luther
                            }
442
                        }
443 6fbdb943 Andreas Kohlbecker
444 c10f70e4 Katja Luther
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
445
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $gallery_html);
446
                        break;
447 6fbdb943 Andreas Kohlbecker
448 c10f70e4 Katja Luther
                    case 'sources':
449
                        $dd_elements = array();
450
                        foreach ($value as $identifiable_source) {
451
                            $dd_elements[] = theme('cdm_OriginalSource', array('source' => $identifiable_source));
452
                        }
453
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements, NULL, 10);
454
                        break;
455
456
457
                    /* ---- DerivedUnitBase --- */
458
                    case 'derivedFrom':
459
                        $derivedFrom = $value;
460
                        break;
461
462
                    case 'collection':
463
                        $sub_dl_groups = array();
464
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('code'), $value->code, NULL, 1);
465
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('codeStandard'), $value->codeStandard, NULL, 2);
466
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('institute'), $value->institute, NULL, 3);
467
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('townOrLocation'), $value->townOrLocation, NULL, 4);
468
                        // TODO "superCollection"
469
                        // TODO may have media
470
471
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),
472
                            array(
473
                                array('#markup' => $value->titleCache),
474
                                array('#theme' => 'description_list', '#groups' => $sub_dl_groups)
475
                            )
476
                        );
477
                        break;
478
479
                    case 'storedUnder':
480
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('storedUnder'), render_taxon_or_name($value));
481
                        break;
482
483
484
                    /* ---- Specimen --- */
485
                    case 'sequences':
486
                        $dd_elements = array();
487
                        foreach ($value as $sequence) {
488
                            $dd_elements[] = compose_cdm_sequence($sequence);
489
                        }
490
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
491
                        break;
492
493
                    // TODO preservation
494
                    // TODO exsiccatum
495
496
497
                    /* ---- FieldObservation --- */
498
                    case 'gatheringEvent':
499
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collector'), $value->actor->titleCache);
500
                        @_description_list_group_add($groups, t('Gathering time'), timePeriodToString($value->timeperiod));
501
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('description'), $value->description);
502
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('locality'), $value->locality->text);
503
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('country'), $value->country->representation_L10n);
504
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingMethod'), $value->collectingMethod);
505
                        if (isset($value->absoluteElevation)) {
506
                            $min_max_markup = min_max_measure($value, 'absoluteElevation');
507
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('absoluteElevation'), $min_max_markup);
508
                        }
509
                        if (isset($value->distanceToGround)) {
510
                            $min_max_markup = min_max_measure($value, 'distanceToGround');
511
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToGround'), $min_max_markup);
512
                        }
513
                        if (isset($value->distanceToWaterSurface)) {
514
                            $min_max_markup = min_max_measure($value, 'distanceToWaterSurface');
515
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToWaterSurface'), $min_max_markup);
516
                        }
517 6fbdb943 Andreas Kohlbecker
518 c10f70e4 Katja Luther
                        if (isset($value->collectingAreas)) {
519
                            $area_representations = array();
520
                            foreach ($value->collectingAreas as $area) {
521
                                $area_representations[] = l($area->representation_L10n, path_to_named_area($area->uuid));
522
                            }
523
                            if (!empty($area_representations))
524
                                @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingAreas'),
525
                                    array(
526
                                        array('#markup' => implode(', ', $area_representations))
527
                                    )
528
                                );
529
                        }
530
                        if (isset($value->exactLocation) && $value->exactLocation->sexagesimalString) {
531
                            $sub_dl_groups = array();
532
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('errorRadius'), $value->exactLocation->errorRadius, ' m', 1);
533
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('longitude'), round($value->exactLocation->longitude, 7), '°', 2);
534
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('latitude'), round($value->exactLocation->latitude, 7), '°', 3);
535
                            if (isset($value->exactLocation->referenceSystem)) {
536
                                @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('referenceSystem'), $value->exactLocation->referenceSystem->representation_L10n, '', 4);
537
                            }
538 6fbdb943 Andreas Kohlbecker
539 c10f70e4 Katja Luther
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('exactLocation'),
540
                                array(
541
                                    array('#markup' => $value->exactLocation->sexagesimalString),
542
                                    array(
543
                                        '#theme' => 'description_list',
544
                                        '#groups' => $sub_dl_groups
545
                                    ),
546
                                )
547
                            );
548
                        }
549
                        break;
550
551
                    /* ---- DerivationEvent --- */
552
                    case 'derivationEvents':
553
                        @_description_list_group_add($groups, t('Association type'), $value->description);
554
                        break;
555
                    case 'preservedSpecimenDTOs':
556
                        $derivates = $value;
557
                        break;
558
                    case 'derivates':
559
                        $derivates = $value;
560
                        break;
561
562
                    default:
563
                        if (is_object($value) || is_array($value)) {
564
                            drupal_set_message("Unhandled type in compose_cdm_specimenOrObservation() for field " . $field, "warning");
565
                        } else {
566
                            _description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value);
567
                        }
568 74ee6b54 Andreas Kohlbecker
569 c10f70e4 Katja Luther
                }
570 f19f47fa Andreas Kohlbecker
571 98262d29 Katja Luther
572 f846e7e7 Andreas Kohlbecker
            }
573 c10f70e4 Katja Luther
        } // END of loop over $derivedUnitFacade fields
574 f19f47fa Andreas Kohlbecker
575 c10f70e4 Katja Luther
        // Extensions
576
        $extensions = cdm_ws_fetch_all(CDM_WS_PORTAL_OCCURRENCE . '/' . $specimenOrObservation->uuid . '/extensions', array($specimenOrObservation->uuid));
577
        if ($extensions && count($extensions)) {
578
579
            $extensions_render_array = compose_extensions($extensions);
580
            @_description_list_group_add($groups, t('Extensions') . ':',
581
                $extensions_render_array,
582
                '', 100);
583 f19f47fa Andreas Kohlbecker
        }
584
585 f846e7e7 Andreas Kohlbecker
586 c10f70e4 Katja Luther
        // template_preprocess_description_list() is not worting by weight so we do it right here
587
        uasort($groups, 'element_sort');
588 0820cdc0 Andreas Kohlbecker
589 c10f70e4 Katja Luther
        $occurrence_elements = array(
590
            '#title' => $title,
591
            '#theme' => 'description_list',
592
            '#groups' => $groups,
593
            '#attributes' => array('class' => html_class_attribute_ref($specimenOrObservation)),
594
        );
595
        $derivatives[] = $occurrence_elements;
596
        // all footnotes which has been assembled so far (e.g. from typeDesignations) to here
597
        $foonote_li_elements = theme('cdm_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey(), 'enclosingTag' => 'span'));
598
        if (!empty($foonote_li_elements)) {
599
            $derivatives[] = array(
600
                '#markup' => '<div class="footnotes">' . $foonote_li_elements . '</div>',
601
            );
602
        }
603 0820cdc0 Andreas Kohlbecker
604 c10f70e4 Katja Luther
        // --- recurse into originals
605
        if (!isset($derivedFrom)) {
606
            $derivedFrom = cdm_ws_get(
607
                CDM_WS_OCCURRENCE,
608
                array($specimenOrObservation->uuid, 'derivedFrom')
609
            );
610
        }
611 f846e7e7 Andreas Kohlbecker
612 c10f70e4 Katja Luther
        if (isset($derivates)) {
613 98262d29 Katja Luther
            if (isset($derivates->originals)) {
614 c10f70e4 Katja Luther
                $derived_from_label = t('derivated');
615
                // $preposition = t('from');
616
                if (isset($derivedFrom->type)) {
617
                    $derived_from_label = $derivedFrom->type->representation_L10n;
618
                    if (isset($derivedFrom->description)) {
619
                        $derived_from_label = $derivedFrom->description;
620
                    }
621
                    //  if($derivedFrom->type->uuid == UUID_DERIVATIONEVENTTYPE_ACCESSIONING){
622
                    //  $preposition = t('of');
623
                    // }
624
                }
625
                if (count($groups) > 0) {
626
                    // TODO  annotations
627 eeb98da8 Andreas Kohlbecker
628 c10f70e4 Katja Luther
                    // only display the derived from information when the derivative has any element which will be diplayed
629
                    $derivatives[] = array(
630
                        '#markup' => '<div class="derived_from">' . $derived_from_label . ': </div>',//' ' . $preposition . ': </div>',
631
                    );
632
                }
633
                // foreach ($derivedFrom->originals as $original) {
634 f846e7e7 Andreas Kohlbecker
635 6fbdb943 Andreas Kohlbecker
636 eeb98da8 Andreas Kohlbecker
637 c10f70e4 Katja Luther
            }
638 4554da02 Andreas Kohlbecker
        }
639 98262d29 Katja Luther
640 c10f70e4 Katja Luther
        if (isset($derivates )) {
641
642
            foreach ($derivates as $derivate){
643 98262d29 Katja Luther
                compose_cdm_specimen_or_observation($derivate, $derivatives);
644 c10f70e4 Katja Luther
            }
645 98262d29 Katja Luther
646 0796d2f9 Andreas Kohlbecker
        }
647 f1f05758 Andreas Kohlbecker
648 c10f70e4 Katja Luther
    } // END of $specimenOrObservation exists
649 c70b93c3 Andreas Kohlbecker
650 c10f70e4 Katja Luther
    return $derivatives;
651 f1f05758 Andreas Kohlbecker
}
652 0de9cf51 Andreas Kohlbecker
653 0820cdc0 Andreas Kohlbecker
654 0de9cf51 Andreas Kohlbecker
/**
655
 * Compose an render array from a CDM Sequence object.
656
 *
657
 * compose_hook() implementation
658
 *
659
 * @param object $sequence
660
 *   CDM instance of type Sequence
661
 * @return array
662
 *   A render array containing the fields of the supplied $sequence
663 5b26b91a Andreas Kohlbecker
 *
664
 * @ingroup compose
665 0de9cf51 Andreas Kohlbecker
 */
666 c10f70e4 Katja Luther
function compose_cdm_sequence($sequence)
667
{
668
669
    $exclude_sequence_fields = &drupal_static(__FUNCTION__);
670
    if (!isset($exclude_sequence_fields)) {
671
        $exclude_sequence_fields = array(
672
            'titleCache',
673
            'protectedTitleCache',
674
            'microReference',
675
            'created',
676
            'updated',
677
            'class',
678
        );
679
    }
680 0de9cf51 Andreas Kohlbecker
681 c10f70e4 Katja Luther
    $groups = array();
682 0de9cf51 Andreas Kohlbecker
683 c10f70e4 Katja Luther
    // -- retrieve additional data if neesscary
684
    // TODO below call disabled since sequences are not yet supported,
685
    //      see  #3347 (services and REST service controller for molecular classes implemented)
686
    //
687
    // cdm_load_annotations($sequence);
688 eeb98da8 Andreas Kohlbecker
689 c10f70e4 Katja Luther
    foreach (get_object_vars($sequence) as $field => $value) {
690 eeb98da8 Andreas Kohlbecker
691
692 c10f70e4 Katja Luther
        if (!in_array($field, $exclude_sequence_fields) && ($value && (!is_object($value) || isset($value->class)))) {
693
            switch ($field) {
694 0de9cf51 Andreas Kohlbecker
695 c10f70e4 Katja Luther
                case 'geneticAccessionNumber';
696
                    $dd_elements = array();
697
                    foreach ($value as $accession) {
698
                        if (isset($accession->uri)) {
699
                            $dd_elements[] = l($accession->accessionNumber, $accession->uri);
700
                        } else {
701
                            $dd_elements[] = $accession->accessionNumber;
702
                        }
703
                    }
704
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements, NULL, 2);
705
                    break;
706
707
708
                case 'locus': // 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.
709
                    if (isset($value->name)) {
710
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value->name, NULL, 3);
711
                    }
712
                    if (isset($value->description)) {
713
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field) . ' ' . t('description'), $value->description, NULL, 4);
714
                    }
715
                    break;
716
717
                case 'consensusSequence':
718
                    // format in genbank style, force linebreaks after each 70 nucleotites
719
                    // see also http://stackoverflow.com/questions/499137/css-how-can-i-force-a-long-string-without-any-blank-to-be-wrapped-in-xul-and
720
                    @_description_list_group_add(
721
                        $groups,
722
                        cdm_occurrence_field_name_label($field),
723
                        array(
724
                            array(
725
                                '#markup' => '<div class="sequence-length">' . $value->length . ' ' . t('pb') . '</div><div>' . wordwrap($value->string, 70, '</br>', TRUE) . '</div>',
726
                                '#wrapper_attributes' => array('class' => 'dna-sequence')
727
                            )
728
                        ),
729
                        5);
730
                    break;
731
732
                case 'dnaSample': // FIXME 3.3 implement
733
                    break;
734
                case 'singleReads': // FIXME 3.3 implement
735
                    break;
736
                case 'contigFile': // FIXME 3.3 implement - Media
737
                    break;
738
                case 'pherograms': // FIXME 3.3 implement - Media
739
                    break;
740
                case 'haplotype': // FIXME 3.3 implement
741
                    break;
742
                case 'dateSequenced': // FIXME 3.3 now in SingelRead
743
                    @_description_list_group_add($groups, t('Sequencing date'), timePeriodToString($value), NULL, 6);
744
                    break;
745
746
                case 'barcode': // boolean
747
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value ? 'Yes' : 'No', NULL, 7);
748
                    break;
749
                case 'barcodeSequencePart': // FIXME 3.3 implement, compose sequence
750
                    break;
751
752
                case 'citation':
753
                    @_description_list_group_add($groups,
754
                        cdm_occurrence_field_name_label($field),
755
                        theme('cdm_reference', array('reference' => $value, 'microReference' => $sequence->microReference)),
756
                        NULL,
757
                        8
758
                    );
759
                    break;
760
761
                case 'publishedIn':
762
                    @_description_list_group_add($groups,
763
                        cdm_occurrence_field_name_label($field),
764
                        theme('cdm_reference', array('reference' => $value)),
765
                        NULL,
766
                        7
767
                    );
768
                    break;
769
770
                case 'rights':
771
                    array_merge($groups, cdm_rights_as_dl_groups($value));
772
                    break;
773
774
                case 'annotations':
775
                    $dd_elements = array();
776
                    foreach ($value as $annotation) {
777
                        // TODO respect annotation type filter settings
778
                        $dd_elements[] = $annotation->text;
779
                    }
780
                    @_description_list_group_add($groups, t('Notes'), $dd_elements, NULL, 9);
781
                    break;
782
783
                case 'markers':
784
                    $dd_elements = array();
785
                    foreach ($value as $marker) {
786
                        $dd_elements[] = compose_cdm_marker($marker);
787
                    }
788
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements, NULL, 10);
789
                    break;
790
791
                case 'chromatograms':
792
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),
793
                        array(
794
                            '#markup' => compose_cdm_media_gallerie(array('medialist' => $value)),
795
                        ),
796
                        NULL,
797
                        11);
798
                    break;
799
800
                default:
801
                    if (is_object($value) || is_array($value)) {
802
                        drupal_set_message("Unhandled type in compose_cdm_sequence() for field " . $field, "warning");
803
                    } else {
804
                        _description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 20);
805
                    }
806 1b57b3c1 Andreas Kohlbecker
            }
807 c10f70e4 Katja Luther
        }
808 0de9cf51 Andreas Kohlbecker
    }
809
810 c10f70e4 Katja Luther
    // template_preprocess_description_list() is not worting by weight so we do it right here
811
    uasort($groups, 'element_sort');
812 eeb98da8 Andreas Kohlbecker
813 c10f70e4 Katja Luther
    $sequence_elements = array(
814
        '#theme' => 'description_list',
815
        '#groups' => $groups
816
    );
817 0de9cf51 Andreas Kohlbecker
818 c10f70e4 Katja Luther
    return $sequence_elements;
819 0de9cf51 Andreas Kohlbecker
}
820 267da0d1 Katja Luther
/**
821
 * Creates an array from a list of FieldUnitDTOs.
822
 *
823
 *
824
 * @param object $specimenOrObservations
825
 *   list of FieldUnitDTOs
826
 * @return array
827
 *   An array containing the hierarchy of the field units corresponding to the taxon
828
 *
829
 * @ingroup compose
830
 */
831
function create_specimen_array(array $specimenOrObservations){
832
    $items_specimen = array();
833
    $items = array();
834
    $children = array();
835
    //we need one more item to contain the items of one level (fieldunit, derivate data etc.)
836
    foreach ($specimenOrObservations as &$specimenOrObservation) {
837 7965ef92 Katja Luther
        $items['data'] = $specimenOrObservation->listLabel;
838 267da0d1 Katja Luther
        $specimen = create_cdm_specimen_or_observation($specimenOrObservation);
839
        $children = array();
840
        $child = array();
841
        $child['data'] =$specimen;
842
       // $children[] = create_specimen_array($specimenOrObservation->derivates);
843
       if (isset($specimenOrObservation->derivates) && sizeof($specimenOrObservation->derivates) > 0){
844
           $child['children']= create_specimen_array($specimenOrObservation->derivates);
845
       }
846
       $children[]=$child;
847
       $items['children'] = $children;
848
       $items_specimen[] = $items;
849
    }
850
    return $items_specimen;
851
}
852
853
854
/**
855
 * Compose an render array from a CDM DerivedUnitFacade object.
856
 *
857
 * compose_hook() implementation
858
 *
859
 * @param object $specimenOrObservation
860
 *   the CDM instance of type SpecimenOrObservation to compose
861
 *   the render array for
862
 * @param array $derivatives
863
 *   the render array which contains the compositions of the derivatives
864
 *   of the supplied $specimenOrObservation
865
 *
866
 * @return array
867
 *   the supplied render array $derivatives to which the composition of the supplied
868
 *   $specimenOrObservation has been added to
869
 *
870
 * @ingroup compose
871
 */
872
873
function create_cdm_specimen_or_observation($specimenOrObservation)
874
{
875
    $exclude_occurrence_fields = &drupal_static(__FUNCTION__);
876
    if (!isset($exclude_occurrence_fields)) {
877
        $exclude_occurrence_fields = array(
878
            'type',
879
            'derivationEvent',
880
            'taxonRelatedDerivedUnits',
881 7965ef92 Katja Luther
            'label',
882 267da0d1 Katja Luther
            'titleCache',
883 7965ef92 Katja Luther
            'listLabel',
884 267da0d1 Katja Luther
            'protectedTitleCache',
885
            'derivedUnitMedia',
886
            'created',
887
            'publish',
888
            'updated',
889
            'class',
890
            'uuid',
891
            'collectionDTO'
892
        );
893
    }
894
    $items = array();
895
896
    // only show uuid it the user is logged in
897
    if (user_is_logged_in() && ($a_idx = array_search('uuid', $exclude_occurrence_fields)) !== FALSE) {
898
      //  unset($exclude_occurrence_fields[$a_idx]);
899
    }
900
901
902
    if (is_object($specimenOrObservation)) {
903
904
        $type_label = $specimenOrObservation->recordBase;
905
        RenderHints::setFootnoteListKey($type_label . '-' . $specimenOrObservation->uuid);
906
907
        // collect typeStatus as label
908
        if (isset($specimenOrObservation->specimenTypeDesignations)) {
909
            $type_status = array();
910
            foreach ($specimenOrObservation->specimenTypeDesignations as $typeDesignation) {
911
                if (isset($typeDesignation->typeStatus->representation_L10n)) {
912
                    $type_status[] = $typeDesignation->typeStatus->representation_L10n;
913
                }
914
            }
915
            if (count($type_status) > 0) {
916
                $type_label = implode(', ', $type_status);
917
            }
918
        }
919
920
        $title = $type_label . ': ' . $specimenOrObservation->titleCache;
921 7965ef92 Katja Luther
        $items['data'] = $title;
922 267da0d1 Katja Luther
923
        $groups = array();
924
        $items['children'] = $groups;
925
        $children_items = array();
926
        // --- add initialized fields
927
        foreach (get_object_vars($specimenOrObservation) as $field => $value) {
928
            $child_item = array();
929
930
            if (!in_array($field, $exclude_occurrence_fields) && ($value && (!is_object($value) || isset($value->class)))) {
931
                switch ($field) {
932
//            case 'recordBasis':
933
//                if ($value != '' /* FieldUnit' */) {
934
//                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value);
935
//                }
936
//                break;
937
                    /* ---- java.lang.Object --- */
938
939
                    case 'markers':
940
                       /* $dd_elements = array();
941
                        foreach ($value as $marker) {
942
                            $dd_elements[] = compose_cdm_marker($marker);
943
                        }
944
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
945
                       */
946
                       break;
947
948
949
                    case 'annotations':
950
                        /*$dd_elements = array();
951
                        foreach ($value as $annotation) {
952
                            // TODO respect annotation type filter settings
953
                            $dd_elements[] = $annotation->text;
954
                        }
955
                        @_description_list_group_add($groups, t('Notes'), $dd_elements);
956
                        */
957
                        break;
958
959
                    /* ---- SpecimenOrObservationBase --- */
960
                    case 'sex':
961
                    case 'lifeStage':
962
                    case 'kindOfUnit':
963
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value->representation_L10n, NULL, 1);
964
                        break;
965
966
                    case 'definition':
967
                        // TODO
968
                        break;
969
970
                    case 'preferredStableUri':
971
972 7965ef92 Katja Luther
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), array(array('#markup' => cdm_external_uri($value, false))));
973 267da0d1 Katja Luther
                        break;
974
975
                    case 'specimenTypeDesignations':
976
                      /*     $groups,
977
                            cdm_occurrence_field_name_label($field),
978
                            array(
979
                                '#markup' => theme('cdm_typedesignations', array('typeDesignations' => $value)),
980
                            )
981
                        );
982
                      */
983
                        break;
984
985
                    case 'determinations':
986
                        /*$dd_elements = array();
987
                        $glue = ', ';
988
989
                        foreach ($value as $determinationEvent) {
990
                            $timeperiod_string = NULL;
991
                            if (isset($determinationEvent->timeperiod)) {
992
                                $timeperiod_string = timePeriodToString($determinationEvent->timeperiod);
993
                            }
994
                            $weight = isset($determinationEvent->preferred) && $determinationEvent->preferred == 1 ? '0' : ($timeperiod_string ? $timeperiod_string : '1');
995
                            // check key exists
996
                            while (array_key_exists($weight, $dd_elements)) {
997
                                $weight .= '0';
998
                            }
999
1000
                            $taxon_name = '';
1001
                            $name_link = '';
1002
                            if ($determinationEvent->taxonName) {
1003
                                $taxon_name = $determinationEvent->taxonName;
1004
                            } else if ($determinationEvent->taxon) {
1005
                                $taxon_name = cdm_ws_get(CDM_WS_TAXON . '/$0/name', $determinationEvent->taxon->uuid);
1006
                                $name_link = path_to_taxon($determinationEvent->taxon->uuid);
1007
                            }
1008
                            if ($taxon_name) {
1009
                                $taxon_html = render_taxon_or_name($taxon_name, $name_link);
1010
                                $dd_elements[$weight] = $taxon_html;
1011
                            }
1012
                            if (isset($determinationEvent->modifier)) {
1013
                            }
1014
                            if ($timeperiod_string) {
1015
                                $dd_elements[$weight] .= $glue . $timeperiod_string;
1016
                            }
1017
                            if (isset($determinationEvent->actor->titleCache)) {
1018
                                $dd_elements[$weight] .= $glue . $determinationEvent->actor->titleCache;
1019
                            }
1020
                            if (isset($determinationEvent->description)) {
1021
                                $dd_elements[$weight] .= $glue . $determinationEvent->description;
1022
                            }
1023
                        }
1024
                        ksort($dd_elements);
1025
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('determinations'), $dd_elements);
1026
                        */
1027
                        break;
1028
1029 7965ef92 Katja Luther
                    case 'listOfMedia':
1030
                        $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
1031
                        $captionElements = array(
1032
                            '#uri' => t('open media'),
1033
                        );
1034
                        $gallery_html = compose_cdm_media_gallerie(array(
1035
                            'mediaList' => $value,
1036
                            'galleryName' => $specimenOrObservation->label,
1037
                            'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
1038
                            'cols' => $gallery_settings['cdm_dataportal_media_cols'],
1039
                            'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
1040
                            'captionElements' => $captionElements,
1041
                            'mediaLinkType' => 'LIGHTBOX',
1042
                            'alternativeMediaUri' => NULL,
1043
                            'galleryLinkUri' => NULL,
1044
                        ));
1045
1046
                         @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $gallery_html);
1047
                         break;
1048 267da0d1 Katja Luther
1049
                    case 'sources':
1050
                        /*
1051
                        $dd_elements = array();
1052
                        foreach ($value as $identifiable_source) {
1053
                            $dd_elements[] = theme('cdm_OriginalSource', array('source' => $identifiable_source));
1054
                        }
1055
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements, NULL, 10);
1056
                        */
1057
                        break;
1058
1059
1060
                    /* ---- DerivedUnitBase --- */
1061
1062 1083804e Andreas Kohlbecker
1063 267da0d1 Katja Luther
                    case 'collection':
1064 7965ef92 Katja Luther
1065 267da0d1 Katja Luther
                        $sub_dl_groups = array();
1066
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('code'), $value->code, NULL, 1);
1067
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('codeStandard'), $value->codeStandard, NULL, 2);
1068
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('institute'), $value->institute, NULL, 3);
1069
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('townOrLocation'), $value->townOrLocation, NULL, 4);
1070
                        // TODO "superCollection"
1071
                        // TODO may have media
1072
1073
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),
1074
                            array(
1075
                                array('#markup' => $value->titleCache),
1076
                                array('#theme' => 'description_list', '#groups' => $sub_dl_groups)
1077
                            )
1078
                        );
1079 7965ef92 Katja Luther
1080 267da0d1 Katja Luther
                        break;
1081
1082
                    case 'storedUnder':
1083
1084
                        //@_description_list_group_add($groups, cdm_occurrence_field_name_label('storedUnder'), render_taxon_or_name($value));
1085
                        break;
1086
1087
1088
                    /* ---- Specimen --- */
1089
                    case 'sequences':
1090
                        /*
1091
                        $dd_elements = array();
1092
                        foreach ($value as $sequence) {
1093
                            $dd_elements[] = compose_cdm_sequence($sequence);
1094
                        }
1095
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
1096
                        */
1097
                        break;
1098
1099
                    // TODO preservation
1100
                    // TODO exsiccatum
1101
1102
1103
                    /* ---- FieldObservation --- */
1104
                    case 'gatheringEvent':
1105
1106
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collector'), $value->actor->titleCache);
1107
                        @_description_list_group_add($groups, t('Gathering time'), timePeriodToString($value->timeperiod));
1108
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('description'), $value->description);
1109
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('locality'), $value->locality->text);
1110
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('country'), $value->country->representation_L10n);
1111
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingMethod'), $value->collectingMethod);
1112
                        if (isset($value->absoluteElevation)) {
1113
                            $min_max_markup = min_max_measure($value, 'absoluteElevation');
1114
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('absoluteElevation'), $min_max_markup);
1115
                        }
1116
                        if (isset($value->distanceToGround)) {
1117
                            $min_max_markup = min_max_measure($value, 'distanceToGround');
1118
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToGround'), $min_max_markup);
1119
                        }
1120
                        if (isset($value->distanceToWaterSurface)) {
1121
                            $min_max_markup = min_max_measure($value, 'distanceToWaterSurface');
1122
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToWaterSurface'), $min_max_markup);
1123
                        }
1124
1125
                        if (isset($value->collectingAreas)) {
1126
                            $area_representations = array();
1127
                            foreach ($value->collectingAreas as $area) {
1128
                                $area_representations[] = l($area->representation_L10n, path_to_named_area($area->uuid));
1129
                            }
1130
                            if (!empty($area_representations))
1131
                                @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingAreas'),
1132
                                    array(
1133
                                        array('#markup' => implode(', ', $area_representations))
1134
                                    )
1135
                                );
1136
                        }
1137
                        if (isset($value->exactLocation)  && $value->exactLocation->sexagesimalString) {
1138
                            $sub_dl_groups = array();
1139
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('errorRadius'), $value->exactLocation->errorRadius, ' m', 1);
1140
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('longitude'), round($value->exactLocation->longitude, 7), '°', 2);
1141
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('latitude'), round($value->exactLocation->latitude, 7), '°', 3);
1142
                            if (isset($value->exactLocation->referenceSystem)) {
1143
                                @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('referenceSystem'), $value->exactLocation->referenceSystem->representation_L10n, '', 4);
1144
                            }
1145
1146
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('exactLocation'),
1147
                                array(
1148
                                    array('#markup' => $value->exactLocation->sexagesimalString),
1149
                                    array(
1150
                                        '#theme' => 'description_list',
1151
                                        '#groups' => $sub_dl_groups
1152
                                    ),
1153
                                )
1154
                            );
1155
                        }
1156
1157
                        break;
1158
1159
                    /* ---- DerivationEvent --- */
1160
                    case 'derivationEvents':
1161
                        //@_description_list_group_add($groups, t('Association type'), $value->description);
1162
                        break;
1163
1164
1165
                    default:
1166
                        if (is_object($value) || is_array($value)) {
1167
                           // drupal_set_message("Unhandled type in compose_cdm_specimenOrObservation() for field " . $field, "warning");
1168
                        } else {
1169
                            _description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value);
1170
                        }
1171
1172
                }
1173
1174
1175
            }
1176
        } // END of loop over $derivedUnitFacade fields
1177
1178
        // Extensions
1179
       /* $extensions = cdm_ws_fetch_all(CDM_WS_PORTAL_OCCURRENCE . '/' . $specimenOrObservation->uuid . '/extensions', array($specimenOrObservation->uuid));
1180
        if ($extensions && count($extensions)) {
1181
1182
            $extensions_render_array = compose_extensions($extensions);
1183
            @_description_list_group_add($groups, t('Extensions') . ':',
1184
                $extensions_render_array,
1185
                '', 100);
1186
        }
1187
*/
1188
1189
        // template_preprocess_description_list() is not worting by weight so we do it right here
1190
        uasort($groups, 'element_sort');
1191
1192
        $occurrence_elements = array(
1193
           // '#title' => $title,
1194
            '#theme' => 'description_list',
1195
            '#groups' => $groups,
1196
            '#attributes' => array('class' => html_class_attribute_ref($specimenOrObservation)),
1197
        );
1198
        $output = drupal_render($occurrence_elements);
1199
1200
1201
1202
1203
1204
1205
1206
1207
    } // END of $specimenOrObservation exists
1208
1209
    return $output;
1210
}