Project

General

Profile

Download (75.4 KB) Statistics
| Branch: | Tag: | Revision:
1 c70b93c3 Andreas Kohlbecker
<?php
2 f19f47fa Andreas Kohlbecker
/**
3
 * @file
4 bff67f14 Patric Plitzner
 * Functions for dealing with CDM entities of type SpecimenOrOccurrences
5 f19f47fa Andreas Kohlbecker
 *
6
 * @copyright
7
 *   (C) 2007-2012 EDIT
8
 *   European Distributed Institute of Taxonomy
9
 *   http://www.e-taxonomy.eu
10
 *
11
 *   The contents of this module are subject to the Mozilla
12
 *   Public License Version 1.1.
13
 * @see http://www.mozilla.org/MPL/MPL-1.1.html
14
 *
15
 * @author
16
 *   - Andreas Kohlbecker <a.kohlbecker@BGBM.org>
17 c70b93c3 Andreas Kohlbecker
 */
18
19 b810158e Patric Plitzner
20
/**
21 30845bda Andreas Kohlbecker
 * Provides the HTML markup for a specimen page
22
 *
23
 * @param $specimen
24
 *
25 b810158e Patric Plitzner
 * @return string
26 30845bda Andreas Kohlbecker
 *  The markup for a specimen page
27 b810158e Patric Plitzner
 */
28 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 cea59762 Andreas Kohlbecker
        $specimenPageLink = l($specimen->accessionNumber, $pathToSpecimen);
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 cea59762 Andreas Kohlbecker
        $stableIdentifierLink = l($specimen->preferredStableUri, $specimen->preferredStableUri);
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 cea59762 Andreas Kohlbecker
            $detail_html .= l("detail page", $pathToSpecimen);
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 44458b04 Andreas Kohlbecker
    if ((variable_get(CDM_SPECIMEN_LIST_VIEW_MODE, CDM_SPECIMEN_LIST_VIEW_MODE_DEFAULT) == CDM_SPECIMEN_LIST_VIEW_MODE_OPTION_DERIVATE_TABLE) || !$isSpecimen_page){
339 a2acff0a Katja Luther
        $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 cae389f9 Andreas Kohlbecker
            // WARNING: adding a List<MediaDTO> as $specimen_or_observation->_derivedUnitMedia
363 a2acff0a Katja Luther
            $specimen_or_observation->_derivedUnitMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array(
364
                $specimen_or_observation->uuid,
365
                'fieldObjectMediaDTO',
366
            ));
367
        }else{
368 cae389f9 Andreas Kohlbecker
            // WARNING: adding a List<Media> as $specimen_or_observation->_derivedUnitMedia
369 a2acff0a Katja Luther
            $specimen_or_observation->_derivedUnitMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array(
370
                $specimen_or_observation->uuid,
371
                'derivedUnitMedia',
372
            ));
373
        }
374 c10f70e4 Katja Luther
375 a2acff0a Katja Luther
        $type_label = $specimen_or_observation->class;
376
        RenderHints::setFootnoteListKey($type_label . '-' . $specimen_or_observation->uuid);
377 c10f70e4 Katja Luther
378
        // collect typeStatus as label
379 a2acff0a Katja Luther
        if (isset($specimen_or_observation->specimenTypeDesignations)) {
380 c10f70e4 Katja Luther
            $type_status = array();
381 a2acff0a Katja Luther
            foreach ($specimen_or_observation->specimenTypeDesignations as $typeDesignation) {
382 c10f70e4 Katja Luther
                if (isset($typeDesignation->typeStatus->representation_L10n)) {
383
                    $type_status[] = $typeDesignation->typeStatus->representation_L10n;
384
                }
385
            }
386
            if (count($type_status) > 0) {
387
                $type_label = implode(', ', $type_status);
388
            }
389 9b9037f3 Andreas Kohlbecker
        }
390
391 a2acff0a Katja Luther
        $title = $type_label . ': ' . $specimen_or_observation->titleCache;
392 c10f70e4 Katja Luther
393
        $groups = array();
394 a2acff0a Katja Luther
395 c10f70e4 Katja Luther
        // --- add initialized fields
396 a2acff0a Katja Luther
        foreach (get_object_vars($specimen_or_observation) as $field => $value) {
397 c10f70e4 Katja Luther
            if (!in_array($field, $exclude_occurrence_fields) && ($value && (!is_object($value) || isset($value->class)))) {
398
                switch ($field) {
399 d3f77ada Katja Luther
400 c10f70e4 Katja Luther
                    /* ---- java.lang.Object --- */
401
                    case 'class':
402
                        if ($value != '' /* FieldUnit' */) {
403
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value);
404
                        }
405
                        break;
406 6fbdb943 Andreas Kohlbecker
407 c10f70e4 Katja Luther
                    case 'markers':
408
                        $dd_elements = array();
409
                        foreach ($value as $marker) {
410
                            $dd_elements[] = compose_cdm_marker($marker);
411
                        }
412
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
413
                        break;
414 4ae6064e Andreas Kohlbecker
415 f19f47fa Andreas Kohlbecker
416 c10f70e4 Katja Luther
                    case 'annotations':
417
                        $dd_elements = array();
418
                        foreach ($value as $annotation) {
419
                            // TODO respect annotation type filter settings
420
                            $dd_elements[] = $annotation->text;
421
                        }
422 50caf951 Katja Luther
                        @_description_list_group_add($groups, t('Notes:'), $dd_elements);
423 c10f70e4 Katja Luther
                        break;
424
425
                    /* ---- SpecimenOrObservationBase --- */
426
                    case 'sex':
427
                    case 'lifeStage':
428
                    case 'kindOfUnit':
429 d3f77ada Katja Luther
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value->representation_L10n);
430 c10f70e4 Katja Luther
                        break;
431
432
                    case 'definition':
433
                        // TODO
434
                        break;
435
436
                    case 'preferredStableUri':
437
438
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), array(array('#markup' => cdm_external_uri($value, false))));
439
                        break;
440
441
                    case 'specimenTypeDesignations':
442 ddbbdb0b Katja Luther
443
                        //TODO: better display of details!!
444 c10f70e4 Katja Luther
                        @_description_list_group_add(
445
                            $groups,
446
                            cdm_occurrence_field_name_label($field),
447
                            array(
448 0c720425 Andreas Kohlbecker
                                '#markup' => render_type_designations($value),
449 c10f70e4 Katja Luther
                            )
450
                        );
451
                        break;
452
453
                    case 'determinations':
454
                        $dd_elements = array();
455
                        $glue = ', ';
456
457
                        foreach ($value as $determinationEvent) {
458
                            $timeperiod_string = NULL;
459
                            if (isset($determinationEvent->timeperiod)) {
460
                                $timeperiod_string = timePeriodToString($determinationEvent->timeperiod);
461
                            }
462
                            $weight = isset($determinationEvent->preferred) && $determinationEvent->preferred == 1 ? '0' : ($timeperiod_string ? $timeperiod_string : '1');
463
                            // check key exists
464
                            while (array_key_exists($weight, $dd_elements)) {
465
                                $weight .= '0';
466
                            }
467 4ae6064e Andreas Kohlbecker
468 c10f70e4 Katja Luther
                            $taxon_name = '';
469
                            $name_link = '';
470
                            if ($determinationEvent->taxonName) {
471 6eaec849 Katja Luther
                                $taxon_name = cdm_ws_get(CDM_WS_NAME, $determinationEvent->taxonName->uuid);
472
                                $taxon_name->taggedName = cdm_ws_get(CDM_WS_NAME, array($determinationEvent->taxonName->uuid, "taggedName"));
473
                                $name_link = path_to_name($determinationEvent->taxonName->uuid);
474 72d57201 Katja Luther
                            } else if ($determinationEvent->taxon) {
475
                                $taxon_name = cdm_ws_get(CDM_WS_TAXON . '/$0/name', $determinationEvent->taxon->uuid);
476
                                $name_link = path_to_taxon($determinationEvent->taxon->uuid);
477 c10f70e4 Katja Luther
                            }
478
                            if ($taxon_name) {
479 4c812e71 Katja Luther
                                //$taxon_html = render_taxon_or_name($taxon_name, $name_link);
480
481 cea59762 Andreas Kohlbecker
                                $taxon_html = l($taxon_name->titleCache, $name_link);
482 c10f70e4 Katja Luther
                                $dd_elements[$weight] = $taxon_html;
483
                            }
484
                            if (isset($determinationEvent->modifier)) {
485
                                $dd_elements[$weight] .= cdm_term_representation($determinationEvent->modifier);
486
                            }
487
                            if ($timeperiod_string) {
488
                                $dd_elements[$weight] .= $glue . $timeperiod_string;
489
                            }
490
                            if (isset($determinationEvent->actor->titleCache)) {
491
                                $dd_elements[$weight] .= $glue . $determinationEvent->actor->titleCache;
492
                            }
493
                            if (isset($determinationEvent->description)) {
494
                                $dd_elements[$weight] .= $glue . $determinationEvent->description;
495
                            }
496
                        }
497
                        ksort($dd_elements);
498
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('determinations'), $dd_elements);
499
                        break;
500 f846e7e7 Andreas Kohlbecker
501 c10f70e4 Katja Luther
                    case 'descriptions':
502
                        $dd_elements = array();
503
                        foreach ($value as $description) {
504
                            $description = cdm_ws_get(CDM_WS_PORTAL_DESCRIPTION, $description->uuid);
505 a2acff0a Katja Luther
506 72d57201 Katja Luther
                            if ($description->imageGallery == TRUE) {
507
                                continue;
508
                            }
509 2527a83c Andreas Kohlbecker
                            $description_string = render_description_string(get_root_nodes_for_dataset($description));
510
                            $dd_elements[] = markup_to_render_array($description_string);
511 c10f70e4 Katja Luther
                        }
512
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
513
                        break;
514 a2acff0a Katja Luther
                    case '_derivedUnitMedia':
515 72d57201 Katja Luther
                        if ($isSpecimen_page) {
516 a2acff0a Katja Luther
                            $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 cae389f9 Andreas Kohlbecker
                                'mediaList' => $value, // WARNING: this is either a List<Media> or List<MediaDTO>, see above ~line 361
522 a2acff0a Katja Luther
                                '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 72d57201 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 72d57201 Katja Luther
                        // $dd_elements[] = markup_to_render_array($gallery_html);
535 a2acff0a Katja Luther
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 a067cc04 Andreas Kohlbecker
                            RenderHints::getFootnoteListKey()
548 4186a152 Katja Luther
                        );
549 72d57201 Katja Luther
                        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 72d57201 Katja Luther
                                if (isset($derivedFrom->description) && $derivedFrom->description != '') {
563 a2acff0a Katja Luther
                                    $description = $derivedFrom->description . ": ";
564
                                }
565
566 cea59762 Andreas Kohlbecker
                                $originals[] = markup_to_render_array(l($description . $original->titleCache, $pathToSpecimen));
567 72d57201 Katja Luther
                                if ($original->class == 'FieldUnit') {
568 4186a152 Katja Luther
                                    $label = t('Field data');
569 72d57201 Katja Luther
                                } else {
570 4186a152 Katja Luther
                                    $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 cea59762 Andreas Kohlbecker
                                    $derived_units[] = markup_to_render_array(l($description . $derived_unit->titleCache, $pathToSpecimen));
591 72d57201 Katja Luther
                                }
592
                            }
593
                            @_description_list_group_add($groups, t('Derivates') . ':',
594 a2acff0a Katja Luther
                                $derived_units,
595 72d57201 Katja Luther
                                '', 100);
596 a2acff0a Katja Luther
597
                        }
598 c10f70e4 Katja Luther
                        break;
599
600
                    case 'collection':
601
                        $sub_dl_groups = array();
602
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('code'), $value->code, NULL, 1);
603
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('codeStandard'), $value->codeStandard, NULL, 2);
604
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('institute'), $value->institute, NULL, 3);
605
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('townOrLocation'), $value->townOrLocation, NULL, 4);
606
                        // TODO "superCollection"
607
                        // TODO may have media
608
609
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),
610
                            array(
611
                                array('#markup' => $value->titleCache),
612
                                array('#theme' => 'description_list', '#groups' => $sub_dl_groups)
613
                            )
614
                        );
615
                        break;
616
617
                    case 'storedUnder':
618
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('storedUnder'), render_taxon_or_name($value));
619
                        break;
620 72d57201 Katja Luther
                    case 'dnaQuality':
621
                        $sub_dl_groups = array();
622
623
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('purificationMethod'), $value->purificationMethod, NULL, 1);
624
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('ratioOfAbsorbance260_230'), $value->ratioOfAbsorbance260_230, NULL, 2);
625
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('ratioOfAbsorbance260_280'), $value->ratioOfAbsorbance260_280, NULL, 3);
626
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('concentration'), $value->concentration, NULL, 4);
627
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('concentrationUnit'), $value->concentrationUnit, NULL, 4);
628
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('qualityTerm'), $value->qualityTerm, NULL, 4);
629
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('qualityCheckDate'), $value->qualityCheckDate, NULL, 4);
630
631
                        if (is_array($sub_dl_groups) && sizeof($sub_dl_groups)>0) {
632
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),
633
                                array(
634
                                    array('#markup' => $value->titleCache),
635
                                    array('#theme' => 'description_list', '#groups' => $sub_dl_groups)
636
                                )
637
                            );
638
                        }
639
                        break;
640
641
                    case 'preservation':
642
                        $sub_dl_groups = array();
643 c10f70e4 Katja Luther
644 72d57201 Katja Luther
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('medium'), $value->medium, NULL, 1);
645
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('temperature'), $value->temperature, NULL, 2);
646
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('definedMaterialOrMethod'), $value->definedMaterialOrMethod, NULL, 3);
647
648
                        if (is_array($sub_dl_groups) && sizeof($sub_dl_groups)>0) {
649
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),
650
                                array(
651
                                    array('#markup' => $value->titleCache),
652
                                    array('#theme' => 'description_list', '#groups' => $sub_dl_groups)
653
                                )
654
                            );
655
                        }
656
                        break;
657 c10f70e4 Katja Luther
658
                    /* ---- Specimen --- */
659
                    case 'sequences':
660
                        $dd_elements = array();
661
                        foreach ($value as $sequence) {
662
                            $dd_elements[] = compose_cdm_sequence($sequence);
663
                        }
664
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
665
                        break;
666
667
                    // TODO preservation
668
                    // TODO exsiccatum
669
670
671
                    /* ---- FieldObservation --- */
672
                    case 'gatheringEvent':
673 abe0b021 Katja Luther
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collector'), $value->actor->titleCache, '', 1);
674
                        @_description_list_group_add($groups, t('Gathering date'), timePeriodToString($value->timeperiod), '', 2);
675
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('description'), $value->description, '', 3);
676
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('locality'), $value->locality->text, '', 10);
677
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('country'), $value->country->representation_L10n, '', 4);
678
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingMethod'), $value->collectingMethod,'',5);
679 c10f70e4 Katja Luther
                        if (isset($value->absoluteElevation)) {
680 2f4646e0 Andreas Kohlbecker
                            $min_max_markup = statistical_values_from_gathering_event($value, 'absoluteElevation');
681 abe0b021 Katja Luther
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('absoluteElevation'), $min_max_markup, '',6);
682 c10f70e4 Katja Luther
                        }
683
                        if (isset($value->distanceToGround)) {
684 2f4646e0 Andreas Kohlbecker
                            $min_max_markup = statistical_values_from_gathering_event($value, 'distanceToGround');
685 abe0b021 Katja Luther
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToGround'), $min_max_markup,'',7);
686 c10f70e4 Katja Luther
                        }
687
                        if (isset($value->distanceToWaterSurface)) {
688 2f4646e0 Andreas Kohlbecker
                            $min_max_markup = statistical_values_from_gathering_event($value, 'distanceToWaterSurface');
689 abe0b021 Katja Luther
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToWaterSurface'), $min_max_markup, '',8);
690 c10f70e4 Katja Luther
                        }
691 abe0b021 Katja Luther
                        if (isset($value->collectingAreas) && count($value->collectingAreas) > 0) {
692 c10f70e4 Katja Luther
                            $area_representations = array();
693
                            foreach ($value->collectingAreas as $area) {
694
                                $area_representations[] = l($area->representation_L10n, path_to_named_area($area->uuid));
695
                            }
696 d3f77ada Katja Luther
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingAreas'),
697
                                array(
698
                                    array('#markup' => implode(', ', $area_representations))
699 abe0b021 Katja Luther
                                ),'',9
700 d3f77ada Katja Luther
                            );
701 c10f70e4 Katja Luther
                        }
702
                        if (isset($value->exactLocation) && $value->exactLocation->sexagesimalString) {
703
                            $sub_dl_groups = array();
704
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('errorRadius'), $value->exactLocation->errorRadius, ' m', 1);
705
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('longitude'), round($value->exactLocation->longitude, 7), '°', 2);
706
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('latitude'), round($value->exactLocation->latitude, 7), '°', 3);
707
                            if (isset($value->exactLocation->referenceSystem)) {
708
                                @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('referenceSystem'), $value->exactLocation->referenceSystem->representation_L10n, '', 4);
709
                            }
710 6fbdb943 Andreas Kohlbecker
711 c10f70e4 Katja Luther
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('exactLocation'),
712
                                array(
713
                                    array('#markup' => $value->exactLocation->sexagesimalString),
714
                                    array(
715
                                        '#theme' => 'description_list',
716
                                        '#groups' => $sub_dl_groups
717
                                    ),
718 abe0b021 Katja Luther
                                ),'',11
719 c10f70e4 Katja Luther
                            );
720
                        }
721
                        break;
722
723
                    default:
724
                        if (is_object($value) || is_array($value)) {
725 d3f77ada Katja Luther
                            drupal_set_message("Unhandled type in compose_cdm_specimen_or_observation() for field " . $field, "warning");
726 c10f70e4 Katja Luther
                        } else {
727 f60b52c4 Katja Luther
                            if ($field == 'RecordBase' && $value == 'DnaSample') {
728
                                _description_list_group_add($groups, cdm_occurrence_field_name_label($field), 'DNA Sample');
729
                            } else {
730 50caf951 Katja Luther
                                _description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value);
731 f60b52c4 Katja Luther
                            }
732 c10f70e4 Katja Luther
                        }
733 74ee6b54 Andreas Kohlbecker
734 c10f70e4 Katja Luther
                }
735 f19f47fa Andreas Kohlbecker
736 f846e7e7 Andreas Kohlbecker
            }
737 c10f70e4 Katja Luther
        } // END of loop over $derivedUnitFacade fields
738 f19f47fa Andreas Kohlbecker
739 c10f70e4 Katja Luther
        // Extensions
740 db9c6559 Andreas Kohlbecker
        // TODO: filter by using visible_extensions_sorted()
741 a2acff0a Katja Luther
        $extensions = cdm_ws_fetch_all(CDM_WS_PORTAL_OCCURRENCE . '/'  . $specimen_or_observation->uuid . '/extensions', array($specimen_or_observation->uuid));
742 c10f70e4 Katja Luther
        if ($extensions && count($extensions)) {
743
744
            $extensions_render_array = compose_extensions($extensions);
745
            @_description_list_group_add($groups, t('Extensions') . ':',
746
                $extensions_render_array,
747
                '', 100);
748 f19f47fa Andreas Kohlbecker
        }
749
750 f846e7e7 Andreas Kohlbecker
751 a2acff0a Katja Luther
752 c10f70e4 Katja Luther
        // template_preprocess_description_list() is not worting by weight so we do it right here
753
        uasort($groups, 'element_sort');
754 0820cdc0 Andreas Kohlbecker
755 c10f70e4 Katja Luther
        $occurrence_elements = array(
756 e89c1115 Katja Luther
           // '#title' => $title,
757 c10f70e4 Katja Luther
            '#theme' => 'description_list',
758
            '#groups' => $groups,
759 a2acff0a Katja Luther
            '#attributes' => array('class' => html_class_attribute_ref($specimen_or_observation)),
760 c10f70e4 Katja Luther
        );
761 a2acff0a Katja Luther
762 43d01429 Andreas Kohlbecker
        $derivatives[] = $occurrence_elements;
763 c10f70e4 Katja Luther
        // all footnotes which has been assembled so far (e.g. from typeDesignations) to here
764 d8069342 Andreas Kohlbecker
//       $foonote_li_elements = render_footnotes(RenderHints::getFootnoteListKey(), 'span');
765 ade2b1f0 Katja Luther
//        if (!empty($foonote_li_elements)) {
766
//            $derivatives[] =  array(
767
//                '#markup' =>  '<div class="footnotes">' . $foonote_li_elements . '</div>',
768
//            );
769
//        }
770 0820cdc0 Andreas Kohlbecker
771 c10f70e4 Katja Luther
        // --- recurse into originals
772 a2acff0a Katja Luther
        if (!isset($derivedFrom)  && !$isSpecimen_page) {
773 c10f70e4 Katja Luther
            $derivedFrom = cdm_ws_get(
774
                CDM_WS_OCCURRENCE,
775 a2acff0a Katja Luther
                array($specimen_or_observation->uuid, 'derivedFrom')
776 c10f70e4 Katja Luther
            );
777
        }
778 a2acff0a Katja Luther
        if (isset($derivedFrom) && !$isSpecimen_page) {
779 d3f77ada Katja Luther
            if (isset($derivedFrom->originals)) {
780
                $derived_from_label = t('derived');
781
                $preposition = t('from');
782
                if(isset($derivedFrom->type)){
783 c10f70e4 Katja Luther
                    $derived_from_label = $derivedFrom->type->representation_L10n;
784 d3f77ada Katja Luther
                    if($derivedFrom->type->uuid == UUID_DERIVATIONEVENTTYPE_ACCESSIONING){
785
                        $preposition = t('of');
786 c10f70e4 Katja Luther
                    }
787
                }
788
                if (count($groups) > 0) {
789
                    // TODO  annotations
790 eeb98da8 Andreas Kohlbecker
791 c10f70e4 Katja Luther
                    // only display the derived from information when the derivative has any element which will be diplayed
792
                    $derivatives[] = array(
793 d3f77ada Katja Luther
                        '#markup' => '<div class="derived_from">' . $derived_from_label . ' ' . $preposition . ': </div>',
794 c10f70e4 Katja Luther
                    );
795
                }
796 d3f77ada Katja Luther
                foreach ($derivedFrom->originals as $original) {
797 a2acff0a Katja Luther
                    compose_cdm_specimen_or_observation($original, $isSpecimen_page, $derivatives);
798 d3f77ada Katja Luther
                }
799 c10f70e4 Katja Luther
            }
800 0796d2f9 Andreas Kohlbecker
        }
801 f1f05758 Andreas Kohlbecker
802 a2acff0a Katja Luther
803
804
805 c10f70e4 Katja Luther
    } // END of $specimenOrObservation exists
806 c70b93c3 Andreas Kohlbecker
807 c10f70e4 Katja Luther
    return $derivatives;
808 f1f05758 Andreas Kohlbecker
}
809 0de9cf51 Andreas Kohlbecker
810 0820cdc0 Andreas Kohlbecker
811 0de9cf51 Andreas Kohlbecker
/**
812
 * Compose an render array from a CDM Sequence object.
813
 *
814
 * compose_hook() implementation
815
 *
816
 * @param object $sequence
817
 *   CDM instance of type Sequence
818
 * @return array
819
 *   A render array containing the fields of the supplied $sequence
820 5b26b91a Andreas Kohlbecker
 *
821
 * @ingroup compose
822 0de9cf51 Andreas Kohlbecker
 */
823 52f57468 Katja Luther
function compose_cdm_sequence($sequence, $isSpecimenPage = false)
824 c10f70e4 Katja Luther
{
825
826
    $exclude_sequence_fields = &drupal_static(__FUNCTION__);
827
    if (!isset($exclude_sequence_fields)) {
828
        $exclude_sequence_fields = array(
829
            'titleCache',
830
            'protectedTitleCache',
831
            'microReference',
832
            'created',
833
            'updated',
834
            'class',
835
        );
836
    }
837 0de9cf51 Andreas Kohlbecker
838 c10f70e4 Katja Luther
    $groups = array();
839 0de9cf51 Andreas Kohlbecker
840 c10f70e4 Katja Luther
    // -- retrieve additional data if neesscary
841
    // TODO below call disabled since sequences are not yet supported,
842
    //      see  #3347 (services and REST service controller for molecular classes implemented)
843
    //
844
    // cdm_load_annotations($sequence);
845 eeb98da8 Andreas Kohlbecker
846 c10f70e4 Katja Luther
    foreach (get_object_vars($sequence) as $field => $value) {
847 eeb98da8 Andreas Kohlbecker
848
849 c10f70e4 Katja Luther
        if (!in_array($field, $exclude_sequence_fields) && ($value && (!is_object($value) || isset($value->class)))) {
850
            switch ($field) {
851 0de9cf51 Andreas Kohlbecker
852 c10f70e4 Katja Luther
                case 'geneticAccessionNumber';
853 52f57468 Katja Luther
854
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 2);
855 c10f70e4 Katja Luther
                    break;
856
857
858 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.
859
                    if (isset($value->name)) {
860 c10f70e4 Katja Luther
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value->name, NULL, 3);
861
                    }
862
                    if (isset($value->description)) {
863
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field) . ' ' . t('description'), $value->description, NULL, 4);
864
                    }
865 52f57468 Katja Luther
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field) , $value, NULL, 4);
866 c10f70e4 Katja Luther
                    break;
867 a2acff0a Katja Luther
868 c10f70e4 Katja Luther
                case 'consensusSequence':
869
                    // format in genbank style, force linebreaks after each 70 nucleotites
870
                    // see also http://stackoverflow.com/questions/499137/css-how-can-i-force-a-long-string-without-any-blank-to-be-wrapped-in-xul-and
871 52f57468 Katja Luther
                    if ($value->length > 0) {
872
                        @_description_list_group_add(
873
                            $groups,
874
                            cdm_occurrence_field_name_label($field),
875 c10f70e4 Katja Luther
                            array(
876 52f57468 Katja Luther
                                array(
877
                                    '#markup' => '<div class="sequence-length">' . $value->length . ' ' . t('pb') . '</div><div>' . wordwrap($value->string, 70, '</br>', TRUE) . '</div>',
878
                                    '#wrapper_attributes' => array('class' => 'dna-sequence')
879
                                )
880
                            ),
881
                            5);
882
                    }
883 c10f70e4 Katja Luther
                    break;
884
885
                case 'dnaSample': // FIXME 3.3 implement
886
                    break;
887
                case 'singleReads': // FIXME 3.3 implement
888
                    break;
889
                case 'contigFile': // FIXME 3.3 implement - Media
890
                    break;
891
                case 'pherograms': // FIXME 3.3 implement - Media
892
                    break;
893
                case 'haplotype': // FIXME 3.3 implement
894
                    break;
895
                case 'dateSequenced': // FIXME 3.3 now in SingelRead
896
                    @_description_list_group_add($groups, t('Sequencing date'), timePeriodToString($value), NULL, 6);
897
                    break;
898
899
                case 'barcode': // boolean
900
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value ? 'Yes' : 'No', NULL, 7);
901
                    break;
902
                case 'barcodeSequencePart': // FIXME 3.3 implement, compose sequence
903
                    break;
904
905
                case 'citation':
906
                    @_description_list_group_add($groups,
907
                        cdm_occurrence_field_name_label($field),
908 e7f3789b Andreas Kohlbecker
                        cdm_reference_markup($value, $sequence->microReference),
909 c10f70e4 Katja Luther
                        NULL,
910
                        8
911
                    );
912
                    break;
913
914
                case 'publishedIn':
915
                    @_description_list_group_add($groups,
916
                        cdm_occurrence_field_name_label($field),
917
                        theme('cdm_reference', array('reference' => $value)),
918
                        NULL,
919
                        7
920
                    );
921
                    break;
922
923
                case 'rights':
924
                    array_merge($groups, cdm_rights_as_dl_groups($value));
925
                    break;
926
927
                case 'annotations':
928
                    $dd_elements = array();
929
                    foreach ($value as $annotation) {
930
                        // TODO respect annotation type filter settings
931
                        $dd_elements[] = $annotation->text;
932
                    }
933
                    @_description_list_group_add($groups, t('Notes'), $dd_elements, NULL, 9);
934
                    break;
935
936
                case 'markers':
937
                    $dd_elements = array();
938
                    foreach ($value as $marker) {
939
                        $dd_elements[] = compose_cdm_marker($marker);
940
                    }
941
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements, NULL, 10);
942
                    break;
943
944
                case 'chromatograms':
945
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),
946
                        array(
947
                            '#markup' => compose_cdm_media_gallerie(array('medialist' => $value)),
948
                        ),
949
                        NULL,
950
                        11);
951
                    break;
952
953
                default:
954
                    if (is_object($value) || is_array($value)) {
955
                        drupal_set_message("Unhandled type in compose_cdm_sequence() for field " . $field, "warning");
956
                    } else {
957 8e15d0fb Katja Luther
                        if (!is_array($value) && strpos($value, 'http:') !== false ){
958
                            //make links for urls
959 cea59762 Andreas Kohlbecker
                            $value = l($value, $value);
960 8e15d0fb Katja Luther
                            $value = markup_to_render_array($value);
961
                        }
962
963 58c1a035 Katja Luther
                       _description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 20);
964 c10f70e4 Katja Luther
                    }
965 1b57b3c1 Andreas Kohlbecker
            }
966 c10f70e4 Katja Luther
        }
967 0de9cf51 Andreas Kohlbecker
    }
968
969 c10f70e4 Katja Luther
    // template_preprocess_description_list() is not worting by weight so we do it right here
970
    uasort($groups, 'element_sort');
971 52f57468 Katja Luther
    if ($isSpecimenPage) {
972
        $sequence_elements = array(
973
            '#title' => $sequence->dnaMarker,
974
            '#theme' => 'description_list',
975
            '#groups' => $groups
976
        );
977
    } else{
978
        $sequence_elements = array(
979
            '#title' => $sequence->dnaMarker -> titleCache,
980
            '#theme' => 'description_list',
981
            '#groups' => $groups
982
        );
983
    }
984 0de9cf51 Andreas Kohlbecker
985 c10f70e4 Katja Luther
    return $sequence_elements;
986 0de9cf51 Andreas Kohlbecker
}
987 961319fe Andreas Kohlbecker
988
/**
989 09762fde Andreas Kohlbecker
 * Crates an array which can be used in render arrays to be passed to the
990
 * theme_table() and theme_list().
991
 *
992 961319fe Andreas Kohlbecker
 * @param array $fieldunit_dtos
993
 *     list of FieldUnitDTOs
994
 */
995
function specimen_render_array_items(array $fieldunit_dtos){
996
997
  $render_array_items = array();
998
  $items = array();
999
1000
  //we need one more item to contain the items of one level (fieldunit, derivate data etc.)
1001
  foreach ($fieldunit_dtos as &$fieldunit_dto) {
1002
1003
    $items['data'] = $fieldunit_dto->listLabel ;
1004
    $specimen = compose_cdm_specimen_or_observation_tree_entry($fieldunit_dto);
1005
    $children = array();
1006
    $child = array();
1007
    $child['data'] =$specimen;
1008
    // $children[] = create_specimen_array($specimenOrObservation->derivates);
1009
    if (isset($fieldunit_dto->derivates) && sizeof($fieldunit_dto->derivates) > 0){
1010
      $child['children']= specimen_render_array_items($fieldunit_dto->derivates);
1011
    }
1012
    $children[]=$child;
1013
    $items['children'] = $children;
1014
    $render_array_items[] = $items;
1015
  }
1016
  return $render_array_items;
1017
}
1018
1019
/**
1020
 * Creates the drupal render array for the table showing all derivatives which
1021
 * stem from a common gathering event.
1022
 *
1023
 * @param $field_unit_uuids array
1024
 *  An array of uuids for cdm FieldUnit entities.
1025
 *
1026
 * @return array
1027
 *  A drupal render array for a table
1028
 *
1029
 * @ingroup compose
1030
 */
1031
1032
function compose_compressed_specimen_derivate_table($field_unit_uuids) {
1033
1034
  // prepare font icons
1035
  $expand_icon = font_awesome_icon_markup(
1036
    'fa-plus-square-o',
1037
    array(
1038
      'alt' => 'Show details',
1039
      'class' => array('expand_icon')
1040
    )
1041
  );
1042
  $collapse_icon = font_awesome_icon_markup(
1043
    'fa-minus-square-o',
1044
    array(
1045
      'alt' => 'Show details',
1046
      'class' => array('collapse_icon')
1047
    )
1048
  );
1049
  $detail_image_icon = '<img title="Detail Image" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/detail_image_derivate-16x16-32.png' . '"/>';
1050
  $checked_box_icon = '<img src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/step_done.gif' . '"/>';
1051
  $sequence_icon = '<img title="Molecular Data" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/sequence_derivate-16x16-32.png' . '"/>';
1052
  $character_data_icon = '<img title="Character Data" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/character_data_derivate-16x16-32.png' . '"/>';
1053
1054
  $rowcount = 0;
1055
  $rows = array();
1056
1057
  foreach ($field_unit_uuids as $field_unit_uuid) {
1058
1059
    //get derivate hierarchy for the FieldUnit
1060
    $derivateHierarchy = cdm_ws_get(CDM_WS_PORTAL_OCCURRENCE, array($field_unit_uuid, 'derivateHierarchy'));
1061
    if ($derivateHierarchy) {
1062
      //summary row
1063
      $rows[] = array(
1064
        'data' => array(
1065
          array(
1066
            'data' => $expand_icon . $collapse_icon,
1067
            'class' => array('summary_row_cell', 'summary_row_icon', 'expand_column')
1068
          ),
1069
          array(
1070
            'data' => $derivateHierarchy->country,
1071
            'class' => array('summary_row_cell')
1072
          ),
1073
          array(
1074
            'data' => $derivateHierarchy->date,
1075
            'class' => array('summary_row_cell')
1076
          ),
1077
          array(
1078
            'data' => $derivateHierarchy->collectingString,
1079
            'class' => array('summary_row_cell')
1080
          ),
1081
          @array(
1082
            'data' => $derivateHierarchy->collection,
1083
            'class' => array('summary_row_cell')
1084
          ),
1085
          array(
1086
            'data' => $derivateHierarchy->hasType ? $checked_box_icon : "",
1087
            'class' => array('summary_row_cell', 'summary_row_icon')
1088
          ),
1089
          array(
1090
            'data' => $derivateHierarchy->hasSpecimenScan ? $checked_box_icon : "",
1091
            'class' => array('summary_row_cell', 'summary_row_icon')
1092
          ),
1093
          array(
1094
            'data' => ($derivateHierarchy->hasDna ? $sequence_icon : "") . " "
1095
              . ($derivateHierarchy->hasDetailImage ? $detail_image_icon : "") . " "
1096
              . ($derivateHierarchy->hasCharacterData ? $character_data_icon : ""),
1097
            'class' => array('summary_row_cell', 'summary_row_icon')
1098
          )
1099
        ),
1100
        'id' => 'derivate_summary' . $rowcount, // summary row id
1101
        'class' => array('summary_row'),
1102
      );
1103
1104
      //assemble field unit details
1105
      $detail_html = "";
1106
      // - citation
1107
      if ($derivateHierarchy->citation) {
1108
        $detail_html .= create_label("Citation") . $derivateHierarchy->citation . "<br>";
1109
      }
1110
      //assemble specimen details
1111
      if ($derivateHierarchy->derivates) {
1112
        foreach ($derivateHierarchy->derivates as $preservedSpecimenDTO) {
1113
          $detail_html .= "<br>";
1114
          $detail_html .= render_cdm_specimenDTO_page($preservedSpecimenDTO);
1115
        }
1116
      }
1117
      $detail_html .= "<br>";
1118
      //detail row resp. one BIG detail cell
1119
      $rows[] = array(
1120
        'data' => array(
1121
          array(
1122
            'data' => "", //empty first column
1123
            'class' => array('expand_column')
1124
          ),
1125
          array(
1126
            'data' => $detail_html,
1127
            'colspan' => 7,
1128
          ),
1129
        ),
1130
        'id' => 'derivate_details' . $rowcount,//details row ID
1131
        'class' => array('detail_row'),
1132
      );
1133
      $rowcount++;
1134
    }
1135
  }
1136
1137
  $tableId = "derivate_hierarchy_table";
1138
  $derivateHierarchyTable = array(
1139
    "#theme" => "table",
1140
    "#weight" => 2,
1141
    "#header" => array(
1142
      array(
1143
        'data' => "",
1144
        'class' => array('expand_column')
1145
      ),
1146
      "Country", "Date", "Collector + collecting number", "Herbaria", "Type", "Scan", "Derivatives"),
1147
    "#rows" => $rows,
1148
    "#attributes" => array(
1149
      "id" => $tableId,
1150
      "border" => 2
1151
    )
1152
  );
1153
1154
  //add toggle functionality to derivate hierarchy table
1155
  drupal_add_js_rowToggle("#" . $tableId);
1156
1157
  return $derivateHierarchyTable;
1158
}
1159
1160 267da0d1 Katja Luther
/**
1161 09762fde Andreas Kohlbecker
 * Composes the view on specimens and occurrences as derivate tree
1162
 * starting from the field unit including all derivatives.
1163 267da0d1 Katja Luther
 *
1164 09762fde Andreas Kohlbecker
 * @see DM_SPECIMEN_LIST_VIEW_MODE_OPTION_DERIVATE_TREE
1165 267da0d1 Katja Luther
 *
1166 ca7468b6 Andreas Kohlbecker
 * @param object $fieldunit_dtos
1167 267da0d1 Katja Luther
 *   list of FieldUnitDTOs
1168
 * @return array
1169 09762fde Andreas Kohlbecker
 *   The Drupal render array
1170 267da0d1 Katja Luther
 *
1171
 * @ingroup compose
1172
 */
1173 961319fe Andreas Kohlbecker
function compose_specimen_table_top_down(array $fieldunit_dtos){
1174 276f39f6 Katja Luther
1175 961319fe Andreas Kohlbecker
  $specimen_render_array_items = specimen_render_array_items($fieldunit_dtos);
1176
1177
    // add icons
1178
  $expand_icon = font_awesome_icon_markup(
1179
    'fa-plus-square-o',
1180
    array(
1181
      'alt' => 'Show details',
1182
      'class' => array('expand_icon')
1183
    )
1184
  );
1185
  $collapse_icon = font_awesome_icon_markup(
1186
    'fa-minus-square-o',
1187
    array(
1188
      'alt' => 'Show details',
1189
      'class' => array('collapse_icon')
1190
    )
1191
  );
1192
  $tableId = "specimen_tree_table";
1193
  $specimen_table = array(
1194
    '#theme' => 'table',
1195
    // prefix attributes and rows with '#' to let it pass toF the theme function,
1196
    // otherwise it is handled as child render array
1197
    '#attributes' => array(
1198 09762fde Andreas Kohlbecker
      'class' => 'specimens ' . CDM_SPECIMEN_LIST_VIEW_MODE_OPTION_DERIVATE_TREE ,
1199 961319fe Andreas Kohlbecker
      'id' => $tableId
1200
    ),
1201
    '#rows' => array(),
1202
  );
1203
  $rowcount = 0;
1204
  foreach($specimen_render_array_items as $value){
1205
    $renderArray = array(
1206
      '#theme' => 'item_list',
1207
      '#items' => $value['children'],
1208
      '#type' => 'ul');
1209
    $output = drupal_render($renderArray);
1210
1211
    $specimen_table['#rows'][] = array(
1212
      'data' =>array(
1213
        array(
1214
          'data' => $expand_icon . $collapse_icon,
1215
          'class' => array('summary_row_cell', 'summary_row_icon', 'expand_column')
1216
        ),
1217
        $value['data']
1218
      ),
1219
      'id' => 'label' . $rowcount, // summary row id
1220
      'class' => array('summary_row'),
1221
    );
1222
    $specimen_table['#rows'][] = array(
1223
      'data' =>  array(
1224
        array(
1225
          'data' => "", //empty first column
1226
          'class' => array('expand_column')
1227
        ),
1228
        array(
1229
          'data' => $output
1230
1231
        )
1232
      ),
1233
      'class' =>  array('detail_row')
1234
//                'class' =>  array(
1235
//                    'descriptionElement',
1236
//                    'descriptionElement_IndividualsAssociation'
1237
      //               ),
1238
    );
1239
    $rowcount++;
1240
1241
  }
1242
  drupal_add_js_rowToggle("#".$tableId);
1243
1244
  return $specimen_table;
1245 267da0d1 Katja Luther
}
1246
1247
1248
/**
1249
 * Compose an render array from a CDM DerivedUnitFacade object.
1250
 *
1251
 * compose_hook() implementation
1252
 *
1253
 * @param object $specimenOrObservation
1254
 *   the CDM instance of type SpecimenOrObservation to compose
1255
 *   the render array for
1256
 * @param array $derivatives
1257
 *   the render array which contains the compositions of the derivatives
1258
 *   of the supplied $specimenOrObservation
1259
 *
1260
 * @return array
1261
 *   the supplied render array $derivatives to which the composition of the supplied
1262
 *   $specimenOrObservation has been added to
1263
 *
1264
 * @ingroup compose
1265
 */
1266
1267 58c1a035 Katja Luther
function compose_cdm_specimen_or_observation_tree_entry($specimen_or_observation)
1268 267da0d1 Katja Luther
{
1269
    $exclude_occurrence_fields = &drupal_static(__FUNCTION__);
1270
    if (!isset($exclude_occurrence_fields)) {
1271
        $exclude_occurrence_fields = array(
1272
            'type',
1273
            'taxonRelatedDerivedUnits',
1274 7965ef92 Katja Luther
            'label',
1275 267da0d1 Katja Luther
            'titleCache',
1276 7965ef92 Katja Luther
            'listLabel',
1277 267da0d1 Katja Luther
            'protectedTitleCache',
1278
            'class',
1279
            'uuid',
1280 ddbbdb0b Katja Luther
            'derivates',
1281
            'collection'
1282 267da0d1 Katja Luther
        );
1283
    }
1284
    $items = array();
1285
1286
    // only show uuid it the user is logged in
1287
    if (user_is_logged_in() && ($a_idx = array_search('uuid', $exclude_occurrence_fields)) !== FALSE) {
1288
      //  unset($exclude_occurrence_fields[$a_idx]);
1289
    }
1290
1291
1292 58c1a035 Katja Luther
    if (is_object($specimen_or_observation)) {
1293 267da0d1 Katja Luther
1294 58c1a035 Katja Luther
        $type_label = $specimen_or_observation->recordBase;
1295
        RenderHints::setFootnoteListKey($type_label . '-' . $specimen_or_observation->uuid);
1296 267da0d1 Katja Luther
1297
        // collect typeStatus as label
1298 58c1a035 Katja Luther
        if (isset($specimen_or_observation->specimenTypeDesignations)) {
1299 267da0d1 Katja Luther
            $type_status = array();
1300 58c1a035 Katja Luther
            foreach ($specimen_or_observation->specimenTypeDesignations as $typeDesignation) {
1301 267da0d1 Katja Luther
                if (isset($typeDesignation->typeStatus->representation_L10n)) {
1302
                    $type_status[] = $typeDesignation->typeStatus->representation_L10n;
1303
                }
1304
            }
1305
            if (count($type_status) > 0) {
1306
                $type_label = implode(', ', $type_status);
1307 0557d51a Andreas Kohlbecker
          }
1308 267da0d1 Katja Luther
        }
1309
1310 0557d51a Andreas Kohlbecker
        if (isset($typeDesignation->typifiedNames)){
1311 6eaec849 Katja Luther
            $title = $type_label . ' for: ' . $typeDesignation->typifiedNames;
1312
        }else{
1313
            $title = $type_label;
1314
        }
1315
1316 7965ef92 Katja Luther
        $items['data'] = $title;
1317 267da0d1 Katja Luther
1318
        $groups = array();
1319
        $items['children'] = $groups;
1320
        $children_items = array();
1321
        // --- add initialized fields
1322 58c1a035 Katja Luther
        foreach (get_object_vars($specimen_or_observation) as $field => $value) {
1323 267da0d1 Katja Luther
            $child_item = array();
1324
1325
            if (!in_array($field, $exclude_occurrence_fields) && ($value && (!is_object($value) || isset($value->class)))) {
1326
                switch ($field) {
1327
1328
                    /* ---- SpecimenOrObservationBase --- */
1329 a2acff0a Katja Luther
                    case 'derivationEvent':
1330
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 1);
1331
                        break;
1332 267da0d1 Katja Luther
                    case 'kindOfUnit':
1333 52f57468 Katja Luther
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 1);
1334 267da0d1 Katja Luther
                        break;
1335 72d57201 Katja Luther
                    case 'accessionNumber':
1336
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 0);
1337
                        break;
1338 267da0d1 Katja Luther
1339
                    case 'preferredStableUri':
1340
1341 7965ef92 Katja Luther
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), array(array('#markup' => cdm_external_uri($value, false))));
1342 267da0d1 Katja Luther
                        break;
1343
1344
                    case 'specimenTypeDesignations':
1345 f1239704 Katja Luther
                        @_description_list_group_add(
1346
                            $groups,
1347 267da0d1 Katja Luther
                            cdm_occurrence_field_name_label($field),
1348
                            array(
1349 0c720425 Andreas Kohlbecker
                                '#markup' => render_type_designations($value),
1350 267da0d1 Katja Luther
                            )
1351
                        );
1352
                        break;
1353
1354
1355 f1239704 Katja Luther
1356 7965ef92 Katja Luther
                    case 'listOfMedia':
1357
                        $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
1358 6eaec849 Katja Luther
1359 7965ef92 Katja Luther
                        $captionElements = array(
1360 6eaec849 Katja Luther
                            'title',
1361 7965ef92 Katja Luther
                            '#uri' => t('open media'),
1362
                        );
1363
                        $gallery_html = compose_cdm_media_gallerie(array(
1364
                            'mediaList' => $value,
1365 72d57201 Katja Luther
                            'galleryName' => $specimen_or_observation->uuid,
1366 7965ef92 Katja Luther
                            'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
1367
                            'cols' => $gallery_settings['cdm_dataportal_media_cols'],
1368
                            'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
1369
                            'captionElements' => $captionElements,
1370
                            'mediaLinkType' => 'LIGHTBOX',
1371
                            'alternativeMediaUri' => NULL,
1372
                            'galleryLinkUri' => NULL,
1373 6eaec849 Katja Luther
                            'showCaption' => true
1374 7965ef92 Katja Luther
                        ));
1375
1376 276f39f6 Katja Luther
                         //@_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $gallery_html);
1377 7965ef92 Katja Luther
                         break;
1378 267da0d1 Katja Luther
1379
1380
1381
                    /* ---- DerivedUnitBase --- */
1382
1383 1083804e Andreas Kohlbecker
1384 a2acff0a Katja Luther
                    case 'collectionDTO':
1385 7965ef92 Katja Luther
1386 267da0d1 Katja Luther
                        $sub_dl_groups = array();
1387
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('code'), $value->code, NULL, 1);
1388
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('codeStandard'), $value->codeStandard, NULL, 2);
1389
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('institute'), $value->institute, NULL, 3);
1390
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('townOrLocation'), $value->townOrLocation, NULL, 4);
1391
                        // TODO "superCollection"
1392
                        // TODO may have media
1393
1394 a2acff0a Katja Luther
                        @_description_list_group_add($groups, 'Collection',
1395 267da0d1 Katja Luther
                            array(
1396
                                array('#markup' => $value->titleCache),
1397
                                array('#theme' => 'description_list', '#groups' => $sub_dl_groups)
1398
                            )
1399
                        );
1400 7965ef92 Katja Luther
1401 267da0d1 Katja Luther
                        break;
1402
1403
1404
1405
1406
                    /* ---- Specimen --- */
1407
                    case 'sequences':
1408
                        $dd_elements = array();
1409
                        foreach ($value as $sequence) {
1410 52f57468 Katja Luther
                            $dd_elements[] = compose_cdm_sequence($sequence, true);
1411
                            $dd_elements[] = "";
1412 267da0d1 Katja Luther
                        }
1413 a0f26798 Katja Luther
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements,'', 100);
1414 267da0d1 Katja Luther
                        break;
1415
1416
                    // TODO preservation
1417
                    // TODO exsiccatum
1418
1419
1420
                    /* ---- FieldObservation --- */
1421
                    case 'gatheringEvent':
1422
1423 52f57468 Katja Luther
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collector'), $value->collector);
1424 abe0b021 Katja Luther
                        @_description_list_group_add($groups, t('Gathering date'), timePeriodToString($value->timeperiod));
1425 267da0d1 Katja Luther
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('description'), $value->description);
1426 abe0b021 Katja Luther
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('locality'), $value->locality, '', 10);
1427 52f57468 Katja Luther
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('country'), $value->country);
1428 267da0d1 Katja Luther
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingMethod'), $value->collectingMethod);
1429
                        if (isset($value->absoluteElevation)) {
1430 2f4646e0 Andreas Kohlbecker
                            $min_max_markup = statistical_values_from_gathering_event($value, 'absoluteElevation');
1431 267da0d1 Katja Luther
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('absoluteElevation'), $min_max_markup);
1432
                        }
1433 276f39f6 Katja Luther
                        if (isset($value->distanceToGround) && $value->distanceToGround >0) {
1434 2f4646e0 Andreas Kohlbecker
                            $min_max_markup = statistical_values_from_gathering_event($value, 'distanceToGround');
1435 267da0d1 Katja Luther
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToGround'), $min_max_markup);
1436
                        }
1437 276f39f6 Katja Luther
                        if (isset($value->distanceToWaterSurface) && $value->distanceToWaterSurface > 0) {
1438 2f4646e0 Andreas Kohlbecker
                            $min_max_markup = statistical_values_from_gathering_event($value, 'distanceToWaterSurface');
1439 267da0d1 Katja Luther
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToWaterSurface'), $min_max_markup);
1440
                        }
1441
1442
                        if (isset($value->collectingAreas)) {
1443
                            $area_representations = array();
1444
                            foreach ($value->collectingAreas as $area) {
1445 52f57468 Katja Luther
                               // $area_representations[] = l($area->representation_L10n, path_to_named_area($area->uuid));
1446
                                $area_representations[] = $area;
1447 267da0d1 Katja Luther
                            }
1448
                            if (!empty($area_representations))
1449
                                @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingAreas'),
1450
                                    array(
1451
                                        array('#markup' => implode(', ', $area_representations))
1452
                                    )
1453
                                );
1454
                        }
1455 106e1cf9 Katja Luther
                        if (isset($value->exactLocation)  ) {
1456 267da0d1 Katja Luther
                            $sub_dl_groups = array();
1457
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('errorRadius'), $value->exactLocation->errorRadius, ' m', 1);
1458
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('longitude'), round($value->exactLocation->longitude, 7), '°', 2);
1459
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('latitude'), round($value->exactLocation->latitude, 7), '°', 3);
1460
                            if (isset($value->exactLocation->referenceSystem)) {
1461
                                @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('referenceSystem'), $value->exactLocation->referenceSystem->representation_L10n, '', 4);
1462
                            }
1463 106e1cf9 Katja Luther
                            if ( isSet($value->exactLocation->sexagesimalString)){
1464
                                @_description_list_group_add($groups, cdm_occurrence_field_name_label('exactLocation'),
1465 267da0d1 Katja Luther
                                    array(
1466 106e1cf9 Katja Luther
                                        array('#markup' => $value->exactLocation->sexagesimalString),
1467
                                        array(
1468
                                            '#theme' => 'description_list',
1469
                                            '#groups' => $sub_dl_groups
1470
                                        ),
1471 abe0b021 Katja Luther
                                    ), '', 11
1472 106e1cf9 Katja Luther
                                );
1473
                            }
1474 267da0d1 Katja Luther
                        }
1475
1476
                        break;
1477
1478
                    /* ---- DerivationEvent --- */
1479
                    case 'derivationEvents':
1480
                        //@_description_list_group_add($groups, t('Association type'), $value->description);
1481
                        break;
1482 72d57201 Katja Luther
                    case 'determinedNames':
1483
                        $dd_elements = array();
1484
                        foreach ($value as $name) {
1485
                            $taxon_name = cdm_ws_get(CDM_WS_NAME, $name->key);
1486
                            $taxon_name->taggedName = cdm_ws_get(CDM_WS_NAME, array($name->key, "taggedName"));
1487
                            $name_link = path_to_name($name->key);
1488
1489
                            //$taxon_html = render_taxon_or_name($taxon_name, $name_link);
1490 cea59762 Andreas Kohlbecker
                            $taxon_html = l($taxon_name->titleCache, $name_link);
1491 72d57201 Katja Luther
                            $dd_elements[] = $taxon_html;
1492
                        }
1493
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label("Identification(s)"), $dd_elements,'', 100);
1494
                        break;
1495 267da0d1 Katja Luther
1496
1497
                    default:
1498
                        if (is_object($value) || is_array($value)) {
1499 52f57468 Katja Luther
                            drupal_set_message("Unhandled type in compose_cdm_specimenOrObservation() for field " . $field, "warning");
1500 267da0d1 Katja Luther
                        } else {
1501 f60b52c4 Katja Luther
                            if ($field == 'recordBase' && $value == 'Dna Sample'){
1502
                                _description_list_group_add($groups, cdm_occurrence_field_name_label($field), 'DNA Sample');
1503
                            }else{
1504
                                _description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value);
1505
                            }
1506 267da0d1 Katja Luther
                        }
1507
                }
1508
            }
1509
        } // END of loop over $derivedUnitFacade fields
1510
1511
        // template_preprocess_description_list() is not worting by weight so we do it right here
1512
        uasort($groups, 'element_sort');
1513
        $occurrence_elements = array(
1514
           // '#title' => $title,
1515
            '#theme' => 'description_list',
1516
            '#groups' => $groups,
1517 58c1a035 Katja Luther
            '#attributes' => array('class' => html_class_attribute_ref($specimen_or_observation)),
1518 267da0d1 Katja Luther
        );
1519
        $output = drupal_render($occurrence_elements);
1520 106e1cf9 Katja Luther
        if (isset($gallery_html)){
1521
            $output .= $gallery_html;
1522
        }
1523 a2acff0a Katja Luther
        $pathToSpecimen = path_to_specimen($specimen_or_observation->uuid);
1524 cea59762 Andreas Kohlbecker
        $output .=  l("Detail page", $pathToSpecimen);
1525 267da0d1 Katja Luther
    } // END of $specimenOrObservation exists
1526
1527
    return $output;
1528
}
1529 1083804e Andreas Kohlbecker
1530 6eaec849 Katja Luther
function compose_table_of_blast_result(array $data){
1531 72d57201 Katja Luther
   // get icon images
1532
  $expand_icon = font_awesome_icon_markup(
1533
      'fa-plus-square-o',
1534
      array(
1535
          'alt' => 'Show details',
1536
          'class' => array('expand_icon')
1537
      )
1538
  );
1539
  $collapse_icon = font_awesome_icon_markup(
1540
      'fa-minus-square-o',
1541
      array(
1542
          'alt' => 'Show details',
1543
          'class' => array('collapse_icon')
1544
      )
1545
  );
1546
  //$detail_image_icon = '<img title="Detail Image" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/detail_image_derivate-16x16-32.png' . '"/>';
1547
    $rowcount = 0;
1548
    $rows = array();
1549 6eaec849 Katja Luther
1550
    foreach ($data as $row_data){
1551
        $pathToSpecimen = path_to_specimen_by_accession_number($row_data['id']);
1552 cea59762 Andreas Kohlbecker
        $specimenPageLink = l($row_data['id'], $pathToSpecimen);
1553
        $ncbiLink = l($row_data['id'], 'https://www.ncbi.nlm.nih.gov/nuccore/'.$row_data['id'].'?report=graph');
1554 6eaec849 Katja Luther
        $rows[] =  array(
1555
            'data' => array(
1556 72d57201 Katja Luther
                array(
1557
                    'data' => $expand_icon . $collapse_icon,
1558
                    'class' => array('summary_row_cell', 'summary_row_icon', 'expand_column')
1559
                ),
1560 6eaec849 Katja Luther
                array(
1561
                    'data' => $row_data['def'],
1562
                ),
1563
                array(
1564
                    'data' => $specimenPageLink,
1565
                ),
1566
                array(
1567
                    'data' => $row_data['hsp_align_length'],
1568
                ),
1569
                array(
1570 ce347d23 Katja Luther
                   'data' => $ncbiLink,
1571 72d57201 Katja Luther
                ),
1572
                array(
1573
                    'data' => $row_data['hsp_identity']/$row_data['hsp_align_length']*100,
1574 6eaec849 Katja Luther
                )
1575 72d57201 Katja Luther
            ),
1576
            'id' => 'blast_summary' . $rowcount, // summary row id
1577
            'class' => array('summary_row'),
1578
        );
1579
        $detail_html = "";
1580
1581
        $detail_html .= create_label("Details") . $row_data["hsp_align_length"] . "<br>";
1582
1583
1584
        $detail_html .= "<br>";
1585
        $detail_html .= $row_data["hsp_midline"];
1586
1587
        //$detail_html .= "<br>";
1588
1589
        $rows[] = array(
1590
            'data' => array(
1591
                array(
1592
                    'data' => "", //empty first column
1593
                    'class' => array('expand_column')
1594
                ),
1595
                array(
1596
                    'data' => $detail_html,
1597
                    'colspan' => 5,
1598
                ),
1599
            ),
1600
            'id' => 'blast_detail' . $rowcount,//details row ID
1601
            'class' => array('detail_row'),
1602 6eaec849 Katja Luther
        );
1603 72d57201 Katja Luther
        $rowcount++;
1604 6eaec849 Katja Luther
    }
1605 72d57201 Katja Luther
1606 6eaec849 Katja Luther
    $tableId = "blast_result_table";
1607
    $blast_result_table = array(
1608
        "#theme" => "table",
1609
        "#weight" => 2,
1610
        "#header" => array(
1611 72d57201 Katja Luther
            array(
1612
                'data' => "",
1613
                'class' => array('expand_column')
1614
            ),
1615 ce347d23 Katja Luther
                        "Name", "Accession Number", "Align Length", "NCBI", "% Identity"),
1616 6eaec849 Katja Luther
        "#rows" => $rows,
1617
        "#attributes" => array(
1618
            "id" => $tableId,
1619
            "border" => 2
1620
        )
1621
    );
1622
1623
    drupal_add_js_rowToggle("#".$tableId);
1624
1625 72d57201 Katja Luther
    $render_array[$tableId] = $blast_result_table;
1626 6eaec849 Katja Luther
    $out = drupal_render($render_array);
1627
   //$blast_result_page-> content = drupal_render($render_array);
1628
   return $out;
1629
}
1630
1631 ca7468b6 Andreas Kohlbecker
1632
/**
1633
 * Composes a BOTTOM-UP-SPECIMEN-TABLE
1634
 * @param $specimensOrObservations
1635
 * @return array
1636
 *  A drupal render array with the following keys:
1637
 *   - 'specimen_list'
1638
 *   - 'pager'
1639
 *
1640
 * @ingroup Compose
1641
 */
1642
function compose_specimens_table_bottom_up($specimensOrObservations)
1643
{
1644
1645
  // --- generate the specimen list as table
1646
  $specimen_table = array(
1647
    '#theme' => 'table',
1648
    '#weight' => 2,
1649
    // prefix attributes and rows with '#' to let it pass toF the theme function,
1650
    // otherwise it is handled as child render array
1651 09762fde Andreas Kohlbecker
    '#attributes' => array('class' => 'specimens '),
1652 ca7468b6 Andreas Kohlbecker
    '#rows' => array(),
1653
  );
1654
1655
  if ($specimensOrObservations) {
1656
1657
    foreach ($specimensOrObservations as $specimenOrObservation) {
1658
1659
      $mediaList = array();
1660
      if (is_array($specimenOrObservation->_fieldObjectMedia)) {
1661
        $mediaList = array_merge($mediaList, $specimenOrObservation->_fieldObjectMedia);
1662
      }
1663
      if (is_array($specimenOrObservation->_derivedUnitMedia)) {
1664
        $mediaList = array_merge($mediaList, $specimenOrObservation->_derivedUnitMedia);
1665
      }
1666
1667
1668
      // typelabel will contain the typeStatus
1669
      $type_label = '';
1670
      $typeDesignationPager = cdm_ws_get(CDM_WS_OCCURRENCE . '/$0/specimenTypeDesignations', $specimenOrObservation->uuid);
1671
      if (isset($typeDesignationPager) and isset($typeDesignationPager->records)) {
1672
        $type_status = array();
1673
        foreach ($typeDesignationPager->records as $typeDesignation) {
1674
          if (isset($typeDesignation->typeStatus->representation_L10n)) {
1675
            $type_status[] = $typeDesignation->typeStatus->representation_L10n;
1676
          }
1677
        }
1678
        $type_label = implode(', ', $type_status);
1679
        if ($type_label) {
1680
          $type_label .= ': ';
1681
        }
1682
      }
1683
1684
      // --- Specimen entry as dynamic label:
1685
      //     -> Dynabox for the specimenOrObservation
1686
      $gallery_name = $specimenOrObservation->uuid;
1687
1688 44458b04 Andreas Kohlbecker
      $derived_unit_ws_request = cdm_compose_ws_url(CDM_WS_OCCURRENCE, array($specimenOrObservation->uuid));
1689 ca7468b6 Andreas Kohlbecker
      // --- Render associated media.
1690
      $gallery_html = '';
1691
      if (count($mediaList) > 0) {
1692
        $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
1693
        $captionElements = array(
1694
          '#uri' => t('open media'),
1695
        );
1696
1697
        $gallery_html = compose_cdm_media_gallerie(array(
1698
          'mediaList' => $mediaList,
1699
          'galleryName' => $gallery_name,
1700
          'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
1701
          'cols' => $gallery_settings['cdm_dataportal_media_cols'],
1702
          'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
1703
          'captionElements' => $captionElements,
1704
          'mediaLinkType' => 'LIGHTBOX',
1705
          'alternativeMediaUri' => NULL,
1706
          'galleryLinkUri' => NULL,
1707
        ));
1708
      }
1709
      //here we should use the data we already have
1710
      $label_html = cdm_dynabox(
1711
        $specimenOrObservation->uuid,
1712
        $type_label . $specimenOrObservation->titleCache,
1713
        $derived_unit_ws_request,
1714
        'cdm_specimen_or_observation',
1715
        'Click for details',
1716
        array('div', 'div'),
1717
        array(),
1718
        null, // $content_element_selector
1719
        'function(){ jQuery(\'#media_gallery_' . $gallery_name . '\').hide(); }', // open_callback
1720
        'function(){ jQuery(\'#media_gallery_' . $gallery_name . '\').show(); }' // close_callback
1721
      );
1722
1723
      // --- Render associated media.
1724
      $gallery_html = '';
1725
      if (count($mediaList) > 0) {
1726
        $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
1727
        $captionElements = array(
1728
          '#uri' => t('open media'),
1729
        );
1730
1731
        $gallery_html = compose_cdm_media_gallerie(array(
1732
          'mediaList' => $mediaList,
1733
          'galleryName' => $gallery_name,
1734
          'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
1735
          'cols' => $gallery_settings['cdm_dataportal_media_cols'],
1736
          'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
1737
          'captionElements' => $captionElements,
1738
          'mediaLinkType' => 'LIGHTBOX',
1739
          'alternativeMediaUri' => NULL,
1740
          'galleryLinkUri' => NULL,
1741
        ));
1742
      }
1743
1744
      $specimen_table['#rows'][] = array(
1745
        // An array of table rows. Every row is an array of cells, or an associative array
1746
        'data' => array(
1747
          // Each cell can be either a string or an associative array
1748
          $label_html . $gallery_html
1749
        ),
1750
        'class' => array(
1751
          'descriptionElement',
1752
          'descriptionElement_IndividualsAssociation'
1753
        ),
1754
      );
1755
    }
1756
  }
1757
1758
  return $specimen_table;
1759
}
1760
1761 961319fe Andreas Kohlbecker
1762
/**
1763
 * Orders occurrences by date but types should be on top of the list.
1764
 *
1765
 * @param $specimensOrObservations_or_fieldUnitDTO
1766
 *
1767
 * @return array
1768
 */
1769
function order_specimens_or_observations_by_date_and_type($specimensOrObservations)
1770
{
1771
// order occurrences by date but types should be on top of the list
1772
  $type_specimens = array();
1773
  $other_occurrences = array();
1774
  foreach ($specimensOrObservations as &$occurrence) {
1775
    $typeDesignationsPager = cdm_ws_get(CDM_WS_OCCURRENCE . '/$0/specimenTypeDesignations', $occurrence->uuid);
1776
    if (isset($typeDesignationsPager->count) && $typeDesignationsPager->count > 0) {
1777
      $type_specimens[] = $occurrence;
1778
    } else {
1779
      $other_occurrences[] = $occurrence;
1780
    }
1781
  }
1782
  $specimensOrObservations = array_merge($type_specimens, $other_occurrences);
1783
  return $specimensOrObservations;
1784
}
1785
1786
/**
1787
 * Orders FieldUnitDTOs by date but types should be on top of the list.
1788
 *
1789
 * Delegates internally to order_specimens_or_observations_by_date_and_type()
1790
 *
1791
 * @param $fieldUnitDTOs
1792
 *
1793
 * @return array
1794
 */
1795
function order_fieldUnitDtos_by_date_and_type($fieldUnitDTOs)
1796
{
1797
  return order_specimens_or_observations_by_date_and_type($fieldUnitDTOs);
1798
}