Project

General

Profile

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

    
19

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

    
140
    if ($types) {
141
        $detail_html .= $isSpecimenPage?"<br>":"";
142
        $detail_html .= create_label("Type(s)") . $types . "<br>";
143
    }
144
    if ($specimenScans and !$isSpecimenPage) {
145
        $detail_html .= create_label("Specimen Scans") . $specimenScans . "<br>";
146
    }
147
    //specimen scan image gallery
148
    if($isSpecimenPage and isset($derivateDataDTO->specimenScanUuids) and !empty($derivateDataDTO->specimenScanUuids)) {
149
        $detail_html .= addImageGallery("Specimen scans", $derivateDataDTO->specimenScanUuids);
150
    }
151

    
152
    if ($molecularData) {
153
        $detail_html .= $isSpecimenPage?"<br>":"";
154
        $detail_html .= create_label("Molecular Data") . $molecularData . "<br>";
155
    }
156

    
157
    if ($detailImages and !$isSpecimenPage) {
158
        $detail_html .= create_label("Detail Images") . $detailImages . "<br>";
159
    }
160

    
161
    //detail image gallery
162
    if($isSpecimenPage and isset($derivateDataDTO->detailImageUuids) and !empty($derivateDataDTO->detailImageUuids)){
163
        $detail_html .= addImageGallery("Detail Images", $derivateDataDTO->detailImageUuids);
164
    }
165

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

    
185
function addImageGallery($galleryName, $imageUuids){
186
    $images = array();
187
    foreach ($imageUuids as $uuid) {
188
        $images[] = cdm_ws_get(CDM_WS_PORTAL_MEDIA, $uuid);
189
    }
190

    
191
    $gallery_html = '';
192
    if (count($imageUuids) > 0) {
193
        $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
194
        $captionElements = array(
195
            'title',
196
            'rights',
197
        );
198
        $alternativeMediaUris = array();
199
        foreach($images as $image){
200
          $mediaUri = getMediaUri($image);
201
          if($mediaUri){
202
            $alternativeMediaUris[] = $mediaUri;
203
          }
204
          else{
205
            $alternativeMediaUris[] = path_to_media($image->uuid);
206
          }
207
        }
208

    
209
        $gallery_html = theme('cdm_media_gallerie', array(
210
            'mediaList' => $images,
211
            'galleryName' => $galleryName,
212
            'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
213
            'cols' => $gallery_settings['cdm_dataportal_media_cols'],
214
            'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
215
            'captionElements' => $captionElements,
216
            'mediaLinkType' => 'LIGHTBOX',
217
            'alternativeMediaUri' => $alternativeMediaUris,
218
            'galleryLinkUri' => NULL,
219
        ));
220
    }
221
    return "<br>".create_label($galleryName)."<br>".$gallery_html;
222
}
223

    
224
function getMediaUri($media){
225
  if(isset($media->representations) && sizeof($media->representations)==1
226
    && isset($media->representations[0]->parts) &&
227
    sizeof($media->representations[0]->parts)==1) {
228
    return $media->representations[0]->parts[0]->uri;
229
  }
230
  return null;
231
}
232

    
233

    
234
/**
235
 * Formats the given string to a label for displaying key-value pairs in HTML
236
 * @return string
237
 */
238
function create_label($label)
239
{
240
    return "<span class='specimen_table_label'>".$label.": </span>";
241
}
242

    
243
/**
244
 * Compose an render array from a CDM DerivedUnitFacade object.
245
 *
246
 * compose_hook() implementation
247
 *
248
 * @param object $specimenOrObservation
249
 *   the CDM instance of type SpecimenOrObservation to compose
250
 *   the render array for
251
 * @param array $derivatives
252
 *   the render array which contains the compositions of the derivatives
253
 *   of the supplied $specimenOrObservation
254
 *
255
 * @return array
256
 *   the supplied render array $derivatives to which the composition of the supplied
257
 *   $specimenOrObservation has been added to
258
 *
259
 * @ingroup compose
260
 */
261
function compose_cdm_specimenOrObservation($specimenOrObservation, &$derivatives = null) {
262

    
263
  $exclude_occurrence_fields = &drupal_static(__FUNCTION__);
264
  if (!isset($exclude_occurrence_fields)) {
265
     $exclude_occurrence_fields = array(
266
        'derivationEvents',
267
        'extensions', // TODO ignored for now, how to handle extensions?
268
        'titleCache',
269
        'protectedTitleCache',
270
        'derivedUnitMedia',
271
        'created',
272
        'publish',
273
        'updated',
274
        'class',
275
        'uuid',
276
       ''
277
    );
278
  }
279

    
280

    
281
  // only show uuid it the user is logged in
282
  if(user_is_logged_in() && ($a_idx = array_search('uuid', $exclude_occurrence_fields)) !== FALSE ) {
283
    unset($exclude_occurrence_fields[$a_idx]);
284
  }
285

    
286
  if (!isset($derivatives)) {
287
    $derivatives = array();
288
  }
289

    
290
  $descriptions = null;
291
  $derivedFrom = null;
292

    
293
  if (is_object($specimenOrObservation)) {
294

    
295
    // request again for deeper initialization
296
    $specimenOrObservation = cdm_ws_get("portal/" . CDM_WS_OCCURRENCE, $specimenOrObservation->uuid);
297

    
298

    
299
    $type_label = $specimenOrObservation->class;
300
    RenderHints::setFootnoteListKey($type_label . '-' . $specimenOrObservation->uuid);
301

    
302
    // collect typeStatus as label
303
    if (isset($specimenOrObservation->specimenTypeDesignations)) {
304
      $type_status = array();
305
      foreach ($specimenOrObservation->specimenTypeDesignations as $typeDesignation) {
306
        if (isset($typeDesignation->typeStatus->representation_L10n)){
307
          $type_status[] = $typeDesignation->typeStatus->representation_L10n;
308
        }
309
      }
310
      if (count($type_status) > 0){
311
        $type_label = implode(', ', $type_status);
312
      }
313
    }
314

    
315
    $title = $type_label . ': '. $specimenOrObservation->titleCache;
316

    
317
    $groups = array();
318
    // --- add initialized fields
319
    foreach (get_object_vars($specimenOrObservation) as $field => $value) {
320
      if (!in_array($field, $exclude_occurrence_fields) && ($value && (!is_object($value) || isset($value->class)))) {
321
        switch ($field) {
322

    
323
          /* ---- java.lang.Object --- */
324
          case 'class':
325
            if($value != '' /* FieldUnit' */){
326
              @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value);
327
            }
328
          break;
329

    
330
          case 'markers':
331
            $dd_elements = array();
332
            foreach ($value as $marker) {
333
              $dd_elements[] = compose_cdm_marker($marker);
334
            }
335
            @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
336
            break;
337

    
338

    
339
          case 'annotations':
340
            $dd_elements = array();
341
            foreach ($value as $annotation) {
342
              // TODO respect annotation type filter settings
343
              $dd_elements[] = $annotation->text;
344
            }
345
            @_description_list_group_add($groups, t('Notes'), $dd_elements);
346
            break;
347

    
348
          /* ---- SpecimenOrObservationBase --- */
349
          case 'sex':
350
          case 'lifeStage':
351
          case 'kindOfUnit':
352
            @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value->representation_L10n);
353
            break;
354

    
355
          case 'definition':
356
            // TODO
357
            break;
358

    
359
          case 'specimenTypeDesignations':
360
            @_description_list_group_add(
361
              $groups,
362
              cdm_occurrence_field_name_label($field),
363
              array(
364
                '#markup'=>theme('cdm_typedesignations', array('typeDesignations' => $value)),
365
              )
366
            );
367
            break;
368

    
369
          case 'determinations':
370
            $dd_elements = array();
371
            $glue = ', ';
372

    
373
            foreach  ($value as $determinationEvent){
374
                $timeperiod_string = NULL;
375
                if (isset($determinationEvent->timeperiod)) {
376
                    $timeperiod_string = timePeriodToString($determinationEvent->timeperiod);
377
                }
378
                $weight = isset($determinationEvent->preferred) && $determinationEvent->preferred == 1 ? '0' : ($timeperiod_string ? $timeperiod_string : '1');
379
                // check key exists
380
                while (array_key_exists($weight, $dd_elements)) {
381
                    $weight .= '0';
382
                }
383
                if($determinationEvent->taxonName){
384
                    $taxon_name = $determinationEvent->taxonName;
385
                    $name_link = "";
386
                }
387
                else if($determinationEvent->taxon){
388
                    $taxon_name = cdm_ws_get(CDM_WS_TAXON . '/$0/name', $determinationEvent->taxon->uuid);
389
                    $name_link = path_to_taxon($determinationEvent->taxon->uuid);
390
                }
391
                $taxon_html = render_taxon_or_name($taxon_name, $name_link);
392
                $dd_elements[$weight] = $taxon_html;
393
                if (isset($determinationEvent->modifier)) {
394
                    $dd_elements[$weight] .= cdm_term_representation($determinationEvent->modifier);
395
                }
396
                if ($timeperiod_string) {
397
                    $dd_elements[$weight] .= $glue . $timeperiod_string;
398
                }
399
                if (isset($determinationEvent->actor->titleCache)) {
400
                    $dd_elements[$weight] .= $glue . $determinationEvent->actor->titleCache;
401
                }
402
                if (isset($determinationEvent->description)) {
403
                    $dd_elements[$weight] .= $glue . $determinationEvent->description;
404
                }
405
            }
406
            ksort($dd_elements);
407
            @_description_list_group_add($groups, cdm_occurrence_field_name_label('determinations'), $dd_elements);
408
            break;
409

    
410
          case 'descriptions':
411
            $descriptions = $value;
412
            $occurrence_featureTree = cdm_get_occurrence_featureTree();
413
            $dd_elements = array();
414

    
415
            foreach ($value as $description) {
416
              $description = cdm_ws_get(CDM_WS_PORTAL_DESCRIPTION, $description->uuid);
417
//               if($description->imageGallery == TRUE) {
418
//                 continue;
419
//               }
420
              $elements_by_feature = _mergeFeatureTreeDescriptions($occurrence_featureTree->root->childNodes, $description->elements);
421
              $description_render_elements = compose_feature_blocks($elements_by_feature, null);
422
              $dd_elements[] = $description_render_elements;
423
            }
424

    
425
            @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
426
            break;
427

    
428
          case 'sources':
429
              $dd_elements = array();
430
              foreach ($value as $identifiable_source) {
431
                $dd_elements[] = theme('cdm_OriginalSource', array('source' => $identifiable_source));
432
              }
433
              @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
434
              break;
435

    
436

    
437
          /* ---- DerivedUnitBase --- */
438
          case 'derivedFrom':
439
            $derivedFrom = $value;
440
            break;
441

    
442
          case 'collection':
443
            $sub_dl_groups = array();
444
            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('code'), $value->code, NULL, 1);
445
            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('codeStandard'),  $value->codeStandard, NULL, 2);
446
            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('institute'), $value->institute, NULL, 3);
447
            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('townOrLocation'), $value->townOrLocation, NULL, 4);
448
            // TODO "superCollection"
449
            // TODO may have media
450

    
451
            @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),
452
                array(
453
                    array('#markup' => $value->titleCache),
454
                    array('#theme' => 'description_list', '#groups' => $sub_dl_groups)
455
                )
456
            );
457
            break;
458

    
459
            case 'storedUnder':
460
              @_description_list_group_add($groups, cdm_occurrence_field_name_label('storedUnder'), render_taxon_or_name($value));
461
              break;
462

    
463

    
464
            /* ---- Specimen --- */
465
            case 'sequences':
466
              $dd_elements = array();
467
              foreach ($value as $sequence) {
468
                $dd_elements[] = compose_cdm_sequence($sequence);
469
              }
470
              @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
471
            break;
472

    
473
            // TODO preservation
474
            // TODO exsiccatum
475

    
476

    
477
          /* ---- FieldObservation --- */
478
          case 'gatheringEvent':
479
            @_description_list_group_add($groups, cdm_occurrence_field_name_label('collector'), $value->actor->titleCache);
480
            @_description_list_group_add($groups, t('Gathering time'), timePeriodToString($value->timeperiod));
481
            @_description_list_group_add($groups, cdm_occurrence_field_name_label('description'), $value->description);
482
            @_description_list_group_add($groups, cdm_occurrence_field_name_label('locality'), $value->locality->text);
483
            @_description_list_group_add($groups, cdm_occurrence_field_name_label('country'), $value->country->representation_L10n);
484
            @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingMethod'), $value->collectingMethod);
485
            if (isset($value->absoluteElevation)) {
486
                $min_max_array = min_max_array();
487
                if(is_numeric($value->absoluteElevation)){
488
                    $min_max_array['Min'] = new stdClass();
489
                    $min_max_array['Min']->_value = $value->absoluteElevation . ' m';
490
                }
491
                if(is_numeric($value->absoluteElevation)){
492
                    $min_max_array['Max'] = new stdClass();
493
                    $min_max_array['Max']->_value = $value->absoluteElevationMax . ' m';
494
                }
495
                $min_max_markup = min_max_markup($min_max_array);
496
                if(isset($value->absoluteElevationError)){
497
                    $min_max_markup .= ' +/-' .  $value->absoluteElevationError . ' m';
498
                }
499
                if(is_string($value->absoluteElevationText)){
500
                    $min_max_markup .= ' ' . $value->absoluteElevationText;
501
                }
502
                @_description_list_group_add($groups, cdm_occurrence_field_name_label('absoluteElevation'), $min_max_markup);
503
            }
504
            if (isset($value->distanceToGround)) {
505
              $min_max_array = min_max_array();
506
              if(is_numeric($value->distanceToGround)){
507
                  $min_max_array['Min'] = new stdClass();
508
                  $min_max_array['Min']->_value = $value->distanceToGround . ' m';
509
              }
510
              if(is_numeric($value->distanceToGround)){
511
                  $min_max_array['Max'] = new stdClass();
512
                  $min_max_array['Max']->_value = $value->distanceToGroundMax . ' m';
513
              }
514
              $min_max_markup = min_max_markup($min_max_array);
515
              if(isset($value->distanceToGroundError)){
516
                  $min_max_markup .= ' +/-' .  $value->distanceToGroundError . ' m';
517
              }
518
              if(is_string($value->distanceToGroundText)){
519
                  $min_max_markup .= ' ' . $value->distanceToGroundText;
520
              }
521
              @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToGround'), $min_max_markup);
522
            }
523
            if (isset($value->distanceToWaterSurface)) {
524
              $min_max_array = min_max_array();
525
              if(is_numeric($value->distanceToWaterSurface)){
526
                  $min_max_array['Min'] = new stdClass();
527
                  $min_max_array['Min']->_value = $value->distanceToWaterSurface . ' m';
528
              }
529
              if(is_numeric($value->distanceToWaterSurface)){
530
                  $min_max_array['Max'] = new stdClass();
531
                  $min_max_array['Max']->_value = $value->distanceToWaterSurfaceMax . ' m';
532
              }
533
              $min_max_markup = min_max_markup($min_max_array);
534
              if(isset($value->distanceToWaterSurfaceError)){
535
                  $min_max_markup .= ' +/-' .  $value->distanceToWaterSurfaceError . ' m';
536
              }
537
              if(is_string($value->distanceToWaterSurfaceText)){
538
                  $min_max_markup .= ' ' . $value->distanceToWaterSurfaceText;
539
              }
540
              @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToWaterSurface'), $min_max_markup);
541
            }
542

    
543
            if (isset($value->collectingAreas)) {
544
              $area_representations = array();
545
              foreach($value->collectingAreas as $area) {
546
                $area_representations[] = $area->representation_L10n;
547
              }
548
              @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingAreas'), implode(', ', $area_representations));
549
            }
550
            if (isset($value->exactLocation) && $value->exactLocation->sexagesimalString) {
551
              $sub_dl_groups = array();
552
              @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('errorRadius'), $value->exactLocation->errorRadius, ' m', 1);
553
              @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('longitude'), round($value->exactLocation->longitude, 7), '°', 2);
554
              @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('latitude'), round($value->exactLocation->latitude, 7), '°', 3);
555
              if (isset($value->exactLocation->referenceSystem)) {
556
                @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('referenceSystem'), $value->exactLocation->referenceSystem->representation_L10n, '', 4);
557
              }
558

    
559
              @_description_list_group_add($groups, cdm_occurrence_field_name_label('exactLocation'),
560
                  array(
561
                      array('#markup' => $value->exactLocation->sexagesimalString),
562
                      array(
563
                          '#theme' => 'description_list',
564
                          '#groups' => $sub_dl_groups
565
                      ),
566
                  )
567
              );
568
            }
569
            break;
570

    
571
          default:
572
            if(is_object($value) || is_array($value)){
573
              drupal_set_message("Unhandled type in compose_cdm_specimenOrObservation() for field " . $field, "warning");
574
            } else {
575
              _description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value);
576
            }
577

    
578
        }
579

    
580
      }
581
    } // END of loop over $derivedUnitFacade fields
582

    
583

    
584
    // template_preprocess_description_list() is not worting by weight so we do it right here
585
    uasort($groups, 'element_sort');
586

    
587
    $occurrence_elements = array(
588
        '#title' => $title,
589
        '#theme' => 'description_list',
590
        '#groups' => $groups,
591
        '#attributes' => array('class' => html_class_attribute_ref($specimenOrObservation)),
592
    );
593
    $derivatives[] = $occurrence_elements;
594
    // all footnotes which has been assembled so far (e.g. from typeDesignations) to here
595
    $foonote_li_elements = theme('cdm_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey(), 'enclosingTag' => 'span'));
596
    if (!empty($foonote_li_elements)) {
597
      $derivatives[] =  array(
598
          '#markup' =>  '<div class="footnotes">' . $foonote_li_elements . '</div>',
599
      );
600
    }
601

    
602
    // --- recurse into originals
603
    if (!isset($derivedFrom)) {
604
      $derivedFrom = cdm_ws_get(
605
          CDM_WS_OCCURRENCE,
606
          array($specimenOrObservation->uuid, 'derivedFrom')
607
        );
608
    }
609

    
610
    if (isset($derivedFrom)) {
611
      if (isset($derivedFrom->originals)) {
612
        $derived_from_label = t('derived');
613
        $preposition = t('from');
614
        if(isset($derivedFrom->type)){
615
          $derived_from_label = $derivedFrom->type->representation_L10n;
616
          if($derivedFrom->type->uuid == UUID_DERIVATIONEVENTTYPE_ACCESSIONING){
617
            $preposition = t('of');
618
          }
619
        }
620
        if (count($groups) > 0) {
621
          // TODO  annotations
622

    
623
          // only display the derived from information when the derivative has any element which will be diplayed
624
          $derivatives[] = array(
625
              '#markup' => '<div class="derived_from">' . $derived_from_label . ' ' . $preposition . ': </div>',
626
          );
627
        }
628
        foreach ($derivedFrom->originals as $original) {
629
          compose_cdm_specimenOrObservation($original, $derivatives);
630
        }
631
      }
632
    }
633

    
634
  } // END of $specimenOrObservation exists
635

    
636
  return $derivatives;
637
}
638

    
639
/**
640
 * Compose an render array from a CDM Sequence object.
641
 *
642
 * compose_hook() implementation
643
 *
644
 * @param object $sequence
645
 *   CDM instance of type Sequence
646
 * @return array
647
 *   A render array containing the fields of the supplied $sequence
648
 *
649
 * @ingroup compose
650
 */
651
function compose_cdm_sequence($sequence) {
652

    
653
  $exclude_sequence_fields = &drupal_static(__FUNCTION__);
654
  if (!isset($exclude_sequence_fields)) {
655
    $exclude_sequence_fields = array(
656
      'titleCache',
657
      'protectedTitleCache',
658
      'microReference',
659
      'created',
660
      'updated',
661
      'class',
662
    );
663
  }
664

    
665
  $groups = array();
666

    
667
  // -- retrieve additional data if neesscary
668
  // TODO below call disabled since sequences are not yet supported,
669
  //      see  #3347 (services and REST service controller for molecular classes implemented)
670
  //
671
  // cdm_load_annotations($sequence);
672

    
673
  foreach (get_object_vars($sequence) as $field => $value) {
674

    
675

    
676
    if (!in_array($field, $exclude_sequence_fields) && ($value && (!is_object($value) || isset($value->class)))) {
677
      switch ($field) {
678

    
679
        case 'geneticAccessionNumber';
680
          $dd_elements = array();
681
          foreach ($value as $accession) {
682
            if (isset($accession->uri) ){
683
              $dd_elements[] = l($accession->accessionNumber, $accession->uri);
684
            } else {
685
              $dd_elements[] = $accession->accessionNumber;
686
            }
687
          }
688
          @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),  $dd_elements, NULL, 1);
689
          break;
690

    
691

    
692
        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.
693
          if (isset($value->name)) {
694
            @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),  $value->name, NULL, 3);
695
          }
696
          if (isset($value->description)) {
697
            @_description_list_group_add($groups, cdm_occurrence_field_name_label($field) . ' ' . t('description') , $value->description, NULL, 4);
698
          }
699
          break;
700

    
701
        case 'consensusSequence':
702
          // format in genbank style, force linebreaks after each 70 nucleotites
703
          // see also http://stackoverflow.com/questions/499137/css-how-can-i-force-a-long-string-without-any-blank-to-be-wrapped-in-xul-and
704
          @_description_list_group_add(
705
            $groups,
706
            cdm_occurrence_field_name_label($field),
707
            array(
708
              array(
709
                '#markup' => '<div class="sequence-length">' . $value->length . ' ' . t('pb'). '</div><div>' . wordwrap($value->string, 70, '</br>', TRUE) . '</div>',
710
                '#wrapper_attributes' => array('class'=>'dna-sequence')
711
                )
712
              ),
713
            5);
714
          break;
715

    
716
         case 'dnaSample': // FIXME 3.3 implement
717
            break;
718
        case 'singleReads': // FIXME 3.3 implement
719
          break;
720
        case 'contigFile': // FIXME 3.3 implement - Media
721
            break;
722
        case 'pherograms': // FIXME 3.3 implement - Media
723
          break;
724
        case 'haplotype': // FIXME 3.3 implement
725
            break;
726
        case 'dateSequenced': // FIXME 3.3 now in SingelRead
727
          @_description_list_group_add($groups, t('Sequencing date'),  timePeriodToString($value), NULL, 6);
728
          break;
729

    
730
        case 'barcode': // boolean
731
          @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value ? 'Yes': 'No', NULL, 7);
732
          break;
733
        case 'barcodeSequencePart': // FIXME 3.3 implement, compose sequence
734
            break;
735

    
736
        case 'citation':
737
          @_description_list_group_add($groups,
738
            cdm_occurrence_field_name_label($field),
739
            theme('cdm_reference', array('reference' =>$value, 'microReference' => $sequence->microReference)),
740
            NULL,
741
            8
742
          );
743
          break;
744

    
745
        case 'publishedIn':
746
          @_description_list_group_add($groups,
747
            cdm_occurrence_field_name_label($field),
748
            theme('cdm_reference', array('reference'=>$value)),
749
            NULL,
750
            7
751
          );
752

    
753
        case 'rights':
754
          array_merge($groups, cdm_rights_as_dl_groups($value));
755
        break;
756

    
757
        case 'annotations':
758
          $dd_elements = array();
759
          foreach ($value as $annotation) {
760
            // TODO respect annotation type filter settings
761
            $dd_elements[] = $annotation->text;
762
          }
763
          @_description_list_group_add($groups, t('Notes'), $dd_elements, NULL, 9);
764
          break;
765

    
766
        case 'markers':
767
          $dd_elements = array();
768
          foreach ($value as $marker) {
769
            $dd_elements[] = compose_cdm_marker($marker);
770
          }
771
          @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements, NULL, 10);
772
          break;
773

    
774
        case 'chromatograms':
775
          @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),
776
              array(
777
                  '#markup'=>theme('cdm_media_gallerie', array('medialist'=>$value)),
778
              ),
779
              NULL,
780
              11);
781
          break;
782

    
783
        default:
784
          if(is_object($value) || is_array($value)){
785
            drupal_set_message("Unhandled type in compose_cdm_sequence() for field " . $field, "warning");
786
          } else {
787
            _description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 20);
788
          }
789
      }
790
    }
791
  }
792

    
793
  // template_preprocess_description_list() is not worting by weight so we do it right here
794
  uasort($groups, 'element_sort');
795

    
796
  $sequence_elements = array(
797
      '#theme' => 'description_list',
798
      '#groups' => $groups
799
  );
800

    
801
  return $sequence_elements;
802
}
803

    
804

    
(6-6/10)