Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

cdm-dataportal / modules / cdm_dataportal / includes / occurrences.inc @ 8e15d0fb

History | View | Annotate | Download (47.1 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 summary: $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>Type for:</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
                        if (!is_array($value) && strpos($value, 'http:') !== false ){
748
                            //make links for urls
749
                            $value = l($value, $value, array('attributes' => array('target' => '_blank')));
750
                            $value = markup_to_render_array($value);
751
                        }
752

    
753
                       _description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 20);
754
                    }
755
            }
756
        }
757
    }
758

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

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

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

    
795
        $items['data'] = $specimenOrObservation->listLabel ;
796
        $specimen = compose_cdm_specimen_or_observation_tree_entry($specimenOrObservation);
797
        $children = array();
798
        $child = array();
799
        $child['data'] =$specimen;
800
       // $children[] = create_specimen_array($specimenOrObservation->derivates);
801
       if (isset($specimenOrObservation->derivates) && sizeof($specimenOrObservation->derivates) > 0){
802
           $child['children']= compose_specimen_array($specimenOrObservation->derivates);
803
       }
804
       $children[]=$child;
805
       $items['children'] = $children;
806
       $items_specimen[] = $items;
807
    }
808
    return $items_specimen;
809
}
810

    
811

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

    
831
function compose_cdm_specimen_or_observation_tree_entry($specimen_or_observation)
832
{
833
    $exclude_occurrence_fields = &drupal_static(__FUNCTION__);
834
    if (!isset($exclude_occurrence_fields)) {
835
        $exclude_occurrence_fields = array(
836
            'type',
837
            'derivationEvent',
838
            'taxonRelatedDerivedUnits',
839
            'label',
840
            'titleCache',
841
            'listLabel',
842
            'protectedTitleCache',
843
            'class',
844
            'uuid',
845
            'collectionDTO',
846
            'derivates'
847
        );
848
    }
849
    $items = array();
850

    
851
    // only show uuid it the user is logged in
852
    if (user_is_logged_in() && ($a_idx = array_search('uuid', $exclude_occurrence_fields)) !== FALSE) {
853
      //  unset($exclude_occurrence_fields[$a_idx]);
854
    }
855

    
856

    
857
    if (is_object($specimen_or_observation)) {
858

    
859
        $type_label = $specimen_or_observation->recordBase;
860
        RenderHints::setFootnoteListKey($type_label . '-' . $specimen_or_observation->uuid);
861

    
862
        // collect typeStatus as label
863
        if (isset($specimen_or_observation->specimenTypeDesignations)) {
864
            $type_status = array();
865
            foreach ($specimen_or_observation->specimenTypeDesignations as $typeDesignation) {
866
                if (isset($typeDesignation->typeStatus->representation_L10n)) {
867
                    $type_status[] = $typeDesignation->typeStatus->representation_L10n;
868
                }
869
            }
870
            if (count($type_status) > 0) {
871
                $type_label = implode(', ', $type_status);
872
            }
873
        }
874

    
875
        $title = $type_label . ': ' . $specimen_or_observation->titleCache;
876
        $items['data'] = $title;
877

    
878
        $groups = array();
879
        $items['children'] = $groups;
880
        $children_items = array();
881
        // --- add initialized fields
882
        foreach (get_object_vars($specimen_or_observation) as $field => $value) {
883
            $child_item = array();
884

    
885
            if (!in_array($field, $exclude_occurrence_fields) && ($value && (!is_object($value) || isset($value->class)))) {
886
                switch ($field) {
887

    
888
                    /* ---- SpecimenOrObservationBase --- */
889

    
890
                    case 'kindOfUnit':
891
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 1);
892
                        break;
893

    
894

    
895
                    case 'preferredStableUri':
896

    
897
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), array(array('#markup' => cdm_external_uri($value, false))));
898
                        break;
899

    
900
                    case 'specimenTypeDesignations':
901
                        @_description_list_group_add(
902
                            $groups,
903
                            cdm_occurrence_field_name_label($field),
904
                            array(
905
                                '#markup' => theme('cdm_typedesignations', array('typeDesignations' => $value)),
906
                            )
907
                        );
908
                        break;
909

    
910

    
911

    
912
                    case 'listOfMedia':
913
                        $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
914
                        $captionElements = array(
915
                            '#uri' => t('open media'),
916
                        );
917
                        $gallery_html = compose_cdm_media_gallerie(array(
918
                            'mediaList' => $value,
919
                            'galleryName' => $specimen_or_observation->label,
920
                            'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
921
                            'cols' => $gallery_settings['cdm_dataportal_media_cols'],
922
                            'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
923
                            'captionElements' => $captionElements,
924
                            'mediaLinkType' => 'LIGHTBOX',
925
                            'alternativeMediaUri' => NULL,
926
                            'galleryLinkUri' => NULL,
927
                        ));
928

    
929
                         //@_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $gallery_html);
930
                         break;
931

    
932

    
933

    
934
                    /* ---- DerivedUnitBase --- */
935

    
936

    
937
                    case 'collection':
938

    
939
                        $sub_dl_groups = array();
940
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('code'), $value->code, NULL, 1);
941
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('codeStandard'), $value->codeStandard, NULL, 2);
942
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('institute'), $value->institute, NULL, 3);
943
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('townOrLocation'), $value->townOrLocation, NULL, 4);
944
                        // TODO "superCollection"
945
                        // TODO may have media
946

    
947
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),
948
                            array(
949
                                array('#markup' => $value->titleCache),
950
                                array('#theme' => 'description_list', '#groups' => $sub_dl_groups)
951
                            )
952
                        );
953

    
954
                        break;
955

    
956

    
957

    
958

    
959
                    /* ---- Specimen --- */
960
                    case 'sequences':
961
                        $dd_elements = array();
962
                        foreach ($value as $sequence) {
963
                            $dd_elements[] = compose_cdm_sequence($sequence, true);
964
                            $dd_elements[] = "";
965
                        }
966
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements,'', 100);
967
                        break;
968

    
969
                    // TODO preservation
970
                    // TODO exsiccatum
971

    
972

    
973
                    /* ---- FieldObservation --- */
974
                    case 'gatheringEvent':
975

    
976
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collector'), $value->collector);
977
                        @_description_list_group_add($groups, t('Gathering time'), timePeriodToString($value->timeperiod));
978
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('description'), $value->description);
979
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('locality'), $value->locality);
980
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('country'), $value->country);
981
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingMethod'), $value->collectingMethod);
982
                        if (isset($value->absoluteElevation)) {
983
                            $min_max_markup = min_max_measure($value, 'absoluteElevation');
984
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('absoluteElevation'), $min_max_markup);
985
                        }
986
                        if (isset($value->distanceToGround) && $value->distanceToGround >0) {
987
                            $min_max_markup = min_max_measure($value, 'distanceToGround');
988
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToGround'), $min_max_markup);
989
                        }
990
                        if (isset($value->distanceToWaterSurface) && $value->distanceToWaterSurface > 0) {
991
                            $min_max_markup = min_max_measure($value, 'distanceToWaterSurface');
992
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToWaterSurface'), $min_max_markup);
993
                        }
994

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

    
1029
                        break;
1030

    
1031
                    /* ---- DerivationEvent --- */
1032
                    case 'derivationEvents':
1033
                        //@_description_list_group_add($groups, t('Association type'), $value->description);
1034
                        break;
1035

    
1036

    
1037
                    default:
1038
                        if (is_object($value) || is_array($value)) {
1039
                            drupal_set_message("Unhandled type in compose_cdm_specimenOrObservation() for field " . $field, "warning");
1040
                        } else {
1041
                            _description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value);
1042
                        }
1043

    
1044
                }
1045

    
1046

    
1047
            }
1048
        } // END of loop over $derivedUnitFacade fields
1049

    
1050

    
1051

    
1052
        // template_preprocess_description_list() is not worting by weight so we do it right here
1053
        uasort($groups, 'element_sort');
1054

    
1055
        $occurrence_elements = array(
1056
           // '#title' => $title,
1057
            '#theme' => 'description_list',
1058
            '#groups' => $groups,
1059
            '#attributes' => array('class' => html_class_attribute_ref($specimen_or_observation)),
1060
        );
1061
        $output = drupal_render($occurrence_elements);
1062
        if (isset($gallery_html)){
1063
            $output .= $gallery_html;
1064
        }
1065
        if (!($specimen_or_observation->type == 'FieldUnit')){
1066
            $pathToSpecimen = path_to_specimen($specimen_or_observation->uuid);
1067
            $output .=  l("detail page", $pathToSpecimen, array('attributes' => array('target' => '_blank')));
1068
        }
1069

    
1070

    
1071

    
1072

    
1073

    
1074

    
1075

    
1076

    
1077

    
1078

    
1079
    } // END of $specimenOrObservation exists
1080

    
1081
    return $output;
1082
}
1083

    
Add picture from clipboard (Maximum size: 40 MB)