Project

General

Profile

Download (63.2 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

    
479
                                $taxon_html = l($taxon_name->titleCache, $name_link, array('attributes' => array('target' => '_blank')));
480
                                $dd_elements[$weight] = $taxon_html;
481
                            }
482
                            if (isset($determinationEvent->modifier)) {
483
                                $dd_elements[$weight] .= cdm_term_representation($determinationEvent->modifier);
484
                            }
485
                            if ($timeperiod_string) {
486
                                $dd_elements[$weight] .= $glue . $timeperiod_string;
487
                            }
488
                            if (isset($determinationEvent->actor->titleCache)) {
489
                                $dd_elements[$weight] .= $glue . $determinationEvent->actor->titleCache;
490
                            }
491
                            if (isset($determinationEvent->description)) {
492
                                $dd_elements[$weight] .= $glue . $determinationEvent->description;
493
                            }
494
                        }
495
                        ksort($dd_elements);
496
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('determinations'), $dd_elements);
497
                        break;
498

    
499
                    case 'descriptions':
500
                        $occurrence_featureTree = cdm_get_occurrence_featureTree();
501
                        $dd_elements = array();
502

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

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

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

    
536
                        // $dd_elements[] = markup_to_render_array($gallery_html);
537

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

    
556

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

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

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

    
599
                        }
600
                        break;
601

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

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

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

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

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

    
643
                    case 'preservation':
644
                        $sub_dl_groups = array();
645

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

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

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

    
669
                    // TODO preservation
670
                    // TODO exsiccatum
671

    
672

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

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

    
725
                    default:
726
                        if (is_object($value) || is_array($value)) {
727
                            drupal_set_message("Unhandled type in compose_cdm_specimen_or_observation() for field " . $field, "warning");
728
                        } else {
729
                            if ($field == 'RecordBase' && $value == 'DnaSample') {
730
                                _description_list_group_add($groups, cdm_occurrence_field_name_label($field), 'DNA Sample');
731
                            } else {
732
                                _description_list_group_add($groups, cdm_occurrence_field_name_label($field), cdm_occurrence_field_name_label($value));
733
                            }
734
                        }
735

    
736
                }
737

    
738
            }
739
        } // END of loop over $derivedUnitFacade fields
740

    
741
        // Extensions
742
        $extensions = cdm_ws_fetch_all(CDM_WS_PORTAL_OCCURRENCE . '/'  . $specimen_or_observation->uuid . '/extensions', array($specimen_or_observation->uuid));
743
        if ($extensions && count($extensions)) {
744

    
745
            $extensions_render_array = compose_extensions($extensions);
746
            @_description_list_group_add($groups, t('Extensions') . ':',
747
                $extensions_render_array,
748
                '', 100);
749
        }
750

    
751

    
752

    
753
        // template_preprocess_description_list() is not worting by weight so we do it right here
754
        uasort($groups, 'element_sort');
755

    
756
        $occurrence_elements = array(
757
           // '#title' => $title,
758
            '#theme' => 'description_list',
759
            '#groups' => $groups,
760
            '#attributes' => array('class' => html_class_attribute_ref($specimen_or_observation)),
761
        );
762

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

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

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

    
803

    
804

    
805

    
806
    } // END of $specimenOrObservation exists
807

    
808
    return $derivatives;
809
}
810

    
811

    
812
/**
813
 * Compose an render array from a CDM Sequence object.
814
 *
815
 * compose_hook() implementation
816
 *
817
 * @param object $sequence
818
 *   CDM instance of type Sequence
819
 * @return array
820
 *   A render array containing the fields of the supplied $sequence
821
 *
822
 * @ingroup compose
823
 */
824
function compose_cdm_sequence($sequence, $isSpecimenPage = false)
825
{
826

    
827
    $exclude_sequence_fields = &drupal_static(__FUNCTION__);
828
    if (!isset($exclude_sequence_fields)) {
829
        $exclude_sequence_fields = array(
830
            'titleCache',
831
            'protectedTitleCache',
832
            'microReference',
833
            'created',
834
            'updated',
835
            'class',
836
        );
837
    }
838

    
839
    $groups = array();
840

    
841
    // -- retrieve additional data if neesscary
842
    // TODO below call disabled since sequences are not yet supported,
843
    //      see  #3347 (services and REST service controller for molecular classes implemented)
844
    //
845
    // cdm_load_annotations($sequence);
846

    
847
    foreach (get_object_vars($sequence) as $field => $value) {
848

    
849

    
850
        if (!in_array($field, $exclude_sequence_fields) && ($value && (!is_object($value) || isset($value->class)))) {
851
            switch ($field) {
852

    
853
                case 'geneticAccessionNumber';
854

    
855
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 2);
856
                    break;
857

    
858

    
859
                case 'dnaMarker': // FIXME 3.3 now dnaMarker (DefinedTerm)  if multiple amplifications where used to build this consensus sequence it may be the super set of the markers used in amplification.
860
                    if (isset($value->name)) {
861
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value->name, NULL, 3);
862
                    }
863
                    if (isset($value->description)) {
864
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field) . ' ' . t('description'), $value->description, NULL, 4);
865
                    }
866
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field) , $value, NULL, 4);
867
                    break;
868

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

    
886
                case 'dnaSample': // FIXME 3.3 implement
887
                    break;
888
                case 'singleReads': // FIXME 3.3 implement
889
                    break;
890
                case 'contigFile': // FIXME 3.3 implement - Media
891
                    break;
892
                case 'pherograms': // FIXME 3.3 implement - Media
893
                    break;
894
                case 'haplotype': // FIXME 3.3 implement
895
                    break;
896
                case 'dateSequenced': // FIXME 3.3 now in SingelRead
897
                    @_description_list_group_add($groups, t('Sequencing date'), timePeriodToString($value), NULL, 6);
898
                    break;
899

    
900
                case 'barcode': // boolean
901
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value ? 'Yes' : 'No', NULL, 7);
902
                    break;
903
                case 'barcodeSequencePart': // FIXME 3.3 implement, compose sequence
904
                    break;
905

    
906
                case 'citation':
907
                    @_description_list_group_add($groups,
908
                        cdm_occurrence_field_name_label($field),
909
                        theme('cdm_reference', array('reference' => $value, 'microReference' => $sequence->microReference)),
910
                        NULL,
911
                        8
912
                    );
913
                    break;
914

    
915
                case 'publishedIn':
916
                    @_description_list_group_add($groups,
917
                        cdm_occurrence_field_name_label($field),
918
                        theme('cdm_reference', array('reference' => $value)),
919
                        NULL,
920
                        7
921
                    );
922
                    break;
923

    
924
                case 'rights':
925
                    array_merge($groups, cdm_rights_as_dl_groups($value));
926
                    break;
927

    
928
                case 'annotations':
929
                    $dd_elements = array();
930
                    foreach ($value as $annotation) {
931
                        // TODO respect annotation type filter settings
932
                        $dd_elements[] = $annotation->text;
933
                    }
934
                    @_description_list_group_add($groups, t('Notes'), $dd_elements, NULL, 9);
935
                    break;
936

    
937
                case 'markers':
938
                    $dd_elements = array();
939
                    foreach ($value as $marker) {
940
                        $dd_elements[] = compose_cdm_marker($marker);
941
                    }
942
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements, NULL, 10);
943
                    break;
944

    
945
                case 'chromatograms':
946
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),
947
                        array(
948
                            '#markup' => compose_cdm_media_gallerie(array('medialist' => $value)),
949
                        ),
950
                        NULL,
951
                        11);
952
                    break;
953

    
954
                default:
955
                    if (is_object($value) || is_array($value)) {
956
                        drupal_set_message("Unhandled type in compose_cdm_sequence() for field " . $field, "warning");
957
                    } else {
958
                        if (!is_array($value) && strpos($value, 'http:') !== false ){
959
                            //make links for urls
960
                            $value = l($value, $value, array('attributes' => array('target' => '_blank')));
961
                            $value = markup_to_render_array($value);
962
                        }
963

    
964
                       _description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 20);
965
                    }
966
            }
967
        }
968
    }
969

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

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

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

    
1006
        $items['data'] = $specimenOrObservation->listLabel ;
1007
        $specimen = compose_cdm_specimen_or_observation_tree_entry($specimenOrObservation);
1008
        $children = array();
1009
        $child = array();
1010
        $child['data'] =$specimen;
1011
       // $children[] = create_specimen_array($specimenOrObservation->derivates);
1012
       if (isset($specimenOrObservation->derivates) && sizeof($specimenOrObservation->derivates) > 0){
1013
           $child['children']= compose_specimen_array($specimenOrObservation->derivates);
1014
       }
1015
       $children[]=$child;
1016
       $items['children'] = $children;
1017
       $items_specimen[] = $items;
1018
    }
1019
    return $items_specimen;
1020
}
1021

    
1022

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

    
1042
function compose_cdm_specimen_or_observation_tree_entry($specimen_or_observation)
1043
{
1044
    $exclude_occurrence_fields = &drupal_static(__FUNCTION__);
1045
    if (!isset($exclude_occurrence_fields)) {
1046
        $exclude_occurrence_fields = array(
1047
            'type',
1048
            'taxonRelatedDerivedUnits',
1049
            'label',
1050
            'titleCache',
1051
            'listLabel',
1052
            'protectedTitleCache',
1053
            'class',
1054
            'uuid',
1055
            'derivates',
1056
            'collection'
1057
        );
1058
    }
1059
    $items = array();
1060

    
1061
    // only show uuid it the user is logged in
1062
    if (user_is_logged_in() && ($a_idx = array_search('uuid', $exclude_occurrence_fields)) !== FALSE) {
1063
      //  unset($exclude_occurrence_fields[$a_idx]);
1064
    }
1065

    
1066

    
1067
    if (is_object($specimen_or_observation)) {
1068

    
1069
        $type_label = $specimen_or_observation->recordBase;
1070
        RenderHints::setFootnoteListKey($type_label . '-' . $specimen_or_observation->uuid);
1071

    
1072
        // collect typeStatus as label
1073
        if (isset($specimen_or_observation->specimenTypeDesignations)) {
1074
            $type_status = array();
1075
            foreach ($specimen_or_observation->specimenTypeDesignations as $typeDesignation) {
1076
                if (isset($typeDesignation->typeStatus->representation_L10n)) {
1077
                    $type_status[] = $typeDesignation->typeStatus->representation_L10n;
1078
                }
1079
            }
1080
            if (count($type_status) > 0) {
1081
                $type_label = implode(', ', $type_status);
1082
          }
1083
        }
1084

    
1085
        if (isset($typeDesignation->typifiedNames)){
1086
            $title = $type_label . ' for: ' . $typeDesignation->typifiedNames;
1087
        }else{
1088
            $title = $type_label;
1089
        }
1090

    
1091
        $items['data'] = $title;
1092

    
1093
        $groups = array();
1094
        $items['children'] = $groups;
1095
        $children_items = array();
1096
        // --- add initialized fields
1097
        foreach (get_object_vars($specimen_or_observation) as $field => $value) {
1098
            $child_item = array();
1099

    
1100
            if (!in_array($field, $exclude_occurrence_fields) && ($value && (!is_object($value) || isset($value->class)))) {
1101
                switch ($field) {
1102

    
1103
                    /* ---- SpecimenOrObservationBase --- */
1104
                    case 'derivationEvent':
1105
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 1);
1106
                        break;
1107
                    case 'kindOfUnit':
1108
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 1);
1109
                        break;
1110
                    case 'accessionNumber':
1111
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 0);
1112
                        break;
1113

    
1114
                    case 'preferredStableUri':
1115

    
1116
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), array(array('#markup' => cdm_external_uri($value, false))));
1117
                        break;
1118

    
1119
                    case 'specimenTypeDesignations':
1120
                        @_description_list_group_add(
1121
                            $groups,
1122
                            cdm_occurrence_field_name_label($field),
1123
                            array(
1124
                                '#markup' => theme('cdm_typedesignations', array('typeDesignations' => $value)),
1125
                            )
1126
                        );
1127
                        break;
1128

    
1129

    
1130

    
1131
                    case 'listOfMedia':
1132
                        $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
1133

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

    
1151
                         //@_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $gallery_html);
1152
                         break;
1153

    
1154

    
1155

    
1156
                    /* ---- DerivedUnitBase --- */
1157

    
1158

    
1159
                    case 'collectionDTO':
1160

    
1161
                        $sub_dl_groups = array();
1162
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('code'), $value->code, NULL, 1);
1163
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('codeStandard'), $value->codeStandard, NULL, 2);
1164
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('institute'), $value->institute, NULL, 3);
1165
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('townOrLocation'), $value->townOrLocation, NULL, 4);
1166
                        // TODO "superCollection"
1167
                        // TODO may have media
1168

    
1169
                        @_description_list_group_add($groups, 'Collection',
1170
                            array(
1171
                                array('#markup' => $value->titleCache),
1172
                                array('#theme' => 'description_list', '#groups' => $sub_dl_groups)
1173
                            )
1174
                        );
1175

    
1176
                        break;
1177

    
1178

    
1179

    
1180

    
1181
                    /* ---- Specimen --- */
1182
                    case 'sequences':
1183
                        $dd_elements = array();
1184
                        foreach ($value as $sequence) {
1185
                            $dd_elements[] = compose_cdm_sequence($sequence, true);
1186
                            $dd_elements[] = "";
1187
                        }
1188
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements,'', 100);
1189
                        break;
1190

    
1191
                    // TODO preservation
1192
                    // TODO exsiccatum
1193

    
1194

    
1195
                    /* ---- FieldObservation --- */
1196
                    case 'gatheringEvent':
1197

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

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

    
1251
                        break;
1252

    
1253
                    /* ---- DerivationEvent --- */
1254
                    case 'derivationEvents':
1255
                        //@_description_list_group_add($groups, t('Association type'), $value->description);
1256
                        break;
1257
                    case 'determinedNames':
1258
                        $dd_elements = array();
1259
                        foreach ($value as $name) {
1260
                            $taxon_name = cdm_ws_get(CDM_WS_NAME, $name->key);
1261
                            $taxon_name->taggedName = cdm_ws_get(CDM_WS_NAME, array($name->key, "taggedName"));
1262
                            $name_link = path_to_name($name->key);
1263

    
1264
                            //$taxon_html = render_taxon_or_name($taxon_name, $name_link);
1265
                            $taxon_html = l($taxon_name->titleCache, $name_link, array('attributes' => array('target' => '_blank')));
1266
                            $dd_elements[] = $taxon_html;
1267
                        }
1268
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label("Identification(s)"), $dd_elements,'', 100);
1269
                        break;
1270

    
1271

    
1272
                    default:
1273
                        if (is_object($value) || is_array($value)) {
1274
                            drupal_set_message("Unhandled type in compose_cdm_specimenOrObservation() for field " . $field, "warning");
1275
                        } else {
1276
                            if ($field == 'recordBase' && $value == 'Dna Sample'){
1277
                                _description_list_group_add($groups, cdm_occurrence_field_name_label($field), 'DNA Sample');
1278
                            }else{
1279
                                _description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value);
1280
                            }
1281

    
1282
                        }
1283

    
1284
                }
1285

    
1286

    
1287
            }
1288
        } // END of loop over $derivedUnitFacade fields
1289

    
1290

    
1291

    
1292
        // template_preprocess_description_list() is not worting by weight so we do it right here
1293
        uasort($groups, 'element_sort');
1294

    
1295
        $occurrence_elements = array(
1296
           // '#title' => $title,
1297
            '#theme' => 'description_list',
1298
            '#groups' => $groups,
1299
            '#attributes' => array('class' => html_class_attribute_ref($specimen_or_observation)),
1300
        );
1301
        $output = drupal_render($occurrence_elements);
1302
        if (isset($gallery_html)){
1303
            $output .= $gallery_html;
1304
        }
1305
        $pathToSpecimen = path_to_specimen($specimen_or_observation->uuid);
1306
        $output .=  l("Detail page", $pathToSpecimen, array('attributes' => array('target' => '_blank')));
1307
    } // END of $specimenOrObservation exists
1308

    
1309
    return $output;
1310
}
1311

    
1312
function compose_table_of_blast_result(array $data){
1313
   // get icon images
1314
  $expand_icon = font_awesome_icon_markup(
1315
      'fa-plus-square-o',
1316
      array(
1317
          'alt' => 'Show details',
1318
          'class' => array('expand_icon')
1319
      )
1320
  );
1321
  $collapse_icon = font_awesome_icon_markup(
1322
      'fa-minus-square-o',
1323
      array(
1324
          'alt' => 'Show details',
1325
          'class' => array('collapse_icon')
1326
      )
1327
  );
1328
  //$detail_image_icon = '<img title="Detail Image" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/detail_image_derivate-16x16-32.png' . '"/>';
1329
    $rowcount = 0;
1330
    $rows = array();
1331

    
1332
    foreach ($data as $row_data){
1333
        $pathToSpecimen = path_to_specimen_by_accession_number($row_data['id']);
1334
        $specimenPageLink = l($row_data['id'], $pathToSpecimen, array('attributes' => array('target' => '_blank')));
1335
        $ncbiLink = l($row_data['id'], 'https://www.ncbi.nlm.nih.gov/nuccore/'.$row_data['id'].'?report=graph', array('attributes' => array('target' => '_blank')));
1336
        $rows[] =  array(
1337
            'data' => array(
1338
                array(
1339
                    'data' => $expand_icon . $collapse_icon,
1340
                    'class' => array('summary_row_cell', 'summary_row_icon', 'expand_column')
1341
                ),
1342
                array(
1343
                    'data' => $row_data['def'],
1344
                ),
1345
                array(
1346
                    'data' => $specimenPageLink,
1347
                ),
1348
                array(
1349
                    'data' => $row_data['hsp_align_length'],
1350
                ),
1351
                array(
1352
                   'data' => $ncbiLink,
1353
                ),
1354
                array(
1355
                    'data' => $row_data['hsp_identity']/$row_data['hsp_align_length']*100,
1356
                )
1357
            ),
1358
            'id' => 'blast_summary' . $rowcount, // summary row id
1359
            'class' => array('summary_row'),
1360
        );
1361
        $detail_html = "";
1362

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

    
1365

    
1366
        $detail_html .= "<br>";
1367
        $detail_html .= $row_data["hsp_midline"];
1368

    
1369
        //$detail_html .= "<br>";
1370

    
1371
        $rows[] = array(
1372
            'data' => array(
1373
                array(
1374
                    'data' => "", //empty first column
1375
                    'class' => array('expand_column')
1376
                ),
1377
                array(
1378
                    'data' => $detail_html,
1379
                    'colspan' => 5,
1380
                ),
1381
            ),
1382
            'id' => 'blast_detail' . $rowcount,//details row ID
1383
            'class' => array('detail_row'),
1384
        );
1385
        $rowcount++;
1386
    }
1387

    
1388
    $tableId = "blast_result_table";
1389
    $blast_result_table = array(
1390
        "#theme" => "table",
1391
        "#weight" => 2,
1392
        "#header" => array(
1393
            array(
1394
                'data' => "",
1395
                'class' => array('expand_column')
1396
            ),
1397
                        "Name", "Accession Number", "Align Length", "NCBI", "% Identity"),
1398
        "#rows" => $rows,
1399
        "#attributes" => array(
1400
            "id" => $tableId,
1401
            "border" => 2
1402
        )
1403
    );
1404

    
1405
    drupal_add_js_rowToggle("#".$tableId);
1406

    
1407
    $render_array[$tableId] = $blast_result_table;
1408
    $out = drupal_render($render_array);
1409
   //$blast_result_page-> content = drupal_render($render_array);
1410
   return $out;
1411
}
1412

    
(6-6/10)