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