Project

General

Profile

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