Project

General

Profile

Download (54.8 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 f37da5d1 Patrick Plitzner
                $detail_html .= l($associatedTaxon->value, path_to_taxon($associatedTaxon->key, "specimens"));//$associatedTaxon->second."<br>";
130 c10f70e4 Katja Luther
            }
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 e89c1115 Katja Luther
 //   if(user_is_logged_in() && ($a_idx = array_search('uuid', $exclude_occurrence_fields)) !== FALSE ) {
341
  //      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 ddbbdb0b Katja Luther
437
                        //TODO: better display of details!!
438 c10f70e4 Katja Luther
                        @_description_list_group_add(
439
                            $groups,
440
                            cdm_occurrence_field_name_label($field),
441
                            array(
442
                                '#markup' => theme('cdm_typedesignations', array('typeDesignations' => $value)),
443
                            )
444
                        );
445
                        break;
446
447
                    case 'determinations':
448
                        $dd_elements = array();
449
                        $glue = ', ';
450
451
                        foreach ($value as $determinationEvent) {
452
                            $timeperiod_string = NULL;
453
                            if (isset($determinationEvent->timeperiod)) {
454
                                $timeperiod_string = timePeriodToString($determinationEvent->timeperiod);
455
                            }
456
                            $weight = isset($determinationEvent->preferred) && $determinationEvent->preferred == 1 ? '0' : ($timeperiod_string ? $timeperiod_string : '1');
457
                            // check key exists
458
                            while (array_key_exists($weight, $dd_elements)) {
459
                                $weight .= '0';
460
                            }
461 4ae6064e Andreas Kohlbecker
462 c10f70e4 Katja Luther
                            $taxon_name = '';
463
                            $name_link = '';
464
                            if ($determinationEvent->taxonName) {
465
                                $taxon_name = $determinationEvent->taxonName;
466
                            } else if ($determinationEvent->taxon) {
467
                                $taxon_name = cdm_ws_get(CDM_WS_TAXON . '/$0/name', $determinationEvent->taxon->uuid);
468
                                $name_link = path_to_taxon($determinationEvent->taxon->uuid);
469
                            }
470
                            if ($taxon_name) {
471
                                $taxon_html = render_taxon_or_name($taxon_name, $name_link);
472
                                $dd_elements[$weight] = $taxon_html;
473
                            }
474
                            if (isset($determinationEvent->modifier)) {
475
                                $dd_elements[$weight] .= cdm_term_representation($determinationEvent->modifier);
476
                            }
477
                            if ($timeperiod_string) {
478
                                $dd_elements[$weight] .= $glue . $timeperiod_string;
479
                            }
480
                            if (isset($determinationEvent->actor->titleCache)) {
481
                                $dd_elements[$weight] .= $glue . $determinationEvent->actor->titleCache;
482
                            }
483
                            if (isset($determinationEvent->description)) {
484
                                $dd_elements[$weight] .= $glue . $determinationEvent->description;
485
                            }
486
                        }
487
                        ksort($dd_elements);
488
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('determinations'), $dd_elements);
489
                        break;
490 f846e7e7 Andreas Kohlbecker
491 c10f70e4 Katja Luther
                    case 'descriptions':
492
                        $occurrence_featureTree = cdm_get_occurrence_featureTree();
493
                        $dd_elements = array();
494 bfb2b81a Andreas Kohlbecker
495 c10f70e4 Katja Luther
                        foreach ($value as $description) {
496
                            $description = cdm_ws_get(CDM_WS_PORTAL_DESCRIPTION, $description->uuid);
497 a2acff0a Katja Luther
498
                        if($description->imageGallery == TRUE) {
499
                            continue;
500
                        }
501 c10f70e4 Katja Luther
                            $elements_by_feature = _mergeFeatureTreeDescriptions($occurrence_featureTree->root->childNodes, $description->elements);
502
                            $description_render_elements = _block_get_renderable_array(make_feature_block_list($elements_by_feature, null));
503
                            $dd_elements[] = $description_render_elements;
504
                        }
505 6fbdb943 Andreas Kohlbecker
506 c10f70e4 Katja Luther
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
507
                        break;
508 a2acff0a Katja Luther
                    case '_derivedUnitMedia':
509
                        if ($isSpecimen_page){
510
                            $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
511
                            $captionElements = array(
512
                                '#uri' => t('open media'),
513
                            );
514
                            $gallery_html = compose_cdm_media_gallerie(array(
515
                                'mediaList' => $value,
516
                                'galleryName' => $specimen_or_observation->titleCache,
517
                                'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
518
                                'cols' => $gallery_settings['cdm_dataportal_media_cols'],
519
                                'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
520
                                'captionElements' => $captionElements,
521
                                'mediaLinkType' => 'LIGHTBOX',
522
                                'alternativeMediaUri' => NULL,
523
                                'galleryLinkUri' => NULL,
524
                            ));
525 abe0b021 Katja Luther
                            @_description_list_group_add($groups, "Detail Images:" , markup_to_render_array($gallery_html),'',20);
526 a2acff0a Katja Luther
                        }
527 6fbdb943 Andreas Kohlbecker
528 a2acff0a Katja Luther
                       // $dd_elements[] = markup_to_render_array($gallery_html);
529
530
                        break;
531 c10f70e4 Katja Luther
                    case 'sources':
532 4186a152 Katja Luther
                        $annotations_and_sources = handle_annotations_and_sources(
533
                            $specimen_or_observation,
534
                            array(
535
                                'sources_as_content' => true,
536
                                'link_to_name_used_in_source' => 1,
537
                                'link_to_reference' => 0,
538
                                'add_footnote_keys' => 0
539
                            ),
540
                            NULL,
541
                            ''
542
                        );
543
                        if(!empty($annotations_and_sources['source_references'])){
544
                            @_description_list_group_add($groups, t('Sources') . ':', join(', ', $annotations_and_sources['source_references']),'',12 );
545 c10f70e4 Katja Luther
                        }
546
                        break;
547
548
549
                    /* ---- DerivedUnitBase --- */
550
                    case 'derivedFrom':
551
                        $derivedFrom = $value;
552 a2acff0a Katja Luther
                        if ($isSpecimen_page) {
553
                            foreach ($derivedFrom->originals as $original) {
554
                                $pathToSpecimen = path_to_specimen($original->uuid);
555
                                $description = "";
556
                                if (isset( $derivedFrom->description) && $derivedFrom->description != ''){
557
                                    $description = $derivedFrom->description . ": ";
558
                                }
559
560
                                $originals[] = markup_to_render_array(l($description . $original->titleCache, $pathToSpecimen, array('attributes' => array('target' => '_blank'))));
561 4186a152 Katja Luther
                                if ($original->class == 'FieldUnit'){
562
                                    $label = t('Field data');
563
                                }else{
564
                                    $label = t('Derived from');
565
                                }
566
                                @_description_list_group_add($groups, $label . ':',
567 a2acff0a Katja Luther
                                    $originals,
568 4186a152 Katja Luther
                                    '', 13);
569 a2acff0a Katja Luther
                            }
570
                        }
571
                        break;
572
                    case 'derivationEvents':
573
                        $derivationEvents = $value;
574
                        $derived_units = array();
575
                        if ($isSpecimen_page) {
576
                            foreach ($derivationEvents as $derivationEvent) {
577
                                foreach ($derivationEvent->derivatives as $derived_unit) {
578
                                    $pathToSpecimen = path_to_specimen($derived_unit->uuid);
579
                                    $description = "";
580
                                    if (isset($derived_unit->description) && $derived_unit->description != '') {
581
                                        $description = $derived_unit->description . ": ";
582
                                    }
583
584
                                    $derived_units[] = markup_to_render_array(l($description . $derived_unit->titleCache, $pathToSpecimen, array('attributes' => array('target' => '_blank'))));
585
                                 }
586
                            } @_description_list_group_add($groups, t('Derivates') . ':',
587
                                $derived_units,
588
                                    '', 100);
589
590
                        }
591 c10f70e4 Katja Luther
                        break;
592
593
                    case 'collection':
594
                        $sub_dl_groups = array();
595
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('code'), $value->code, NULL, 1);
596
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('codeStandard'), $value->codeStandard, NULL, 2);
597
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('institute'), $value->institute, NULL, 3);
598
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('townOrLocation'), $value->townOrLocation, NULL, 4);
599
                        // TODO "superCollection"
600
                        // TODO may have media
601
602
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),
603
                            array(
604
                                array('#markup' => $value->titleCache),
605
                                array('#theme' => 'description_list', '#groups' => $sub_dl_groups)
606
                            )
607
                        );
608
                        break;
609
610
                    case 'storedUnder':
611
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('storedUnder'), render_taxon_or_name($value));
612
                        break;
613
614
615
                    /* ---- Specimen --- */
616
                    case 'sequences':
617
                        $dd_elements = array();
618
                        foreach ($value as $sequence) {
619
                            $dd_elements[] = compose_cdm_sequence($sequence);
620
                        }
621
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
622
                        break;
623
624
                    // TODO preservation
625
                    // TODO exsiccatum
626
627
628
                    /* ---- FieldObservation --- */
629
                    case 'gatheringEvent':
630 abe0b021 Katja Luther
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collector'), $value->actor->titleCache, '', 1);
631
                        @_description_list_group_add($groups, t('Gathering date'), timePeriodToString($value->timeperiod), '', 2);
632
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('description'), $value->description, '', 3);
633
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('locality'), $value->locality->text, '', 10);
634
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('country'), $value->country->representation_L10n, '', 4);
635
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingMethod'), $value->collectingMethod,'',5);
636 c10f70e4 Katja Luther
                        if (isset($value->absoluteElevation)) {
637
                            $min_max_markup = min_max_measure($value, 'absoluteElevation');
638 abe0b021 Katja Luther
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('absoluteElevation'), $min_max_markup, '',6);
639 c10f70e4 Katja Luther
                        }
640
                        if (isset($value->distanceToGround)) {
641
                            $min_max_markup = min_max_measure($value, 'distanceToGround');
642 abe0b021 Katja Luther
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToGround'), $min_max_markup,'',7);
643 c10f70e4 Katja Luther
                        }
644
                        if (isset($value->distanceToWaterSurface)) {
645
                            $min_max_markup = min_max_measure($value, 'distanceToWaterSurface');
646 abe0b021 Katja Luther
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToWaterSurface'), $min_max_markup, '',8);
647 c10f70e4 Katja Luther
                        }
648 abe0b021 Katja Luther
                        if (isset($value->collectingAreas) && count($value->collectingAreas) > 0) {
649 c10f70e4 Katja Luther
                            $area_representations = array();
650
                            foreach ($value->collectingAreas as $area) {
651
                                $area_representations[] = l($area->representation_L10n, path_to_named_area($area->uuid));
652
                            }
653 d3f77ada Katja Luther
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingAreas'),
654
                                array(
655
                                    array('#markup' => implode(', ', $area_representations))
656 abe0b021 Katja Luther
                                ),'',9
657 d3f77ada Katja Luther
                            );
658 c10f70e4 Katja Luther
                        }
659
                        if (isset($value->exactLocation) && $value->exactLocation->sexagesimalString) {
660
                            $sub_dl_groups = array();
661
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('errorRadius'), $value->exactLocation->errorRadius, ' m', 1);
662
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('longitude'), round($value->exactLocation->longitude, 7), '°', 2);
663
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('latitude'), round($value->exactLocation->latitude, 7), '°', 3);
664
                            if (isset($value->exactLocation->referenceSystem)) {
665
                                @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('referenceSystem'), $value->exactLocation->referenceSystem->representation_L10n, '', 4);
666
                            }
667 6fbdb943 Andreas Kohlbecker
668 c10f70e4 Katja Luther
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('exactLocation'),
669
                                array(
670
                                    array('#markup' => $value->exactLocation->sexagesimalString),
671
                                    array(
672
                                        '#theme' => 'description_list',
673
                                        '#groups' => $sub_dl_groups
674
                                    ),
675 abe0b021 Katja Luther
                                ),'',11
676 c10f70e4 Katja Luther
                            );
677
                        }
678
                        break;
679
680
                    default:
681
                        if (is_object($value) || is_array($value)) {
682 d3f77ada Katja Luther
                            drupal_set_message("Unhandled type in compose_cdm_specimen_or_observation() for field " . $field, "warning");
683 c10f70e4 Katja Luther
                        } else {
684 4186a152 Katja Luther
                            _description_list_group_add($groups, cdm_occurrence_field_name_label($field), cdm_occurrence_field_name_label($value));
685 c10f70e4 Katja Luther
                        }
686 74ee6b54 Andreas Kohlbecker
687 c10f70e4 Katja Luther
                }
688 f19f47fa Andreas Kohlbecker
689 f846e7e7 Andreas Kohlbecker
            }
690 c10f70e4 Katja Luther
        } // END of loop over $derivedUnitFacade fields
691 f19f47fa Andreas Kohlbecker
692 c10f70e4 Katja Luther
        // Extensions
693 a2acff0a Katja Luther
        $extensions = cdm_ws_fetch_all(CDM_WS_PORTAL_OCCURRENCE . '/'  . $specimen_or_observation->uuid . '/extensions', array($specimen_or_observation->uuid));
694 c10f70e4 Katja Luther
        if ($extensions && count($extensions)) {
695
696
            $extensions_render_array = compose_extensions($extensions);
697
            @_description_list_group_add($groups, t('Extensions') . ':',
698
                $extensions_render_array,
699
                '', 100);
700 f19f47fa Andreas Kohlbecker
        }
701
702 f846e7e7 Andreas Kohlbecker
703 a2acff0a Katja Luther
704 c10f70e4 Katja Luther
        // template_preprocess_description_list() is not worting by weight so we do it right here
705
        uasort($groups, 'element_sort');
706 0820cdc0 Andreas Kohlbecker
707 c10f70e4 Katja Luther
        $occurrence_elements = array(
708 e89c1115 Katja Luther
           // '#title' => $title,
709 c10f70e4 Katja Luther
            '#theme' => 'description_list',
710
            '#groups' => $groups,
711 a2acff0a Katja Luther
            '#attributes' => array('class' => html_class_attribute_ref($specimen_or_observation)),
712 c10f70e4 Katja Luther
        );
713 a2acff0a Katja Luther
714 e89c1115 Katja Luther
        $derivatives[] = drupal_render($occurrence_elements);
715 c10f70e4 Katja Luther
        // all footnotes which has been assembled so far (e.g. from typeDesignations) to here
716 ade2b1f0 Katja Luther
//       $foonote_li_elements = theme('cdm_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey(), 'enclosingTag' => 'span'));
717
//        if (!empty($foonote_li_elements)) {
718
//            $derivatives[] =  array(
719
//                '#markup' =>  '<div class="footnotes">' . $foonote_li_elements . '</div>',
720
//            );
721
//        }
722 0820cdc0 Andreas Kohlbecker
723 c10f70e4 Katja Luther
        // --- recurse into originals
724 a2acff0a Katja Luther
        if (!isset($derivedFrom)  && !$isSpecimen_page) {
725 c10f70e4 Katja Luther
            $derivedFrom = cdm_ws_get(
726
                CDM_WS_OCCURRENCE,
727 a2acff0a Katja Luther
                array($specimen_or_observation->uuid, 'derivedFrom')
728 c10f70e4 Katja Luther
            );
729
        }
730 a2acff0a Katja Luther
        if (isset($derivedFrom) && !$isSpecimen_page) {
731 d3f77ada Katja Luther
            if (isset($derivedFrom->originals)) {
732
                $derived_from_label = t('derived');
733
                $preposition = t('from');
734
                if(isset($derivedFrom->type)){
735 c10f70e4 Katja Luther
                    $derived_from_label = $derivedFrom->type->representation_L10n;
736 d3f77ada Katja Luther
                    if($derivedFrom->type->uuid == UUID_DERIVATIONEVENTTYPE_ACCESSIONING){
737
                        $preposition = t('of');
738 c10f70e4 Katja Luther
                    }
739
                }
740
                if (count($groups) > 0) {
741
                    // TODO  annotations
742 eeb98da8 Andreas Kohlbecker
743 c10f70e4 Katja Luther
                    // only display the derived from information when the derivative has any element which will be diplayed
744
                    $derivatives[] = array(
745 d3f77ada Katja Luther
                        '#markup' => '<div class="derived_from">' . $derived_from_label . ' ' . $preposition . ': </div>',
746 c10f70e4 Katja Luther
                    );
747
                }
748 d3f77ada Katja Luther
                foreach ($derivedFrom->originals as $original) {
749 a2acff0a Katja Luther
                    compose_cdm_specimen_or_observation($original, $isSpecimen_page, $derivatives);
750 d3f77ada Katja Luther
                }
751 c10f70e4 Katja Luther
            }
752 0796d2f9 Andreas Kohlbecker
        }
753 f1f05758 Andreas Kohlbecker
754 a2acff0a Katja Luther
755
756
757 c10f70e4 Katja Luther
    } // END of $specimenOrObservation exists
758 c70b93c3 Andreas Kohlbecker
759 c10f70e4 Katja Luther
    return $derivatives;
760 f1f05758 Andreas Kohlbecker
}
761 0de9cf51 Andreas Kohlbecker
762 0820cdc0 Andreas Kohlbecker
763 0de9cf51 Andreas Kohlbecker
/**
764
 * Compose an render array from a CDM Sequence object.
765
 *
766
 * compose_hook() implementation
767
 *
768
 * @param object $sequence
769
 *   CDM instance of type Sequence
770
 * @return array
771
 *   A render array containing the fields of the supplied $sequence
772 5b26b91a Andreas Kohlbecker
 *
773
 * @ingroup compose
774 0de9cf51 Andreas Kohlbecker
 */
775 52f57468 Katja Luther
function compose_cdm_sequence($sequence, $isSpecimenPage = false)
776 c10f70e4 Katja Luther
{
777
778
    $exclude_sequence_fields = &drupal_static(__FUNCTION__);
779
    if (!isset($exclude_sequence_fields)) {
780
        $exclude_sequence_fields = array(
781
            'titleCache',
782
            'protectedTitleCache',
783
            'microReference',
784
            'created',
785
            'updated',
786
            'class',
787
        );
788
    }
789 0de9cf51 Andreas Kohlbecker
790 c10f70e4 Katja Luther
    $groups = array();
791 0de9cf51 Andreas Kohlbecker
792 c10f70e4 Katja Luther
    // -- retrieve additional data if neesscary
793
    // TODO below call disabled since sequences are not yet supported,
794
    //      see  #3347 (services and REST service controller for molecular classes implemented)
795
    //
796
    // cdm_load_annotations($sequence);
797 eeb98da8 Andreas Kohlbecker
798 c10f70e4 Katja Luther
    foreach (get_object_vars($sequence) as $field => $value) {
799 eeb98da8 Andreas Kohlbecker
800
801 c10f70e4 Katja Luther
        if (!in_array($field, $exclude_sequence_fields) && ($value && (!is_object($value) || isset($value->class)))) {
802
            switch ($field) {
803 0de9cf51 Andreas Kohlbecker
804 c10f70e4 Katja Luther
                case 'geneticAccessionNumber';
805 52f57468 Katja Luther
806
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 2);
807 c10f70e4 Katja Luther
                    break;
808
809
810 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.
811
                    if (isset($value->name)) {
812 c10f70e4 Katja Luther
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value->name, NULL, 3);
813
                    }
814
                    if (isset($value->description)) {
815
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field) . ' ' . t('description'), $value->description, NULL, 4);
816
                    }
817 52f57468 Katja Luther
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field) , $value, NULL, 4);
818 c10f70e4 Katja Luther
                    break;
819 a2acff0a Katja Luther
820 c10f70e4 Katja Luther
                case 'consensusSequence':
821
                    // format in genbank style, force linebreaks after each 70 nucleotites
822
                    // see also http://stackoverflow.com/questions/499137/css-how-can-i-force-a-long-string-without-any-blank-to-be-wrapped-in-xul-and
823 52f57468 Katja Luther
                    if ($value->length > 0) {
824
                        @_description_list_group_add(
825
                            $groups,
826
                            cdm_occurrence_field_name_label($field),
827 c10f70e4 Katja Luther
                            array(
828 52f57468 Katja Luther
                                array(
829
                                    '#markup' => '<div class="sequence-length">' . $value->length . ' ' . t('pb') . '</div><div>' . wordwrap($value->string, 70, '</br>', TRUE) . '</div>',
830
                                    '#wrapper_attributes' => array('class' => 'dna-sequence')
831
                                )
832
                            ),
833
                            5);
834
                    }
835 c10f70e4 Katja Luther
                    break;
836
837
                case 'dnaSample': // FIXME 3.3 implement
838
                    break;
839
                case 'singleReads': // FIXME 3.3 implement
840
                    break;
841
                case 'contigFile': // FIXME 3.3 implement - Media
842
                    break;
843
                case 'pherograms': // FIXME 3.3 implement - Media
844
                    break;
845
                case 'haplotype': // FIXME 3.3 implement
846
                    break;
847
                case 'dateSequenced': // FIXME 3.3 now in SingelRead
848
                    @_description_list_group_add($groups, t('Sequencing date'), timePeriodToString($value), NULL, 6);
849
                    break;
850
851
                case 'barcode': // boolean
852
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value ? 'Yes' : 'No', NULL, 7);
853
                    break;
854
                case 'barcodeSequencePart': // FIXME 3.3 implement, compose sequence
855
                    break;
856
857
                case 'citation':
858
                    @_description_list_group_add($groups,
859
                        cdm_occurrence_field_name_label($field),
860
                        theme('cdm_reference', array('reference' => $value, 'microReference' => $sequence->microReference)),
861
                        NULL,
862
                        8
863
                    );
864
                    break;
865
866
                case 'publishedIn':
867
                    @_description_list_group_add($groups,
868
                        cdm_occurrence_field_name_label($field),
869
                        theme('cdm_reference', array('reference' => $value)),
870
                        NULL,
871
                        7
872
                    );
873
                    break;
874
875
                case 'rights':
876
                    array_merge($groups, cdm_rights_as_dl_groups($value));
877
                    break;
878
879
                case 'annotations':
880
                    $dd_elements = array();
881
                    foreach ($value as $annotation) {
882
                        // TODO respect annotation type filter settings
883
                        $dd_elements[] = $annotation->text;
884
                    }
885
                    @_description_list_group_add($groups, t('Notes'), $dd_elements, NULL, 9);
886
                    break;
887
888
                case 'markers':
889
                    $dd_elements = array();
890
                    foreach ($value as $marker) {
891
                        $dd_elements[] = compose_cdm_marker($marker);
892
                    }
893
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements, NULL, 10);
894
                    break;
895
896
                case 'chromatograms':
897
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),
898
                        array(
899
                            '#markup' => compose_cdm_media_gallerie(array('medialist' => $value)),
900
                        ),
901
                        NULL,
902
                        11);
903
                    break;
904
905
                default:
906
                    if (is_object($value) || is_array($value)) {
907
                        drupal_set_message("Unhandled type in compose_cdm_sequence() for field " . $field, "warning");
908
                    } else {
909 8e15d0fb Katja Luther
                        if (!is_array($value) && strpos($value, 'http:') !== false ){
910
                            //make links for urls
911
                            $value = l($value, $value, array('attributes' => array('target' => '_blank')));
912
                            $value = markup_to_render_array($value);
913
                        }
914
915 58c1a035 Katja Luther
                       _description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 20);
916 c10f70e4 Katja Luther
                    }
917 1b57b3c1 Andreas Kohlbecker
            }
918 c10f70e4 Katja Luther
        }
919 0de9cf51 Andreas Kohlbecker
    }
920
921 c10f70e4 Katja Luther
    // template_preprocess_description_list() is not worting by weight so we do it right here
922
    uasort($groups, 'element_sort');
923 52f57468 Katja Luther
    if ($isSpecimenPage) {
924
        $sequence_elements = array(
925
            '#title' => $sequence->dnaMarker,
926
            '#theme' => 'description_list',
927
            '#groups' => $groups
928
        );
929
    } else{
930
        $sequence_elements = array(
931
            '#title' => $sequence->dnaMarker -> titleCache,
932
            '#theme' => 'description_list',
933
            '#groups' => $groups
934
        );
935
    }
936 0de9cf51 Andreas Kohlbecker
937 c10f70e4 Katja Luther
    return $sequence_elements;
938 0de9cf51 Andreas Kohlbecker
}
939 267da0d1 Katja Luther
/**
940
 * Creates an array from a list of FieldUnitDTOs.
941
 *
942
 *
943
 * @param object $specimenOrObservations
944
 *   list of FieldUnitDTOs
945
 * @return array
946
 *   An array containing the hierarchy of the field units corresponding to the taxon
947
 *
948
 * @ingroup compose
949
 */
950 106e1cf9 Katja Luther
function compose_specimen_array(array $specimenOrObservations){
951 267da0d1 Katja Luther
    $items_specimen = array();
952
    $items = array();
953 276f39f6 Katja Luther
954 267da0d1 Katja Luther
    //we need one more item to contain the items of one level (fieldunit, derivate data etc.)
955
    foreach ($specimenOrObservations as &$specimenOrObservation) {
956 416bc78f Katja Luther
957
        $items['data'] = $specimenOrObservation->listLabel ;
958 106e1cf9 Katja Luther
        $specimen = compose_cdm_specimen_or_observation_tree_entry($specimenOrObservation);
959 267da0d1 Katja Luther
        $children = array();
960
        $child = array();
961
        $child['data'] =$specimen;
962
       // $children[] = create_specimen_array($specimenOrObservation->derivates);
963
       if (isset($specimenOrObservation->derivates) && sizeof($specimenOrObservation->derivates) > 0){
964 106e1cf9 Katja Luther
           $child['children']= compose_specimen_array($specimenOrObservation->derivates);
965 267da0d1 Katja Luther
       }
966
       $children[]=$child;
967
       $items['children'] = $children;
968
       $items_specimen[] = $items;
969
    }
970
    return $items_specimen;
971
}
972
973
974
/**
975
 * Compose an render array from a CDM DerivedUnitFacade object.
976
 *
977
 * compose_hook() implementation
978
 *
979
 * @param object $specimenOrObservation
980
 *   the CDM instance of type SpecimenOrObservation to compose
981
 *   the render array for
982
 * @param array $derivatives
983
 *   the render array which contains the compositions of the derivatives
984
 *   of the supplied $specimenOrObservation
985
 *
986
 * @return array
987
 *   the supplied render array $derivatives to which the composition of the supplied
988
 *   $specimenOrObservation has been added to
989
 *
990
 * @ingroup compose
991
 */
992
993 58c1a035 Katja Luther
function compose_cdm_specimen_or_observation_tree_entry($specimen_or_observation)
994 267da0d1 Katja Luther
{
995
    $exclude_occurrence_fields = &drupal_static(__FUNCTION__);
996
    if (!isset($exclude_occurrence_fields)) {
997
        $exclude_occurrence_fields = array(
998
            'type',
999
            'taxonRelatedDerivedUnits',
1000 7965ef92 Katja Luther
            'label',
1001 267da0d1 Katja Luther
            'titleCache',
1002 7965ef92 Katja Luther
            'listLabel',
1003 267da0d1 Katja Luther
            'protectedTitleCache',
1004
            'class',
1005
            'uuid',
1006 ddbbdb0b Katja Luther
            'derivates',
1007
            'collection'
1008 267da0d1 Katja Luther
        );
1009
    }
1010
    $items = array();
1011
1012
    // only show uuid it the user is logged in
1013
    if (user_is_logged_in() && ($a_idx = array_search('uuid', $exclude_occurrence_fields)) !== FALSE) {
1014
      //  unset($exclude_occurrence_fields[$a_idx]);
1015
    }
1016
1017
1018 58c1a035 Katja Luther
    if (is_object($specimen_or_observation)) {
1019 267da0d1 Katja Luther
1020 58c1a035 Katja Luther
        $type_label = $specimen_or_observation->recordBase;
1021
        RenderHints::setFootnoteListKey($type_label . '-' . $specimen_or_observation->uuid);
1022 267da0d1 Katja Luther
1023
        // collect typeStatus as label
1024 58c1a035 Katja Luther
        if (isset($specimen_or_observation->specimenTypeDesignations)) {
1025 267da0d1 Katja Luther
            $type_status = array();
1026 58c1a035 Katja Luther
            foreach ($specimen_or_observation->specimenTypeDesignations as $typeDesignation) {
1027 267da0d1 Katja Luther
                if (isset($typeDesignation->typeStatus->representation_L10n)) {
1028
                    $type_status[] = $typeDesignation->typeStatus->representation_L10n;
1029
                }
1030
            }
1031
            if (count($type_status) > 0) {
1032
                $type_label = implode(', ', $type_status);
1033
            }
1034
        }
1035
1036 58c1a035 Katja Luther
        $title = $type_label . ': ' . $specimen_or_observation->titleCache;
1037 7965ef92 Katja Luther
        $items['data'] = $title;
1038 267da0d1 Katja Luther
1039
        $groups = array();
1040
        $items['children'] = $groups;
1041
        $children_items = array();
1042
        // --- add initialized fields
1043 58c1a035 Katja Luther
        foreach (get_object_vars($specimen_or_observation) as $field => $value) {
1044 267da0d1 Katja Luther
            $child_item = array();
1045
1046
            if (!in_array($field, $exclude_occurrence_fields) && ($value && (!is_object($value) || isset($value->class)))) {
1047
                switch ($field) {
1048
1049
                    /* ---- SpecimenOrObservationBase --- */
1050 a2acff0a Katja Luther
                    case 'derivationEvent':
1051
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 1);
1052
                        break;
1053 267da0d1 Katja Luther
                    case 'kindOfUnit':
1054 52f57468 Katja Luther
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 1);
1055 267da0d1 Katja Luther
                        break;
1056
1057
1058
                    case 'preferredStableUri':
1059
1060 7965ef92 Katja Luther
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), array(array('#markup' => cdm_external_uri($value, false))));
1061 267da0d1 Katja Luther
                        break;
1062
1063
                    case 'specimenTypeDesignations':
1064 f1239704 Katja Luther
                        @_description_list_group_add(
1065
                            $groups,
1066 267da0d1 Katja Luther
                            cdm_occurrence_field_name_label($field),
1067
                            array(
1068
                                '#markup' => theme('cdm_typedesignations', array('typeDesignations' => $value)),
1069
                            )
1070
                        );
1071
                        break;
1072
1073
1074 f1239704 Katja Luther
1075 7965ef92 Katja Luther
                    case 'listOfMedia':
1076
                        $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
1077
                        $captionElements = array(
1078
                            '#uri' => t('open media'),
1079
                        );
1080
                        $gallery_html = compose_cdm_media_gallerie(array(
1081
                            'mediaList' => $value,
1082 58c1a035 Katja Luther
                            'galleryName' => $specimen_or_observation->label,
1083 7965ef92 Katja Luther
                            'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
1084
                            'cols' => $gallery_settings['cdm_dataportal_media_cols'],
1085
                            'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
1086
                            'captionElements' => $captionElements,
1087
                            'mediaLinkType' => 'LIGHTBOX',
1088
                            'alternativeMediaUri' => NULL,
1089
                            'galleryLinkUri' => NULL,
1090
                        ));
1091
1092 276f39f6 Katja Luther
                         //@_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $gallery_html);
1093 7965ef92 Katja Luther
                         break;
1094 267da0d1 Katja Luther
1095
1096
1097
                    /* ---- DerivedUnitBase --- */
1098
1099 1083804e Andreas Kohlbecker
1100 a2acff0a Katja Luther
                    case 'collectionDTO':
1101 7965ef92 Katja Luther
1102 267da0d1 Katja Luther
                        $sub_dl_groups = array();
1103
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('code'), $value->code, NULL, 1);
1104
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('codeStandard'), $value->codeStandard, NULL, 2);
1105
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('institute'), $value->institute, NULL, 3);
1106
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('townOrLocation'), $value->townOrLocation, NULL, 4);
1107
                        // TODO "superCollection"
1108
                        // TODO may have media
1109
1110 a2acff0a Katja Luther
                        @_description_list_group_add($groups, 'Collection',
1111 267da0d1 Katja Luther
                            array(
1112
                                array('#markup' => $value->titleCache),
1113
                                array('#theme' => 'description_list', '#groups' => $sub_dl_groups)
1114
                            )
1115
                        );
1116 7965ef92 Katja Luther
1117 267da0d1 Katja Luther
                        break;
1118
1119
1120
1121
1122
                    /* ---- Specimen --- */
1123
                    case 'sequences':
1124
                        $dd_elements = array();
1125
                        foreach ($value as $sequence) {
1126 52f57468 Katja Luther
                            $dd_elements[] = compose_cdm_sequence($sequence, true);
1127
                            $dd_elements[] = "";
1128 267da0d1 Katja Luther
                        }
1129 a0f26798 Katja Luther
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements,'', 100);
1130 267da0d1 Katja Luther
                        break;
1131
1132
                    // TODO preservation
1133
                    // TODO exsiccatum
1134
1135
1136
                    /* ---- FieldObservation --- */
1137
                    case 'gatheringEvent':
1138
1139 52f57468 Katja Luther
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collector'), $value->collector);
1140 abe0b021 Katja Luther
                        @_description_list_group_add($groups, t('Gathering date'), timePeriodToString($value->timeperiod));
1141 267da0d1 Katja Luther
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('description'), $value->description);
1142 abe0b021 Katja Luther
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('locality'), $value->locality, '', 10);
1143 52f57468 Katja Luther
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('country'), $value->country);
1144 267da0d1 Katja Luther
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingMethod'), $value->collectingMethod);
1145
                        if (isset($value->absoluteElevation)) {
1146
                            $min_max_markup = min_max_measure($value, 'absoluteElevation');
1147
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('absoluteElevation'), $min_max_markup);
1148
                        }
1149 276f39f6 Katja Luther
                        if (isset($value->distanceToGround) && $value->distanceToGround >0) {
1150 267da0d1 Katja Luther
                            $min_max_markup = min_max_measure($value, 'distanceToGround');
1151
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToGround'), $min_max_markup);
1152
                        }
1153 276f39f6 Katja Luther
                        if (isset($value->distanceToWaterSurface) && $value->distanceToWaterSurface > 0) {
1154 267da0d1 Katja Luther
                            $min_max_markup = min_max_measure($value, 'distanceToWaterSurface');
1155
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToWaterSurface'), $min_max_markup);
1156
                        }
1157
1158
                        if (isset($value->collectingAreas)) {
1159
                            $area_representations = array();
1160
                            foreach ($value->collectingAreas as $area) {
1161 52f57468 Katja Luther
                               // $area_representations[] = l($area->representation_L10n, path_to_named_area($area->uuid));
1162
                                $area_representations[] = $area;
1163 267da0d1 Katja Luther
                            }
1164
                            if (!empty($area_representations))
1165
                                @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingAreas'),
1166
                                    array(
1167
                                        array('#markup' => implode(', ', $area_representations))
1168
                                    )
1169
                                );
1170
                        }
1171 106e1cf9 Katja Luther
                        if (isset($value->exactLocation)  ) {
1172 267da0d1 Katja Luther
                            $sub_dl_groups = array();
1173
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('errorRadius'), $value->exactLocation->errorRadius, ' m', 1);
1174
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('longitude'), round($value->exactLocation->longitude, 7), '°', 2);
1175
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('latitude'), round($value->exactLocation->latitude, 7), '°', 3);
1176
                            if (isset($value->exactLocation->referenceSystem)) {
1177
                                @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('referenceSystem'), $value->exactLocation->referenceSystem->representation_L10n, '', 4);
1178
                            }
1179 106e1cf9 Katja Luther
                            if ( isSet($value->exactLocation->sexagesimalString)){
1180
                                @_description_list_group_add($groups, cdm_occurrence_field_name_label('exactLocation'),
1181 267da0d1 Katja Luther
                                    array(
1182 106e1cf9 Katja Luther
                                        array('#markup' => $value->exactLocation->sexagesimalString),
1183
                                        array(
1184
                                            '#theme' => 'description_list',
1185
                                            '#groups' => $sub_dl_groups
1186
                                        ),
1187 abe0b021 Katja Luther
                                    ), '', 11
1188 106e1cf9 Katja Luther
                                );
1189
                            }
1190 267da0d1 Katja Luther
                        }
1191
1192
                        break;
1193
1194
                    /* ---- DerivationEvent --- */
1195
                    case 'derivationEvents':
1196
                        //@_description_list_group_add($groups, t('Association type'), $value->description);
1197
                        break;
1198
1199
1200
                    default:
1201
                        if (is_object($value) || is_array($value)) {
1202 52f57468 Katja Luther
                            drupal_set_message("Unhandled type in compose_cdm_specimenOrObservation() for field " . $field, "warning");
1203 267da0d1 Katja Luther
                        } else {
1204
                            _description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value);
1205
                        }
1206
1207
                }
1208
1209
1210
            }
1211
        } // END of loop over $derivedUnitFacade fields
1212
1213
1214
1215
        // template_preprocess_description_list() is not worting by weight so we do it right here
1216
        uasort($groups, 'element_sort');
1217
1218
        $occurrence_elements = array(
1219
           // '#title' => $title,
1220
            '#theme' => 'description_list',
1221
            '#groups' => $groups,
1222 58c1a035 Katja Luther
            '#attributes' => array('class' => html_class_attribute_ref($specimen_or_observation)),
1223 267da0d1 Katja Luther
        );
1224
        $output = drupal_render($occurrence_elements);
1225 106e1cf9 Katja Luther
        if (isset($gallery_html)){
1226
            $output .= $gallery_html;
1227
        }
1228 a2acff0a Katja Luther
        $pathToSpecimen = path_to_specimen($specimen_or_observation->uuid);
1229
        $output .=  l("detail page", $pathToSpecimen, array('attributes' => array('target' => '_blank')));
1230 267da0d1 Katja Luther
    } // END of $specimenOrObservation exists
1231
1232
    return $output;
1233
}