Project

General

Profile

Download (56.7 KB) Statistics
| Branch: | Tag: | Revision:
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
                            } @_description_list_group_add($groups, t('Derivates') . ':',
593
                                $derived_units,
594
                                    '', 100);
595

    
596
                        }
597
                        break;
598

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

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

    
616
                    case 'storedUnder':
617
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('storedUnder'), render_taxon_or_name($value));
618
                        break;
619

    
620

    
621
                    /* ---- Specimen --- */
622
                    case 'sequences':
623
                        $dd_elements = array();
624
                        foreach ($value as $sequence) {
625
                            $dd_elements[] = compose_cdm_sequence($sequence);
626
                        }
627
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
628
                        break;
629

    
630
                    // TODO preservation
631
                    // TODO exsiccatum
632

    
633

    
634
                    /* ---- FieldObservation --- */
635
                    case 'gatheringEvent':
636
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collector'), $value->actor->titleCache, '', 1);
637
                        @_description_list_group_add($groups, t('Gathering date'), timePeriodToString($value->timeperiod), '', 2);
638
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('description'), $value->description, '', 3);
639
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('locality'), $value->locality->text, '', 10);
640
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('country'), $value->country->representation_L10n, '', 4);
641
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingMethod'), $value->collectingMethod,'',5);
642
                        if (isset($value->absoluteElevation)) {
643
                            $min_max_markup = min_max_measure($value, 'absoluteElevation');
644
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('absoluteElevation'), $min_max_markup, '',6);
645
                        }
646
                        if (isset($value->distanceToGround)) {
647
                            $min_max_markup = min_max_measure($value, 'distanceToGround');
648
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToGround'), $min_max_markup,'',7);
649
                        }
650
                        if (isset($value->distanceToWaterSurface)) {
651
                            $min_max_markup = min_max_measure($value, 'distanceToWaterSurface');
652
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToWaterSurface'), $min_max_markup, '',8);
653
                        }
654
                        if (isset($value->collectingAreas) && count($value->collectingAreas) > 0) {
655
                            $area_representations = array();
656
                            foreach ($value->collectingAreas as $area) {
657
                                $area_representations[] = l($area->representation_L10n, path_to_named_area($area->uuid));
658
                            }
659
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingAreas'),
660
                                array(
661
                                    array('#markup' => implode(', ', $area_representations))
662
                                ),'',9
663
                            );
664
                        }
665
                        if (isset($value->exactLocation) && $value->exactLocation->sexagesimalString) {
666
                            $sub_dl_groups = array();
667
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('errorRadius'), $value->exactLocation->errorRadius, ' m', 1);
668
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('longitude'), round($value->exactLocation->longitude, 7), '°', 2);
669
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('latitude'), round($value->exactLocation->latitude, 7), '°', 3);
670
                            if (isset($value->exactLocation->referenceSystem)) {
671
                                @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('referenceSystem'), $value->exactLocation->referenceSystem->representation_L10n, '', 4);
672
                            }
673

    
674
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('exactLocation'),
675
                                array(
676
                                    array('#markup' => $value->exactLocation->sexagesimalString),
677
                                    array(
678
                                        '#theme' => 'description_list',
679
                                        '#groups' => $sub_dl_groups
680
                                    ),
681
                                ),'',11
682
                            );
683
                        }
684
                        break;
685

    
686
                    default:
687
                        if (is_object($value) || is_array($value)) {
688
                            drupal_set_message("Unhandled type in compose_cdm_specimen_or_observation() for field " . $field, "warning");
689
                        } else {
690
                            _description_list_group_add($groups, cdm_occurrence_field_name_label($field), cdm_occurrence_field_name_label($value));
691
                        }
692

    
693
                }
694

    
695
            }
696
        } // END of loop over $derivedUnitFacade fields
697

    
698
        // Extensions
699
        $extensions = cdm_ws_fetch_all(CDM_WS_PORTAL_OCCURRENCE . '/'  . $specimen_or_observation->uuid . '/extensions', array($specimen_or_observation->uuid));
700
        if ($extensions && count($extensions)) {
701

    
702
            $extensions_render_array = compose_extensions($extensions);
703
            @_description_list_group_add($groups, t('Extensions') . ':',
704
                $extensions_render_array,
705
                '', 100);
706
        }
707

    
708

    
709

    
710
        // template_preprocess_description_list() is not worting by weight so we do it right here
711
        uasort($groups, 'element_sort');
712

    
713
        $occurrence_elements = array(
714
           // '#title' => $title,
715
            '#theme' => 'description_list',
716
            '#groups' => $groups,
717
            '#attributes' => array('class' => html_class_attribute_ref($specimen_or_observation)),
718
        );
719

    
720
        $derivatives[] = drupal_render($occurrence_elements);
721
        // all footnotes which has been assembled so far (e.g. from typeDesignations) to here
722
//       $foonote_li_elements = theme('cdm_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey(), 'enclosingTag' => 'span'));
723
//        if (!empty($foonote_li_elements)) {
724
//            $derivatives[] =  array(
725
//                '#markup' =>  '<div class="footnotes">' . $foonote_li_elements . '</div>',
726
//            );
727
//        }
728

    
729
        // --- recurse into originals
730
        if (!isset($derivedFrom)  && !$isSpecimen_page) {
731
            $derivedFrom = cdm_ws_get(
732
                CDM_WS_OCCURRENCE,
733
                array($specimen_or_observation->uuid, 'derivedFrom')
734
            );
735
        }
736
        if (isset($derivedFrom) && !$isSpecimen_page) {
737
            if (isset($derivedFrom->originals)) {
738
                $derived_from_label = t('derived');
739
                $preposition = t('from');
740
                if(isset($derivedFrom->type)){
741
                    $derived_from_label = $derivedFrom->type->representation_L10n;
742
                    if($derivedFrom->type->uuid == UUID_DERIVATIONEVENTTYPE_ACCESSIONING){
743
                        $preposition = t('of');
744
                    }
745
                }
746
                if (count($groups) > 0) {
747
                    // TODO  annotations
748

    
749
                    // only display the derived from information when the derivative has any element which will be diplayed
750
                    $derivatives[] = array(
751
                        '#markup' => '<div class="derived_from">' . $derived_from_label . ' ' . $preposition . ': </div>',
752
                    );
753
                }
754
                foreach ($derivedFrom->originals as $original) {
755
                    compose_cdm_specimen_or_observation($original, $isSpecimen_page, $derivatives);
756
                }
757
            }
758
        }
759

    
760

    
761

    
762

    
763
    } // END of $specimenOrObservation exists
764

    
765
    return $derivatives;
766
}
767

    
768

    
769
/**
770
 * Compose an render array from a CDM Sequence object.
771
 *
772
 * compose_hook() implementation
773
 *
774
 * @param object $sequence
775
 *   CDM instance of type Sequence
776
 * @return array
777
 *   A render array containing the fields of the supplied $sequence
778
 *
779
 * @ingroup compose
780
 */
781
function compose_cdm_sequence($sequence, $isSpecimenPage = false)
782
{
783

    
784
    $exclude_sequence_fields = &drupal_static(__FUNCTION__);
785
    if (!isset($exclude_sequence_fields)) {
786
        $exclude_sequence_fields = array(
787
            'titleCache',
788
            'protectedTitleCache',
789
            'microReference',
790
            'created',
791
            'updated',
792
            'class',
793
        );
794
    }
795

    
796
    $groups = array();
797

    
798
    // -- retrieve additional data if neesscary
799
    // TODO below call disabled since sequences are not yet supported,
800
    //      see  #3347 (services and REST service controller for molecular classes implemented)
801
    //
802
    // cdm_load_annotations($sequence);
803

    
804
    foreach (get_object_vars($sequence) as $field => $value) {
805

    
806

    
807
        if (!in_array($field, $exclude_sequence_fields) && ($value && (!is_object($value) || isset($value->class)))) {
808
            switch ($field) {
809

    
810
                case 'geneticAccessionNumber';
811

    
812
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 2);
813
                    break;
814

    
815

    
816
                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.
817
                    if (isset($value->name)) {
818
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value->name, NULL, 3);
819
                    }
820
                    if (isset($value->description)) {
821
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field) . ' ' . t('description'), $value->description, NULL, 4);
822
                    }
823
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field) , $value, NULL, 4);
824
                    break;
825

    
826
                case 'consensusSequence':
827
                    // format in genbank style, force linebreaks after each 70 nucleotites
828
                    // see also http://stackoverflow.com/questions/499137/css-how-can-i-force-a-long-string-without-any-blank-to-be-wrapped-in-xul-and
829
                    if ($value->length > 0) {
830
                        @_description_list_group_add(
831
                            $groups,
832
                            cdm_occurrence_field_name_label($field),
833
                            array(
834
                                array(
835
                                    '#markup' => '<div class="sequence-length">' . $value->length . ' ' . t('pb') . '</div><div>' . wordwrap($value->string, 70, '</br>', TRUE) . '</div>',
836
                                    '#wrapper_attributes' => array('class' => 'dna-sequence')
837
                                )
838
                            ),
839
                            5);
840
                    }
841
                    break;
842

    
843
                case 'dnaSample': // FIXME 3.3 implement
844
                    break;
845
                case 'singleReads': // FIXME 3.3 implement
846
                    break;
847
                case 'contigFile': // FIXME 3.3 implement - Media
848
                    break;
849
                case 'pherograms': // FIXME 3.3 implement - Media
850
                    break;
851
                case 'haplotype': // FIXME 3.3 implement
852
                    break;
853
                case 'dateSequenced': // FIXME 3.3 now in SingelRead
854
                    @_description_list_group_add($groups, t('Sequencing date'), timePeriodToString($value), NULL, 6);
855
                    break;
856

    
857
                case 'barcode': // boolean
858
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value ? 'Yes' : 'No', NULL, 7);
859
                    break;
860
                case 'barcodeSequencePart': // FIXME 3.3 implement, compose sequence
861
                    break;
862

    
863
                case 'citation':
864
                    @_description_list_group_add($groups,
865
                        cdm_occurrence_field_name_label($field),
866
                        theme('cdm_reference', array('reference' => $value, 'microReference' => $sequence->microReference)),
867
                        NULL,
868
                        8
869
                    );
870
                    break;
871

    
872
                case 'publishedIn':
873
                    @_description_list_group_add($groups,
874
                        cdm_occurrence_field_name_label($field),
875
                        theme('cdm_reference', array('reference' => $value)),
876
                        NULL,
877
                        7
878
                    );
879
                    break;
880

    
881
                case 'rights':
882
                    array_merge($groups, cdm_rights_as_dl_groups($value));
883
                    break;
884

    
885
                case 'annotations':
886
                    $dd_elements = array();
887
                    foreach ($value as $annotation) {
888
                        // TODO respect annotation type filter settings
889
                        $dd_elements[] = $annotation->text;
890
                    }
891
                    @_description_list_group_add($groups, t('Notes'), $dd_elements, NULL, 9);
892
                    break;
893

    
894
                case 'markers':
895
                    $dd_elements = array();
896
                    foreach ($value as $marker) {
897
                        $dd_elements[] = compose_cdm_marker($marker);
898
                    }
899
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements, NULL, 10);
900
                    break;
901

    
902
                case 'chromatograms':
903
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),
904
                        array(
905
                            '#markup' => compose_cdm_media_gallerie(array('medialist' => $value)),
906
                        ),
907
                        NULL,
908
                        11);
909
                    break;
910

    
911
                default:
912
                    if (is_object($value) || is_array($value)) {
913
                        drupal_set_message("Unhandled type in compose_cdm_sequence() for field " . $field, "warning");
914
                    } else {
915
                        if (!is_array($value) && strpos($value, 'http:') !== false ){
916
                            //make links for urls
917
                            $value = l($value, $value, array('attributes' => array('target' => '_blank')));
918
                            $value = markup_to_render_array($value);
919
                        }
920

    
921
                       _description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 20);
922
                    }
923
            }
924
        }
925
    }
926

    
927
    // template_preprocess_description_list() is not worting by weight so we do it right here
928
    uasort($groups, 'element_sort');
929
    if ($isSpecimenPage) {
930
        $sequence_elements = array(
931
            '#title' => $sequence->dnaMarker,
932
            '#theme' => 'description_list',
933
            '#groups' => $groups
934
        );
935
    } else{
936
        $sequence_elements = array(
937
            '#title' => $sequence->dnaMarker -> titleCache,
938
            '#theme' => 'description_list',
939
            '#groups' => $groups
940
        );
941
    }
942

    
943
    return $sequence_elements;
944
}
945
/**
946
 * Creates an array from a list of FieldUnitDTOs.
947
 *
948
 *
949
 * @param object $specimenOrObservations
950
 *   list of FieldUnitDTOs
951
 * @return array
952
 *   An array containing the hierarchy of the field units corresponding to the taxon
953
 *
954
 * @ingroup compose
955
 */
956
function compose_specimen_array(array $specimenOrObservations){
957
    $items_specimen = array();
958
    $items = array();
959

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

    
963
        $items['data'] = $specimenOrObservation->listLabel ;
964
        $specimen = compose_cdm_specimen_or_observation_tree_entry($specimenOrObservation);
965
        $children = array();
966
        $child = array();
967
        $child['data'] =$specimen;
968
       // $children[] = create_specimen_array($specimenOrObservation->derivates);
969
       if (isset($specimenOrObservation->derivates) && sizeof($specimenOrObservation->derivates) > 0){
970
           $child['children']= compose_specimen_array($specimenOrObservation->derivates);
971
       }
972
       $children[]=$child;
973
       $items['children'] = $children;
974
       $items_specimen[] = $items;
975
    }
976
    return $items_specimen;
977
}
978

    
979

    
980
/**
981
 * Compose an render array from a CDM DerivedUnitFacade object.
982
 *
983
 * compose_hook() implementation
984
 *
985
 * @param object $specimenOrObservation
986
 *   the CDM instance of type SpecimenOrObservation to compose
987
 *   the render array for
988
 * @param array $derivatives
989
 *   the render array which contains the compositions of the derivatives
990
 *   of the supplied $specimenOrObservation
991
 *
992
 * @return array
993
 *   the supplied render array $derivatives to which the composition of the supplied
994
 *   $specimenOrObservation has been added to
995
 *
996
 * @ingroup compose
997
 */
998

    
999
function compose_cdm_specimen_or_observation_tree_entry($specimen_or_observation)
1000
{
1001
    $exclude_occurrence_fields = &drupal_static(__FUNCTION__);
1002
    if (!isset($exclude_occurrence_fields)) {
1003
        $exclude_occurrence_fields = array(
1004
            'type',
1005
            'taxonRelatedDerivedUnits',
1006
            'label',
1007
            'titleCache',
1008
            'listLabel',
1009
            'protectedTitleCache',
1010
            'class',
1011
            'uuid',
1012
            'derivates',
1013
            'collection'
1014
        );
1015
    }
1016
    $items = array();
1017

    
1018
    // only show uuid it the user is logged in
1019
    if (user_is_logged_in() && ($a_idx = array_search('uuid', $exclude_occurrence_fields)) !== FALSE) {
1020
      //  unset($exclude_occurrence_fields[$a_idx]);
1021
    }
1022

    
1023

    
1024
    if (is_object($specimen_or_observation)) {
1025

    
1026
        $type_label = $specimen_or_observation->recordBase;
1027
        RenderHints::setFootnoteListKey($type_label . '-' . $specimen_or_observation->uuid);
1028

    
1029
        // collect typeStatus as label
1030
        if (isset($specimen_or_observation->specimenTypeDesignations)) {
1031
            $type_status = array();
1032
            foreach ($specimen_or_observation->specimenTypeDesignations as $typeDesignation) {
1033
                if (isset($typeDesignation->typeStatus->representation_L10n)) {
1034
                    $type_status[] = $typeDesignation->typeStatus->representation_L10n;
1035
                }
1036
            }
1037
            if (count($type_status) > 0) {
1038
                $type_label = implode(', ', $type_status);
1039
            }
1040
        }
1041

    
1042
        if (isset($typeDesignation)){
1043
            $title = $type_label . ' for: ' . $typeDesignation->typifiedNames;
1044
        }else{
1045
            $title = $type_label;
1046
        }
1047

    
1048
        $items['data'] = $title;
1049

    
1050
        $groups = array();
1051
        $items['children'] = $groups;
1052
        $children_items = array();
1053
        // --- add initialized fields
1054
        foreach (get_object_vars($specimen_or_observation) as $field => $value) {
1055
            $child_item = array();
1056

    
1057
            if (!in_array($field, $exclude_occurrence_fields) && ($value && (!is_object($value) || isset($value->class)))) {
1058
                switch ($field) {
1059

    
1060
                    /* ---- SpecimenOrObservationBase --- */
1061
                    case 'derivationEvent':
1062
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 1);
1063
                        break;
1064
                    case 'kindOfUnit':
1065
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 1);
1066
                        break;
1067

    
1068

    
1069
                    case 'preferredStableUri':
1070

    
1071
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), array(array('#markup' => cdm_external_uri($value, false))));
1072
                        break;
1073

    
1074
                    case 'specimenTypeDesignations':
1075
                        @_description_list_group_add(
1076
                            $groups,
1077
                            cdm_occurrence_field_name_label($field),
1078
                            array(
1079
                                '#markup' => theme('cdm_typedesignations', array('typeDesignations' => $value)),
1080
                            )
1081
                        );
1082
                        break;
1083

    
1084

    
1085

    
1086
                    case 'listOfMedia':
1087
                        $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
1088

    
1089
                        $captionElements = array(
1090
                            'title',
1091
                            '#uri' => t('open media'),
1092
                        );
1093
                        $gallery_html = compose_cdm_media_gallerie(array(
1094
                            'mediaList' => $value,
1095
                            'galleryName' => $specimen_or_observation->label,
1096
                            'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
1097
                            'cols' => $gallery_settings['cdm_dataportal_media_cols'],
1098
                            'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
1099
                            'captionElements' => $captionElements,
1100
                            'mediaLinkType' => 'LIGHTBOX',
1101
                            'alternativeMediaUri' => NULL,
1102
                            'galleryLinkUri' => NULL,
1103
                            'showCaption' => true
1104
                        ));
1105

    
1106
                         //@_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $gallery_html);
1107
                         break;
1108

    
1109

    
1110

    
1111
                    /* ---- DerivedUnitBase --- */
1112

    
1113

    
1114
                    case 'collectionDTO':
1115

    
1116
                        $sub_dl_groups = array();
1117
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('code'), $value->code, NULL, 1);
1118
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('codeStandard'), $value->codeStandard, NULL, 2);
1119
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('institute'), $value->institute, NULL, 3);
1120
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('townOrLocation'), $value->townOrLocation, NULL, 4);
1121
                        // TODO "superCollection"
1122
                        // TODO may have media
1123

    
1124
                        @_description_list_group_add($groups, 'Collection',
1125
                            array(
1126
                                array('#markup' => $value->titleCache),
1127
                                array('#theme' => 'description_list', '#groups' => $sub_dl_groups)
1128
                            )
1129
                        );
1130

    
1131
                        break;
1132

    
1133

    
1134

    
1135

    
1136
                    /* ---- Specimen --- */
1137
                    case 'sequences':
1138
                        $dd_elements = array();
1139
                        foreach ($value as $sequence) {
1140
                            $dd_elements[] = compose_cdm_sequence($sequence, true);
1141
                            $dd_elements[] = "";
1142
                        }
1143
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements,'', 100);
1144
                        break;
1145

    
1146
                    // TODO preservation
1147
                    // TODO exsiccatum
1148

    
1149

    
1150
                    /* ---- FieldObservation --- */
1151
                    case 'gatheringEvent':
1152

    
1153
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collector'), $value->collector);
1154
                        @_description_list_group_add($groups, t('Gathering date'), timePeriodToString($value->timeperiod));
1155
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('description'), $value->description);
1156
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('locality'), $value->locality, '', 10);
1157
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('country'), $value->country);
1158
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingMethod'), $value->collectingMethod);
1159
                        if (isset($value->absoluteElevation)) {
1160
                            $min_max_markup = min_max_measure($value, 'absoluteElevation');
1161
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('absoluteElevation'), $min_max_markup);
1162
                        }
1163
                        if (isset($value->distanceToGround) && $value->distanceToGround >0) {
1164
                            $min_max_markup = min_max_measure($value, 'distanceToGround');
1165
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToGround'), $min_max_markup);
1166
                        }
1167
                        if (isset($value->distanceToWaterSurface) && $value->distanceToWaterSurface > 0) {
1168
                            $min_max_markup = min_max_measure($value, 'distanceToWaterSurface');
1169
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToWaterSurface'), $min_max_markup);
1170
                        }
1171

    
1172
                        if (isset($value->collectingAreas)) {
1173
                            $area_representations = array();
1174
                            foreach ($value->collectingAreas as $area) {
1175
                               // $area_representations[] = l($area->representation_L10n, path_to_named_area($area->uuid));
1176
                                $area_representations[] = $area;
1177
                            }
1178
                            if (!empty($area_representations))
1179
                                @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingAreas'),
1180
                                    array(
1181
                                        array('#markup' => implode(', ', $area_representations))
1182
                                    )
1183
                                );
1184
                        }
1185
                        if (isset($value->exactLocation)  ) {
1186
                            $sub_dl_groups = array();
1187
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('errorRadius'), $value->exactLocation->errorRadius, ' m', 1);
1188
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('longitude'), round($value->exactLocation->longitude, 7), '°', 2);
1189
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('latitude'), round($value->exactLocation->latitude, 7), '°', 3);
1190
                            if (isset($value->exactLocation->referenceSystem)) {
1191
                                @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('referenceSystem'), $value->exactLocation->referenceSystem->representation_L10n, '', 4);
1192
                            }
1193
                            if ( isSet($value->exactLocation->sexagesimalString)){
1194
                                @_description_list_group_add($groups, cdm_occurrence_field_name_label('exactLocation'),
1195
                                    array(
1196
                                        array('#markup' => $value->exactLocation->sexagesimalString),
1197
                                        array(
1198
                                            '#theme' => 'description_list',
1199
                                            '#groups' => $sub_dl_groups
1200
                                        ),
1201
                                    ), '', 11
1202
                                );
1203
                            }
1204
                        }
1205

    
1206
                        break;
1207

    
1208
                    /* ---- DerivationEvent --- */
1209
                    case 'derivationEvents':
1210
                        //@_description_list_group_add($groups, t('Association type'), $value->description);
1211
                        break;
1212

    
1213

    
1214
                    default:
1215
                        if (is_object($value) || is_array($value)) {
1216
                            drupal_set_message("Unhandled type in compose_cdm_specimenOrObservation() for field " . $field, "warning");
1217
                        } else {
1218
                            _description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value);
1219
                        }
1220

    
1221
                }
1222

    
1223

    
1224
            }
1225
        } // END of loop over $derivedUnitFacade fields
1226

    
1227

    
1228

    
1229
        // template_preprocess_description_list() is not worting by weight so we do it right here
1230
        uasort($groups, 'element_sort');
1231

    
1232
        $occurrence_elements = array(
1233
           // '#title' => $title,
1234
            '#theme' => 'description_list',
1235
            '#groups' => $groups,
1236
            '#attributes' => array('class' => html_class_attribute_ref($specimen_or_observation)),
1237
        );
1238
        $output = drupal_render($occurrence_elements);
1239
        if (isset($gallery_html)){
1240
            $output .= $gallery_html;
1241
        }
1242
        $pathToSpecimen = path_to_specimen($specimen_or_observation->uuid);
1243
        $output .=  l("detail page", $pathToSpecimen, array('attributes' => array('target' => '_blank')));
1244
    } // END of $specimenOrObservation exists
1245

    
1246
    return $output;
1247
}
1248

    
1249
function compose_table_of_blast_result(array $data){
1250

    
1251
    foreach ($data as $row_data){
1252
        $pathToSpecimen = path_to_specimen_by_accession_number($row_data['id']);
1253
        $specimenPageLink = l($row_data['id'], $pathToSpecimen, array('attributes' => array('target' => '_blank')));
1254

    
1255
        $rows[] =  array(
1256
            'data' => array(
1257
                array(
1258
                    'data' => $row_data['def'],
1259
                ),
1260
                array(
1261
                    'data' => $specimenPageLink,
1262
                ),
1263
                array(
1264
                    'data' => $row_data['hsp_align_length'],
1265
                ),
1266
              //  array(
1267
              //     'data' => $row_data['midline'],
1268
              //  ),
1269
                array(
1270
                    'data' => $row_data['hsp_evalue'],
1271
                )
1272
            )
1273
        );
1274
    }
1275
    $tableId = "blast_result_table";
1276
    $blast_result_table = array(
1277
        "#theme" => "table",
1278
        "#weight" => 2,
1279
        "#header" => array(
1280
                        "Name", "id", "Align Length", "e Value"),
1281
        "#rows" => $rows,
1282
        "#attributes" => array(
1283
            "id" => $tableId,
1284
            "border" => 2
1285
        )
1286
    );
1287

    
1288
    drupal_add_js_rowToggle("#".$tableId);
1289

    
1290
    $render_array['content'] = $blast_result_table;
1291
    $out = drupal_render($render_array);
1292
   //$blast_result_page-> content = drupal_render($render_array);
1293
   return $out;
1294
}
1295

    
1296

    
1297

    
(6-6/10)