Project

General

Profile

Download (51.4 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 d3f77ada Katja Luther
            'derivationEvents',
248 c10f70e4 Katja Luther
            'titleCache',
249
            'protectedTitleCache',
250
            'derivedUnitMedia',
251
            'created',
252
            'publish',
253
            'updated',
254
            'class',
255
            'uuid',
256 d3f77ada Katja Luther
            ''
257 c10f70e4 Katja Luther
        );
258
    }
259 f846e7e7 Andreas Kohlbecker
260 9b9037f3 Andreas Kohlbecker
261 c10f70e4 Katja Luther
    // only show uuid it the user is logged in
262 d3f77ada Katja Luther
    if(user_is_logged_in() && ($a_idx = array_search('uuid', $exclude_occurrence_fields)) !== FALSE ) {
263 c10f70e4 Katja Luther
        unset($exclude_occurrence_fields[$a_idx]);
264
    }
265 15b7c460 Andreas Kohlbecker
266 c10f70e4 Katja Luther
    if (!isset($derivatives)) {
267
        $derivatives = array();
268
    }
269 15b7c460 Andreas Kohlbecker
270 c10f70e4 Katja Luther
    $descriptions = null;
271
    $derivedFrom = null;
272
273
    if (is_object($specimenOrObservation)) {
274
275
        // request again for deeper initialization
276 d3f77ada Katja Luther
        $specimenOrObservation = cdm_ws_get("portal/" . CDM_WS_OCCURRENCE, $specimenOrObservation->uuid);
277 c10f70e4 Katja Luther
278
279 d3f77ada Katja Luther
        $type_label = $specimenOrObservation->class;
280 c10f70e4 Katja Luther
        RenderHints::setFootnoteListKey($type_label . '-' . $specimenOrObservation->uuid);
281
282
        // collect typeStatus as label
283
        if (isset($specimenOrObservation->specimenTypeDesignations)) {
284
            $type_status = array();
285
            foreach ($specimenOrObservation->specimenTypeDesignations as $typeDesignation) {
286
                if (isset($typeDesignation->typeStatus->representation_L10n)) {
287
                    $type_status[] = $typeDesignation->typeStatus->representation_L10n;
288
                }
289
            }
290
            if (count($type_status) > 0) {
291
                $type_label = implode(', ', $type_status);
292
            }
293 9b9037f3 Andreas Kohlbecker
        }
294
295 c10f70e4 Katja Luther
        $title = $type_label . ': ' . $specimenOrObservation->titleCache;
296
297
        $groups = array();
298
        // --- add initialized fields
299
        foreach (get_object_vars($specimenOrObservation) as $field => $value) {
300
            if (!in_array($field, $exclude_occurrence_fields) && ($value && (!is_object($value) || isset($value->class)))) {
301
                switch ($field) {
302 d3f77ada Katja Luther
303 c10f70e4 Katja Luther
                    /* ---- java.lang.Object --- */
304
                    case 'class':
305
                        if ($value != '' /* FieldUnit' */) {
306
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value);
307
                        }
308
                        break;
309 6fbdb943 Andreas Kohlbecker
310 c10f70e4 Katja Luther
                    case 'markers':
311
                        $dd_elements = array();
312
                        foreach ($value as $marker) {
313
                            $dd_elements[] = compose_cdm_marker($marker);
314
                        }
315
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
316
                        break;
317 4ae6064e Andreas Kohlbecker
318 f19f47fa Andreas Kohlbecker
319 c10f70e4 Katja Luther
                    case 'annotations':
320
                        $dd_elements = array();
321
                        foreach ($value as $annotation) {
322
                            // TODO respect annotation type filter settings
323
                            $dd_elements[] = $annotation->text;
324
                        }
325
                        @_description_list_group_add($groups, t('Notes'), $dd_elements);
326
                        break;
327
328
                    /* ---- SpecimenOrObservationBase --- */
329
                    case 'sex':
330
                    case 'lifeStage':
331
                    case 'kindOfUnit':
332 d3f77ada Katja Luther
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value->representation_L10n);
333 c10f70e4 Katja Luther
                        break;
334
335
                    case 'definition':
336
                        // TODO
337
                        break;
338
339
                    case 'preferredStableUri':
340
341
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), array(array('#markup' => cdm_external_uri($value, false))));
342
                        break;
343
344
                    case 'specimenTypeDesignations':
345
                        @_description_list_group_add(
346
                            $groups,
347
                            cdm_occurrence_field_name_label($field),
348
                            array(
349
                                '#markup' => theme('cdm_typedesignations', array('typeDesignations' => $value)),
350
                            )
351
                        );
352
                        break;
353
354
                    case 'determinations':
355
                        $dd_elements = array();
356
                        $glue = ', ';
357
358
                        foreach ($value as $determinationEvent) {
359
                            $timeperiod_string = NULL;
360
                            if (isset($determinationEvent->timeperiod)) {
361
                                $timeperiod_string = timePeriodToString($determinationEvent->timeperiod);
362
                            }
363
                            $weight = isset($determinationEvent->preferred) && $determinationEvent->preferred == 1 ? '0' : ($timeperiod_string ? $timeperiod_string : '1');
364
                            // check key exists
365
                            while (array_key_exists($weight, $dd_elements)) {
366
                                $weight .= '0';
367
                            }
368 4ae6064e Andreas Kohlbecker
369 c10f70e4 Katja Luther
                            $taxon_name = '';
370
                            $name_link = '';
371
                            if ($determinationEvent->taxonName) {
372
                                $taxon_name = $determinationEvent->taxonName;
373
                            } else if ($determinationEvent->taxon) {
374
                                $taxon_name = cdm_ws_get(CDM_WS_TAXON . '/$0/name', $determinationEvent->taxon->uuid);
375
                                $name_link = path_to_taxon($determinationEvent->taxon->uuid);
376
                            }
377
                            if ($taxon_name) {
378
                                $taxon_html = render_taxon_or_name($taxon_name, $name_link);
379
                                $dd_elements[$weight] = $taxon_html;
380
                            }
381
                            if (isset($determinationEvent->modifier)) {
382
                                $dd_elements[$weight] .= cdm_term_representation($determinationEvent->modifier);
383
                            }
384
                            if ($timeperiod_string) {
385
                                $dd_elements[$weight] .= $glue . $timeperiod_string;
386
                            }
387
                            if (isset($determinationEvent->actor->titleCache)) {
388
                                $dd_elements[$weight] .= $glue . $determinationEvent->actor->titleCache;
389
                            }
390
                            if (isset($determinationEvent->description)) {
391
                                $dd_elements[$weight] .= $glue . $determinationEvent->description;
392
                            }
393
                        }
394
                        ksort($dd_elements);
395
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('determinations'), $dd_elements);
396
                        break;
397 f846e7e7 Andreas Kohlbecker
398 c10f70e4 Katja Luther
                    case 'descriptions':
399
                        $occurrence_featureTree = cdm_get_occurrence_featureTree();
400
                        $dd_elements = array();
401 bfb2b81a Andreas Kohlbecker
402 c10f70e4 Katja Luther
                        foreach ($value as $description) {
403
                            $description = cdm_ws_get(CDM_WS_PORTAL_DESCRIPTION, $description->uuid);
404 a67e7364 Andreas Kohlbecker
//               if($description->imageGallery == TRUE) {
405
//                 continue;
406
//               }
407 c10f70e4 Katja Luther
                            $elements_by_feature = _mergeFeatureTreeDescriptions($occurrence_featureTree->root->childNodes, $description->elements);
408
                            $description_render_elements = _block_get_renderable_array(make_feature_block_list($elements_by_feature, null));
409
                            $dd_elements[] = $description_render_elements;
410
                        }
411 6fbdb943 Andreas Kohlbecker
412 c10f70e4 Katja Luther
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
413
                        break;
414 6fbdb943 Andreas Kohlbecker
415 c10f70e4 Katja Luther
                    case 'sources':
416
                        $dd_elements = array();
417
                        foreach ($value as $identifiable_source) {
418
                            $dd_elements[] = theme('cdm_OriginalSource', array('source' => $identifiable_source));
419
                        }
420 d3f77ada Katja Luther
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
421 c10f70e4 Katja Luther
                        break;
422
423
424
                    /* ---- DerivedUnitBase --- */
425
                    case 'derivedFrom':
426
                        $derivedFrom = $value;
427
                        break;
428
429
                    case 'collection':
430
                        $sub_dl_groups = array();
431
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('code'), $value->code, NULL, 1);
432
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('codeStandard'), $value->codeStandard, NULL, 2);
433
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('institute'), $value->institute, NULL, 3);
434
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('townOrLocation'), $value->townOrLocation, NULL, 4);
435
                        // TODO "superCollection"
436
                        // TODO may have media
437
438
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),
439
                            array(
440
                                array('#markup' => $value->titleCache),
441
                                array('#theme' => 'description_list', '#groups' => $sub_dl_groups)
442
                            )
443
                        );
444
                        break;
445
446
                    case 'storedUnder':
447
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('storedUnder'), render_taxon_or_name($value));
448
                        break;
449
450
451
                    /* ---- Specimen --- */
452
                    case 'sequences':
453
                        $dd_elements = array();
454
                        foreach ($value as $sequence) {
455
                            $dd_elements[] = compose_cdm_sequence($sequence);
456
                        }
457
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
458
                        break;
459
460
                    // TODO preservation
461
                    // TODO exsiccatum
462
463
464
                    /* ---- FieldObservation --- */
465
                    case 'gatheringEvent':
466
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collector'), $value->actor->titleCache);
467
                        @_description_list_group_add($groups, t('Gathering time'), timePeriodToString($value->timeperiod));
468
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('description'), $value->description);
469
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('locality'), $value->locality->text);
470
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('country'), $value->country->representation_L10n);
471
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingMethod'), $value->collectingMethod);
472
                        if (isset($value->absoluteElevation)) {
473
                            $min_max_markup = min_max_measure($value, 'absoluteElevation');
474
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('absoluteElevation'), $min_max_markup);
475
                        }
476
                        if (isset($value->distanceToGround)) {
477
                            $min_max_markup = min_max_measure($value, 'distanceToGround');
478
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToGround'), $min_max_markup);
479
                        }
480
                        if (isset($value->distanceToWaterSurface)) {
481
                            $min_max_markup = min_max_measure($value, 'distanceToWaterSurface');
482
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToWaterSurface'), $min_max_markup);
483
                        }
484 6fbdb943 Andreas Kohlbecker
485 2228f46b Andreas Kohlbecker
            if (isset($value->collectingAreas) && count($value->collectingAreas) > 0) {
486 c10f70e4 Katja Luther
                            $area_representations = array();
487
                            foreach ($value->collectingAreas as $area) {
488
                                $area_representations[] = l($area->representation_L10n, path_to_named_area($area->uuid));
489
                            }
490 d3f77ada Katja Luther
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingAreas'),
491
                                array(
492
                                    array('#markup' => implode(', ', $area_representations))
493
                                )
494
                            );
495 c10f70e4 Katja Luther
                        }
496
                        if (isset($value->exactLocation) && $value->exactLocation->sexagesimalString) {
497
                            $sub_dl_groups = array();
498
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('errorRadius'), $value->exactLocation->errorRadius, ' m', 1);
499
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('longitude'), round($value->exactLocation->longitude, 7), '°', 2);
500
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('latitude'), round($value->exactLocation->latitude, 7), '°', 3);
501
                            if (isset($value->exactLocation->referenceSystem)) {
502
                                @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('referenceSystem'), $value->exactLocation->referenceSystem->representation_L10n, '', 4);
503
                            }
504 6fbdb943 Andreas Kohlbecker
505 c10f70e4 Katja Luther
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('exactLocation'),
506
                                array(
507
                                    array('#markup' => $value->exactLocation->sexagesimalString),
508
                                    array(
509
                                        '#theme' => 'description_list',
510
                                        '#groups' => $sub_dl_groups
511
                                    ),
512
                                )
513
                            );
514
                        }
515
                        break;
516
517
                    default:
518
                        if (is_object($value) || is_array($value)) {
519 d3f77ada Katja Luther
                            drupal_set_message("Unhandled type in compose_cdm_specimen_or_observation() for field " . $field, "warning");
520 c10f70e4 Katja Luther
                        } else {
521
                            _description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value);
522
                        }
523 74ee6b54 Andreas Kohlbecker
524 c10f70e4 Katja Luther
                }
525 f19f47fa Andreas Kohlbecker
526 f846e7e7 Andreas Kohlbecker
            }
527 c10f70e4 Katja Luther
        } // END of loop over $derivedUnitFacade fields
528 f19f47fa Andreas Kohlbecker
529 c10f70e4 Katja Luther
        // Extensions
530 d3f77ada Katja Luther
        $extensions = cdm_ws_fetch_all(CDM_WS_PORTAL_OCCURRENCE . '/'  . $specimenOrObservation->uuid . '/extensions', array($specimenOrObservation->uuid));
531 c10f70e4 Katja Luther
        if ($extensions && count($extensions)) {
532
533
            $extensions_render_array = compose_extensions($extensions);
534
            @_description_list_group_add($groups, t('Extensions') . ':',
535
                $extensions_render_array,
536
                '', 100);
537 f19f47fa Andreas Kohlbecker
        }
538
539 f846e7e7 Andreas Kohlbecker
540 c10f70e4 Katja Luther
        // template_preprocess_description_list() is not worting by weight so we do it right here
541
        uasort($groups, 'element_sort');
542 0820cdc0 Andreas Kohlbecker
543 c10f70e4 Katja Luther
        $occurrence_elements = array(
544
            '#title' => $title,
545
            '#theme' => 'description_list',
546
            '#groups' => $groups,
547
            '#attributes' => array('class' => html_class_attribute_ref($specimenOrObservation)),
548
        );
549
        $derivatives[] = $occurrence_elements;
550
        // all footnotes which has been assembled so far (e.g. from typeDesignations) to here
551
        $foonote_li_elements = theme('cdm_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey(), 'enclosingTag' => 'span'));
552
        if (!empty($foonote_li_elements)) {
553 d3f77ada Katja Luther
            $derivatives[] =  array(
554
                '#markup' =>  '<div class="footnotes">' . $foonote_li_elements . '</div>',
555 c10f70e4 Katja Luther
            );
556
        }
557 0820cdc0 Andreas Kohlbecker
558 c10f70e4 Katja Luther
        // --- recurse into originals
559
        if (!isset($derivedFrom)) {
560
            $derivedFrom = cdm_ws_get(
561
                CDM_WS_OCCURRENCE,
562
                array($specimenOrObservation->uuid, 'derivedFrom')
563
            );
564
        }
565 f846e7e7 Andreas Kohlbecker
566 d3f77ada Katja Luther
        if (isset($derivedFrom)) {
567
            if (isset($derivedFrom->originals)) {
568
                $derived_from_label = t('derived');
569
                $preposition = t('from');
570
                if(isset($derivedFrom->type)){
571 c10f70e4 Katja Luther
                    $derived_from_label = $derivedFrom->type->representation_L10n;
572 d3f77ada Katja Luther
                    if($derivedFrom->type->uuid == UUID_DERIVATIONEVENTTYPE_ACCESSIONING){
573
                        $preposition = t('of');
574 c10f70e4 Katja Luther
                    }
575
                }
576
                if (count($groups) > 0) {
577
                    // TODO  annotations
578 eeb98da8 Andreas Kohlbecker
579 c10f70e4 Katja Luther
                    // only display the derived from information when the derivative has any element which will be diplayed
580
                    $derivatives[] = array(
581 d3f77ada Katja Luther
                        '#markup' => '<div class="derived_from">' . $derived_from_label . ' ' . $preposition . ': </div>',
582 c10f70e4 Katja Luther
                    );
583
                }
584 d3f77ada Katja Luther
                foreach ($derivedFrom->originals as $original) {
585
                    compose_cdm_specimen_or_observation($original, $derivatives);
586
                }
587 c10f70e4 Katja Luther
            }
588 0796d2f9 Andreas Kohlbecker
        }
589 f1f05758 Andreas Kohlbecker
590 c10f70e4 Katja Luther
    } // END of $specimenOrObservation exists
591 c70b93c3 Andreas Kohlbecker
592 c10f70e4 Katja Luther
    return $derivatives;
593 f1f05758 Andreas Kohlbecker
}
594 0de9cf51 Andreas Kohlbecker
595 0820cdc0 Andreas Kohlbecker
596 0de9cf51 Andreas Kohlbecker
/**
597
 * Compose an render array from a CDM Sequence object.
598
 *
599
 * compose_hook() implementation
600
 *
601
 * @param object $sequence
602
 *   CDM instance of type Sequence
603
 * @return array
604
 *   A render array containing the fields of the supplied $sequence
605 5b26b91a Andreas Kohlbecker
 *
606
 * @ingroup compose
607 0de9cf51 Andreas Kohlbecker
 */
608 52f57468 Katja Luther
function compose_cdm_sequence($sequence, $isSpecimenPage = false)
609 c10f70e4 Katja Luther
{
610
611
    $exclude_sequence_fields = &drupal_static(__FUNCTION__);
612
    if (!isset($exclude_sequence_fields)) {
613
        $exclude_sequence_fields = array(
614
            'titleCache',
615
            'protectedTitleCache',
616
            'microReference',
617
            'created',
618
            'updated',
619
            'class',
620 52f57468 Katja Luther
            'dnaMarker'
621 c10f70e4 Katja Luther
        );
622
    }
623 0de9cf51 Andreas Kohlbecker
624 c10f70e4 Katja Luther
    $groups = array();
625 0de9cf51 Andreas Kohlbecker
626 c10f70e4 Katja Luther
    // -- retrieve additional data if neesscary
627
    // TODO below call disabled since sequences are not yet supported,
628
    //      see  #3347 (services and REST service controller for molecular classes implemented)
629
    //
630
    // cdm_load_annotations($sequence);
631 eeb98da8 Andreas Kohlbecker
632 c10f70e4 Katja Luther
    foreach (get_object_vars($sequence) as $field => $value) {
633 eeb98da8 Andreas Kohlbecker
634
635 c10f70e4 Katja Luther
        if (!in_array($field, $exclude_sequence_fields) && ($value && (!is_object($value) || isset($value->class)))) {
636
            switch ($field) {
637 0de9cf51 Andreas Kohlbecker
638 c10f70e4 Katja Luther
                case 'geneticAccessionNumber';
639 52f57468 Katja Luther
640
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 2);
641 c10f70e4 Katja Luther
                    break;
642
643
644 52f57468 Katja Luther
                /*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.
645
                    /*if (isset($value->name)) {
646 c10f70e4 Katja Luther
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value->name, NULL, 3);
647
                    }
648
                    if (isset($value->description)) {
649
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field) . ' ' . t('description'), $value->description, NULL, 4);
650
                    }
651 52f57468 Katja Luther
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field) , $value, NULL, 4);
652 c10f70e4 Katja Luther
                    break;
653 52f57468 Katja Luther
                */
654 c10f70e4 Katja Luther
                case 'consensusSequence':
655
                    // format in genbank style, force linebreaks after each 70 nucleotites
656
                    // see also http://stackoverflow.com/questions/499137/css-how-can-i-force-a-long-string-without-any-blank-to-be-wrapped-in-xul-and
657 52f57468 Katja Luther
                    if ($value->length > 0) {
658
                        @_description_list_group_add(
659
                            $groups,
660
                            cdm_occurrence_field_name_label($field),
661 c10f70e4 Katja Luther
                            array(
662 52f57468 Katja Luther
                                array(
663
                                    '#markup' => '<div class="sequence-length">' . $value->length . ' ' . t('pb') . '</div><div>' . wordwrap($value->string, 70, '</br>', TRUE) . '</div>',
664
                                    '#wrapper_attributes' => array('class' => 'dna-sequence')
665
                                )
666
                            ),
667
                            5);
668
                    }
669 c10f70e4 Katja Luther
                    break;
670
671
                case 'dnaSample': // FIXME 3.3 implement
672
                    break;
673
                case 'singleReads': // FIXME 3.3 implement
674
                    break;
675
                case 'contigFile': // FIXME 3.3 implement - Media
676
                    break;
677
                case 'pherograms': // FIXME 3.3 implement - Media
678
                    break;
679
                case 'haplotype': // FIXME 3.3 implement
680
                    break;
681
                case 'dateSequenced': // FIXME 3.3 now in SingelRead
682
                    @_description_list_group_add($groups, t('Sequencing date'), timePeriodToString($value), NULL, 6);
683
                    break;
684
685
                case 'barcode': // boolean
686
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value ? 'Yes' : 'No', NULL, 7);
687
                    break;
688
                case 'barcodeSequencePart': // FIXME 3.3 implement, compose sequence
689
                    break;
690
691
                case 'citation':
692
                    @_description_list_group_add($groups,
693
                        cdm_occurrence_field_name_label($field),
694
                        theme('cdm_reference', array('reference' => $value, 'microReference' => $sequence->microReference)),
695
                        NULL,
696
                        8
697
                    );
698
                    break;
699
700
                case 'publishedIn':
701
                    @_description_list_group_add($groups,
702
                        cdm_occurrence_field_name_label($field),
703
                        theme('cdm_reference', array('reference' => $value)),
704
                        NULL,
705
                        7
706
                    );
707
                    break;
708
709
                case 'rights':
710
                    array_merge($groups, cdm_rights_as_dl_groups($value));
711
                    break;
712
713
                case 'annotations':
714
                    $dd_elements = array();
715
                    foreach ($value as $annotation) {
716
                        // TODO respect annotation type filter settings
717
                        $dd_elements[] = $annotation->text;
718
                    }
719
                    @_description_list_group_add($groups, t('Notes'), $dd_elements, NULL, 9);
720
                    break;
721
722
                case 'markers':
723
                    $dd_elements = array();
724
                    foreach ($value as $marker) {
725
                        $dd_elements[] = compose_cdm_marker($marker);
726
                    }
727
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements, NULL, 10);
728
                    break;
729
730
                case 'chromatograms':
731
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),
732
                        array(
733
                            '#markup' => compose_cdm_media_gallerie(array('medialist' => $value)),
734
                        ),
735
                        NULL,
736
                        11);
737
                    break;
738
739
                default:
740
                    if (is_object($value) || is_array($value)) {
741
                        drupal_set_message("Unhandled type in compose_cdm_sequence() for field " . $field, "warning");
742
                    } else {
743
                        _description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 20);
744
                    }
745 1b57b3c1 Andreas Kohlbecker
            }
746 c10f70e4 Katja Luther
        }
747 0de9cf51 Andreas Kohlbecker
    }
748
749 c10f70e4 Katja Luther
    // template_preprocess_description_list() is not worting by weight so we do it right here
750
    uasort($groups, 'element_sort');
751 52f57468 Katja Luther
    if ($isSpecimenPage) {
752
        $sequence_elements = array(
753
            '#title' => $sequence->dnaMarker,
754
            '#theme' => 'description_list',
755
            '#groups' => $groups
756
        );
757
    } else{
758
        $sequence_elements = array(
759
            '#title' => $sequence->dnaMarker -> titleCache,
760
            '#theme' => 'description_list',
761
            '#groups' => $groups
762
        );
763
    }
764 0de9cf51 Andreas Kohlbecker
765 c10f70e4 Katja Luther
    return $sequence_elements;
766 0de9cf51 Andreas Kohlbecker
}
767 267da0d1 Katja Luther
/**
768
 * Creates an array from a list of FieldUnitDTOs.
769
 *
770
 *
771
 * @param object $specimenOrObservations
772
 *   list of FieldUnitDTOs
773
 * @return array
774
 *   An array containing the hierarchy of the field units corresponding to the taxon
775
 *
776
 * @ingroup compose
777
 */
778
function create_specimen_array(array $specimenOrObservations){
779
    $items_specimen = array();
780
    $items = array();
781 276f39f6 Katja Luther
782 267da0d1 Katja Luther
    //we need one more item to contain the items of one level (fieldunit, derivate data etc.)
783
    foreach ($specimenOrObservations as &$specimenOrObservation) {
784 416bc78f Katja Luther
785
        $items['data'] = $specimenOrObservation->listLabel ;
786 267da0d1 Katja Luther
        $specimen = create_cdm_specimen_or_observation($specimenOrObservation);
787
        $children = array();
788
        $child = array();
789
        $child['data'] =$specimen;
790
       // $children[] = create_specimen_array($specimenOrObservation->derivates);
791
       if (isset($specimenOrObservation->derivates) && sizeof($specimenOrObservation->derivates) > 0){
792
           $child['children']= create_specimen_array($specimenOrObservation->derivates);
793
       }
794
       $children[]=$child;
795
       $items['children'] = $children;
796
       $items_specimen[] = $items;
797
    }
798
    return $items_specimen;
799
}
800
801
802
/**
803
 * Compose an render array from a CDM DerivedUnitFacade object.
804
 *
805
 * compose_hook() implementation
806
 *
807
 * @param object $specimenOrObservation
808
 *   the CDM instance of type SpecimenOrObservation to compose
809
 *   the render array for
810
 * @param array $derivatives
811
 *   the render array which contains the compositions of the derivatives
812
 *   of the supplied $specimenOrObservation
813
 *
814
 * @return array
815
 *   the supplied render array $derivatives to which the composition of the supplied
816
 *   $specimenOrObservation has been added to
817
 *
818
 * @ingroup compose
819
 */
820
821
function create_cdm_specimen_or_observation($specimenOrObservation)
822
{
823
    $exclude_occurrence_fields = &drupal_static(__FUNCTION__);
824
    if (!isset($exclude_occurrence_fields)) {
825
        $exclude_occurrence_fields = array(
826
            'type',
827
            'derivationEvent',
828
            'taxonRelatedDerivedUnits',
829 7965ef92 Katja Luther
            'label',
830 267da0d1 Katja Luther
            'titleCache',
831 7965ef92 Katja Luther
            'listLabel',
832 267da0d1 Katja Luther
            'protectedTitleCache',
833
            'class',
834
            'uuid',
835 52f57468 Katja Luther
            'collectionDTO',
836
            'derivates'
837 267da0d1 Katja Luther
        );
838
    }
839
    $items = array();
840
841
    // only show uuid it the user is logged in
842
    if (user_is_logged_in() && ($a_idx = array_search('uuid', $exclude_occurrence_fields)) !== FALSE) {
843
      //  unset($exclude_occurrence_fields[$a_idx]);
844
    }
845
846
847
    if (is_object($specimenOrObservation)) {
848
849
        $type_label = $specimenOrObservation->recordBase;
850
        RenderHints::setFootnoteListKey($type_label . '-' . $specimenOrObservation->uuid);
851
852
        // collect typeStatus as label
853
        if (isset($specimenOrObservation->specimenTypeDesignations)) {
854
            $type_status = array();
855
            foreach ($specimenOrObservation->specimenTypeDesignations as $typeDesignation) {
856
                if (isset($typeDesignation->typeStatus->representation_L10n)) {
857
                    $type_status[] = $typeDesignation->typeStatus->representation_L10n;
858
                }
859
            }
860
            if (count($type_status) > 0) {
861
                $type_label = implode(', ', $type_status);
862
            }
863
        }
864
865
        $title = $type_label . ': ' . $specimenOrObservation->titleCache;
866 7965ef92 Katja Luther
        $items['data'] = $title;
867 267da0d1 Katja Luther
868
        $groups = array();
869
        $items['children'] = $groups;
870
        $children_items = array();
871
        // --- add initialized fields
872
        foreach (get_object_vars($specimenOrObservation) as $field => $value) {
873
            $child_item = array();
874
875
            if (!in_array($field, $exclude_occurrence_fields) && ($value && (!is_object($value) || isset($value->class)))) {
876
                switch ($field) {
877
//            case 'recordBasis':
878
//                if ($value != '' /* FieldUnit' */) {
879
//                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value);
880
//                }
881
//                break;
882
                    /* ---- java.lang.Object --- */
883
884
                    case 'markers':
885
                       /* $dd_elements = array();
886
                        foreach ($value as $marker) {
887
                            $dd_elements[] = compose_cdm_marker($marker);
888
                        }
889
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
890
                       */
891
                       break;
892
893
894
                    case 'annotations':
895
                        /*$dd_elements = array();
896
                        foreach ($value as $annotation) {
897
                            // TODO respect annotation type filter settings
898
                            $dd_elements[] = $annotation->text;
899
                        }
900
                        @_description_list_group_add($groups, t('Notes'), $dd_elements);
901
                        */
902
                        break;
903
904
                    /* ---- SpecimenOrObservationBase --- */
905
                    case 'sex':
906
                    case 'lifeStage':
907
                    case 'kindOfUnit':
908 52f57468 Katja Luther
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 1);
909 267da0d1 Katja Luther
                        break;
910
911
                    case 'definition':
912
                        // TODO
913
                        break;
914
915
                    case 'preferredStableUri':
916
917 7965ef92 Katja Luther
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), array(array('#markup' => cdm_external_uri($value, false))));
918 267da0d1 Katja Luther
                        break;
919
920
                    case 'specimenTypeDesignations':
921
                      /*     $groups,
922
                            cdm_occurrence_field_name_label($field),
923
                            array(
924
                                '#markup' => theme('cdm_typedesignations', array('typeDesignations' => $value)),
925
                            )
926
                        );
927
                      */
928
                        break;
929
930
                    case 'determinations':
931
                        /*$dd_elements = array();
932
                        $glue = ', ';
933
934
                        foreach ($value as $determinationEvent) {
935
                            $timeperiod_string = NULL;
936
                            if (isset($determinationEvent->timeperiod)) {
937
                                $timeperiod_string = timePeriodToString($determinationEvent->timeperiod);
938
                            }
939
                            $weight = isset($determinationEvent->preferred) && $determinationEvent->preferred == 1 ? '0' : ($timeperiod_string ? $timeperiod_string : '1');
940
                            // check key exists
941
                            while (array_key_exists($weight, $dd_elements)) {
942
                                $weight .= '0';
943
                            }
944
945
                            $taxon_name = '';
946
                            $name_link = '';
947
                            if ($determinationEvent->taxonName) {
948
                                $taxon_name = $determinationEvent->taxonName;
949
                            } else if ($determinationEvent->taxon) {
950
                                $taxon_name = cdm_ws_get(CDM_WS_TAXON . '/$0/name', $determinationEvent->taxon->uuid);
951
                                $name_link = path_to_taxon($determinationEvent->taxon->uuid);
952
                            }
953
                            if ($taxon_name) {
954
                                $taxon_html = render_taxon_or_name($taxon_name, $name_link);
955
                                $dd_elements[$weight] = $taxon_html;
956
                            }
957
                            if (isset($determinationEvent->modifier)) {
958
                            }
959
                            if ($timeperiod_string) {
960
                                $dd_elements[$weight] .= $glue . $timeperiod_string;
961
                            }
962
                            if (isset($determinationEvent->actor->titleCache)) {
963
                                $dd_elements[$weight] .= $glue . $determinationEvent->actor->titleCache;
964
                            }
965
                            if (isset($determinationEvent->description)) {
966
                                $dd_elements[$weight] .= $glue . $determinationEvent->description;
967
                            }
968
                        }
969
                        ksort($dd_elements);
970
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('determinations'), $dd_elements);
971
                        */
972
                        break;
973
974 7965ef92 Katja Luther
                    case 'listOfMedia':
975
                        $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
976
                        $captionElements = array(
977
                            '#uri' => t('open media'),
978
                        );
979
                        $gallery_html = compose_cdm_media_gallerie(array(
980
                            'mediaList' => $value,
981
                            'galleryName' => $specimenOrObservation->label,
982
                            'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
983
                            'cols' => $gallery_settings['cdm_dataportal_media_cols'],
984
                            'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
985
                            'captionElements' => $captionElements,
986
                            'mediaLinkType' => 'LIGHTBOX',
987
                            'alternativeMediaUri' => NULL,
988
                            'galleryLinkUri' => NULL,
989
                        ));
990
991 276f39f6 Katja Luther
                         //@_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $gallery_html);
992 7965ef92 Katja Luther
                         break;
993 267da0d1 Katja Luther
994
                    case 'sources':
995
                        /*
996
                        $dd_elements = array();
997
                        foreach ($value as $identifiable_source) {
998
                            $dd_elements[] = theme('cdm_OriginalSource', array('source' => $identifiable_source));
999
                        }
1000
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements, NULL, 10);
1001
                        */
1002
                        break;
1003
1004
1005
                    /* ---- DerivedUnitBase --- */
1006
1007 1083804e Andreas Kohlbecker
1008 267da0d1 Katja Luther
                    case 'collection':
1009 7965ef92 Katja Luther
1010 267da0d1 Katja Luther
                        $sub_dl_groups = array();
1011
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('code'), $value->code, NULL, 1);
1012
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('codeStandard'), $value->codeStandard, NULL, 2);
1013
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('institute'), $value->institute, NULL, 3);
1014
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('townOrLocation'), $value->townOrLocation, NULL, 4);
1015
                        // TODO "superCollection"
1016
                        // TODO may have media
1017
1018
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),
1019
                            array(
1020
                                array('#markup' => $value->titleCache),
1021
                                array('#theme' => 'description_list', '#groups' => $sub_dl_groups)
1022
                            )
1023
                        );
1024 7965ef92 Katja Luther
1025 267da0d1 Katja Luther
                        break;
1026
1027
                    case 'storedUnder':
1028
1029
                        //@_description_list_group_add($groups, cdm_occurrence_field_name_label('storedUnder'), render_taxon_or_name($value));
1030
                        break;
1031
1032
1033
                    /* ---- Specimen --- */
1034
                    case 'sequences':
1035
                        $dd_elements = array();
1036
                        foreach ($value as $sequence) {
1037 52f57468 Katja Luther
                            $dd_elements[] = compose_cdm_sequence($sequence, true);
1038
                            $dd_elements[] = "";
1039 267da0d1 Katja Luther
                        }
1040
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
1041
                        break;
1042
1043
                    // TODO preservation
1044
                    // TODO exsiccatum
1045
1046
1047
                    /* ---- FieldObservation --- */
1048
                    case 'gatheringEvent':
1049
1050 52f57468 Katja Luther
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collector'), $value->collector);
1051 267da0d1 Katja Luther
                        @_description_list_group_add($groups, t('Gathering time'), timePeriodToString($value->timeperiod));
1052
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('description'), $value->description);
1053 52f57468 Katja Luther
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('locality'), $value->locality);
1054
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('country'), $value->country);
1055 267da0d1 Katja Luther
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingMethod'), $value->collectingMethod);
1056
                        if (isset($value->absoluteElevation)) {
1057
                            $min_max_markup = min_max_measure($value, 'absoluteElevation');
1058
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('absoluteElevation'), $min_max_markup);
1059
                        }
1060 276f39f6 Katja Luther
                        if (isset($value->distanceToGround) && $value->distanceToGround >0) {
1061 267da0d1 Katja Luther
                            $min_max_markup = min_max_measure($value, 'distanceToGround');
1062
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToGround'), $min_max_markup);
1063
                        }
1064 276f39f6 Katja Luther
                        if (isset($value->distanceToWaterSurface) && $value->distanceToWaterSurface > 0) {
1065 267da0d1 Katja Luther
                            $min_max_markup = min_max_measure($value, 'distanceToWaterSurface');
1066
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToWaterSurface'), $min_max_markup);
1067
                        }
1068
1069
                        if (isset($value->collectingAreas)) {
1070
                            $area_representations = array();
1071
                            foreach ($value->collectingAreas as $area) {
1072 52f57468 Katja Luther
                               // $area_representations[] = l($area->representation_L10n, path_to_named_area($area->uuid));
1073
                                $area_representations[] = $area;
1074 267da0d1 Katja Luther
                            }
1075
                            if (!empty($area_representations))
1076
                                @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingAreas'),
1077
                                    array(
1078
                                        array('#markup' => implode(', ', $area_representations))
1079
                                    )
1080
                                );
1081
                        }
1082
                        if (isset($value->exactLocation)  && $value->exactLocation->sexagesimalString) {
1083
                            $sub_dl_groups = array();
1084
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('errorRadius'), $value->exactLocation->errorRadius, ' m', 1);
1085
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('longitude'), round($value->exactLocation->longitude, 7), '°', 2);
1086
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('latitude'), round($value->exactLocation->latitude, 7), '°', 3);
1087
                            if (isset($value->exactLocation->referenceSystem)) {
1088
                                @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('referenceSystem'), $value->exactLocation->referenceSystem->representation_L10n, '', 4);
1089
                            }
1090
1091
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('exactLocation'),
1092
                                array(
1093
                                    array('#markup' => $value->exactLocation->sexagesimalString),
1094
                                    array(
1095
                                        '#theme' => 'description_list',
1096
                                        '#groups' => $sub_dl_groups
1097
                                    ),
1098
                                )
1099
                            );
1100
                        }
1101
1102
                        break;
1103
1104
                    /* ---- DerivationEvent --- */
1105
                    case 'derivationEvents':
1106
                        //@_description_list_group_add($groups, t('Association type'), $value->description);
1107
                        break;
1108
1109
1110
                    default:
1111
                        if (is_object($value) || is_array($value)) {
1112 52f57468 Katja Luther
                            drupal_set_message("Unhandled type in compose_cdm_specimenOrObservation() for field " . $field, "warning");
1113 267da0d1 Katja Luther
                        } else {
1114
                            _description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value);
1115
                        }
1116
1117
                }
1118
1119
1120
            }
1121
        } // END of loop over $derivedUnitFacade fields
1122
1123
        // Extensions
1124
       /* $extensions = cdm_ws_fetch_all(CDM_WS_PORTAL_OCCURRENCE . '/' . $specimenOrObservation->uuid . '/extensions', array($specimenOrObservation->uuid));
1125
        if ($extensions && count($extensions)) {
1126
1127
            $extensions_render_array = compose_extensions($extensions);
1128
            @_description_list_group_add($groups, t('Extensions') . ':',
1129
                $extensions_render_array,
1130
                '', 100);
1131
        }
1132
*/
1133
1134
        // template_preprocess_description_list() is not worting by weight so we do it right here
1135
        uasort($groups, 'element_sort');
1136
1137
        $occurrence_elements = array(
1138
           // '#title' => $title,
1139
            '#theme' => 'description_list',
1140
            '#groups' => $groups,
1141
            '#attributes' => array('class' => html_class_attribute_ref($specimenOrObservation)),
1142
        );
1143
        $output = drupal_render($occurrence_elements);
1144 276f39f6 Katja Luther
        $output .= $gallery_html;
1145 416bc78f Katja Luther
        $pathToSpecimen = path_to_specimen($specimenOrObservation->uuid);
1146
        $output .=  l("detail page", $pathToSpecimen, array('attributes' => array('target' => '_blank')));
1147
1148 267da0d1 Katja Luther
1149
1150
1151
1152
1153
1154
1155
1156
    } // END of $specimenOrObservation exists
1157
1158
    return $output;
1159
}