Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

cdm-dataportal / modules / cdm_dataportal / includes / occurrences.inc @ 72d57201

History | View | Annotate | Download (62.3 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)
29
{
30

    
31
    $specimen_details = compose_cdm_specimen_or_observation($specimen, true);
32
    //$detail_html .= drupal_render($specimen_details);
33

    
34
    $specimen->_fieldObjectMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array(
35
        $specimen->uuid,
36
        'fieldObjectMediaDTO',
37
    ));
38
    $specimen->_derivedUnitMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array(
39
        $specimen->uuid,
40
        'derivedUnitMedia',
41
    ));
42
    $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
43
    $captionElements = array(
44
        'title',
45
        '#uri' => t('open media'),
46
    );
47
    if (isset($specimen->fieldObjectMediaDTO) ) {
48
        $gallery_html = compose_cdm_media_gallerie(array(
49
            'mediaList' => $specimen->fieldObjectMediaDTO,
50
            'galleryName' => $specimen->titleCache,
51
            'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
52
            'cols' => $gallery_settings['cdm_dataportal_media_cols'],
53
            'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
54
            'captionElements' => $captionElements,
55
            'mediaLinkType' => 'LIGHTBOX',
56
            'alternativeMediaUri' => NULL,
57
            'galleryLinkUri' => NULL,
58
        ));
59
        $specimen_details[] = markup_to_render_array($gallery_html);
60
    }
61

    
62
    if (isset($specimen->_derivedUnitMedia) ) {
63
        $gallery_html = compose_cdm_media_gallerie(array(
64
            'mediaList' => $specimen->_derivedUnitMedia,
65
            'galleryName' => $specimen->titleCache,
66
            'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
67
            'cols' => $gallery_settings['cdm_dataportal_media_cols'],
68
            'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
69
            'captionElements' => $captionElements,
70
            'mediaLinkType' => 'LIGHTBOX',
71
            'alternativeMediaUri' => NULL,
72
            'galleryLinkUri' => NULL,
73
        ));
74
        $specimen_details[] = markup_to_render_array($gallery_html);
75
    }
76

    
77
    $specimen_array = $specimen_details;
78
    $output = "";
79
    foreach($specimen_array as $value){
80
        $renderArray = array(
81
            '#theme' => 'item_list',
82
            '#items' => array($value),
83
            '#type' => 'ul');
84
        $output .= drupal_render($renderArray);
85
    }
86

    
87

    
88
    return $output;
89
}
90

    
91

    
92
/**
93
 * Provides the HTML markup for a specimen page
94
 *
95
 * @param $specimen
96
 *
97
 * @return string
98
 *  The markup for a specimen page
99
 */
100
function render_cdm_specimenDTO_page($specimen, $is_specimen_page = false)
101
{
102
    $detail_html = "";
103
    //link to specimen page
104
    $pathToSpecimen = path_to_specimen($specimen->uuid);
105
    if (!$is_specimen_page) {
106
        $specimenPageLink = l($specimen->accessionNumber, $pathToSpecimen, array('attributes' => array('target' => '_blank')));
107
        $detail_html .= "<strong>Specimen summary: $specimenPageLink</strong><br>";
108
    }
109

    
110

    
111
    if($is_specimen_page) {
112
        if($specimen->citation){
113
            $detail_html .= "<br>".$specimen->citation."<br>";
114

    
115
        }
116
    }
117
    if ($specimen->preferredStableUri) {
118
        $stableIdentifierLink = l($specimen->preferredStableUri, $specimen->preferredStableUri, array('attributes' => array('target' => '_blank')));
119
        $detail_html .= create_label("Preferred stable URI") . $stableIdentifierLink . "<br>";
120
    }
121
    if ($is_specimen_page) {
122
        // associated taxa
123
        if ($specimen->associatedTaxa) {
124
            $detail_html .= "<br>";
125
            $detail_html .= create_label("Associated with");
126
            if (sizeof($specimen->associatedTaxa) > 1) {
127
                $detail_html .= "<br>";
128
            }
129
            foreach ($specimen->associatedTaxa as $associatedTaxon) {
130
                $detail_html .= l($associatedTaxon->value, path_to_taxon($associatedTaxon->key, "specimens"));//$associatedTaxon->second."<br>";
131
            }
132
            $detail_html .= "<br>";
133
        }
134
    }
135
    // - type information
136
    $types = "";
137
    if (isset($specimen->types)) {
138
        //typed taxa
139
        foreach ($specimen->types as $typeStatus => $typedTaxa) {
140
            if($specimen->types){
141
                if(empty($typeStatus) || $typeStatus == "_empty_"|| $typeStatus == ""){
142
                    $detail_html .= "<i>Type for:</i> ";
143
                } else {
144
                    $detail_html .= "<i>".$typeStatus."</i> of ";
145
                }
146
                foreach($typedTaxa as $typedTaxon){
147
                    $detail_html .= $typedTaxon." ";
148

    
149
                }
150
            } else {
151
                $types .= $typeStatus . " ";
152

    
153
            }
154
        }
155
    }
156
    $derivateDataDTO = $specimen->derivateDataDTO;
157
    // - specimen scans
158
    $specimenScans = create_html_links($derivateDataDTO->specimenScans, true);
159
    // - molecular data
160
    $molecularData = "";
161
    if ($derivateDataDTO->molecularDataList) {
162
        foreach ($derivateDataDTO->molecularDataList as $molecular) {
163
            //provider link
164
            if (isset($molecular->providerLink)) {
165
                $molecularData .= create_html_link($molecular->providerLink, true);
166
            } else {
167
                $molecularData .= "[no provider]";
168
            }
169
            //contig link
170
            if (isset($molecular->contigFiles)) {
171
                $molecularData .= "[";
172
                if (sizeof($molecular->contigFiles) > 0) {
173
                    foreach ($molecular->contigFiles as $contigFile) {
174
                        if (isset($contigFile->contigLink)) {
175
                            if (isset($contigFile->contigLink->uri) and $contigFile->contigLink->uri != null) {
176
                                $molecularData .= create_html_link($contigFile->contigLink, true) . " ";
177
                            }
178
                        } else {
179
                            $molecularData .= "no contig ";
180
                        }
181
                        //primer links
182
                        if (isset($contigFile->primerLinks)) {
183
                            $molecularData .= create_html_links($contigFile->primerLinks, true);
184
                        }
185
                    }
186
                }
187
                $molecularData = rtrim($molecularData, " ");
188
                $molecularData .= "]";
189
            }
190
            //FIXME separate with comma (remove trailing comma)
191
        }
192
    }
193
    // - detail images
194
    $detailImages = create_html_links($derivateDataDTO->detailImages, true);
195

    
196
    if ($types) {
197
        $detail_html .= $is_specimen_page ? "<br>" : "";
198
        $detail_html .= create_label("Type(s)") . $types . "<br>";
199
    }
200
    if ($specimenScans and !$is_specimen_page) {
201
        $detail_html .= create_label("Specimen Scans") . $specimenScans . "<br>";
202
    }
203
    //specimen scan image gallery
204
    if ($is_specimen_page and isset($derivateDataDTO->specimenScanUuids) and !empty($derivateDataDTO->specimenScanUuids)) {
205
        $detail_html .= addImageGallery("Specimen scans", $derivateDataDTO->specimenScanUuids);
206
    }
207

    
208
    if ($molecularData) {
209
        $detail_html .= $is_specimen_page ? "<br>" : "";
210
        $detail_html .= create_label("Molecular Data") . $molecularData . "<br>";
211
    }
212

    
213
    if ($detailImages and !$is_specimen_page) {
214
        $detail_html .= create_label("Detail Images") . $detailImages . "<br>";
215
    }
216

    
217
    //detail image gallery
218
    if ($is_specimen_page and isset($derivateDataDTO->detailImageUuids) and !empty($derivateDataDTO->detailImageUuids)) {
219
        $detail_html .= addImageGallery("Detail Images", $derivateDataDTO->detailImageUuids);
220
    }
221

    
222
    //character data
223
    if ($specimen->characterData) {
224
        $detail_html .= $is_specimen_page ? "<br>" : "";
225
        $detail_html .= create_label("Character Data");
226
        if ($is_specimen_page) {
227
            $detail_html .= "<br>";
228
            foreach ($specimen->characterData as $characterStatePair) {
229
                $detail_html .= "<i>" . $characterStatePair->first . "</i>:" . $characterStatePair->second;
230
                $detail_html .= "<br>";
231
            }
232
        } else {
233
            $detail_html .= l("detail page", $pathToSpecimen, array('attributes' => array('target' => '_blank')));
234
            $detail_html .= "<br>";
235
        }
236
    }
237
    return $detail_html;
238
}
239

    
240
function addImageGallery($galleryName, $imageUuids)
241
{
242
    $images = array();
243
    foreach ($imageUuids as $uuid) {
244
        $images[] = cdm_ws_get(CDM_WS_PORTAL_MEDIA, $uuid);
245
    }
246

    
247
    $gallery_html = '';
248
    if (count($imageUuids) > 0) {
249
        $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
250
        $captionElements = array(
251
            'title',
252
            'rights',
253
        );
254
        $alternativeMediaUris = array();
255
        foreach ($images as $image) {
256
            $mediaUri = getMediaUri($image);
257
            if ($mediaUri) {
258
                $alternativeMediaUris[] = $mediaUri;
259
            } else {
260
                $alternativeMediaUris[] = path_to_media($image->uuid);
261
            }
262
        }
263

    
264

    
265

    
266
        $gallery_html = compose_cdm_media_gallerie(array(
267
            'mediaList' => $images,
268
            'galleryName' => $galleryName,
269
            'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
270
            'cols' => $gallery_settings['cdm_dataportal_media_cols'],
271
            'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
272
            'captionElements' => $captionElements,
273
            'mediaLinkType' => 'LIGHTBOX',
274
          // 'alternativeMediaUri' => $alternativeMediaUris,
275
            'alternativeMediaUri' => NULL,
276
            'galleryLinkUri' => NULL,
277
        ));
278
    }
279
    return "<br>" . create_label($galleryName) . "<br>" . $gallery_html;
280
}
281

    
282
function getMediaUri($media)
283
{
284
    if (isset($media->representations) && sizeof($media->representations) == 1
285
        && isset($media->representations[0]->parts) &&
286
        sizeof($media->representations[0]->parts) == 1) {
287
        return $media->representations[0]->parts[0]->uri;
288
    }
289
    return null;
290
}
291

    
292

    
293
/**
294
 * Formats the given string to a label for displaying key-object pairs in HTML
295
 * @return string
296
 */
297
function create_label($label)
298
{
299
    return "<span class='specimen_table_label'>" . $label . ": </span>";
300
}
301

    
302
/**
303
 * Compose an render array from a CDM DerivedUnitFacade object.
304
 *
305
 * compose_hook() implementation
306
 *
307
 * @param object $specimenOrObservation
308
 *   the CDM instance of type SpecimenOrObservation to compose
309
 *   the render array for
310
 * @param array $derivatives
311
 *   the render array which contains the compositions of the derivatives
312
 *   of the supplied $specimenOrObservation
313
 *
314
 * @return array
315
 *   the supplied render array $derivatives to which the composition of the supplied
316
 *   $specimenOrObservation has been added to
317
 *
318
 * @ingroup compose
319
 */
320

    
321
function compose_cdm_specimen_or_observation($specimen_or_observation, $isSpecimen_page = false, &$derivatives = null)
322
{
323
    $exclude_occurrence_fields = &drupal_static(__FUNCTION__);
324
    if (!isset($exclude_occurrence_fields)) {
325
        $exclude_occurrence_fields = array(
326

    
327
            'titleCache',
328
            'protectedTitleCache',
329
            'derivedUnitMedia',
330
            'created',
331
            'publish',
332
            'updated',
333
            'class',
334
            'uuid',
335
            ''
336
        );
337
    }
338
    if (variable_get('cdm_dataportal_compressed_specimen_derivate_table') || !$isSpecimen_page){
339
        $exclude_occurrence_fields[] = 'derivationEvents';
340
    }
341

    
342

    
343
    // only show uuid it the user is logged in
344
 //   if(user_is_logged_in() && ($a_idx = array_search('uuid', $exclude_occurrence_fields)) !== FALSE ) {
345
  //      unset($exclude_occurrence_fields[$a_idx]);
346
  //  }
347

    
348
    if (!isset($derivatives)) {
349
        $derivatives = array();
350
    }
351

    
352
    $descriptions = null;
353
    $derivedFrom = null;
354

    
355

    
356

    
357
    if (is_object($specimen_or_observation)) {
358

    
359
        // request again for deeper initialization
360
        $specimen_or_observation = cdm_ws_get("portal/" . CDM_WS_OCCURRENCE, $specimen_or_observation->uuid);
361
        if ($specimen_or_observation->class == 'FieldUnit'){
362
            $specimen_or_observation->_derivedUnitMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array(
363
                $specimen_or_observation->uuid,
364
                'fieldObjectMediaDTO',
365
            ));
366
        }else{
367
            $specimen_or_observation->_derivedUnitMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array(
368
                $specimen_or_observation->uuid,
369
                'derivedUnitMedia',
370
            ));
371
        }
372

    
373
        $type_label = $specimen_or_observation->class;
374
        RenderHints::setFootnoteListKey($type_label . '-' . $specimen_or_observation->uuid);
375

    
376
        // collect typeStatus as label
377
        if (isset($specimen_or_observation->specimenTypeDesignations)) {
378
            $type_status = array();
379
            foreach ($specimen_or_observation->specimenTypeDesignations as $typeDesignation) {
380
                if (isset($typeDesignation->typeStatus->representation_L10n)) {
381
                    $type_status[] = $typeDesignation->typeStatus->representation_L10n;
382
                }
383
            }
384
            if (count($type_status) > 0) {
385
                $type_label = implode(', ', $type_status);
386
            }
387
        }
388

    
389
        $title = $type_label . ': ' . $specimen_or_observation->titleCache;
390

    
391
        $groups = array();
392

    
393
        // --- add initialized fields
394
        foreach (get_object_vars($specimen_or_observation) as $field => $value) {
395
            if (!in_array($field, $exclude_occurrence_fields) && ($value && (!is_object($value) || isset($value->class)))) {
396
                switch ($field) {
397

    
398
                    /* ---- java.lang.Object --- */
399
                    case 'class':
400
                        if ($value != '' /* FieldUnit' */) {
401
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value);
402
                        }
403
                        break;
404

    
405
                    case 'markers':
406
                        $dd_elements = array();
407
                        foreach ($value as $marker) {
408
                            $dd_elements[] = compose_cdm_marker($marker);
409
                        }
410
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
411
                        break;
412

    
413

    
414
                    case 'annotations':
415
                        $dd_elements = array();
416
                        foreach ($value as $annotation) {
417
                            // TODO respect annotation type filter settings
418
                            $dd_elements[] = $annotation->text;
419
                        }
420
                        @_description_list_group_add($groups, t('Notes'), $dd_elements);
421
                        break;
422

    
423
                    /* ---- SpecimenOrObservationBase --- */
424
                    case 'sex':
425
                    case 'lifeStage':
426
                    case 'kindOfUnit':
427
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value->representation_L10n);
428
                        break;
429

    
430
                    case 'definition':
431
                        // TODO
432
                        break;
433

    
434
                    case 'preferredStableUri':
435

    
436
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), array(array('#markup' => cdm_external_uri($value, false))));
437
                        break;
438

    
439
                    case 'specimenTypeDesignations':
440

    
441
                        //TODO: better display of details!!
442
                        @_description_list_group_add(
443
                            $groups,
444
                            cdm_occurrence_field_name_label($field),
445
                            array(
446
                                '#markup' => theme('cdm_typedesignations', array('typeDesignations' => $value)),
447
                            )
448
                        );
449
                        break;
450

    
451
                    case 'determinations':
452
                        $dd_elements = array();
453
                        $glue = ', ';
454

    
455
                        foreach ($value as $determinationEvent) {
456
                            $timeperiod_string = NULL;
457
                            if (isset($determinationEvent->timeperiod)) {
458
                                $timeperiod_string = timePeriodToString($determinationEvent->timeperiod);
459
                            }
460
                            $weight = isset($determinationEvent->preferred) && $determinationEvent->preferred == 1 ? '0' : ($timeperiod_string ? $timeperiod_string : '1');
461
                            // check key exists
462
                            while (array_key_exists($weight, $dd_elements)) {
463
                                $weight .= '0';
464
                            }
465

    
466
                            $taxon_name = '';
467
                            $name_link = '';
468
                            if ($determinationEvent->taxonName) {
469
                                $taxon_name = cdm_ws_get(CDM_WS_NAME, $determinationEvent->taxonName->uuid);
470
                                $taxon_name->taggedName = cdm_ws_get(CDM_WS_NAME, array($determinationEvent->taxonName->uuid, "taggedName"));
471
                                $name_link = path_to_name($determinationEvent->taxonName->uuid);
472
                            } else if ($determinationEvent->taxon) {
473
                                $taxon_name = cdm_ws_get(CDM_WS_TAXON . '/$0/name', $determinationEvent->taxon->uuid);
474
                                $name_link = path_to_taxon($determinationEvent->taxon->uuid);
475
                            }
476
                            if ($taxon_name) {
477
                                $taxon_html = render_taxon_or_name($taxon_name, $name_link);
478
                                $dd_elements[$weight] = $taxon_html;
479
                            }
480
                            if (isset($determinationEvent->modifier)) {
481
                                $dd_elements[$weight] .= cdm_term_representation($determinationEvent->modifier);
482
                            }
483
                            if ($timeperiod_string) {
484
                                $dd_elements[$weight] .= $glue . $timeperiod_string;
485
                            }
486
                            if (isset($determinationEvent->actor->titleCache)) {
487
                                $dd_elements[$weight] .= $glue . $determinationEvent->actor->titleCache;
488
                            }
489
                            if (isset($determinationEvent->description)) {
490
                                $dd_elements[$weight] .= $glue . $determinationEvent->description;
491
                            }
492
                        }
493
                        ksort($dd_elements);
494
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('determinations'), $dd_elements);
495
                        break;
496

    
497
                    case 'descriptions':
498
                        $occurrence_featureTree = cdm_get_occurrence_featureTree();
499
                        $dd_elements = array();
500

    
501
                        foreach ($value as $description) {
502
                            $description = cdm_ws_get(CDM_WS_PORTAL_DESCRIPTION, $description->uuid);
503

    
504
                            if ($description->imageGallery == TRUE) {
505
                                continue;
506
                            }
507
                            $elements_by_feature = _mergeFeatureTreeDescriptions($occurrence_featureTree->root->childNodes, $description->elements);
508
                            $description_render_elements = _block_get_renderable_array(make_feature_block_list($elements_by_feature, null));
509
                            $dd_elements[] = $description_render_elements;
510
                        }
511

    
512
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
513
                        break;
514
                    case '_derivedUnitMedia':
515
                        if ($isSpecimen_page) {
516
                            $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
517
                            $captionElements = array(
518
                                '#uri' => t('open media'),
519
                            );
520
                            $gallery_html = compose_cdm_media_gallerie(array(
521
                                'mediaList' => $value,
522
                                'galleryName' => $specimen_or_observation->titleCache,
523
                                'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
524
                                'cols' => $gallery_settings['cdm_dataportal_media_cols'],
525
                                'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
526
                                'captionElements' => $captionElements,
527
                                'mediaLinkType' => 'LIGHTBOX',
528
                                'alternativeMediaUri' => NULL,
529
                                'galleryLinkUri' => NULL,
530
                            ));
531
                            @_description_list_group_add($groups, "Detail Images:", markup_to_render_array($gallery_html), '', 20);
532
                        }
533

    
534
                        // $dd_elements[] = markup_to_render_array($gallery_html);
535

    
536
                        break;
537
                    case 'sources':
538
                        $annotations_and_sources = handle_annotations_and_sources(
539
                            $specimen_or_observation,
540
                            array(
541
                                'sources_as_content' => true,
542
                                'link_to_name_used_in_source' => 1,
543
                                'link_to_reference' => 0,
544
                                'add_footnote_keys' => 0
545
                            ),
546
                            NULL,
547
                            ''
548
                        );
549
                        if (!empty($annotations_and_sources['source_references'])) {
550
                            @_description_list_group_add($groups, t('Sources') . ':', join(', ', $annotations_and_sources['source_references']), '', 12);
551
                        }
552
                        break;
553

    
554

    
555
                    /* ---- DerivedUnitBase --- */
556
                    case 'derivedFrom':
557
                        $derivedFrom = $value;
558
                        if ($isSpecimen_page) {
559
                            foreach ($derivedFrom->originals as $original) {
560
                                $pathToSpecimen = path_to_specimen($original->uuid);
561
                                $description = "";
562
                                if (isset($derivedFrom->description) && $derivedFrom->description != '') {
563
                                    $description = $derivedFrom->description . ": ";
564
                                }
565

    
566
                                $originals[] = markup_to_render_array(l($description . $original->titleCache, $pathToSpecimen, array('attributes' => array('target' => '_blank'))));
567
                                if ($original->class == 'FieldUnit') {
568
                                    $label = t('Field data');
569
                                } else {
570
                                    $label = t('Derived from');
571
                                }
572
                                @_description_list_group_add($groups, $label . ':',
573
                                    $originals,
574
                                    '', 13);
575
                            }
576
                        }
577
                        break;
578
                    case 'derivationEvents':
579
                        $derivationEvents = $value;
580
                        $derived_units = array();
581
                        if ($isSpecimen_page) {
582
                            foreach ($derivationEvents as $derivationEvent) {
583
                                foreach ($derivationEvent->derivatives as $derived_unit) {
584
                                    $pathToSpecimen = path_to_specimen($derived_unit->uuid);
585
                                    $description = "";
586
                                    if (isset($derived_unit->description) && $derived_unit->description != '') {
587
                                        $description = $derived_unit->description . ": ";
588
                                    }
589

    
590
                                    $derived_units[] = markup_to_render_array(l($description . $derived_unit->titleCache, $pathToSpecimen, array('attributes' => array('target' => '_blank'))));
591
                                }
592
                            }
593
                            @_description_list_group_add($groups, t('Derivates') . ':',
594
                                $derived_units,
595
                                '', 100);
596

    
597
                        }
598
                        break;
599

    
600
                    case 'collection':
601
                        $sub_dl_groups = array();
602
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('code'), $value->code, NULL, 1);
603
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('codeStandard'), $value->codeStandard, NULL, 2);
604
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('institute'), $value->institute, NULL, 3);
605
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('townOrLocation'), $value->townOrLocation, NULL, 4);
606
                        // TODO "superCollection"
607
                        // TODO may have media
608

    
609
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),
610
                            array(
611
                                array('#markup' => $value->titleCache),
612
                                array('#theme' => 'description_list', '#groups' => $sub_dl_groups)
613
                            )
614
                        );
615
                        break;
616

    
617
                    case 'storedUnder':
618
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('storedUnder'), render_taxon_or_name($value));
619
                        break;
620
                    case 'dnaQuality':
621
                        $sub_dl_groups = array();
622

    
623
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('purificationMethod'), $value->purificationMethod, NULL, 1);
624
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('ratioOfAbsorbance260_230'), $value->ratioOfAbsorbance260_230, NULL, 2);
625
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('ratioOfAbsorbance260_280'), $value->ratioOfAbsorbance260_280, NULL, 3);
626
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('concentration'), $value->concentration, NULL, 4);
627
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('concentrationUnit'), $value->concentrationUnit, NULL, 4);
628
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('qualityTerm'), $value->qualityTerm, NULL, 4);
629
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('qualityCheckDate'), $value->qualityCheckDate, NULL, 4);
630

    
631
                        if (is_array($sub_dl_groups) && sizeof($sub_dl_groups)>0) {
632
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),
633
                                array(
634
                                    array('#markup' => $value->titleCache),
635
                                    array('#theme' => 'description_list', '#groups' => $sub_dl_groups)
636
                                )
637
                            );
638
                        }
639
                        break;
640

    
641
                    case 'preservation':
642
                        $sub_dl_groups = array();
643

    
644
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('medium'), $value->medium, NULL, 1);
645
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('temperature'), $value->temperature, NULL, 2);
646
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('definedMaterialOrMethod'), $value->definedMaterialOrMethod, NULL, 3);
647

    
648
                        if (is_array($sub_dl_groups) && sizeof($sub_dl_groups)>0) {
649
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),
650
                                array(
651
                                    array('#markup' => $value->titleCache),
652
                                    array('#theme' => 'description_list', '#groups' => $sub_dl_groups)
653
                                )
654
                            );
655
                        }
656
                        break;
657

    
658
                    /* ---- Specimen --- */
659
                    case 'sequences':
660
                        $dd_elements = array();
661
                        foreach ($value as $sequence) {
662
                            $dd_elements[] = compose_cdm_sequence($sequence);
663
                        }
664
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
665
                        break;
666

    
667
                    // TODO preservation
668
                    // TODO exsiccatum
669

    
670

    
671
                    /* ---- FieldObservation --- */
672
                    case 'gatheringEvent':
673
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collector'), $value->actor->titleCache, '', 1);
674
                        @_description_list_group_add($groups, t('Gathering date'), timePeriodToString($value->timeperiod), '', 2);
675
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('description'), $value->description, '', 3);
676
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('locality'), $value->locality->text, '', 10);
677
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('country'), $value->country->representation_L10n, '', 4);
678
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingMethod'), $value->collectingMethod,'',5);
679
                        if (isset($value->absoluteElevation)) {
680
                            $min_max_markup = min_max_measure($value, 'absoluteElevation');
681
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('absoluteElevation'), $min_max_markup, '',6);
682
                        }
683
                        if (isset($value->distanceToGround)) {
684
                            $min_max_markup = min_max_measure($value, 'distanceToGround');
685
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToGround'), $min_max_markup,'',7);
686
                        }
687
                        if (isset($value->distanceToWaterSurface)) {
688
                            $min_max_markup = min_max_measure($value, 'distanceToWaterSurface');
689
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToWaterSurface'), $min_max_markup, '',8);
690
                        }
691
                        if (isset($value->collectingAreas) && count($value->collectingAreas) > 0) {
692
                            $area_representations = array();
693
                            foreach ($value->collectingAreas as $area) {
694
                                $area_representations[] = l($area->representation_L10n, path_to_named_area($area->uuid));
695
                            }
696
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingAreas'),
697
                                array(
698
                                    array('#markup' => implode(', ', $area_representations))
699
                                ),'',9
700
                            );
701
                        }
702
                        if (isset($value->exactLocation) && $value->exactLocation->sexagesimalString) {
703
                            $sub_dl_groups = array();
704
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('errorRadius'), $value->exactLocation->errorRadius, ' m', 1);
705
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('longitude'), round($value->exactLocation->longitude, 7), '°', 2);
706
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('latitude'), round($value->exactLocation->latitude, 7), '°', 3);
707
                            if (isset($value->exactLocation->referenceSystem)) {
708
                                @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('referenceSystem'), $value->exactLocation->referenceSystem->representation_L10n, '', 4);
709
                            }
710

    
711
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('exactLocation'),
712
                                array(
713
                                    array('#markup' => $value->exactLocation->sexagesimalString),
714
                                    array(
715
                                        '#theme' => 'description_list',
716
                                        '#groups' => $sub_dl_groups
717
                                    ),
718
                                ),'',11
719
                            );
720
                        }
721
                        break;
722

    
723
                    default:
724
                        if (is_object($value) || is_array($value)) {
725
                            drupal_set_message("Unhandled type in compose_cdm_specimen_or_observation() for field " . $field, "warning");
726
                        } else {
727
                            _description_list_group_add($groups, cdm_occurrence_field_name_label($field), cdm_occurrence_field_name_label($value));
728
                        }
729

    
730
                }
731

    
732
            }
733
        } // END of loop over $derivedUnitFacade fields
734

    
735
        // Extensions
736
        $extensions = cdm_ws_fetch_all(CDM_WS_PORTAL_OCCURRENCE . '/'  . $specimen_or_observation->uuid . '/extensions', array($specimen_or_observation->uuid));
737
        if ($extensions && count($extensions)) {
738

    
739
            $extensions_render_array = compose_extensions($extensions);
740
            @_description_list_group_add($groups, t('Extensions') . ':',
741
                $extensions_render_array,
742
                '', 100);
743
        }
744

    
745

    
746

    
747
        // template_preprocess_description_list() is not worting by weight so we do it right here
748
        uasort($groups, 'element_sort');
749

    
750
        $occurrence_elements = array(
751
           // '#title' => $title,
752
            '#theme' => 'description_list',
753
            '#groups' => $groups,
754
            '#attributes' => array('class' => html_class_attribute_ref($specimen_or_observation)),
755
        );
756

    
757
        $derivatives[] = drupal_render($occurrence_elements);
758
        // all footnotes which has been assembled so far (e.g. from typeDesignations) to here
759
//       $foonote_li_elements = theme('cdm_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey(), 'enclosingTag' => 'span'));
760
//        if (!empty($foonote_li_elements)) {
761
//            $derivatives[] =  array(
762
//                '#markup' =>  '<div class="footnotes">' . $foonote_li_elements . '</div>',
763
//            );
764
//        }
765

    
766
        // --- recurse into originals
767
        if (!isset($derivedFrom)  && !$isSpecimen_page) {
768
            $derivedFrom = cdm_ws_get(
769
                CDM_WS_OCCURRENCE,
770
                array($specimen_or_observation->uuid, 'derivedFrom')
771
            );
772
        }
773
        if (isset($derivedFrom) && !$isSpecimen_page) {
774
            if (isset($derivedFrom->originals)) {
775
                $derived_from_label = t('derived');
776
                $preposition = t('from');
777
                if(isset($derivedFrom->type)){
778
                    $derived_from_label = $derivedFrom->type->representation_L10n;
779
                    if($derivedFrom->type->uuid == UUID_DERIVATIONEVENTTYPE_ACCESSIONING){
780
                        $preposition = t('of');
781
                    }
782
                }
783
                if (count($groups) > 0) {
784
                    // TODO  annotations
785

    
786
                    // only display the derived from information when the derivative has any element which will be diplayed
787
                    $derivatives[] = array(
788
                        '#markup' => '<div class="derived_from">' . $derived_from_label . ' ' . $preposition . ': </div>',
789
                    );
790
                }
791
                foreach ($derivedFrom->originals as $original) {
792
                    compose_cdm_specimen_or_observation($original, $isSpecimen_page, $derivatives);
793
                }
794
            }
795
        }
796

    
797

    
798

    
799

    
800
    } // END of $specimenOrObservation exists
801

    
802
    return $derivatives;
803
}
804

    
805

    
806
/**
807
 * Compose an render array from a CDM Sequence object.
808
 *
809
 * compose_hook() implementation
810
 *
811
 * @param object $sequence
812
 *   CDM instance of type Sequence
813
 * @return array
814
 *   A render array containing the fields of the supplied $sequence
815
 *
816
 * @ingroup compose
817
 */
818
function compose_cdm_sequence($sequence, $isSpecimenPage = false)
819
{
820

    
821
    $exclude_sequence_fields = &drupal_static(__FUNCTION__);
822
    if (!isset($exclude_sequence_fields)) {
823
        $exclude_sequence_fields = array(
824
            'titleCache',
825
            'protectedTitleCache',
826
            'microReference',
827
            'created',
828
            'updated',
829
            'class',
830
        );
831
    }
832

    
833
    $groups = array();
834

    
835
    // -- retrieve additional data if neesscary
836
    // TODO below call disabled since sequences are not yet supported,
837
    //      see  #3347 (services and REST service controller for molecular classes implemented)
838
    //
839
    // cdm_load_annotations($sequence);
840

    
841
    foreach (get_object_vars($sequence) as $field => $value) {
842

    
843

    
844
        if (!in_array($field, $exclude_sequence_fields) && ($value && (!is_object($value) || isset($value->class)))) {
845
            switch ($field) {
846

    
847
                case 'geneticAccessionNumber';
848

    
849
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 2);
850
                    break;
851

    
852

    
853
                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.
854
                    if (isset($value->name)) {
855
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value->name, NULL, 3);
856
                    }
857
                    if (isset($value->description)) {
858
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field) . ' ' . t('description'), $value->description, NULL, 4);
859
                    }
860
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field) , $value, NULL, 4);
861
                    break;
862

    
863
                case 'consensusSequence':
864
                    // format in genbank style, force linebreaks after each 70 nucleotites
865
                    // see also http://stackoverflow.com/questions/499137/css-how-can-i-force-a-long-string-without-any-blank-to-be-wrapped-in-xul-and
866
                    if ($value->length > 0) {
867
                        @_description_list_group_add(
868
                            $groups,
869
                            cdm_occurrence_field_name_label($field),
870
                            array(
871
                                array(
872
                                    '#markup' => '<div class="sequence-length">' . $value->length . ' ' . t('pb') . '</div><div>' . wordwrap($value->string, 70, '</br>', TRUE) . '</div>',
873
                                    '#wrapper_attributes' => array('class' => 'dna-sequence')
874
                                )
875
                            ),
876
                            5);
877
                    }
878
                    break;
879

    
880
                case 'dnaSample': // FIXME 3.3 implement
881
                    break;
882
                case 'singleReads': // FIXME 3.3 implement
883
                    break;
884
                case 'contigFile': // FIXME 3.3 implement - Media
885
                    break;
886
                case 'pherograms': // FIXME 3.3 implement - Media
887
                    break;
888
                case 'haplotype': // FIXME 3.3 implement
889
                    break;
890
                case 'dateSequenced': // FIXME 3.3 now in SingelRead
891
                    @_description_list_group_add($groups, t('Sequencing date'), timePeriodToString($value), NULL, 6);
892
                    break;
893

    
894
                case 'barcode': // boolean
895
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value ? 'Yes' : 'No', NULL, 7);
896
                    break;
897
                case 'barcodeSequencePart': // FIXME 3.3 implement, compose sequence
898
                    break;
899

    
900
                case 'citation':
901
                    @_description_list_group_add($groups,
902
                        cdm_occurrence_field_name_label($field),
903
                        theme('cdm_reference', array('reference' => $value, 'microReference' => $sequence->microReference)),
904
                        NULL,
905
                        8
906
                    );
907
                    break;
908

    
909
                case 'publishedIn':
910
                    @_description_list_group_add($groups,
911
                        cdm_occurrence_field_name_label($field),
912
                        theme('cdm_reference', array('reference' => $value)),
913
                        NULL,
914
                        7
915
                    );
916
                    break;
917

    
918
                case 'rights':
919
                    array_merge($groups, cdm_rights_as_dl_groups($value));
920
                    break;
921

    
922
                case 'annotations':
923
                    $dd_elements = array();
924
                    foreach ($value as $annotation) {
925
                        // TODO respect annotation type filter settings
926
                        $dd_elements[] = $annotation->text;
927
                    }
928
                    @_description_list_group_add($groups, t('Notes'), $dd_elements, NULL, 9);
929
                    break;
930

    
931
                case 'markers':
932
                    $dd_elements = array();
933
                    foreach ($value as $marker) {
934
                        $dd_elements[] = compose_cdm_marker($marker);
935
                    }
936
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements, NULL, 10);
937
                    break;
938

    
939
                case 'chromatograms':
940
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),
941
                        array(
942
                            '#markup' => compose_cdm_media_gallerie(array('medialist' => $value)),
943
                        ),
944
                        NULL,
945
                        11);
946
                    break;
947

    
948
                default:
949
                    if (is_object($value) || is_array($value)) {
950
                        drupal_set_message("Unhandled type in compose_cdm_sequence() for field " . $field, "warning");
951
                    } else {
952
                        if (!is_array($value) && strpos($value, 'http:') !== false ){
953
                            //make links for urls
954
                            $value = l($value, $value, array('attributes' => array('target' => '_blank')));
955
                            $value = markup_to_render_array($value);
956
                        }
957

    
958
                       _description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 20);
959
                    }
960
            }
961
        }
962
    }
963

    
964
    // template_preprocess_description_list() is not worting by weight so we do it right here
965
    uasort($groups, 'element_sort');
966
    if ($isSpecimenPage) {
967
        $sequence_elements = array(
968
            '#title' => $sequence->dnaMarker,
969
            '#theme' => 'description_list',
970
            '#groups' => $groups
971
        );
972
    } else{
973
        $sequence_elements = array(
974
            '#title' => $sequence->dnaMarker -> titleCache,
975
            '#theme' => 'description_list',
976
            '#groups' => $groups
977
        );
978
    }
979

    
980
    return $sequence_elements;
981
}
982
/**
983
 * Creates an array from a list of FieldUnitDTOs.
984
 *
985
 *
986
 * @param object $specimenOrObservations
987
 *   list of FieldUnitDTOs
988
 * @return array
989
 *   An array containing the hierarchy of the field units corresponding to the taxon
990
 *
991
 * @ingroup compose
992
 */
993
function compose_specimen_array(array $specimenOrObservations){
994
    $items_specimen = array();
995
    $items = array();
996

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

    
1000
        $items['data'] = $specimenOrObservation->listLabel ;
1001
        $specimen = compose_cdm_specimen_or_observation_tree_entry($specimenOrObservation);
1002
        $children = array();
1003
        $child = array();
1004
        $child['data'] =$specimen;
1005
       // $children[] = create_specimen_array($specimenOrObservation->derivates);
1006
       if (isset($specimenOrObservation->derivates) && sizeof($specimenOrObservation->derivates) > 0){
1007
           $child['children']= compose_specimen_array($specimenOrObservation->derivates);
1008
       }
1009
       $children[]=$child;
1010
       $items['children'] = $children;
1011
       $items_specimen[] = $items;
1012
    }
1013
    return $items_specimen;
1014
}
1015

    
1016

    
1017
/**
1018
 * Compose an render array from a CDM DerivedUnitFacade object.
1019
 *
1020
 * compose_hook() implementation
1021
 *
1022
 * @param object $specimenOrObservation
1023
 *   the CDM instance of type SpecimenOrObservation to compose
1024
 *   the render array for
1025
 * @param array $derivatives
1026
 *   the render array which contains the compositions of the derivatives
1027
 *   of the supplied $specimenOrObservation
1028
 *
1029
 * @return array
1030
 *   the supplied render array $derivatives to which the composition of the supplied
1031
 *   $specimenOrObservation has been added to
1032
 *
1033
 * @ingroup compose
1034
 */
1035

    
1036
function compose_cdm_specimen_or_observation_tree_entry($specimen_or_observation)
1037
{
1038
    $exclude_occurrence_fields = &drupal_static(__FUNCTION__);
1039
    if (!isset($exclude_occurrence_fields)) {
1040
        $exclude_occurrence_fields = array(
1041
            'type',
1042
            'taxonRelatedDerivedUnits',
1043
            'label',
1044
            'titleCache',
1045
            'listLabel',
1046
            'protectedTitleCache',
1047
            'class',
1048
            'uuid',
1049
            'derivates',
1050
            'collection'
1051
        );
1052
    }
1053
    $items = array();
1054

    
1055
    // only show uuid it the user is logged in
1056
    if (user_is_logged_in() && ($a_idx = array_search('uuid', $exclude_occurrence_fields)) !== FALSE) {
1057
      //  unset($exclude_occurrence_fields[$a_idx]);
1058
    }
1059

    
1060

    
1061
    if (is_object($specimen_or_observation)) {
1062

    
1063
        $type_label = $specimen_or_observation->recordBase;
1064
        RenderHints::setFootnoteListKey($type_label . '-' . $specimen_or_observation->uuid);
1065

    
1066
        // collect typeStatus as label
1067
        if (isset($specimen_or_observation->specimenTypeDesignations)) {
1068
            $type_status = array();
1069
            foreach ($specimen_or_observation->specimenTypeDesignations as $typeDesignation) {
1070
                if (isset($typeDesignation->typeStatus->representation_L10n)) {
1071
                    $type_status[] = $typeDesignation->typeStatus->representation_L10n;
1072
                }
1073
            }
1074
            if (count($type_status) > 0) {
1075
                $type_label = implode(', ', $type_status);
1076
            }
1077
        }
1078

    
1079
        if (isset($typeDesignation)){
1080
            $title = $type_label . ' for: ' . $typeDesignation->typifiedNames;
1081
        }else{
1082
            $title = $type_label;
1083
        }
1084

    
1085
        $items['data'] = $title;
1086

    
1087
        $groups = array();
1088
        $items['children'] = $groups;
1089
        $children_items = array();
1090
        // --- add initialized fields
1091
        foreach (get_object_vars($specimen_or_observation) as $field => $value) {
1092
            $child_item = array();
1093

    
1094
            if (!in_array($field, $exclude_occurrence_fields) && ($value && (!is_object($value) || isset($value->class)))) {
1095
                switch ($field) {
1096

    
1097
                    /* ---- SpecimenOrObservationBase --- */
1098
                    case 'derivationEvent':
1099
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 1);
1100
                        break;
1101
                    case 'kindOfUnit':
1102
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 1);
1103
                        break;
1104
                    case 'accessionNumber':
1105
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 0);
1106
                        break;
1107

    
1108
                    case 'preferredStableUri':
1109

    
1110
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), array(array('#markup' => cdm_external_uri($value, false))));
1111
                        break;
1112

    
1113
                    case 'specimenTypeDesignations':
1114
                        @_description_list_group_add(
1115
                            $groups,
1116
                            cdm_occurrence_field_name_label($field),
1117
                            array(
1118
                                '#markup' => theme('cdm_typedesignations', array('typeDesignations' => $value)),
1119
                            )
1120
                        );
1121
                        break;
1122

    
1123

    
1124

    
1125
                    case 'listOfMedia':
1126
                        $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
1127

    
1128
                        $captionElements = array(
1129
                            'title',
1130
                            '#uri' => t('open media'),
1131
                        );
1132
                        $gallery_html = compose_cdm_media_gallerie(array(
1133
                            'mediaList' => $value,
1134
                            'galleryName' => $specimen_or_observation->uuid,
1135
                            'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
1136
                            'cols' => $gallery_settings['cdm_dataportal_media_cols'],
1137
                            'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
1138
                            'captionElements' => $captionElements,
1139
                            'mediaLinkType' => 'LIGHTBOX',
1140
                            'alternativeMediaUri' => NULL,
1141
                            'galleryLinkUri' => NULL,
1142
                            'showCaption' => true
1143
                        ));
1144

    
1145
                         //@_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $gallery_html);
1146
                         break;
1147

    
1148

    
1149

    
1150
                    /* ---- DerivedUnitBase --- */
1151

    
1152

    
1153
                    case 'collectionDTO':
1154

    
1155
                        $sub_dl_groups = array();
1156
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('code'), $value->code, NULL, 1);
1157
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('codeStandard'), $value->codeStandard, NULL, 2);
1158
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('institute'), $value->institute, NULL, 3);
1159
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('townOrLocation'), $value->townOrLocation, NULL, 4);
1160
                        // TODO "superCollection"
1161
                        // TODO may have media
1162

    
1163
                        @_description_list_group_add($groups, 'Collection',
1164
                            array(
1165
                                array('#markup' => $value->titleCache),
1166
                                array('#theme' => 'description_list', '#groups' => $sub_dl_groups)
1167
                            )
1168
                        );
1169

    
1170
                        break;
1171

    
1172

    
1173

    
1174

    
1175
                    /* ---- Specimen --- */
1176
                    case 'sequences':
1177
                        $dd_elements = array();
1178
                        foreach ($value as $sequence) {
1179
                            $dd_elements[] = compose_cdm_sequence($sequence, true);
1180
                            $dd_elements[] = "";
1181
                        }
1182
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements,'', 100);
1183
                        break;
1184

    
1185
                    // TODO preservation
1186
                    // TODO exsiccatum
1187

    
1188

    
1189
                    /* ---- FieldObservation --- */
1190
                    case 'gatheringEvent':
1191

    
1192
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collector'), $value->collector);
1193
                        @_description_list_group_add($groups, t('Gathering date'), timePeriodToString($value->timeperiod));
1194
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('description'), $value->description);
1195
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('locality'), $value->locality, '', 10);
1196
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('country'), $value->country);
1197
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingMethod'), $value->collectingMethod);
1198
                        if (isset($value->absoluteElevation)) {
1199
                            $min_max_markup = min_max_measure($value, 'absoluteElevation');
1200
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('absoluteElevation'), $min_max_markup);
1201
                        }
1202
                        if (isset($value->distanceToGround) && $value->distanceToGround >0) {
1203
                            $min_max_markup = min_max_measure($value, 'distanceToGround');
1204
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToGround'), $min_max_markup);
1205
                        }
1206
                        if (isset($value->distanceToWaterSurface) && $value->distanceToWaterSurface > 0) {
1207
                            $min_max_markup = min_max_measure($value, 'distanceToWaterSurface');
1208
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToWaterSurface'), $min_max_markup);
1209
                        }
1210

    
1211
                        if (isset($value->collectingAreas)) {
1212
                            $area_representations = array();
1213
                            foreach ($value->collectingAreas as $area) {
1214
                               // $area_representations[] = l($area->representation_L10n, path_to_named_area($area->uuid));
1215
                                $area_representations[] = $area;
1216
                            }
1217
                            if (!empty($area_representations))
1218
                                @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingAreas'),
1219
                                    array(
1220
                                        array('#markup' => implode(', ', $area_representations))
1221
                                    )
1222
                                );
1223
                        }
1224
                        if (isset($value->exactLocation)  ) {
1225
                            $sub_dl_groups = array();
1226
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('errorRadius'), $value->exactLocation->errorRadius, ' m', 1);
1227
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('longitude'), round($value->exactLocation->longitude, 7), '°', 2);
1228
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('latitude'), round($value->exactLocation->latitude, 7), '°', 3);
1229
                            if (isset($value->exactLocation->referenceSystem)) {
1230
                                @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('referenceSystem'), $value->exactLocation->referenceSystem->representation_L10n, '', 4);
1231
                            }
1232
                            if ( isSet($value->exactLocation->sexagesimalString)){
1233
                                @_description_list_group_add($groups, cdm_occurrence_field_name_label('exactLocation'),
1234
                                    array(
1235
                                        array('#markup' => $value->exactLocation->sexagesimalString),
1236
                                        array(
1237
                                            '#theme' => 'description_list',
1238
                                            '#groups' => $sub_dl_groups
1239
                                        ),
1240
                                    ), '', 11
1241
                                );
1242
                            }
1243
                        }
1244

    
1245
                        break;
1246

    
1247
                    /* ---- DerivationEvent --- */
1248
                    case 'derivationEvents':
1249
                        //@_description_list_group_add($groups, t('Association type'), $value->description);
1250
                        break;
1251
                    case 'determinedNames':
1252
                        $dd_elements = array();
1253
                        foreach ($value as $name) {
1254
                            $taxon_name = cdm_ws_get(CDM_WS_NAME, $name->key);
1255
                            $taxon_name->taggedName = cdm_ws_get(CDM_WS_NAME, array($name->key, "taggedName"));
1256
                            $name_link = path_to_name($name->key);
1257

    
1258
                            //$taxon_html = render_taxon_or_name($taxon_name, $name_link);
1259
                            $taxon_html = l($taxon_name->titleCache, $name_link, array('attributes' => array('target' => '_blank')));
1260
                            $dd_elements[] = $taxon_html;
1261
                        }
1262
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label("Identification(s)"), $dd_elements,'', 100);
1263
                        break;
1264

    
1265

    
1266
                    default:
1267
                        if (is_object($value) || is_array($value)) {
1268
                            drupal_set_message("Unhandled type in compose_cdm_specimenOrObservation() for field " . $field, "warning");
1269
                        } else {
1270
                            _description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value);
1271
                        }
1272

    
1273
                }
1274

    
1275

    
1276
            }
1277
        } // END of loop over $derivedUnitFacade fields
1278

    
1279

    
1280

    
1281
        // template_preprocess_description_list() is not worting by weight so we do it right here
1282
        uasort($groups, 'element_sort');
1283

    
1284
        $occurrence_elements = array(
1285
           // '#title' => $title,
1286
            '#theme' => 'description_list',
1287
            '#groups' => $groups,
1288
            '#attributes' => array('class' => html_class_attribute_ref($specimen_or_observation)),
1289
        );
1290
        $output = drupal_render($occurrence_elements);
1291
        if (isset($gallery_html)){
1292
            $output .= $gallery_html;
1293
        }
1294
        $pathToSpecimen = path_to_specimen($specimen_or_observation->uuid);
1295
        $output .=  l("Detail page", $pathToSpecimen, array('attributes' => array('target' => '_blank')));
1296
    } // END of $specimenOrObservation exists
1297

    
1298
    return $output;
1299
}
1300

    
1301
function compose_table_of_blast_result(array $data){
1302
   // get icon images
1303
  $expand_icon = font_awesome_icon_markup(
1304
      'fa-plus-square-o',
1305
      array(
1306
          'alt' => 'Show details',
1307
          'class' => array('expand_icon')
1308
      )
1309
  );
1310
  $collapse_icon = font_awesome_icon_markup(
1311
      'fa-minus-square-o',
1312
      array(
1313
          'alt' => 'Show details',
1314
          'class' => array('collapse_icon')
1315
      )
1316
  );
1317
  //$detail_image_icon = '<img title="Detail Image" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/detail_image_derivate-16x16-32.png' . '"/>';
1318
    $rowcount = 0;
1319
    $rows = array();
1320

    
1321
    foreach ($data as $row_data){
1322
        $pathToSpecimen = path_to_specimen_by_accession_number($row_data['id']);
1323
        $specimenPageLink = l($row_data['id'], $pathToSpecimen, array('attributes' => array('target' => '_blank')));
1324

    
1325
        $rows[] =  array(
1326
            'data' => array(
1327
                array(
1328
                    'data' => $expand_icon . $collapse_icon,
1329
                    'class' => array('summary_row_cell', 'summary_row_icon', 'expand_column')
1330
                ),
1331
                array(
1332
                    'data' => $row_data['def'],
1333
                ),
1334
                array(
1335
                    'data' => $specimenPageLink,
1336
                ),
1337
                array(
1338
                    'data' => $row_data['hsp_align_length'],
1339
                ),
1340
                array(
1341
                   'data' => $row_data['hsp_identity'],
1342
                ),
1343
                array(
1344
                    'data' => $row_data['hsp_identity']/$row_data['hsp_align_length']*100,
1345
                )
1346
            ),
1347
            'id' => 'blast_summary' . $rowcount, // summary row id
1348
            'class' => array('summary_row'),
1349
        );
1350
        $detail_html = "";
1351

    
1352
        $detail_html .= create_label("Details") . $row_data["hsp_align_length"] . "<br>";
1353

    
1354

    
1355
        $detail_html .= "<br>";
1356
        $detail_html .= $row_data["hsp_midline"];
1357

    
1358
        //$detail_html .= "<br>";
1359

    
1360
        $rows[] = array(
1361
            'data' => array(
1362
                array(
1363
                    'data' => "", //empty first column
1364
                    'class' => array('expand_column')
1365
                ),
1366
                array(
1367
                    'data' => $detail_html,
1368
                    'colspan' => 5,
1369
                ),
1370
            ),
1371
            'id' => 'blast_detail' . $rowcount,//details row ID
1372
            'class' => array('detail_row'),
1373
        );
1374
        $rowcount++;
1375
    }
1376

    
1377
    $tableId = "blast_result_table";
1378
    $blast_result_table = array(
1379
        "#theme" => "table",
1380
        "#weight" => 2,
1381
        "#header" => array(
1382
            array(
1383
                'data' => "",
1384
                'class' => array('expand_column')
1385
            ),
1386
                        "Name", "Accession Number", "Align Length", "Identity", "% Identity"),
1387
        "#rows" => $rows,
1388
        "#attributes" => array(
1389
            "id" => $tableId,
1390
            "border" => 2
1391
        )
1392
    );
1393

    
1394
    drupal_add_js_rowToggle("#".$tableId);
1395

    
1396
    $render_array[$tableId] = $blast_result_table;
1397
    $out = drupal_render($render_array);
1398
   //$blast_result_page-> content = drupal_render($render_array);
1399
   return $out;
1400
}
1401

    
Add picture from clipboard (Maximum size: 40 MB)