Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

cdm-dataportal / modules / cdm_dataportal / includes / occurrences.inc @ 2f4646e0

History | View | Annotate | Download (75.3 KB)

1
<?php
2
/**
3
 * @file
4
 * Functions for dealing with CDM entities of type SpecimenOrOccurrences
5
 *
6
 * @copyright
7
 *   (C) 2007-2012 EDIT
8
 *   European Distributed Institute of Taxonomy
9
 *   http://www.e-taxonomy.eu
10
 *
11
 *   The contents of this module are subject to the Mozilla
12
 *   Public License Version 1.1.
13
 * @see http://www.mozilla.org/MPL/MPL-1.1.html
14
 *
15
 * @author
16
 *   - Andreas Kohlbecker <a.kohlbecker@BGBM.org>
17
 */
18

    
19

    
20
/**
21
 * Provides the HTML markup for a specimen page
22
 *
23
 * @param $specimen
24
 *
25
 * @return string
26
 *  The markup for a specimen page
27
 */
28
function render_cdm_specimen_page($specimen)
29
{
30

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

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

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

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

    
87

    
88
    return $output;
89
}
90

    
91

    
92
/**
93
 * Provides the HTML markup for a specimen page
94
 *
95
 * @param $specimen
96
 *
97
 * @return string
98
 *  The markup for a specimen page
99
 */
100
function render_cdm_specimenDTO_page($specimen, $is_specimen_page = false)
101
{
102
    $detail_html = "";
103
    //link to specimen page
104
    $pathToSpecimen = path_to_specimen($specimen->uuid);
105
    if (!$is_specimen_page) {
106
        $specimenPageLink = l($specimen->accessionNumber, $pathToSpecimen);
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);
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);
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);
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));
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));
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 = statistical_values_from_gathering_event($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 = statistical_values_from_gathering_event($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 = statistical_values_from_gathering_event($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), $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);
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
/**
990
 * Crates an array which can be used in render arrays to be passed to the theme_table() and theme_list().
991
 * @param array $fieldunit_dtos
992
 *     list of FieldUnitDTOs
993
 */
994
function specimen_render_array_items(array $fieldunit_dtos){
995

    
996
  $render_array_items = array();
997
  $items = array();
998

    
999
  //we need one more item to contain the items of one level (fieldunit, derivate data etc.)
1000
  foreach ($fieldunit_dtos as &$fieldunit_dto) {
1001

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

    
1018
/**
1019
 * Creates the drupal render array for the table showing all derivatives which
1020
 * stem from a common gathering event.
1021
 *
1022
 * @param $field_unit_uuids array
1023
 *  An array of uuids for cdm FieldUnit entities.
1024
 *
1025
 * @return array
1026
 *  A drupal render array for a table
1027
 *
1028
 * @ingroup compose
1029
 */
1030

    
1031
function compose_compressed_specimen_derivate_table($field_unit_uuids) {
1032

    
1033
  // prepare font icons
1034
  $expand_icon = font_awesome_icon_markup(
1035
    'fa-plus-square-o',
1036
    array(
1037
      'alt' => 'Show details',
1038
      'class' => array('expand_icon')
1039
    )
1040
  );
1041
  $collapse_icon = font_awesome_icon_markup(
1042
    'fa-minus-square-o',
1043
    array(
1044
      'alt' => 'Show details',
1045
      'class' => array('collapse_icon')
1046
    )
1047
  );
1048
  $detail_image_icon = '<img title="Detail Image" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/detail_image_derivate-16x16-32.png' . '"/>';
1049
  $checked_box_icon = '<img src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/step_done.gif' . '"/>';
1050
  $sequence_icon = '<img title="Molecular Data" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/sequence_derivate-16x16-32.png' . '"/>';
1051
  $character_data_icon = '<img title="Character Data" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/character_data_derivate-16x16-32.png' . '"/>';
1052

    
1053
  $rowcount = 0;
1054
  $rows = array();
1055

    
1056
  foreach ($field_unit_uuids as $field_unit_uuid) {
1057

    
1058
    //get derivate hierarchy for the FieldUnit
1059
    $derivateHierarchy = cdm_ws_get(CDM_WS_PORTAL_OCCURRENCE, array($field_unit_uuid, 'derivateHierarchy'));
1060
    if ($derivateHierarchy) {
1061
      //summary row
1062
      $rows[] = array(
1063
        'data' => array(
1064
          array(
1065
            'data' => $expand_icon . $collapse_icon,
1066
            'class' => array('summary_row_cell', 'summary_row_icon', 'expand_column')
1067
          ),
1068
          array(
1069
            'data' => $derivateHierarchy->country,
1070
            'class' => array('summary_row_cell')
1071
          ),
1072
          array(
1073
            'data' => $derivateHierarchy->date,
1074
            'class' => array('summary_row_cell')
1075
          ),
1076
          array(
1077
            'data' => $derivateHierarchy->collectingString,
1078
            'class' => array('summary_row_cell')
1079
          ),
1080
          @array(
1081
            'data' => $derivateHierarchy->collection,
1082
            'class' => array('summary_row_cell')
1083
          ),
1084
          array(
1085
            'data' => $derivateHierarchy->hasType ? $checked_box_icon : "",
1086
            'class' => array('summary_row_cell', 'summary_row_icon')
1087
          ),
1088
          array(
1089
            'data' => $derivateHierarchy->hasSpecimenScan ? $checked_box_icon : "",
1090
            'class' => array('summary_row_cell', 'summary_row_icon')
1091
          ),
1092
          array(
1093
            'data' => ($derivateHierarchy->hasDna ? $sequence_icon : "") . " "
1094
              . ($derivateHierarchy->hasDetailImage ? $detail_image_icon : "") . " "
1095
              . ($derivateHierarchy->hasCharacterData ? $character_data_icon : ""),
1096
            'class' => array('summary_row_cell', 'summary_row_icon')
1097
          )
1098
        ),
1099
        'id' => 'derivate_summary' . $rowcount, // summary row id
1100
        'class' => array('summary_row'),
1101
      );
1102

    
1103
      //assemble field unit details
1104
      $detail_html = "";
1105
      // - citation
1106
      if ($derivateHierarchy->citation) {
1107
        $detail_html .= create_label("Citation") . $derivateHierarchy->citation . "<br>";
1108
      }
1109
      //assemble specimen details
1110
      if ($derivateHierarchy->derivates) {
1111
        foreach ($derivateHierarchy->derivates as $preservedSpecimenDTO) {
1112
          $detail_html .= "<br>";
1113
          $detail_html .= render_cdm_specimenDTO_page($preservedSpecimenDTO);
1114
        }
1115
      }
1116
      $detail_html .= "<br>";
1117
      //detail row resp. one BIG detail cell
1118
      $rows[] = array(
1119
        'data' => array(
1120
          array(
1121
            'data' => "", //empty first column
1122
            'class' => array('expand_column')
1123
          ),
1124
          array(
1125
            'data' => $detail_html,
1126
            'colspan' => 7,
1127
          ),
1128
        ),
1129
        'id' => 'derivate_details' . $rowcount,//details row ID
1130
        'class' => array('detail_row'),
1131
      );
1132
      $rowcount++;
1133
    }
1134
  }
1135

    
1136
  $tableId = "derivate_hierarchy_table";
1137
  $derivateHierarchyTable = array(
1138
    "#theme" => "table",
1139
    "#weight" => 2,
1140
    "#header" => array(
1141
      array(
1142
        'data' => "",
1143
        'class' => array('expand_column')
1144
      ),
1145
      "Country", "Date", "Collector + collecting number", "Herbaria", "Type", "Scan", "Derivatives"),
1146
    "#rows" => $rows,
1147
    "#attributes" => array(
1148
      "id" => $tableId,
1149
      "border" => 2
1150
    )
1151
  );
1152

    
1153
  //add toggle functionality to derivate hierarchy table
1154
  drupal_add_js_rowToggle("#" . $tableId);
1155

    
1156
  return $derivateHierarchyTable;
1157
}
1158

    
1159
/**
1160
 * Creates an array from a list of FieldUnitDTOs.
1161
 *
1162
 *
1163
 * @param object $fieldunit_dtos
1164
 *   list of FieldUnitDTOs
1165
 * @return array
1166
 *   An array containing the hierarchy of the field units corresponding to the taxon
1167
 *
1168
 * @ingroup compose
1169
 */
1170
function compose_specimen_table_top_down(array $fieldunit_dtos){
1171

    
1172
  $specimen_render_array_items = specimen_render_array_items($fieldunit_dtos);
1173

    
1174
    // add icons
1175
  $expand_icon = font_awesome_icon_markup(
1176
    'fa-plus-square-o',
1177
    array(
1178
      'alt' => 'Show details',
1179
      'class' => array('expand_icon')
1180
    )
1181
  );
1182
  $collapse_icon = font_awesome_icon_markup(
1183
    'fa-minus-square-o',
1184
    array(
1185
      'alt' => 'Show details',
1186
      'class' => array('collapse_icon')
1187
    )
1188
  );
1189
  $tableId = "specimen_tree_table";
1190
  $specimen_table = array(
1191
    '#theme' => 'table',
1192
    // prefix attributes and rows with '#' to let it pass toF the theme function,
1193
    // otherwise it is handled as child render array
1194
    '#attributes' => array(
1195
      'class' => 'specimens',
1196
      'id' => $tableId
1197
    ),
1198
    '#rows' => array(),
1199
  );
1200
  $rowcount = 0;
1201
  foreach($specimen_render_array_items as $value){
1202
    $renderArray = array(
1203
      '#theme' => 'item_list',
1204
      '#items' => $value['children'],
1205
      '#type' => 'ul');
1206
    $output = drupal_render($renderArray);
1207

    
1208
    $specimen_table['#rows'][] = array(
1209
      'data' =>array(
1210
        array(
1211
          'data' => $expand_icon . $collapse_icon,
1212
          'class' => array('summary_row_cell', 'summary_row_icon', 'expand_column')
1213
        ),
1214
        $value['data']
1215
      ),
1216
      'id' => 'label' . $rowcount, // summary row id
1217
      'class' => array('summary_row'),
1218
    );
1219
    $specimen_table['#rows'][] = array(
1220
      'data' =>  array(
1221
        array(
1222
          'data' => "", //empty first column
1223
          'class' => array('expand_column')
1224
        ),
1225
        array(
1226
          'data' => $output
1227

    
1228
        )
1229
      ),
1230
      'class' =>  array('detail_row')
1231
//                'class' =>  array(
1232
//                    'descriptionElement',
1233
//                    'descriptionElement_IndividualsAssociation'
1234
      //               ),
1235
    );
1236
    $rowcount++;
1237

    
1238
  }
1239
  drupal_add_js_rowToggle("#".$tableId);
1240

    
1241
  return $specimen_table;
1242
}
1243

    
1244

    
1245
/**
1246
 * Compose an render array from a CDM DerivedUnitFacade object.
1247
 *
1248
 * compose_hook() implementation
1249
 *
1250
 * @param object $specimenOrObservation
1251
 *   the CDM instance of type SpecimenOrObservation to compose
1252
 *   the render array for
1253
 * @param array $derivatives
1254
 *   the render array which contains the compositions of the derivatives
1255
 *   of the supplied $specimenOrObservation
1256
 *
1257
 * @return array
1258
 *   the supplied render array $derivatives to which the composition of the supplied
1259
 *   $specimenOrObservation has been added to
1260
 *
1261
 * @ingroup compose
1262
 */
1263

    
1264
function compose_cdm_specimen_or_observation_tree_entry($specimen_or_observation)
1265
{
1266
    $exclude_occurrence_fields = &drupal_static(__FUNCTION__);
1267
    if (!isset($exclude_occurrence_fields)) {
1268
        $exclude_occurrence_fields = array(
1269
            'type',
1270
            'taxonRelatedDerivedUnits',
1271
            'label',
1272
            'titleCache',
1273
            'listLabel',
1274
            'protectedTitleCache',
1275
            'class',
1276
            'uuid',
1277
            'derivates',
1278
            'collection'
1279
        );
1280
    }
1281
    $items = array();
1282

    
1283
    // only show uuid it the user is logged in
1284
    if (user_is_logged_in() && ($a_idx = array_search('uuid', $exclude_occurrence_fields)) !== FALSE) {
1285
      //  unset($exclude_occurrence_fields[$a_idx]);
1286
    }
1287

    
1288

    
1289
    if (is_object($specimen_or_observation)) {
1290

    
1291
        $type_label = $specimen_or_observation->recordBase;
1292
        RenderHints::setFootnoteListKey($type_label . '-' . $specimen_or_observation->uuid);
1293

    
1294
        // collect typeStatus as label
1295
        if (isset($specimen_or_observation->specimenTypeDesignations)) {
1296
            $type_status = array();
1297
            foreach ($specimen_or_observation->specimenTypeDesignations as $typeDesignation) {
1298
                if (isset($typeDesignation->typeStatus->representation_L10n)) {
1299
                    $type_status[] = $typeDesignation->typeStatus->representation_L10n;
1300
                }
1301
            }
1302
            if (count($type_status) > 0) {
1303
                $type_label = implode(', ', $type_status);
1304
          }
1305
        }
1306

    
1307
        if (isset($typeDesignation->typifiedNames)){
1308
            $title = $type_label . ' for: ' . $typeDesignation->typifiedNames;
1309
        }else{
1310
            $title = $type_label;
1311
        }
1312

    
1313
        $items['data'] = $title;
1314

    
1315
        $groups = array();
1316
        $items['children'] = $groups;
1317
        $children_items = array();
1318
        // --- add initialized fields
1319
        foreach (get_object_vars($specimen_or_observation) as $field => $value) {
1320
            $child_item = array();
1321

    
1322
            if (!in_array($field, $exclude_occurrence_fields) && ($value && (!is_object($value) || isset($value->class)))) {
1323
                switch ($field) {
1324

    
1325
                    /* ---- SpecimenOrObservationBase --- */
1326
                    case 'derivationEvent':
1327
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 1);
1328
                        break;
1329
                    case 'kindOfUnit':
1330
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 1);
1331
                        break;
1332
                    case 'accessionNumber':
1333
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 0);
1334
                        break;
1335

    
1336
                    case 'preferredStableUri':
1337

    
1338
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), array(array('#markup' => cdm_external_uri($value, false))));
1339
                        break;
1340

    
1341
                    case 'specimenTypeDesignations':
1342
                        @_description_list_group_add(
1343
                            $groups,
1344
                            cdm_occurrence_field_name_label($field),
1345
                            array(
1346
                                '#markup' => theme('cdm_typedesignations', array('typeDesignations' => $value)),
1347
                            )
1348
                        );
1349
                        break;
1350

    
1351

    
1352

    
1353
                    case 'listOfMedia':
1354
                        $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
1355

    
1356
                        $captionElements = array(
1357
                            'title',
1358
                            '#uri' => t('open media'),
1359
                        );
1360
                        $gallery_html = compose_cdm_media_gallerie(array(
1361
                            'mediaList' => $value,
1362
                            'galleryName' => $specimen_or_observation->uuid,
1363
                            'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
1364
                            'cols' => $gallery_settings['cdm_dataportal_media_cols'],
1365
                            'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
1366
                            'captionElements' => $captionElements,
1367
                            'mediaLinkType' => 'LIGHTBOX',
1368
                            'alternativeMediaUri' => NULL,
1369
                            'galleryLinkUri' => NULL,
1370
                            'showCaption' => true
1371
                        ));
1372

    
1373
                         //@_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $gallery_html);
1374
                         break;
1375

    
1376

    
1377

    
1378
                    /* ---- DerivedUnitBase --- */
1379

    
1380

    
1381
                    case 'collectionDTO':
1382

    
1383
                        $sub_dl_groups = array();
1384
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('code'), $value->code, NULL, 1);
1385
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('codeStandard'), $value->codeStandard, NULL, 2);
1386
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('institute'), $value->institute, NULL, 3);
1387
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('townOrLocation'), $value->townOrLocation, NULL, 4);
1388
                        // TODO "superCollection"
1389
                        // TODO may have media
1390

    
1391
                        @_description_list_group_add($groups, 'Collection',
1392
                            array(
1393
                                array('#markup' => $value->titleCache),
1394
                                array('#theme' => 'description_list', '#groups' => $sub_dl_groups)
1395
                            )
1396
                        );
1397

    
1398
                        break;
1399

    
1400

    
1401

    
1402

    
1403
                    /* ---- Specimen --- */
1404
                    case 'sequences':
1405
                        $dd_elements = array();
1406
                        foreach ($value as $sequence) {
1407
                            $dd_elements[] = compose_cdm_sequence($sequence, true);
1408
                            $dd_elements[] = "";
1409
                        }
1410
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements,'', 100);
1411
                        break;
1412

    
1413
                    // TODO preservation
1414
                    // TODO exsiccatum
1415

    
1416

    
1417
                    /* ---- FieldObservation --- */
1418
                    case 'gatheringEvent':
1419

    
1420
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collector'), $value->collector);
1421
                        @_description_list_group_add($groups, t('Gathering date'), timePeriodToString($value->timeperiod));
1422
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('description'), $value->description);
1423
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('locality'), $value->locality, '', 10);
1424
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('country'), $value->country);
1425
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingMethod'), $value->collectingMethod);
1426
                        if (isset($value->absoluteElevation)) {
1427
                            $min_max_markup = statistical_values_from_gathering_event($value, 'absoluteElevation');
1428
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('absoluteElevation'), $min_max_markup);
1429
                        }
1430
                        if (isset($value->distanceToGround) && $value->distanceToGround >0) {
1431
                            $min_max_markup = statistical_values_from_gathering_event($value, 'distanceToGround');
1432
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToGround'), $min_max_markup);
1433
                        }
1434
                        if (isset($value->distanceToWaterSurface) && $value->distanceToWaterSurface > 0) {
1435
                            $min_max_markup = statistical_values_from_gathering_event($value, 'distanceToWaterSurface');
1436
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToWaterSurface'), $min_max_markup);
1437
                        }
1438

    
1439
                        if (isset($value->collectingAreas)) {
1440
                            $area_representations = array();
1441
                            foreach ($value->collectingAreas as $area) {
1442
                               // $area_representations[] = l($area->representation_L10n, path_to_named_area($area->uuid));
1443
                                $area_representations[] = $area;
1444
                            }
1445
                            if (!empty($area_representations))
1446
                                @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingAreas'),
1447
                                    array(
1448
                                        array('#markup' => implode(', ', $area_representations))
1449
                                    )
1450
                                );
1451
                        }
1452
                        if (isset($value->exactLocation)  ) {
1453
                            $sub_dl_groups = array();
1454
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('errorRadius'), $value->exactLocation->errorRadius, ' m', 1);
1455
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('longitude'), round($value->exactLocation->longitude, 7), '°', 2);
1456
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('latitude'), round($value->exactLocation->latitude, 7), '°', 3);
1457
                            if (isset($value->exactLocation->referenceSystem)) {
1458
                                @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('referenceSystem'), $value->exactLocation->referenceSystem->representation_L10n, '', 4);
1459
                            }
1460
                            if ( isSet($value->exactLocation->sexagesimalString)){
1461
                                @_description_list_group_add($groups, cdm_occurrence_field_name_label('exactLocation'),
1462
                                    array(
1463
                                        array('#markup' => $value->exactLocation->sexagesimalString),
1464
                                        array(
1465
                                            '#theme' => 'description_list',
1466
                                            '#groups' => $sub_dl_groups
1467
                                        ),
1468
                                    ), '', 11
1469
                                );
1470
                            }
1471
                        }
1472

    
1473
                        break;
1474

    
1475
                    /* ---- DerivationEvent --- */
1476
                    case 'derivationEvents':
1477
                        //@_description_list_group_add($groups, t('Association type'), $value->description);
1478
                        break;
1479
                    case 'determinedNames':
1480
                        $dd_elements = array();
1481
                        foreach ($value as $name) {
1482
                            $taxon_name = cdm_ws_get(CDM_WS_NAME, $name->key);
1483
                            $taxon_name->taggedName = cdm_ws_get(CDM_WS_NAME, array($name->key, "taggedName"));
1484
                            $name_link = path_to_name($name->key);
1485

    
1486
                            //$taxon_html = render_taxon_or_name($taxon_name, $name_link);
1487
                            $taxon_html = l($taxon_name->titleCache, $name_link);
1488
                            $dd_elements[] = $taxon_html;
1489
                        }
1490
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label("Identification(s)"), $dd_elements,'', 100);
1491
                        break;
1492

    
1493

    
1494
                    default:
1495
                        if (is_object($value) || is_array($value)) {
1496
                            drupal_set_message("Unhandled type in compose_cdm_specimenOrObservation() for field " . $field, "warning");
1497
                        } else {
1498
                            if ($field == 'recordBase' && $value == 'Dna Sample'){
1499
                                _description_list_group_add($groups, cdm_occurrence_field_name_label($field), 'DNA Sample');
1500
                            }else{
1501
                                _description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value);
1502
                            }
1503

    
1504
                        }
1505

    
1506
                }
1507

    
1508

    
1509
            }
1510
        } // END of loop over $derivedUnitFacade fields
1511

    
1512

    
1513

    
1514
        // template_preprocess_description_list() is not worting by weight so we do it right here
1515
        uasort($groups, 'element_sort');
1516

    
1517
        $occurrence_elements = array(
1518
           // '#title' => $title,
1519
            '#theme' => 'description_list',
1520
            '#groups' => $groups,
1521
            '#attributes' => array('class' => html_class_attribute_ref($specimen_or_observation)),
1522
        );
1523
        $output = drupal_render($occurrence_elements);
1524
        if (isset($gallery_html)){
1525
            $output .= $gallery_html;
1526
        }
1527
        $pathToSpecimen = path_to_specimen($specimen_or_observation->uuid);
1528
        $output .=  l("Detail page", $pathToSpecimen);
1529
    } // END of $specimenOrObservation exists
1530

    
1531
    return $output;
1532
}
1533

    
1534
function compose_table_of_blast_result(array $data){
1535
   // get icon images
1536
  $expand_icon = font_awesome_icon_markup(
1537
      'fa-plus-square-o',
1538
      array(
1539
          'alt' => 'Show details',
1540
          'class' => array('expand_icon')
1541
      )
1542
  );
1543
  $collapse_icon = font_awesome_icon_markup(
1544
      'fa-minus-square-o',
1545
      array(
1546
          'alt' => 'Show details',
1547
          'class' => array('collapse_icon')
1548
      )
1549
  );
1550
  //$detail_image_icon = '<img title="Detail Image" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/detail_image_derivate-16x16-32.png' . '"/>';
1551
    $rowcount = 0;
1552
    $rows = array();
1553

    
1554
    foreach ($data as $row_data){
1555
        $pathToSpecimen = path_to_specimen_by_accession_number($row_data['id']);
1556
        $specimenPageLink = l($row_data['id'], $pathToSpecimen);
1557
        $ncbiLink = l($row_data['id'], 'https://www.ncbi.nlm.nih.gov/nuccore/'.$row_data['id'].'?report=graph');
1558
        $rows[] =  array(
1559
            'data' => array(
1560
                array(
1561
                    'data' => $expand_icon . $collapse_icon,
1562
                    'class' => array('summary_row_cell', 'summary_row_icon', 'expand_column')
1563
                ),
1564
                array(
1565
                    'data' => $row_data['def'],
1566
                ),
1567
                array(
1568
                    'data' => $specimenPageLink,
1569
                ),
1570
                array(
1571
                    'data' => $row_data['hsp_align_length'],
1572
                ),
1573
                array(
1574
                   'data' => $ncbiLink,
1575
                ),
1576
                array(
1577
                    'data' => $row_data['hsp_identity']/$row_data['hsp_align_length']*100,
1578
                )
1579
            ),
1580
            'id' => 'blast_summary' . $rowcount, // summary row id
1581
            'class' => array('summary_row'),
1582
        );
1583
        $detail_html = "";
1584

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

    
1587

    
1588
        $detail_html .= "<br>";
1589
        $detail_html .= $row_data["hsp_midline"];
1590

    
1591
        //$detail_html .= "<br>";
1592

    
1593
        $rows[] = array(
1594
            'data' => array(
1595
                array(
1596
                    'data' => "", //empty first column
1597
                    'class' => array('expand_column')
1598
                ),
1599
                array(
1600
                    'data' => $detail_html,
1601
                    'colspan' => 5,
1602
                ),
1603
            ),
1604
            'id' => 'blast_detail' . $rowcount,//details row ID
1605
            'class' => array('detail_row'),
1606
        );
1607
        $rowcount++;
1608
    }
1609

    
1610
    $tableId = "blast_result_table";
1611
    $blast_result_table = array(
1612
        "#theme" => "table",
1613
        "#weight" => 2,
1614
        "#header" => array(
1615
            array(
1616
                'data' => "",
1617
                'class' => array('expand_column')
1618
            ),
1619
                        "Name", "Accession Number", "Align Length", "NCBI", "% Identity"),
1620
        "#rows" => $rows,
1621
        "#attributes" => array(
1622
            "id" => $tableId,
1623
            "border" => 2
1624
        )
1625
    );
1626

    
1627
    drupal_add_js_rowToggle("#".$tableId);
1628

    
1629
    $render_array[$tableId] = $blast_result_table;
1630
    $out = drupal_render($render_array);
1631
   //$blast_result_page-> content = drupal_render($render_array);
1632
   return $out;
1633
}
1634

    
1635

    
1636
/**
1637
 * Composes a BOTTOM-UP-SPECIMEN-TABLE
1638
 * @param $specimensOrObservations
1639
 * @return array
1640
 *  A drupal render array with the following keys:
1641
 *   - 'specimen_list'
1642
 *   - 'pager'
1643
 *
1644
 * @ingroup Compose
1645
 */
1646
function compose_specimens_table_bottom_up($specimensOrObservations)
1647
{
1648

    
1649
  // --- generate the specimen list as table
1650
  $specimen_table = array(
1651
    '#theme' => 'table',
1652
    '#weight' => 2,
1653
    // prefix attributes and rows with '#' to let it pass toF the theme function,
1654
    // otherwise it is handled as child render array
1655
    '#attributes' => array('class' => 'specimens'),
1656
    '#rows' => array(),
1657
  );
1658

    
1659
  if ($specimensOrObservations) {
1660

    
1661
    foreach ($specimensOrObservations as $specimenOrObservation) {
1662

    
1663
      $mediaList = array();
1664
      if (is_array($specimenOrObservation->_fieldObjectMedia)) {
1665
        $mediaList = array_merge($mediaList, $specimenOrObservation->_fieldObjectMedia);
1666
      }
1667
      if (is_array($specimenOrObservation->_derivedUnitMedia)) {
1668
        $mediaList = array_merge($mediaList, $specimenOrObservation->_derivedUnitMedia);
1669
      }
1670

    
1671

    
1672
      // typelabel will contain the typeStatus
1673
      $type_label = '';
1674
      $typeDesignationPager = cdm_ws_get(CDM_WS_OCCURRENCE . '/$0/specimenTypeDesignations', $specimenOrObservation->uuid);
1675
      if (isset($typeDesignationPager) and isset($typeDesignationPager->records)) {
1676
        $type_status = array();
1677
        foreach ($typeDesignationPager->records as $typeDesignation) {
1678
          if (isset($typeDesignation->typeStatus->representation_L10n)) {
1679
            $type_status[] = $typeDesignation->typeStatus->representation_L10n;
1680
          }
1681
        }
1682
        $type_label = implode(', ', $type_status);
1683
        if ($type_label) {
1684
          $type_label .= ': ';
1685
        }
1686
      }
1687

    
1688
      // --- Specimen entry as dynamic label:
1689
      //     -> Dynabox for the specimenOrObservation
1690
      $gallery_name = $specimenOrObservation->uuid;
1691

    
1692
      $derived_unit_ws_request = cdm_compose_url(CDM_WS_OCCURRENCE, array($specimenOrObservation->uuid));
1693
      // --- Render associated media.
1694
      $gallery_html = '';
1695
      if (count($mediaList) > 0) {
1696
        $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
1697
        $captionElements = array(
1698
          '#uri' => t('open media'),
1699
        );
1700

    
1701
        $gallery_html = compose_cdm_media_gallerie(array(
1702
          'mediaList' => $mediaList,
1703
          'galleryName' => $gallery_name,
1704
          'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
1705
          'cols' => $gallery_settings['cdm_dataportal_media_cols'],
1706
          'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
1707
          'captionElements' => $captionElements,
1708
          'mediaLinkType' => 'LIGHTBOX',
1709
          'alternativeMediaUri' => NULL,
1710
          'galleryLinkUri' => NULL,
1711
        ));
1712
      }
1713
      //here we should use the data we already have
1714
      $label_html = cdm_dynabox(
1715
        $specimenOrObservation->uuid,
1716
        $type_label . $specimenOrObservation->titleCache,
1717
        $derived_unit_ws_request,
1718
        'cdm_specimen_or_observation',
1719
        'Click for details',
1720
        array('div', 'div'),
1721
        array(),
1722
        null, // $content_element_selector
1723
        'function(){ jQuery(\'#media_gallery_' . $gallery_name . '\').hide(); }', // open_callback
1724
        'function(){ jQuery(\'#media_gallery_' . $gallery_name . '\').show(); }' // close_callback
1725
      );
1726

    
1727
      // --- Render associated media.
1728
      $gallery_html = '';
1729
      if (count($mediaList) > 0) {
1730
        $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
1731
        $captionElements = array(
1732
          '#uri' => t('open media'),
1733
        );
1734

    
1735
        $gallery_html = compose_cdm_media_gallerie(array(
1736
          'mediaList' => $mediaList,
1737
          'galleryName' => $gallery_name,
1738
          'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
1739
          'cols' => $gallery_settings['cdm_dataportal_media_cols'],
1740
          'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
1741
          'captionElements' => $captionElements,
1742
          'mediaLinkType' => 'LIGHTBOX',
1743
          'alternativeMediaUri' => NULL,
1744
          'galleryLinkUri' => NULL,
1745
        ));
1746
      }
1747

    
1748
      $specimen_table['#rows'][] = array(
1749
        // An array of table rows. Every row is an array of cells, or an associative array
1750
        'data' => array(
1751
          // Each cell can be either a string or an associative array
1752
          $label_html . $gallery_html
1753
        ),
1754
        'class' => array(
1755
          'descriptionElement',
1756
          'descriptionElement_IndividualsAssociation'
1757
        ),
1758
      );
1759
    }
1760
  }
1761

    
1762
  return $specimen_table;
1763
}
1764

    
1765

    
1766
/**
1767
 * Orders occurrences by date but types should be on top of the list.
1768
 *
1769
 * @param $specimensOrObservations_or_fieldUnitDTO
1770
 *
1771
 * @return array
1772
 */
1773
function order_specimens_or_observations_by_date_and_type($specimensOrObservations)
1774
{
1775
// order occurrences by date but types should be on top of the list
1776
  $type_specimens = array();
1777
  $other_occurrences = array();
1778
  foreach ($specimensOrObservations as &$occurrence) {
1779
    $typeDesignationsPager = cdm_ws_get(CDM_WS_OCCURRENCE . '/$0/specimenTypeDesignations', $occurrence->uuid);
1780
    if (isset($typeDesignationsPager->count) && $typeDesignationsPager->count > 0) {
1781
      $type_specimens[] = $occurrence;
1782
    } else {
1783
      $other_occurrences[] = $occurrence;
1784
    }
1785
  }
1786
  $specimensOrObservations = array_merge($type_specimens, $other_occurrences);
1787
  return $specimensOrObservations;
1788
}
1789

    
1790
/**
1791
 * Orders FieldUnitDTOs by date but types should be on top of the list.
1792
 *
1793
 * Delegates internally to order_specimens_or_observations_by_date_and_type()
1794
 *
1795
 * @param $fieldUnitDTOs
1796
 *
1797
 * @return array
1798
 */
1799
function order_fieldUnitDtos_by_date_and_type($fieldUnitDTOs)
1800
{
1801
  return order_specimens_or_observations_by_date_and_type($fieldUnitDTOs);
1802
}
1803

    
Add picture from clipboard (Maximum size: 40 MB)