Project

General

Profile

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