Project

General

Profile

Download (75.4 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);
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_SPECIMEN_LIST_VIEW_MODE, CDM_SPECIMEN_LIST_VIEW_MODE_DEFAULT) == CDM_SPECIMEN_LIST_VIEW_MODE_OPTION_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
            // WARNING: adding a List<MediaDTO> as $specimen_or_observation->_derivedUnitMedia
363
            $specimen_or_observation->_derivedUnitMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array(
364
                $specimen_or_observation->uuid,
365
                'fieldObjectMediaDTO',
366
            ));
367
        }else{
368
            // WARNING: adding a List<Media> as $specimen_or_observation->_derivedUnitMedia
369
            $specimen_or_observation->_derivedUnitMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array(
370
                $specimen_or_observation->uuid,
371
                'derivedUnitMedia',
372
            ));
373
        }
374

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

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

    
391
        $title = $type_label . ': ' . $specimen_or_observation->titleCache;
392

    
393
        $groups = array();
394

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

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

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

    
415

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

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

    
432
                    case 'definition':
433
                        // TODO
434
                        break;
435

    
436
                    case 'preferredStableUri':
437

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

    
441
                    case 'specimenTypeDesignations':
442

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

    
453
                    case 'determinations':
454
                        $dd_elements = array();
455
                        $glue = ', ';
456

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

    
468
                            $taxon_name = '';
469
                            $name_link = '';
470
                            if ($determinationEvent->taxonName) {
471
                                $taxon_name = cdm_ws_get(CDM_WS_NAME, $determinationEvent->taxonName->uuid);
472
                                $taxon_name->taggedName = cdm_ws_get(CDM_WS_NAME, array($determinationEvent->taxonName->uuid, "taggedName"));
473
                                $name_link = path_to_name($determinationEvent->taxonName->uuid);
474
                            } else if ($determinationEvent->taxon) {
475
                                $taxon_name = cdm_ws_get(CDM_WS_TAXON . '/$0/name', $determinationEvent->taxon->uuid);
476
                                $name_link = path_to_taxon($determinationEvent->taxon->uuid);
477
                            }
478
                            if ($taxon_name) {
479
                                //$taxon_html = render_taxon_or_name($taxon_name, $name_link);
480

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

    
501
                    case 'descriptions':
502
                        $dd_elements = array();
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
                            $description_string = render_description_string(get_root_nodes_for_dataset($description));
510
                            $dd_elements[] = markup_to_render_array($description_string);
511
                        }
512
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
513
                        break;
514
                    case '_derivedUnitMedia':
515
                        if ($isSpecimen_page) {
516
                            $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
517
                            $captionElements = array(
518
                                '#uri' => t('open media'),
519
                            );
520
                            $gallery_html = compose_cdm_media_gallerie(array(
521
                                'mediaList' => $value, // WARNING: this is either a List<Media> or List<MediaDTO>, see above ~line 361
522
                                'galleryName' => $specimen_or_observation->titleCache,
523
                                'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
524
                                'cols' => $gallery_settings['cdm_dataportal_media_cols'],
525
                                'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
526
                                'captionElements' => $captionElements,
527
                                'mediaLinkType' => 'LIGHTBOX',
528
                                'alternativeMediaUri' => NULL,
529
                                'galleryLinkUri' => NULL,
530
                            ));
531
                            @_description_list_group_add($groups, "Detail Images:", markup_to_render_array($gallery_html), '', 20);
532
                        }
533

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

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

    
554

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

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

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

    
597
                        }
598
                        break;
599

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

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

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

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

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

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

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

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

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

    
667
                    // TODO preservation
668
                    // TODO exsiccatum
669

    
670

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

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

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

    
734
                }
735

    
736
            }
737
        } // END of loop over $derivedUnitFacade fields
738

    
739
        // Extensions
740
        // TODO: filter by using visible_extensions_sorted()
741
        $extensions = cdm_ws_fetch_all(CDM_WS_PORTAL_OCCURRENCE . '/'  . $specimen_or_observation->uuid . '/extensions', array($specimen_or_observation->uuid));
742
        if ($extensions && count($extensions)) {
743

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

    
750

    
751

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

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

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

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

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

    
802

    
803

    
804

    
805
    } // END of $specimenOrObservation exists
806

    
807
    return $derivatives;
808
}
809

    
810

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

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

    
838
    $groups = array();
839

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

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

    
848

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

    
852
                case 'geneticAccessionNumber';
853

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

    
857

    
858
                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.
859
                    if (isset($value->name)) {
860
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value->name, NULL, 3);
861
                    }
862
                    if (isset($value->description)) {
863
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field) . ' ' . t('description'), $value->description, NULL, 4);
864
                    }
865
                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field) , $value, NULL, 4);
866
                    break;
867

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

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

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

    
905
                case 'citation':
906
                    @_description_list_group_add($groups,
907
                        cdm_occurrence_field_name_label($field),
908
                        cdm_reference_markup($value, $sequence->microReference),
909
                        NULL,
910
                        8
911
                    );
912
                    break;
913

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

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

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

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

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

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

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

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

    
985
    return $sequence_elements;
986
}
987

    
988
/**
989
 * Crates an array which can be used in render arrays to be passed to the
990
 * theme_table() and theme_list().
991
 *
992
 * @param array $fieldunit_dtos
993
 *     list of FieldUnitDTOs
994
 */
995
function specimen_render_array_items(array $fieldunit_dtos){
996

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

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

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

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

    
1032
function compose_compressed_specimen_derivate_table($field_unit_uuids) {
1033

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

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

    
1057
  foreach ($field_unit_uuids as $field_unit_uuid) {
1058

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

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

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

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

    
1157
  return $derivateHierarchyTable;
1158
}
1159

    
1160
/**
1161
 * Composes the view on specimens and occurrences as derivate tree
1162
 * starting from the field unit including all derivatives.
1163
 *
1164
 * @see DM_SPECIMEN_LIST_VIEW_MODE_OPTION_DERIVATE_TREE
1165
 *
1166
 * @param object $fieldunit_dtos
1167
 *   list of FieldUnitDTOs
1168
 * @return array
1169
 *   The Drupal render array
1170
 *
1171
 * @ingroup compose
1172
 */
1173
function compose_specimen_table_top_down(array $fieldunit_dtos){
1174

    
1175
  $specimen_render_array_items = specimen_render_array_items($fieldunit_dtos);
1176

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

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

    
1231
        )
1232
      ),
1233
      'class' =>  array('detail_row')
1234
//                'class' =>  array(
1235
//                    'descriptionElement',
1236
//                    'descriptionElement_IndividualsAssociation'
1237
      //               ),
1238
    );
1239
    $rowcount++;
1240

    
1241
  }
1242
  drupal_add_js_rowToggle("#".$tableId);
1243

    
1244
  return $specimen_table;
1245
}
1246

    
1247

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

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

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

    
1291

    
1292
    if (is_object($specimen_or_observation)) {
1293

    
1294
        $type_label = $specimen_or_observation->recordBase;
1295
        RenderHints::setFootnoteListKey($type_label . '-' . $specimen_or_observation->uuid);
1296

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

    
1310
        if (isset($typeDesignation->typifiedNames)){
1311
            $title = $type_label . ' for: ' . $typeDesignation->typifiedNames;
1312
        }else{
1313
            $title = $type_label;
1314
        }
1315

    
1316
        $items['data'] = $title;
1317

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

    
1325
            if (!in_array($field, $exclude_occurrence_fields) && ($value && (!is_object($value) || isset($value->class)))) {
1326
                switch ($field) {
1327

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

    
1339
                    case 'preferredStableUri':
1340

    
1341
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), array(array('#markup' => cdm_external_uri($value, false))));
1342
                        break;
1343

    
1344
                    case 'specimenTypeDesignations':
1345
                        @_description_list_group_add(
1346
                            $groups,
1347
                            cdm_occurrence_field_name_label($field),
1348
                            array(
1349
                                '#markup' => render_type_designations($value),
1350
                            )
1351
                        );
1352
                        break;
1353

    
1354

    
1355

    
1356
                    case 'listOfMedia':
1357
                        $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
1358

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

    
1376
                         //@_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $gallery_html);
1377
                         break;
1378

    
1379

    
1380

    
1381
                    /* ---- DerivedUnitBase --- */
1382

    
1383

    
1384
                    case 'collectionDTO':
1385

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

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

    
1401
                        break;
1402

    
1403

    
1404

    
1405

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

    
1416
                    // TODO preservation
1417
                    // TODO exsiccatum
1418

    
1419

    
1420
                    /* ---- FieldObservation --- */
1421
                    case 'gatheringEvent':
1422

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

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

    
1476
                        break;
1477

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

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

    
1496

    
1497
                    default:
1498
                        if (is_object($value) || is_array($value)) {
1499
                            drupal_set_message("Unhandled type in compose_cdm_specimenOrObservation() for field " . $field, "warning");
1500
                        } else {
1501
                            if ($field == 'recordBase' && $value == 'Dna Sample'){
1502
                                _description_list_group_add($groups, cdm_occurrence_field_name_label($field), 'DNA Sample');
1503
                            }else{
1504
                                _description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value);
1505
                            }
1506
                        }
1507
                }
1508
            }
1509
        } // END of loop over $derivedUnitFacade fields
1510

    
1511
        // template_preprocess_description_list() is not worting by weight so we do it right here
1512
        uasort($groups, 'element_sort');
1513
        $occurrence_elements = array(
1514
           // '#title' => $title,
1515
            '#theme' => 'description_list',
1516
            '#groups' => $groups,
1517
            '#attributes' => array('class' => html_class_attribute_ref($specimen_or_observation)),
1518
        );
1519
        $output = drupal_render($occurrence_elements);
1520
        if (isset($gallery_html)){
1521
            $output .= $gallery_html;
1522
        }
1523
        $pathToSpecimen = path_to_specimen($specimen_or_observation->uuid);
1524
        $output .=  l("Detail page", $pathToSpecimen);
1525
    } // END of $specimenOrObservation exists
1526

    
1527
    return $output;
1528
}
1529

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

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

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

    
1583

    
1584
        $detail_html .= "<br>";
1585
        $detail_html .= $row_data["hsp_midline"];
1586

    
1587
        //$detail_html .= "<br>";
1588

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

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

    
1623
    drupal_add_js_rowToggle("#".$tableId);
1624

    
1625
    $render_array[$tableId] = $blast_result_table;
1626
    $out = drupal_render($render_array);
1627
   //$blast_result_page-> content = drupal_render($render_array);
1628
   return $out;
1629
}
1630

    
1631

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

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

    
1655
  if ($specimensOrObservations) {
1656

    
1657
    foreach ($specimensOrObservations as $specimenOrObservation) {
1658

    
1659
      $mediaList = array();
1660
      if (is_array($specimenOrObservation->_fieldObjectMedia)) {
1661
        $mediaList = array_merge($mediaList, $specimenOrObservation->_fieldObjectMedia);
1662
      }
1663
      if (is_array($specimenOrObservation->_derivedUnitMedia)) {
1664
        $mediaList = array_merge($mediaList, $specimenOrObservation->_derivedUnitMedia);
1665
      }
1666

    
1667

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

    
1684
      // --- Specimen entry as dynamic label:
1685
      //     -> Dynabox for the specimenOrObservation
1686
      $gallery_name = $specimenOrObservation->uuid;
1687

    
1688
      $derived_unit_ws_request = cdm_compose_ws_url(CDM_WS_OCCURRENCE, array($specimenOrObservation->uuid));
1689
      // --- Render associated media.
1690
      $gallery_html = '';
1691
      if (count($mediaList) > 0) {
1692
        $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
1693
        $captionElements = array(
1694
          '#uri' => t('open media'),
1695
        );
1696

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

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

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

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

    
1758
  return $specimen_table;
1759
}
1760

    
1761

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

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

    
(8-8/14)