Project

General

Profile

Download (30.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
 * @param $preservedSpecimenDTO
22
 * @param $detail_html
23
 * @return string
24
 */
25
function compose_cdm_specimen_page($specimenUuid)
26
{
27
    drupal_set_title("Specimen Details");
28
    $preservedSpecimenDTO = cdm_ws_get(CDM_WS_PORTAL_OCCURRENCE, array($specimenUuid, 'specimenDerivates'));
29

    
30
    $render_array = array();
31
    RenderHints::pushToRenderStack('specimen_page');
32

    
33
    $detail_html = compose_cdm_specimen_page_html($preservedSpecimenDTO, true);
34
    $render_array['specimen_html'] = array(
35
        '#markup' => $detail_html
36
    );
37

    
38
    RenderHints::popFromRenderStack();
39
    return $render_array;
40
}
41

    
42
/**
43
 * @param $preservedSpecimenDTO
44
 * @return string
45
 */
46
function compose_cdm_specimen_page_html($preservedSpecimenDTO, $isSpecimenPage = false)
47
{
48
    $detail_html = "";
49
    //link to specimen page
50
    $pathToSpecimen = path_to_specimen($preservedSpecimenDTO->uuid);
51
    if (!$isSpecimenPage) {
52
        $specimenPageLink = l($preservedSpecimenDTO->accessionNumber, $pathToSpecimen, array('attributes' => array('target' => '_blank')));
53
        $detail_html .= "<strong>$specimenPageLink</strong><br>";
54
    }
55

    
56
    if($isSpecimenPage) {
57
        if($preservedSpecimenDTO->citation){
58
            $detail_html .= "<br>".create_label("Citation") . $preservedSpecimenDTO->citation . "<br>";
59
        }
60
    }
61
    if($isSpecimenPage){
62
        // associated taxa
63
        if($preservedSpecimenDTO->associatedTaxa){
64
            $detail_html .= "<br>";
65
            $detail_html .= create_label("Associated with");
66
                if(sizeof($preservedSpecimenDTO->associatedTaxa)>1){
67
                    $detail_html .= "<br>";
68
                }
69
            foreach($preservedSpecimenDTO->associatedTaxa as $associatedTaxon){
70
                $detail_html .= l($associatedTaxon->second, path_to_taxon($associatedTaxon->first, "specimens"));//$associatedTaxon->second."<br>";
71
            }
72
        }
73
    }
74
    // - type information
75
    $types = "";
76
    if (isset($preservedSpecimenDTO->types)) {
77
        //typed taxa
78
        if(sizeof($preservedSpecimenDTO->types)>1){
79
            $detail_html .= "<br>";
80
        }
81
        foreach ($preservedSpecimenDTO->types as $typeStatus => $typedTaxa) {
82
            if($isSpecimenPage){
83
                if($preservedSpecimenDTO->types){
84
                    $detail_html .= "<i>".$typeStatus."</i>: ";
85
                    foreach($typedTaxa as $typedTaxon){
86
                        $detail_html .= $typedTaxon." ";
87
                    }
88
                    $detail_html .= "<br>";
89
                }
90
            }
91
            else{
92
                $types .= $typeStatus." ";
93
            }
94
        }
95
    }
96
    $derivateDataDTO = $preservedSpecimenDTO->derivateDataDTO;
97
    // - specimen scans
98
    $specimenScans = create_links($derivateDataDTO->specimenScans);
99
    // - molecular data
100
    $molecularData = "";
101
    if ($derivateDataDTO->molecularDataList) {
102
        foreach ($derivateDataDTO->molecularDataList as $molecular) {
103
            //provider link
104
            if (isset($molecular->providerLink)) {
105
                $molecularData .= create_html_link($molecular->providerLink);
106
            }
107
            //contig link
108
            if (isset($molecular->contigFiles[0])) {//FIXME check if empty
109
                $molecularData .= "[";
110
                if (isset($molecular->contigFiles)) {
111
                    foreach ($molecular->contigFiles as $contigFile) {
112
                        if (isset($contigFile->contigLink)){
113
                            if(isset($contigFile->contigLink->uri) and $contigFile->contigLink->uri!=null) {
114
                               $molecularData .= create_html_link($contigFile->contigLink)." ";
115
                            }
116
                            //primer links
117
                            $molecularData .= create_html_links($contigFile->primerLinks);
118
                        }
119
                    }
120
                } else {
121
                    $molecularData .= "no contig";
122
                }
123
                $molecularData = rtrim($molecularData, " ");
124
                $molecularData .= "]";
125
            }
126
            //FIXME separate with comma (remove trailing comma)
127
        }
128
    }
129
    // - detail images
130
    $detailImages = create_links($derivateDataDTO->detailImages);
131

    
132
    if ($types) {
133
        $detail_html .= $isSpecimenPage?"<br>":"";
134
        $detail_html .= create_label("Type(s)") . $types . "<br>";
135
    }
136
    if ($specimenScans and !$isSpecimenPage) {
137
        $detail_html .= $isSpecimenPage?"<br>":"";
138
        $detail_html .= create_label("Specimen Scans") . $specimenScans . "<br>";
139
    }
140
    //specimen scan image gallery
141
    if($isSpecimenPage and isset($derivateDataDTO->specimenScanUuids) and !empty($derivateDataDTO->specimenScanUuids)) {
142
        $detail_html .= addImageGallery("Specimen scans", $derivateDataDTO->specimenScanUuids);
143
    }
144

    
145
    if ($molecularData) {
146
        $detail_html .= $isSpecimenPage?"<br>":"";
147
        $detail_html .= create_label("Molecular Data") . $molecularData . "<br>";
148
    }
149

    
150
    if ($detailImages and !$isSpecimenPage) {
151
        $detail_html .= $isSpecimenPage?"<br>":"";
152
        $detail_html .= create_label("Detail Images") . $detailImages . "<br>";
153
    }
154

    
155
    //detail image gallery
156
    if($isSpecimenPage and isset($derivateDataDTO->detailImageUuids) and !empty($derivateDataDTO->detailImageUuids)){
157
        $detail_html .= addImageGallery("Detail Images", $derivateDataDTO->detailImageUuids);
158
    }
159

    
160
    //character data
161
    if ($preservedSpecimenDTO->characterData) {
162
        $detail_html .= $isSpecimenPage?"<br>":"";
163
        $detail_html .= create_label("Character Data");
164
        if($isSpecimenPage) {
165
            $detail_html .= "<br>";
166
            foreach ($preservedSpecimenDTO->characterData as $characterStatePair) {
167
                $detail_html .= "<i>" . $characterStatePair->first . "</i>:" . $characterStatePair->second;
168
                $detail_html .= "<br>";
169
            }
170
        }
171
        else{
172
            $detail_html .= l("detail page", $pathToSpecimen,array('attributes' => array('target'=>'_blank')));
173
            $detail_html .= "<br>";
174
        }
175
    }
176
    return $detail_html;
177
}
178

    
179
function addImageGallery($galleryName, $imageUuids){
180
    $images = array();
181
    foreach ($imageUuids as $uuid) {
182
        $images[] = cdm_ws_get(CDM_WS_PORTAL_MEDIA, $uuid);
183
    }
184

    
185
    $gallery_html = '';
186
    if (count($imageUuids) > 0) {
187
        $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
188
        $captionElements = array(
189
            'title',
190
            'rights',
191
        );
192
        $alternativeMediaUris = array();
193
        foreach($images as $image){
194
            $alternativeMediaUris[] = path_to_media($image->uuid);
195
        }
196

    
197
        $gallery_html = theme('cdm_media_gallerie', array(
198
            'mediaList' => $images,
199
            'galleryName' => $galleryName,
200
            'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
201
            'cols' => $gallery_settings['cdm_dataportal_media_cols'],
202
            'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
203
            'captionElements' => $captionElements,
204
            'mediaLinkType' => 'LIGHTBOX',
205
            'alternativeMediaUri' => $alternativeMediaUris,
206
            'galleryLinkUri' => NULL,
207
        ));
208
    }
209
    return "<br>".create_label($galleryName)."<br>".$gallery_html;
210
}
211

    
212

    
213
/**
214
 * Formats the given string to a label for displaying key-value pairs in HTML
215
 * @return string
216
 */
217
function create_label($label)
218
{
219
    return "<span class='specimen_table_label'>".$label.": </span>";
220
}
221

    
222
/**
223
 * Compose an render array from a CDM DerivedUnitFacade object.
224
 *
225
 * compose_hook() implementation
226
 *
227
 * @param object $specimenOrObservation
228
 *   the CDM instance of type SpecimenOrObservation to compose
229
 *   the render array for
230
 * @param array $derivatives
231
 *   the render array which contains the compositions of the derivatives
232
 *   of the supplied $specimenOrObservation
233
 *
234
 * @return array
235
 *   the supplied render array $derivatives to which the composition of the supplied
236
 *   $specimenOrObservation has been added to
237
 *
238
 * @ingroup compose
239
 */
240
function compose_cdm_specimenOrObservation($specimenOrObservation, &$derivatives = null) {
241

    
242
  $exclude_occurrence_fields = &drupal_static(__FUNCTION__);
243
  if (!isset($exclude_occurrence_fields)) {
244
     $exclude_occurrence_fields = array(
245
        'derivationEvents',
246
        'extensions', // TODO ignored for now, how to handle extensions?
247
        'titleCache',
248
        'protectedTitleCache',
249
        'derivedUnitMedia',
250
        'created',
251
        'publish',
252
        'updated',
253
        'class',
254
        'uuid',
255
       ''
256
    );
257
  }
258

    
259

    
260
  // only show uuid it the user is logged in
261
  if(user_is_logged_in() && ($a_idx = array_search('uuid', $exclude_occurrence_fields)) !== FALSE ) {
262
    unset($exclude_occurrence_fields[$a_idx]);
263
  }
264

    
265
  if (!isset($derivatives)) {
266
    $derivatives = array();
267
  }
268

    
269
  $descriptions = null;
270
  $derivedFrom = null;
271

    
272
  if (is_object($specimenOrObservation)) {
273

    
274
    // request again for deeper initialization
275
    $specimenOrObservation = cdm_ws_get("portal/" . CDM_WS_OCCURRENCE, $specimenOrObservation->uuid);
276

    
277

    
278
    $type_label = $specimenOrObservation->class;
279
    RenderHints::setFootnoteListKey($type_label . '-' . $specimenOrObservation->uuid);
280

    
281
    // collect typeStatus as label
282
    if (isset($specimenOrObservation->specimenTypeDesignations)) {
283
      $type_status = array();
284
      foreach ($specimenOrObservation->specimenTypeDesignations as $typeDesignation) {
285
        if (isset($typeDesignation->typeStatus->representation_L10n)){
286
          $type_status[] = $typeDesignation->typeStatus->representation_L10n;
287
        }
288
      }
289
      if (count($type_status) > 0){
290
        $type_label = implode(', ', $type_status);
291
      }
292
    }
293

    
294
    $title = $type_label . ': '. $specimenOrObservation->titleCache;
295

    
296
    $groups = array();
297
    // --- add initialized fields
298
    foreach (get_object_vars($specimenOrObservation) as $field => $value) {
299
      if (!in_array($field, $exclude_occurrence_fields) && ($value && (!is_object($value) || isset($value->class)))) {
300
        switch ($field) {
301

    
302
          /* ---- java.lang.Object --- */
303
          case 'class':
304
            if($value != '' /* FieldUnit' */){
305
              @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value);
306
            }
307
          break;
308

    
309
          case 'markers':
310
            $dd_elements = array();
311
            foreach ($value as $marker) {
312
              $dd_elements[] = compose_cdm_marker($marker);
313
            }
314
            @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
315
            break;
316

    
317

    
318
          case 'annotations':
319
            $dd_elements = array();
320
            foreach ($value as $annotation) {
321
              // TODO respect annotation type filter settings
322
              $dd_elements[] = $annotation->text;
323
            }
324
            @_description_list_group_add($groups, t('Notes'), $dd_elements);
325
            break;
326

    
327
          /* ---- SpecimenOrObservationBase --- */
328
          case 'sex':
329
          case 'lifeStage':
330
          case 'kindOfUnit':
331
            @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value->representation_L10n);
332
            break;
333

    
334
          case 'definition':
335
            // TODO
336
            break;
337

    
338
          case 'specimenTypeDesignations':
339
            @_description_list_group_add(
340
              $groups,
341
              cdm_occurrence_field_name_label($field),
342
              array(
343
                '#markup'=>theme('cdm_typedesignations', array('typeDesignations' => $value)),
344
              )
345
            );
346
            break;
347

    
348
          case 'determinations':
349
            $dd_elements = array();
350
            $glue = ', ';
351

    
352
            foreach  ($value as $determinationEvent){
353
                $timeperiod_string = NULL;
354
                if (isset($determinationEvent->timeperiod)) {
355
                    $timeperiod_string = timePeriodToString($determinationEvent->timeperiod);
356
                }
357
                $weight = isset($determinationEvent->preferred) && $determinationEvent->preferred == 1 ? '0' : ($timeperiod_string ? $timeperiod_string : '1');
358
                // check key exists
359
                while (array_key_exists($weight, $dd_elements)) {
360
                    $weight .= '0';
361
                }
362
                if($determinationEvent->taxonName){
363
                    $taxon_name = $determinationEvent->taxonName;
364
                    $name_link = "";
365
                }
366
                else if($determinationEvent->taxon){
367
                    $taxon_name = cdm_ws_get(CDM_WS_TAXON . '/$0/name', $determinationEvent->taxon->uuid);
368
                    $name_link = path_to_taxon($determinationEvent->taxon->uuid);
369
                }
370
                $taxon_html = render_taxon_or_name($taxon_name, $name_link);
371
                $dd_elements[$weight] = $taxon_html;
372
                if (isset($determinationEvent->modifier)) {
373
                    $dd_elements[$weight] .= cdm_term_representation($determinationEvent->modifier);
374
                }
375
                if ($timeperiod_string) {
376
                    $dd_elements[$weight] .= $glue . $timeperiod_string;
377
                }
378
                if (isset($determinationEvent->actor->titleCache)) {
379
                    $dd_elements[$weight] .= $glue . $determinationEvent->actor->titleCache;
380
                }
381
                if (isset($determinationEvent->description)) {
382
                    $dd_elements[$weight] .= $glue . $determinationEvent->description;
383
                }
384
            }
385
            ksort($dd_elements);
386
            @_description_list_group_add($groups, cdm_occurrence_field_name_label('determinations'), $dd_elements);
387
            break;
388

    
389
          case 'descriptions':
390
            $descriptions = $value;
391
            $occurrence_featureTree = cdm_get_occurrence_featureTree();
392
            $dd_elements = array();
393

    
394
            foreach ($value as $description) {
395
              $description = cdm_ws_get(CDM_WS_PORTAL_DESCRIPTION, $description->uuid);
396
//               if($description->imageGallery == TRUE) {
397
//                 continue;
398
//               }
399
              $elements_by_feature = _mergeFeatureTreeDescriptions($occurrence_featureTree->root->childNodes, $description->elements);
400
              $description_render_elements = compose_feature_blocks($elements_by_feature, null);
401
              $dd_elements[] = $description_render_elements;
402
            }
403

    
404
            @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
405
            break;
406

    
407
          case 'sources':
408
              $dd_elements = array();
409
              foreach ($value as $identifiable_source) {
410
                $dd_elements[] = theme('cdm_OriginalSource', array('source' => $identifiable_source));
411
              }
412
              @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
413
              break;
414

    
415

    
416
          /* ---- DerivedUnitBase --- */
417
          case 'derivedFrom':
418
            $derivedFrom = $value;
419
            break;
420

    
421
          case 'collection':
422
            $sub_dl_groups = array();
423
            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('code'), $value->code, NULL, 1);
424
            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('codeStandard'),  $value->codeStandard, NULL, 2);
425
            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('institute'), $value->institute, NULL, 3);
426
            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('townOrLocation'), $value->townOrLocation, NULL, 4);
427
            // TODO "superCollection"
428
            // TODO may have media
429

    
430
            @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),
431
                array(
432
                    array('#markup' => $value->titleCache),
433
                    array('#theme' => 'description_list', '#groups' => $sub_dl_groups)
434
                )
435
            );
436
            break;
437

    
438
            case 'storedUnder':
439
              @_description_list_group_add($groups, cdm_occurrence_field_name_label('storedUnder'), render_taxon_or_name($value));
440
              break;
441

    
442

    
443
            /* ---- Specimen --- */
444
            case 'sequences':
445
              $dd_elements = array();
446
              foreach ($value as $sequence) {
447
                $dd_elements[] = compose_cdm_sequence($sequence);
448
              }
449
              @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
450
            break;
451

    
452
            // TODO preservation
453
            // TODO exsiccatum
454

    
455

    
456
          /* ---- FieldObservation --- */
457
          case 'gatheringEvent':
458
            @_description_list_group_add($groups, cdm_occurrence_field_name_label('collector'), $value->actor->titleCache);
459
            @_description_list_group_add($groups, t('Gathering time'), timePeriodToString($value->timeperiod));
460
            @_description_list_group_add($groups, cdm_occurrence_field_name_label('description'), $value->description);
461
            @_description_list_group_add($groups, cdm_occurrence_field_name_label('locality'), $value->locality->text);
462
            @_description_list_group_add($groups, cdm_occurrence_field_name_label('country'), $value->country->representation_L10n);
463
            @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingMethod'), $value->collectingMethod);
464
            if (isset($value->absoluteElevation)) {
465
                $min_max_array = min_max_array();
466
                if(is_numeric($value->absoluteElevation)){
467
                    $min_max_array['Min'] = new stdClass();
468
                    $min_max_array['Min']->_value = $value->absoluteElevation . ' m';
469
                }
470
                if(is_numeric($value->absoluteElevation)){
471
                    $min_max_array['Max'] = new stdClass();
472
                    $min_max_array['Max']->_value = $value->absoluteElevationMax . ' m';
473
                }
474
                $min_max_markup = min_max_markup($min_max_array);
475
                if(isset($value->absoluteElevationError)){
476
                    $min_max_markup .= ' +/-' .  $value->absoluteElevationError . ' m';
477
                }
478
                if(is_string($value->absoluteElevationText)){
479
                    $min_max_markup .= ' ' . $value->absoluteElevationText;
480
                }
481
                @_description_list_group_add($groups, cdm_occurrence_field_name_label('absoluteElevation'), $min_max_markup);
482
            }
483
            if (isset($value->distanceToGround)) {
484
              $min_max_array = min_max_array();
485
              if(is_numeric($value->distanceToGround)){
486
                  $min_max_array['Min'] = new stdClass();
487
                  $min_max_array['Min']->_value = $value->distanceToGround . ' m';
488
              }
489
              if(is_numeric($value->distanceToGround)){
490
                  $min_max_array['Max'] = new stdClass();
491
                  $min_max_array['Max']->_value = $value->distanceToGroundMax . ' m';
492
              }
493
              $min_max_markup = min_max_markup($min_max_array);
494
              if(isset($value->distanceToGroundError)){
495
                  $min_max_markup .= ' +/-' .  $value->distanceToGroundError . ' m';
496
              }
497
              if(is_string($value->distanceToGroundText)){
498
                  $min_max_markup .= ' ' . $value->distanceToGroundText;
499
              }
500
              @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToGround'), $min_max_markup);
501
            }
502
            if (isset($value->distanceToWaterSurface)) {
503
              $min_max_array = min_max_array();
504
              if(is_numeric($value->distanceToWaterSurface)){
505
                  $min_max_array['Min'] = new stdClass();
506
                  $min_max_array['Min']->_value = $value->distanceToWaterSurface . ' m';
507
              }
508
              if(is_numeric($value->distanceToWaterSurface)){
509
                  $min_max_array['Max'] = new stdClass();
510
                  $min_max_array['Max']->_value = $value->distanceToWaterSurfaceMax . ' m';
511
              }
512
              $min_max_markup = min_max_markup($min_max_array);
513
              if(isset($value->distanceToWaterSurfaceError)){
514
                  $min_max_markup .= ' +/-' .  $value->distanceToWaterSurfaceError . ' m';
515
              }
516
              if(is_string($value->distanceToWaterSurfaceText)){
517
                  $min_max_markup .= ' ' . $value->distanceToWaterSurfaceText;
518
              }
519
              @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToWaterSurface'), $min_max_markup);
520
            }
521

    
522
            if (isset($value->collectingAreas)) {
523
              $area_representations = array();
524
              foreach($value->collectingAreas as $area) {
525
                $area_representations[] = $area->representation_L10n;
526
              }
527
              @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingAreas'), implode(', ', $area_representations));
528
            }
529
            if (isset($value->exactLocation) && $value->exactLocation->sexagesimalString) {
530
              $sub_dl_groups = array();
531
              @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('errorRadius'), $value->exactLocation->errorRadius, ' m', 1);
532
              @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('longitude'), round($value->exactLocation->longitude, 7), '°', 2);
533
              @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('latitude'), round($value->exactLocation->latitude, 7), '°', 3);
534
              if (isset($value->exactLocation->referenceSystem)) {
535
                @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('referenceSystem'), $value->exactLocation->referenceSystem->representation_L10n, '', 4);
536
              }
537

    
538
              @_description_list_group_add($groups, cdm_occurrence_field_name_label('exactLocation'),
539
                  array(
540
                      array('#markup' => $value->exactLocation->sexagesimalString),
541
                      array(
542
                          '#theme' => 'description_list',
543
                          '#groups' => $sub_dl_groups
544
                      ),
545
                  )
546
              );
547
            }
548
            break;
549

    
550
          default:
551
            if(is_object($value) || is_array($value)){
552
              drupal_set_message("Unhandled type in compose_cdm_specimenOrObservation() for field " . $field, "warning");
553
            } else {
554
              _description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value);
555
            }
556

    
557
        }
558

    
559
      }
560
    } // END of loop over $derivedUnitFacade fields
561

    
562

    
563
    // template_preprocess_description_list() is not worting by weight so we do it right here
564
    uasort($groups, 'element_sort');
565

    
566
    $occurrence_elements = array(
567
        '#title' => $title,
568
        '#theme' => 'description_list',
569
        '#groups' => $groups,
570
        '#attributes' => array('class' => html_class_attribute_ref($specimenOrObservation)),
571
    );
572
    $derivatives[] = $occurrence_elements;
573
    // all footnotes which has been assembled so far (e.g. from typeDesignations) to here
574
    $foonote_li_elements = theme('cdm_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey(), 'enclosingTag' => 'span'));
575
    if (!empty($foonote_li_elements)) {
576
      $derivatives[] =  array(
577
          '#markup' =>  '<div class="footnotes">' . $foonote_li_elements . '</div>',
578
      );
579
    }
580

    
581
    // --- recurse into originals
582
    if (!isset($derivedFrom)) {
583
      $derivedFrom = cdm_ws_get(
584
          CDM_WS_OCCURRENCE,
585
          array($specimenOrObservation->uuid, 'derivedFrom')
586
        );
587
    }
588

    
589
    if (isset($derivedFrom)) {
590
      if (isset($derivedFrom->originals)) {
591
        $derived_from_label = t('derived');
592
        $preposition = t('from');
593
        if(isset($derivedFrom->type)){
594
          $derived_from_label = $derivedFrom->type->representation_L10n;
595
          if($derivedFrom->type->uuid == UUID_DERIVATIONEVENTTYPE_ACCESSIONING){
596
            $preposition = t('of');
597
          }
598
        }
599
        if (count($groups) > 0) {
600
          // TODO  annotations
601

    
602
          // only display the derived from information when the derivative has any element which will be diplayed
603
          $derivatives[] = array(
604
              '#markup' => '<div class="derived_from">' . $derived_from_label . ' ' . $preposition . ': </div>',
605
          );
606
        }
607
        foreach ($derivedFrom->originals as $original) {
608
          compose_cdm_specimenOrObservation($original, $derivatives);
609
        }
610
      }
611
    }
612

    
613
  } // END of $specimenOrObservation exists
614

    
615
  return $derivatives;
616
}
617

    
618
/**
619
 * Compose an render array from a CDM Sequence object.
620
 *
621
 * compose_hook() implementation
622
 *
623
 * @param object $sequence
624
 *   CDM instance of type Sequence
625
 * @return array
626
 *   A render array containing the fields of the supplied $sequence
627
 *
628
 * @ingroup compose
629
 */
630
function compose_cdm_sequence($sequence) {
631

    
632
  $exclude_sequence_fields = &drupal_static(__FUNCTION__);
633
  if (!isset($exclude_sequence_fields)) {
634
    $exclude_sequence_fields = array(
635
      'titleCache',
636
      'protectedTitleCache',
637
      'microReference',
638
      'created',
639
      'updated',
640
      'class',
641
    );
642
  }
643

    
644
  $groups = array();
645

    
646
  // -- retrieve additional data if neesscary
647
  // TODO below call disabled since sequences are not yet supported,
648
  //      see  #3347 (services and REST service controller for molecular classes implemented)
649
  //
650
  // cdm_load_annotations($sequence);
651

    
652
  foreach (get_object_vars($sequence) as $field => $value) {
653

    
654

    
655
    if (!in_array($field, $exclude_sequence_fields) && ($value && (!is_object($value) || isset($value->class)))) {
656
      switch ($field) {
657

    
658
        case 'geneticAccessionNumber';
659
          $dd_elements = array();
660
          foreach ($value as $accession) {
661
            if (isset($accession->uri) ){
662
              $dd_elements[] = l($accession->accessionNumber, $accession->uri);
663
            } else {
664
              $dd_elements[] = $accession->accessionNumber;
665
            }
666
          }
667
          @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),  $dd_elements, NULL, 1);
668
          break;
669

    
670

    
671
        case 'locus': // 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.
672
          if (isset($value->name)) {
673
            @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),  $value->name, NULL, 3);
674
          }
675
          if (isset($value->description)) {
676
            @_description_list_group_add($groups, cdm_occurrence_field_name_label($field) . ' ' . t('description') , $value->description, NULL, 4);
677
          }
678
          break;
679

    
680
        case 'consensusSequence':
681
          // format in genbank style, force linebreaks after each 70 nucleotites
682
          // see also http://stackoverflow.com/questions/499137/css-how-can-i-force-a-long-string-without-any-blank-to-be-wrapped-in-xul-and
683
          @_description_list_group_add(
684
            $groups,
685
            cdm_occurrence_field_name_label($field),
686
            array(
687
              array(
688
                '#markup' => '<div class="sequence-length">' . $value->length . ' ' . t('pb'). '</div><div>' . wordwrap($value->string, 70, '</br>', TRUE) . '</div>',
689
                '#wrapper_attributes' => array('class'=>'dna-sequence')
690
                )
691
              ),
692
            5);
693
          break;
694

    
695
         case 'dnaSample': // FIXME 3.3 implement
696
            break;
697
        case 'singleReads': // FIXME 3.3 implement
698
          break;
699
        case 'contigFile': // FIXME 3.3 implement - Media
700
            break;
701
        case 'pherograms': // FIXME 3.3 implement - Media
702
          break;
703
        case 'haplotype': // FIXME 3.3 implement
704
            break;
705
        case 'dateSequenced': // FIXME 3.3 now in SingelRead
706
          @_description_list_group_add($groups, t('Sequencing date'),  timePeriodToString($value), NULL, 6);
707
          break;
708

    
709
        case 'barcode': // boolean
710
          @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value ? 'Yes': 'No', NULL, 7);
711
          break;
712
        case 'barcodeSequencePart': // FIXME 3.3 implement, compose sequence
713
            break;
714

    
715
        case 'citation':
716
          @_description_list_group_add($groups,
717
            cdm_occurrence_field_name_label($field),
718
            theme('cdm_reference', array('reference' =>$value, 'microReference' => $sequence->microReference)),
719
            NULL,
720
            8
721
          );
722
          break;
723

    
724
        case 'publishedIn':
725
          @_description_list_group_add($groups,
726
            cdm_occurrence_field_name_label($field),
727
            theme('cdm_reference', array('reference'=>$value)),
728
            NULL,
729
            7
730
          );
731

    
732
        case 'rights':
733
          array_merge($groups, cdm_rights_as_dl_groups($value));
734
        break;
735

    
736
        case 'annotations':
737
          $dd_elements = array();
738
          foreach ($value as $annotation) {
739
            // TODO respect annotation type filter settings
740
            $dd_elements[] = $annotation->text;
741
          }
742
          @_description_list_group_add($groups, t('Notes'), $dd_elements, NULL, 9);
743
          break;
744

    
745
        case 'markers':
746
          $dd_elements = array();
747
          foreach ($value as $marker) {
748
            $dd_elements[] = compose_cdm_marker($marker);
749
          }
750
          @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements, NULL, 10);
751
          break;
752

    
753
        case 'chromatograms':
754
          @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),
755
              array(
756
                  '#markup'=>theme('cdm_media_gallerie', array('medialist'=>$value)),
757
              ),
758
              NULL,
759
              11);
760
          break;
761

    
762
        default:
763
          if(is_object($value) || is_array($value)){
764
            drupal_set_message("Unhandled type in compose_cdm_sequence() for field " . $field, "warning");
765
          } else {
766
            _description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 20);
767
          }
768
      }
769
    }
770
  }
771

    
772
  // template_preprocess_description_list() is not worting by weight so we do it right here
773
  uasort($groups, 'element_sort');
774

    
775
  $sequence_elements = array(
776
      '#theme' => 'description_list',
777
      '#groups' => $groups
778
  );
779

    
780
  return $sequence_elements;
781
}
782

    
783

    
(6-6/8)