Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

cdm-dataportal / modules / cdm_dataportal / includes / occurrences.inc @ a0f26798

History | View | Annotate | Download (46.7 KB)

1
<?php
2
/**
3
 * @file
4
 * Functions for dealing with CDM entities of type SpecimenOrOccurrences
5
 *
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
 */
18

    
19

    
20
/**
21
 * Provides the HTML markup for a specimen page
22
 *
23
 * @param $specimen
24
 *
25
 * @return string
26
 *  The markup for a specimen page
27
 */
28
function render_cdm_specimen_page($specimen, $is_specimen_page = false)
29
{
30
    $detail_html = "";
31
    //link to specimen page
32
    $pathToSpecimen = path_to_specimen($specimen->uuid);
33
    if (!$is_specimen_page) {
34
        $specimenPageLink = l($specimen->accessionNumber, $pathToSpecimen, array('attributes' => array('target' => '_blank')));
35
        $detail_html .= "<strong>Specimen page: $specimenPageLink</strong><br>";
36
    }
37

    
38

    
39
    if($is_specimen_page) {
40
        if($specimen->citation){
41
            $detail_html .= "<br>".$specimen->citation."<br>";
42

    
43
        }
44
    }
45
    if ($specimen->preferredStableUri) {
46
        $stableIdentifierLink = l($specimen->preferredStableUri, $specimen->preferredStableUri, array('attributes' => array('target' => '_blank')));
47
        $detail_html .= create_label("Preferred stable URI") . $stableIdentifierLink . "<br>";
48
    }
49
    if ($is_specimen_page) {
50
        // associated taxa
51
        if ($specimen->associatedTaxa) {
52
            $detail_html .= "<br>";
53
            $detail_html .= create_label("Associated with");
54
            if (sizeof($specimen->associatedTaxa) > 1) {
55
                $detail_html .= "<br>";
56
            }
57
            foreach ($specimen->associatedTaxa as $associatedTaxon) {
58
                $detail_html .= l($associatedTaxon->second, path_to_taxon($associatedTaxon->first, "specimens"));//$associatedTaxon->second."<br>";
59
            }
60
            $detail_html .= "<br>";
61
        }
62
    }
63
    // - type information
64
    $types = "";
65
    if (isset($specimen->types)) {
66
        //typed taxa
67
        foreach ($specimen->types as $typeStatus => $typedTaxa) {
68
            if($specimen->types){
69
                if(empty($typeStatus) || $typeStatus == "_empty_"|| $typeStatus == ""){
70
                    $detail_html .= "<i>no type status set:</i> ";
71
                } else {
72
                    $detail_html .= "<i>".$typeStatus."</i> of ";
73
                }
74
                foreach($typedTaxa as $typedTaxon){
75
                    $detail_html .= $typedTaxon." ";
76

    
77
                }
78
            } else {
79
                $types .= $typeStatus . " ";
80

    
81
            }
82
        }
83
    }
84
    $derivateDataDTO = $specimen->derivateDataDTO;
85
    // - specimen scans
86
    $specimenScans = create_html_links($derivateDataDTO->specimenScans, true);
87
    // - molecular data
88
    $molecularData = "";
89
    if ($derivateDataDTO->molecularDataList) {
90
        foreach ($derivateDataDTO->molecularDataList as $molecular) {
91
            //provider link
92
            if (isset($molecular->providerLink)) {
93
                $molecularData .= create_html_link($molecular->providerLink, true);
94
            } else {
95
                $molecularData .= "[no provider]";
96
            }
97
            //contig link
98
            if (isset($molecular->contigFiles)) {
99
                $molecularData .= "[";
100
                if (sizeof($molecular->contigFiles) > 0) {
101
                    foreach ($molecular->contigFiles as $contigFile) {
102
                        if (isset($contigFile->contigLink)) {
103
                            if (isset($contigFile->contigLink->uri) and $contigFile->contigLink->uri != null) {
104
                                $molecularData .= create_html_link($contigFile->contigLink, true) . " ";
105
                            }
106
                        } else {
107
                            $molecularData .= "no contig ";
108
                        }
109
                        //primer links
110
                        if (isset($contigFile->primerLinks)) {
111
                            $molecularData .= create_html_links($contigFile->primerLinks, true);
112
                        }
113
                    }
114
                }
115
                $molecularData = rtrim($molecularData, " ");
116
                $molecularData .= "]";
117
            }
118
            //FIXME separate with comma (remove trailing comma)
119
        }
120
    }
121
    // - detail images
122
    $detailImages = create_html_links($derivateDataDTO->detailImages, true);
123

    
124
    if ($types) {
125
        $detail_html .= $is_specimen_page ? "<br>" : "";
126
        $detail_html .= create_label("Type(s)") . $types . "<br>";
127
    }
128
    if ($specimenScans and !$is_specimen_page) {
129
        $detail_html .= create_label("Specimen Scans") . $specimenScans . "<br>";
130
    }
131
    //specimen scan image gallery
132
    if ($is_specimen_page and isset($derivateDataDTO->specimenScanUuids) and !empty($derivateDataDTO->specimenScanUuids)) {
133
        $detail_html .= addImageGallery("Specimen scans", $derivateDataDTO->specimenScanUuids);
134
    }
135

    
136
    if ($molecularData) {
137
        $detail_html .= $is_specimen_page ? "<br>" : "";
138
        $detail_html .= create_label("Molecular Data") . $molecularData . "<br>";
139
    }
140

    
141
    if ($detailImages and !$is_specimen_page) {
142
        $detail_html .= create_label("Detail Images") . $detailImages . "<br>";
143
    }
144

    
145
    //detail image gallery
146
    if ($is_specimen_page and isset($derivateDataDTO->detailImageUuids) and !empty($derivateDataDTO->detailImageUuids)) {
147
        $detail_html .= addImageGallery("Detail Images", $derivateDataDTO->detailImageUuids);
148
    }
149

    
150
    //character data
151
    if ($specimen->characterData) {
152
        $detail_html .= $is_specimen_page ? "<br>" : "";
153
        $detail_html .= create_label("Character Data");
154
        if ($is_specimen_page) {
155
            $detail_html .= "<br>";
156
            foreach ($specimen->characterData as $characterStatePair) {
157
                $detail_html .= "<i>" . $characterStatePair->first . "</i>:" . $characterStatePair->second;
158
                $detail_html .= "<br>";
159
            }
160
        } else {
161
            $detail_html .= l("detail page", $pathToSpecimen, array('attributes' => array('target' => '_blank')));
162
            $detail_html .= "<br>";
163
        }
164
    }
165
    return $detail_html;
166
}
167

    
168
function addImageGallery($galleryName, $imageUuids)
169
{
170
    $images = array();
171
    foreach ($imageUuids as $uuid) {
172
        $images[] = cdm_ws_get(CDM_WS_PORTAL_MEDIA, $uuid);
173
    }
174

    
175
    $gallery_html = '';
176
    if (count($imageUuids) > 0) {
177
        $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
178
        $captionElements = array(
179
            'title',
180
            'rights',
181
        );
182
        $alternativeMediaUris = array();
183
        foreach ($images as $image) {
184
            $mediaUri = getMediaUri($image);
185
            if ($mediaUri) {
186
                $alternativeMediaUris[] = $mediaUri;
187
            } else {
188
                $alternativeMediaUris[] = path_to_media($image->uuid);
189
            }
190
        }
191

    
192
        $gallery_html = compose_cdm_media_gallerie(array(
193
            'mediaList' => $images,
194
            'galleryName' => $galleryName,
195
            'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
196
            'cols' => $gallery_settings['cdm_dataportal_media_cols'],
197
            'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
198
            'captionElements' => $captionElements,
199
            'mediaLinkType' => 'LIGHTBOX',
200
            'alternativeMediaUri' => $alternativeMediaUris,
201
            'galleryLinkUri' => NULL,
202
        ));
203
    }
204
    return "<br>" . create_label($galleryName) . "<br>" . $gallery_html;
205
}
206

    
207
function getMediaUri($media)
208
{
209
    if (isset($media->representations) && sizeof($media->representations) == 1
210
        && isset($media->representations[0]->parts) &&
211
        sizeof($media->representations[0]->parts) == 1) {
212
        return $media->representations[0]->parts[0]->uri;
213
    }
214
    return null;
215
}
216

    
217

    
218
/**
219
 * Formats the given string to a label for displaying key-object pairs in HTML
220
 * @return string
221
 */
222
function create_label($label)
223
{
224
    return "<span class='specimen_table_label'>" . $label . ": </span>";
225
}
226

    
227
/**
228
 * Compose an render array from a CDM DerivedUnitFacade object.
229
 *
230
 * compose_hook() implementation
231
 *
232
 * @param object $specimenOrObservation
233
 *   the CDM instance of type SpecimenOrObservation to compose
234
 *   the render array for
235
 * @param array $derivatives
236
 *   the render array which contains the compositions of the derivatives
237
 *   of the supplied $specimenOrObservation
238
 *
239
 * @return array
240
 *   the supplied render array $derivatives to which the composition of the supplied
241
 *   $specimenOrObservation has been added to
242
 *
243
 * @ingroup compose
244
 */
245

    
246
function compose_cdm_specimen_or_observation($specimenOrObservation, &$derivatives = null)
247
{
248
    $exclude_occurrence_fields = &drupal_static(__FUNCTION__);
249
    if (!isset($exclude_occurrence_fields)) {
250
        $exclude_occurrence_fields = array(
251
            'derivationEvents',
252
            'titleCache',
253
            'protectedTitleCache',
254
            'derivedUnitMedia',
255
            'created',
256
            'publish',
257
            'updated',
258
            'class',
259
            'uuid',
260
            ''
261
        );
262
    }
263

    
264

    
265
    // only show uuid it the user is logged in
266
    if(user_is_logged_in() && ($a_idx = array_search('uuid', $exclude_occurrence_fields)) !== FALSE ) {
267
        unset($exclude_occurrence_fields[$a_idx]);
268
    }
269

    
270
    if (!isset($derivatives)) {
271
        $derivatives = array();
272
    }
273

    
274
    $descriptions = null;
275
    $derivedFrom = null;
276

    
277
    if (is_object($specimenOrObservation)) {
278

    
279
        // request again for deeper initialization
280
        $specimenOrObservation = cdm_ws_get("portal/" . CDM_WS_OCCURRENCE, $specimenOrObservation->uuid);
281

    
282

    
283
        $type_label = $specimenOrObservation->class;
284
        RenderHints::setFootnoteListKey($type_label . '-' . $specimenOrObservation->uuid);
285

    
286
        // collect typeStatus as label
287
        if (isset($specimenOrObservation->specimenTypeDesignations)) {
288
            $type_status = array();
289
            foreach ($specimenOrObservation->specimenTypeDesignations as $typeDesignation) {
290
                if (isset($typeDesignation->typeStatus->representation_L10n)) {
291
                    $type_status[] = $typeDesignation->typeStatus->representation_L10n;
292
                }
293
            }
294
            if (count($type_status) > 0) {
295
                $type_label = implode(', ', $type_status);
296
            }
297
        }
298

    
299
        $title = $type_label . ': ' . $specimenOrObservation->titleCache;
300

    
301
        $groups = array();
302
        // --- add initialized fields
303
        foreach (get_object_vars($specimenOrObservation) as $field => $value) {
304
            if (!in_array($field, $exclude_occurrence_fields) && ($value && (!is_object($value) || isset($value->class)))) {
305
                switch ($field) {
306

    
307
                    /* ---- java.lang.Object --- */
308
                    case 'class':
309
                        if ($value != '' /* FieldUnit' */) {
310
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value);
311
                        }
312
                        break;
313

    
314
                    case 'markers':
315
                        $dd_elements = array();
316
                        foreach ($value as $marker) {
317
                            $dd_elements[] = compose_cdm_marker($marker);
318
                        }
319
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
320
                        break;
321

    
322

    
323
                    case 'annotations':
324
                        $dd_elements = array();
325
                        foreach ($value as $annotation) {
326
                            // TODO respect annotation type filter settings
327
                            $dd_elements[] = $annotation->text;
328
                        }
329
                        @_description_list_group_add($groups, t('Notes'), $dd_elements);
330
                        break;
331

    
332
                    /* ---- SpecimenOrObservationBase --- */
333
                    case 'sex':
334
                    case 'lifeStage':
335
                    case 'kindOfUnit':
336
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value->representation_L10n);
337
                        break;
338

    
339
                    case 'definition':
340
                        // TODO
341
                        break;
342

    
343
                    case 'preferredStableUri':
344

    
345
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), array(array('#markup' => cdm_external_uri($value, false))));
346
                        break;
347

    
348
                    case 'specimenTypeDesignations':
349
                        @_description_list_group_add(
350
                            $groups,
351
                            cdm_occurrence_field_name_label($field),
352
                            array(
353
                                '#markup' => theme('cdm_typedesignations', array('typeDesignations' => $value)),
354
                            )
355
                        );
356
                        break;
357

    
358
                    case 'determinations':
359
                        $dd_elements = array();
360
                        $glue = ', ';
361

    
362
                        foreach ($value as $determinationEvent) {
363
                            $timeperiod_string = NULL;
364
                            if (isset($determinationEvent->timeperiod)) {
365
                                $timeperiod_string = timePeriodToString($determinationEvent->timeperiod);
366
                            }
367
                            $weight = isset($determinationEvent->preferred) && $determinationEvent->preferred == 1 ? '0' : ($timeperiod_string ? $timeperiod_string : '1');
368
                            // check key exists
369
                            while (array_key_exists($weight, $dd_elements)) {
370
                                $weight .= '0';
371
                            }
372

    
373
                            $taxon_name = '';
374
                            $name_link = '';
375
                            if ($determinationEvent->taxonName) {
376
                                $taxon_name = $determinationEvent->taxonName;
377
                            } else if ($determinationEvent->taxon) {
378
                                $taxon_name = cdm_ws_get(CDM_WS_TAXON . '/$0/name', $determinationEvent->taxon->uuid);
379
                                $name_link = path_to_taxon($determinationEvent->taxon->uuid);
380
                            }
381
                            if ($taxon_name) {
382
                                $taxon_html = render_taxon_or_name($taxon_name, $name_link);
383
                                $dd_elements[$weight] = $taxon_html;
384
                            }
385
                            if (isset($determinationEvent->modifier)) {
386
                                $dd_elements[$weight] .= cdm_term_representation($determinationEvent->modifier);
387
                            }
388
                            if ($timeperiod_string) {
389
                                $dd_elements[$weight] .= $glue . $timeperiod_string;
390
                            }
391
                            if (isset($determinationEvent->actor->titleCache)) {
392
                                $dd_elements[$weight] .= $glue . $determinationEvent->actor->titleCache;
393
                            }
394
                            if (isset($determinationEvent->description)) {
395
                                $dd_elements[$weight] .= $glue . $determinationEvent->description;
396
                            }
397
                        }
398
                        ksort($dd_elements);
399
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('determinations'), $dd_elements);
400
                        break;
401

    
402
                    case 'descriptions':
403
                        $occurrence_featureTree = cdm_get_occurrence_featureTree();
404
                        $dd_elements = array();
405

    
406
                        foreach ($value as $description) {
407
                            $description = cdm_ws_get(CDM_WS_PORTAL_DESCRIPTION, $description->uuid);
408
//               if($description->imageGallery == TRUE) {
409
//                 continue;
410
//               }
411
                            $elements_by_feature = _mergeFeatureTreeDescriptions($occurrence_featureTree->root->childNodes, $description->elements);
412
                            $description_render_elements = _block_get_renderable_array(make_feature_block_list($elements_by_feature, null));
413
                            $dd_elements[] = $description_render_elements;
414
                        }
415

    
416
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
417
                        break;
418

    
419
                    case 'sources':
420
                        $dd_elements = array();
421
                        foreach ($value as $identifiable_source) {
422
                            $dd_elements[] = theme('cdm_OriginalSource', array('source' => $identifiable_source));
423
                        }
424
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
425
                        break;
426

    
427

    
428
                    /* ---- DerivedUnitBase --- */
429
                    case 'derivedFrom':
430
                        $derivedFrom = $value;
431
                        break;
432

    
433
                    case 'collection':
434
                        $sub_dl_groups = array();
435
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('code'), $value->code, NULL, 1);
436
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('codeStandard'), $value->codeStandard, NULL, 2);
437
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('institute'), $value->institute, NULL, 3);
438
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('townOrLocation'), $value->townOrLocation, NULL, 4);
439
                        // TODO "superCollection"
440
                        // TODO may have media
441

    
442
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),
443
                            array(
444
                                array('#markup' => $value->titleCache),
445
                                array('#theme' => 'description_list', '#groups' => $sub_dl_groups)
446
                            )
447
                        );
448
                        break;
449

    
450
                    case 'storedUnder':
451
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('storedUnder'), render_taxon_or_name($value));
452
                        break;
453

    
454

    
455
                    /* ---- Specimen --- */
456
                    case 'sequences':
457
                        $dd_elements = array();
458
                        foreach ($value as $sequence) {
459
                            $dd_elements[] = compose_cdm_sequence($sequence);
460
                        }
461
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
462
                        break;
463

    
464
                    // TODO preservation
465
                    // TODO exsiccatum
466

    
467

    
468
                    /* ---- FieldObservation --- */
469
                    case 'gatheringEvent':
470
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collector'), $value->actor->titleCache);
471
                        @_description_list_group_add($groups, t('Gathering time'), timePeriodToString($value->timeperiod));
472
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('description'), $value->description);
473
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('locality'), $value->locality->text);
474
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('country'), $value->country->representation_L10n);
475
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingMethod'), $value->collectingMethod);
476
                        if (isset($value->absoluteElevation)) {
477
                            $min_max_markup = min_max_measure($value, 'absoluteElevation');
478
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('absoluteElevation'), $min_max_markup);
479
                        }
480
                        if (isset($value->distanceToGround)) {
481
                            $min_max_markup = min_max_measure($value, 'distanceToGround');
482
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToGround'), $min_max_markup);
483
                        }
484
                        if (isset($value->distanceToWaterSurface)) {
485
                            $min_max_markup = min_max_measure($value, 'distanceToWaterSurface');
486
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToWaterSurface'), $min_max_markup);
487
                        }
488

    
489
            if (isset($value->collectingAreas) && count($value->collectingAreas) > 0) {
490
                            $area_representations = array();
491
                            foreach ($value->collectingAreas as $area) {
492
                                $area_representations[] = l($area->representation_L10n, path_to_named_area($area->uuid));
493
                            }
494
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingAreas'),
495
                                array(
496
                                    array('#markup' => implode(', ', $area_representations))
497
                                )
498
                            );
499
                        }
500
                        if (isset($value->exactLocation) && $value->exactLocation->sexagesimalString) {
501
                            $sub_dl_groups = array();
502
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('errorRadius'), $value->exactLocation->errorRadius, ' m', 1);
503
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('longitude'), round($value->exactLocation->longitude, 7), '°', 2);
504
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('latitude'), round($value->exactLocation->latitude, 7), '°', 3);
505
                            if (isset($value->exactLocation->referenceSystem)) {
506
                                @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('referenceSystem'), $value->exactLocation->referenceSystem->representation_L10n, '', 4);
507
                            }
508

    
509
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('exactLocation'),
510
                                array(
511
                                    array('#markup' => $value->exactLocation->sexagesimalString),
512
                                    array(
513
                                        '#theme' => 'description_list',
514
                                        '#groups' => $sub_dl_groups
515
                                    ),
516
                                )
517
                            );
518
                        }
519
                        break;
520

    
521
                    default:
522
                        if (is_object($value) || is_array($value)) {
523
                            drupal_set_message("Unhandled type in compose_cdm_specimen_or_observation() for field " . $field, "warning");
524
                        } else {
525
                            _description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value);
526
                        }
527

    
528
                }
529

    
530
            }
531
        } // END of loop over $derivedUnitFacade fields
532

    
533
        // Extensions
534
        $extensions = cdm_ws_fetch_all(CDM_WS_PORTAL_OCCURRENCE . '/'  . $specimenOrObservation->uuid . '/extensions', array($specimenOrObservation->uuid));
535
        if ($extensions && count($extensions)) {
536

    
537
            $extensions_render_array = compose_extensions($extensions);
538
            @_description_list_group_add($groups, t('Extensions') . ':',
539
                $extensions_render_array,
540
                '', 100);
541
        }
542

    
543

    
544
        // template_preprocess_description_list() is not worting by weight so we do it right here
545
        uasort($groups, 'element_sort');
546

    
547
        $occurrence_elements = array(
548
            '#title' => $title,
549
            '#theme' => 'description_list',
550
            '#groups' => $groups,
551
            '#attributes' => array('class' => html_class_attribute_ref($specimenOrObservation)),
552
        );
553
        $derivatives[] = $occurrence_elements;
554
        // all footnotes which has been assembled so far (e.g. from typeDesignations) to here
555
        $foonote_li_elements = theme('cdm_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey(), 'enclosingTag' => 'span'));
556
        if (!empty($foonote_li_elements)) {
557
            $derivatives[] =  array(
558
                '#markup' =>  '<div class="footnotes">' . $foonote_li_elements . '</div>',
559
            );
560
        }
561

    
562
        // --- recurse into originals
563
        if (!isset($derivedFrom)) {
564
            $derivedFrom = cdm_ws_get(
565
                CDM_WS_OCCURRENCE,
566
                array($specimenOrObservation->uuid, 'derivedFrom')
567
            );
568
        }
569

    
570
        if (isset($derivedFrom)) {
571
            if (isset($derivedFrom->originals)) {
572
                $derived_from_label = t('derived');
573
                $preposition = t('from');
574
                if(isset($derivedFrom->type)){
575
                    $derived_from_label = $derivedFrom->type->representation_L10n;
576
                    if($derivedFrom->type->uuid == UUID_DERIVATIONEVENTTYPE_ACCESSIONING){
577
                        $preposition = t('of');
578
                    }
579
                }
580
                if (count($groups) > 0) {
581
                    // TODO  annotations
582

    
583
                    // only display the derived from information when the derivative has any element which will be diplayed
584
                    $derivatives[] = array(
585
                        '#markup' => '<div class="derived_from">' . $derived_from_label . ' ' . $preposition . ': </div>',
586
                    );
587
                }
588
                foreach ($derivedFrom->originals as $original) {
589
                    compose_cdm_specimen_or_observation($original, $derivatives);
590
                }
591
            }
592
        }
593

    
594
    } // END of $specimenOrObservation exists
595

    
596
    return $derivatives;
597
}
598

    
599

    
600
/**
601
 * Compose an render array from a CDM Sequence object.
602
 *
603
 * compose_hook() implementation
604
 *
605
 * @param object $sequence
606
 *   CDM instance of type Sequence
607
 * @return array
608
 *   A render array containing the fields of the supplied $sequence
609
 *
610
 * @ingroup compose
611
 */
612
function compose_cdm_sequence($sequence, $isSpecimenPage = false)
613
{
614

    
615
    $exclude_sequence_fields = &drupal_static(__FUNCTION__);
616
    if (!isset($exclude_sequence_fields)) {
617
        $exclude_sequence_fields = array(
618
            'titleCache',
619
            'protectedTitleCache',
620
            'microReference',
621
            'created',
622
            'updated',
623
            'class',
624
            'dnaMarker'
625
        );
626
    }
627

    
628
    $groups = array();
629

    
630
    // -- retrieve additional data if neesscary
631
    // TODO below call disabled since sequences are not yet supported,
632
    //      see  #3347 (services and REST service controller for molecular classes implemented)
633
    //
634
    // cdm_load_annotations($sequence);
635

    
636
    foreach (get_object_vars($sequence) as $field => $value) {
637

    
638

    
639
        if (!in_array($field, $exclude_sequence_fields) && ($value && (!is_object($value) || isset($value->class)))) {
640
            switch ($field) {
641

    
642
                case 'geneticAccessionNumber';
643

    
644
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 2);
645
                    break;
646

    
647

    
648
                /*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.
649
                    /*if (isset($value->name)) {
650
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value->name, NULL, 3);
651
                    }
652
                    if (isset($value->description)) {
653
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field) . ' ' . t('description'), $value->description, NULL, 4);
654
                    }
655
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field) , $value, NULL, 4);
656
                    break;
657
                */
658
                case 'consensusSequence':
659
                    // format in genbank style, force linebreaks after each 70 nucleotites
660
                    // see also http://stackoverflow.com/questions/499137/css-how-can-i-force-a-long-string-without-any-blank-to-be-wrapped-in-xul-and
661
                    if ($value->length > 0) {
662
                        @_description_list_group_add(
663
                            $groups,
664
                            cdm_occurrence_field_name_label($field),
665
                            array(
666
                                array(
667
                                    '#markup' => '<div class="sequence-length">' . $value->length . ' ' . t('pb') . '</div><div>' . wordwrap($value->string, 70, '</br>', TRUE) . '</div>',
668
                                    '#wrapper_attributes' => array('class' => 'dna-sequence')
669
                                )
670
                            ),
671
                            5);
672
                    }
673
                    break;
674

    
675
                case 'dnaSample': // FIXME 3.3 implement
676
                    break;
677
                case 'singleReads': // FIXME 3.3 implement
678
                    break;
679
                case 'contigFile': // FIXME 3.3 implement - Media
680
                    break;
681
                case 'pherograms': // FIXME 3.3 implement - Media
682
                    break;
683
                case 'haplotype': // FIXME 3.3 implement
684
                    break;
685
                case 'dateSequenced': // FIXME 3.3 now in SingelRead
686
                    @_description_list_group_add($groups, t('Sequencing date'), timePeriodToString($value), NULL, 6);
687
                    break;
688

    
689
                case 'barcode': // boolean
690
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value ? 'Yes' : 'No', NULL, 7);
691
                    break;
692
                case 'barcodeSequencePart': // FIXME 3.3 implement, compose sequence
693
                    break;
694

    
695
                case 'citation':
696
                    @_description_list_group_add($groups,
697
                        cdm_occurrence_field_name_label($field),
698
                        theme('cdm_reference', array('reference' => $value, 'microReference' => $sequence->microReference)),
699
                        NULL,
700
                        8
701
                    );
702
                    break;
703

    
704
                case 'publishedIn':
705
                    @_description_list_group_add($groups,
706
                        cdm_occurrence_field_name_label($field),
707
                        theme('cdm_reference', array('reference' => $value)),
708
                        NULL,
709
                        7
710
                    );
711
                    break;
712

    
713
                case 'rights':
714
                    array_merge($groups, cdm_rights_as_dl_groups($value));
715
                    break;
716

    
717
                case 'annotations':
718
                    $dd_elements = array();
719
                    foreach ($value as $annotation) {
720
                        // TODO respect annotation type filter settings
721
                        $dd_elements[] = $annotation->text;
722
                    }
723
                    @_description_list_group_add($groups, t('Notes'), $dd_elements, NULL, 9);
724
                    break;
725

    
726
                case 'markers':
727
                    $dd_elements = array();
728
                    foreach ($value as $marker) {
729
                        $dd_elements[] = compose_cdm_marker($marker);
730
                    }
731
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements, NULL, 10);
732
                    break;
733

    
734
                case 'chromatograms':
735
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),
736
                        array(
737
                            '#markup' => compose_cdm_media_gallerie(array('medialist' => $value)),
738
                        ),
739
                        NULL,
740
                        11);
741
                    break;
742

    
743
                default:
744
                    if (is_object($value) || is_array($value)) {
745
                        drupal_set_message("Unhandled type in compose_cdm_sequence() for field " . $field, "warning");
746
                    } else {
747
                        _description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 20);
748
                    }
749
            }
750
        }
751
    }
752

    
753
    // template_preprocess_description_list() is not worting by weight so we do it right here
754
    uasort($groups, 'element_sort');
755
    if ($isSpecimenPage) {
756
        $sequence_elements = array(
757
            '#title' => $sequence->dnaMarker,
758
            '#theme' => 'description_list',
759
            '#groups' => $groups
760
        );
761
    } else{
762
        $sequence_elements = array(
763
            '#title' => $sequence->dnaMarker -> titleCache,
764
            '#theme' => 'description_list',
765
            '#groups' => $groups
766
        );
767
    }
768

    
769
    return $sequence_elements;
770
}
771
/**
772
 * Creates an array from a list of FieldUnitDTOs.
773
 *
774
 *
775
 * @param object $specimenOrObservations
776
 *   list of FieldUnitDTOs
777
 * @return array
778
 *   An array containing the hierarchy of the field units corresponding to the taxon
779
 *
780
 * @ingroup compose
781
 */
782
function compose_specimen_array(array $specimenOrObservations){
783
    $items_specimen = array();
784
    $items = array();
785

    
786
    //we need one more item to contain the items of one level (fieldunit, derivate data etc.)
787
    foreach ($specimenOrObservations as &$specimenOrObservation) {
788

    
789
        $items['data'] = $specimenOrObservation->listLabel ;
790
        $specimen = compose_cdm_specimen_or_observation_tree_entry($specimenOrObservation);
791
        $children = array();
792
        $child = array();
793
        $child['data'] =$specimen;
794
       // $children[] = create_specimen_array($specimenOrObservation->derivates);
795
       if (isset($specimenOrObservation->derivates) && sizeof($specimenOrObservation->derivates) > 0){
796
           $child['children']= compose_specimen_array($specimenOrObservation->derivates);
797
       }
798
       $children[]=$child;
799
       $items['children'] = $children;
800
       $items_specimen[] = $items;
801
    }
802
    return $items_specimen;
803
}
804

    
805

    
806
/**
807
 * Compose an render array from a CDM DerivedUnitFacade object.
808
 *
809
 * compose_hook() implementation
810
 *
811
 * @param object $specimenOrObservation
812
 *   the CDM instance of type SpecimenOrObservation to compose
813
 *   the render array for
814
 * @param array $derivatives
815
 *   the render array which contains the compositions of the derivatives
816
 *   of the supplied $specimenOrObservation
817
 *
818
 * @return array
819
 *   the supplied render array $derivatives to which the composition of the supplied
820
 *   $specimenOrObservation has been added to
821
 *
822
 * @ingroup compose
823
 */
824

    
825
function compose_cdm_specimen_or_observation_tree_entry($specimenOrObservation)
826
{
827
    $exclude_occurrence_fields = &drupal_static(__FUNCTION__);
828
    if (!isset($exclude_occurrence_fields)) {
829
        $exclude_occurrence_fields = array(
830
            'type',
831
            'derivationEvent',
832
            'taxonRelatedDerivedUnits',
833
            'label',
834
            'titleCache',
835
            'listLabel',
836
            'protectedTitleCache',
837
            'class',
838
            'uuid',
839
            'collectionDTO',
840
            'derivates'
841
        );
842
    }
843
    $items = array();
844

    
845
    // only show uuid it the user is logged in
846
    if (user_is_logged_in() && ($a_idx = array_search('uuid', $exclude_occurrence_fields)) !== FALSE) {
847
      //  unset($exclude_occurrence_fields[$a_idx]);
848
    }
849

    
850

    
851
    if (is_object($specimenOrObservation)) {
852

    
853
        $type_label = $specimenOrObservation->recordBase;
854
        RenderHints::setFootnoteListKey($type_label . '-' . $specimenOrObservation->uuid);
855

    
856
        // collect typeStatus as label
857
        if (isset($specimenOrObservation->specimenTypeDesignations)) {
858
            $type_status = array();
859
            foreach ($specimenOrObservation->specimenTypeDesignations as $typeDesignation) {
860
                if (isset($typeDesignation->typeStatus->representation_L10n)) {
861
                    $type_status[] = $typeDesignation->typeStatus->representation_L10n;
862
                }
863
            }
864
            if (count($type_status) > 0) {
865
                $type_label = implode(', ', $type_status);
866
            }
867
        }
868

    
869
        $title = $type_label . ': ' . $specimenOrObservation->titleCache;
870
        $items['data'] = $title;
871

    
872
        $groups = array();
873
        $items['children'] = $groups;
874
        $children_items = array();
875
        // --- add initialized fields
876
        foreach (get_object_vars($specimenOrObservation) as $field => $value) {
877
            $child_item = array();
878

    
879
            if (!in_array($field, $exclude_occurrence_fields) && ($value && (!is_object($value) || isset($value->class)))) {
880
                switch ($field) {
881

    
882
                    /* ---- SpecimenOrObservationBase --- */
883

    
884
                    case 'kindOfUnit':
885
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 1);
886
                        break;
887

    
888

    
889
                    case 'preferredStableUri':
890

    
891
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), array(array('#markup' => cdm_external_uri($value, false))));
892
                        break;
893

    
894
                    case 'specimenTypeDesignations':
895
                      /*     $groups,
896
                            cdm_occurrence_field_name_label($field),
897
                            array(
898
                                '#markup' => theme('cdm_typedesignations', array('typeDesignations' => $value)),
899
                            )
900
                        );
901
                      */
902
                        break;
903

    
904

    
905
                    case 'listOfMedia':
906
                        $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
907
                        $captionElements = array(
908
                            '#uri' => t('open media'),
909
                        );
910
                        $gallery_html = compose_cdm_media_gallerie(array(
911
                            'mediaList' => $value,
912
                            'galleryName' => $specimenOrObservation->label,
913
                            'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
914
                            'cols' => $gallery_settings['cdm_dataportal_media_cols'],
915
                            'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
916
                            'captionElements' => $captionElements,
917
                            'mediaLinkType' => 'LIGHTBOX',
918
                            'alternativeMediaUri' => NULL,
919
                            'galleryLinkUri' => NULL,
920
                        ));
921

    
922
                         //@_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $gallery_html);
923
                         break;
924

    
925

    
926

    
927
                    /* ---- DerivedUnitBase --- */
928

    
929

    
930
                    case 'collection':
931

    
932
                        $sub_dl_groups = array();
933
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('code'), $value->code, NULL, 1);
934
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('codeStandard'), $value->codeStandard, NULL, 2);
935
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('institute'), $value->institute, NULL, 3);
936
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('townOrLocation'), $value->townOrLocation, NULL, 4);
937
                        // TODO "superCollection"
938
                        // TODO may have media
939

    
940
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),
941
                            array(
942
                                array('#markup' => $value->titleCache),
943
                                array('#theme' => 'description_list', '#groups' => $sub_dl_groups)
944
                            )
945
                        );
946

    
947
                        break;
948

    
949

    
950

    
951

    
952
                    /* ---- Specimen --- */
953
                    case 'sequences':
954
                        $dd_elements = array();
955
                        foreach ($value as $sequence) {
956
                            $dd_elements[] = compose_cdm_sequence($sequence, true);
957
                            $dd_elements[] = "";
958
                        }
959
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements,'', 100);
960
                        break;
961

    
962
                    // TODO preservation
963
                    // TODO exsiccatum
964

    
965

    
966
                    /* ---- FieldObservation --- */
967
                    case 'gatheringEvent':
968

    
969
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collector'), $value->collector);
970
                        @_description_list_group_add($groups, t('Gathering time'), timePeriodToString($value->timeperiod));
971
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('description'), $value->description);
972
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('locality'), $value->locality);
973
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('country'), $value->country);
974
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingMethod'), $value->collectingMethod);
975
                        if (isset($value->absoluteElevation)) {
976
                            $min_max_markup = min_max_measure($value, 'absoluteElevation');
977
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('absoluteElevation'), $min_max_markup);
978
                        }
979
                        if (isset($value->distanceToGround) && $value->distanceToGround >0) {
980
                            $min_max_markup = min_max_measure($value, 'distanceToGround');
981
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToGround'), $min_max_markup);
982
                        }
983
                        if (isset($value->distanceToWaterSurface) && $value->distanceToWaterSurface > 0) {
984
                            $min_max_markup = min_max_measure($value, 'distanceToWaterSurface');
985
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToWaterSurface'), $min_max_markup);
986
                        }
987

    
988
                        if (isset($value->collectingAreas)) {
989
                            $area_representations = array();
990
                            foreach ($value->collectingAreas as $area) {
991
                               // $area_representations[] = l($area->representation_L10n, path_to_named_area($area->uuid));
992
                                $area_representations[] = $area;
993
                            }
994
                            if (!empty($area_representations))
995
                                @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingAreas'),
996
                                    array(
997
                                        array('#markup' => implode(', ', $area_representations))
998
                                    )
999
                                );
1000
                        }
1001
                        if (isset($value->exactLocation)  ) {
1002
                            $sub_dl_groups = array();
1003
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('errorRadius'), $value->exactLocation->errorRadius, ' m', 1);
1004
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('longitude'), round($value->exactLocation->longitude, 7), '°', 2);
1005
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('latitude'), round($value->exactLocation->latitude, 7), '°', 3);
1006
                            if (isset($value->exactLocation->referenceSystem)) {
1007
                                @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('referenceSystem'), $value->exactLocation->referenceSystem->representation_L10n, '', 4);
1008
                            }
1009
                            if ( isSet($value->exactLocation->sexagesimalString)){
1010
                                @_description_list_group_add($groups, cdm_occurrence_field_name_label('exactLocation'),
1011
                                    array(
1012
                                        array('#markup' => $value->exactLocation->sexagesimalString),
1013
                                        array(
1014
                                            '#theme' => 'description_list',
1015
                                            '#groups' => $sub_dl_groups
1016
                                        ),
1017
                                    )
1018
                                );
1019
                            }
1020
                        }
1021

    
1022
                        break;
1023

    
1024
                    /* ---- DerivationEvent --- */
1025
                    case 'derivationEvents':
1026
                        //@_description_list_group_add($groups, t('Association type'), $value->description);
1027
                        break;
1028

    
1029

    
1030
                    default:
1031
                        if (is_object($value) || is_array($value)) {
1032
                            drupal_set_message("Unhandled type in compose_cdm_specimenOrObservation() for field " . $field, "warning");
1033
                        } else {
1034
                            _description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value);
1035
                        }
1036

    
1037
                }
1038

    
1039

    
1040
            }
1041
        } // END of loop over $derivedUnitFacade fields
1042

    
1043

    
1044

    
1045
        // template_preprocess_description_list() is not worting by weight so we do it right here
1046
        uasort($groups, 'element_sort');
1047

    
1048
        $occurrence_elements = array(
1049
           // '#title' => $title,
1050
            '#theme' => 'description_list',
1051
            '#groups' => $groups,
1052
            '#attributes' => array('class' => html_class_attribute_ref($specimenOrObservation)),
1053
        );
1054
        $output = drupal_render($occurrence_elements);
1055
        if (isset($gallery_html)){
1056
            $output .= $gallery_html;
1057
        }
1058
        if (!($specimenOrObservation->type == 'FieldUnit')){
1059
            $pathToSpecimen = path_to_specimen($specimenOrObservation->uuid);
1060
            $output .=  l("detail page", $pathToSpecimen, array('attributes' => array('target' => '_blank')));
1061
        }
1062

    
1063

    
1064

    
1065

    
1066

    
1067

    
1068

    
1069

    
1070

    
1071

    
1072
    } // END of $specimenOrObservation exists
1073

    
1074
    return $output;
1075
}
1076

    
Add picture from clipboard (Maximum size: 40 MB)