Project

General

Profile

Download (29.3 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") . cdm_external_uri($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-object 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
        'titleCache',
268
        'protectedTitleCache',
269
        'derivedUnitMedia',
270
        'created',
271
        'publish',
272
        'updated',
273
        'class',
274
        'uuid',
275
       ''
276
    );
277
  }
278

    
279

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

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

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

    
292
  if (is_object($specimenOrObservation)) {
293

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

    
297

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

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

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

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

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

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

    
337

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

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

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

    
358
          case 'preferredStableUri':
359

    
360
            @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), array(array('#markup' => cdm_external_uri($value, false))));
361
            break;
362

    
363
          case 'specimenTypeDesignations':
364
            @_description_list_group_add(
365
              $groups,
366
              cdm_occurrence_field_name_label($field),
367
              array(
368
                '#markup' => theme('cdm_typedesignations', array('typeDesignations' => $value)),
369
              )
370
            );
371
            break;
372

    
373
          case 'determinations':
374
            $dd_elements = array();
375
            $glue = ', ';
376

    
377
            foreach ($value as $determinationEvent) {
378
              $timeperiod_string = NULL;
379
              if (isset($determinationEvent->timeperiod)) {
380
                $timeperiod_string = timePeriodToString($determinationEvent->timeperiod);
381
              }
382
              $weight = isset($determinationEvent->preferred) && $determinationEvent->preferred == 1 ? '0' : ($timeperiod_string ? $timeperiod_string : '1');
383
              // check key exists
384
              while (array_key_exists($weight, $dd_elements)) {
385
                $weight .= '0';
386
              }
387

    
388
              $taxon_name = '';
389
              $name_link = '';
390
              if ($determinationEvent->taxonName) {
391
                $taxon_name = $determinationEvent->taxonName;
392
              } else if ($determinationEvent->taxon) {
393
                $taxon_name = cdm_ws_get(CDM_WS_TAXON . '/$0/name', $determinationEvent->taxon->uuid);
394
                $name_link = path_to_taxon($determinationEvent->taxon->uuid);
395
              }
396
              if ($taxon_name) {
397
                $taxon_html = render_taxon_or_name($taxon_name, $name_link);
398
                $dd_elements[$weight] = $taxon_html;
399
              }
400
              if (isset($determinationEvent->modifier)) {
401
                $dd_elements[$weight] .= cdm_term_representation($determinationEvent->modifier);
402
              }
403
              if ($timeperiod_string) {
404
                $dd_elements[$weight] .= $glue . $timeperiod_string;
405
              }
406
              if (isset($determinationEvent->actor->titleCache)) {
407
                $dd_elements[$weight] .= $glue . $determinationEvent->actor->titleCache;
408
              }
409
              if (isset($determinationEvent->description)) {
410
                $dd_elements[$weight] .= $glue . $determinationEvent->description;
411
              }
412
            }
413
            ksort($dd_elements);
414
            @_description_list_group_add($groups, cdm_occurrence_field_name_label('determinations'), $dd_elements);
415
            break;
416

    
417
          case 'descriptions':
418
            $occurrence_featureTree = cdm_get_occurrence_featureTree();
419
            $dd_elements = array();
420

    
421
            foreach ($value as $description) {
422
              $description = cdm_ws_get(CDM_WS_PORTAL_DESCRIPTION, $description->uuid);
423
//               if($description->imageGallery == TRUE) {
424
//                 continue;
425
//               }
426
              $elements_by_feature = _mergeFeatureTreeDescriptions($occurrence_featureTree->root->childNodes, $description->elements);
427
              $description_render_elements = compose_feature_blocks($elements_by_feature, null);
428
              $dd_elements[] = $description_render_elements;
429
            }
430

    
431
            @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
432
            break;
433

    
434
          case 'sources':
435
            $dd_elements = array();
436
            foreach ($value as $identifiable_source) {
437
              $dd_elements[] = theme('cdm_OriginalSource', array('source' => $identifiable_source));
438
            }
439
            @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
440
            break;
441

    
442

    
443
          /* ---- DerivedUnitBase --- */
444
          case 'derivedFrom':
445
            $derivedFrom = $value;
446
            break;
447

    
448
          case 'collection':
449
            $sub_dl_groups = array();
450
            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('code'), $value->code, NULL, 1);
451
            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('codeStandard'), $value->codeStandard, NULL, 2);
452
            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('institute'), $value->institute, NULL, 3);
453
            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('townOrLocation'), $value->townOrLocation, NULL, 4);
454
            // TODO "superCollection"
455
            // TODO may have media
456

    
457
            @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),
458
              array(
459
                array('#markup' => $value->titleCache),
460
                array('#theme' => 'description_list', '#groups' => $sub_dl_groups)
461
              )
462
            );
463
            break;
464

    
465
          case 'storedUnder':
466
            @_description_list_group_add($groups, cdm_occurrence_field_name_label('storedUnder'), render_taxon_or_name($value));
467
            break;
468

    
469

    
470
          /* ---- Specimen --- */
471
          case 'sequences':
472
            $dd_elements = array();
473
            foreach ($value as $sequence) {
474
              $dd_elements[] = compose_cdm_sequence($sequence);
475
            }
476
            @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
477
            break;
478

    
479
          // TODO preservation
480
          // TODO exsiccatum
481

    
482

    
483
          /* ---- FieldObservation --- */
484
          case 'gatheringEvent':
485
            @_description_list_group_add($groups, cdm_occurrence_field_name_label('collector'), $value->actor->titleCache);
486
            @_description_list_group_add($groups, t('Gathering time'), timePeriodToString($value->timeperiod));
487
            @_description_list_group_add($groups, cdm_occurrence_field_name_label('description'), $value->description);
488
            @_description_list_group_add($groups, cdm_occurrence_field_name_label('locality'), $value->locality->text);
489
            @_description_list_group_add($groups, cdm_occurrence_field_name_label('country'), $value->country->representation_L10n);
490
            @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingMethod'), $value->collectingMethod);
491
            if (isset($value->absoluteElevation)) {
492
              $min_max_markup = min_max_measure($value, 'absoluteElevation');
493
              @_description_list_group_add($groups, cdm_occurrence_field_name_label('absoluteElevation'), $min_max_markup);
494
            }
495
            if (isset($value->distanceToGround)) {
496
              $min_max_markup = min_max_measure($value, 'distanceToGround');
497
              @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToGround'), $min_max_markup);
498
            }
499
            if (isset($value->distanceToWaterSurface)) {
500
              $min_max_markup = min_max_measure($value, 'distanceToWaterSurface');
501
              @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToWaterSurface'), $min_max_markup);
502
            }
503

    
504
            if (isset($value->collectingAreas)) {
505
              $area_representations = array();
506
              foreach ($value->collectingAreas as $area) {
507
                $area_representations[] = $area->representation_L10n;
508
              }
509
              @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingAreas'), implode(', ', $area_representations));
510
            }
511
            if (isset($value->exactLocation) && $value->exactLocation->sexagesimalString) {
512
              $sub_dl_groups = array();
513
              @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('errorRadius'), $value->exactLocation->errorRadius, ' m', 1);
514
              @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('longitude'), round($value->exactLocation->longitude, 7), '°', 2);
515
              @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('latitude'), round($value->exactLocation->latitude, 7), '°', 3);
516
              if (isset($value->exactLocation->referenceSystem)) {
517
                @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('referenceSystem'), $value->exactLocation->referenceSystem->representation_L10n, '', 4);
518
              }
519

    
520
              @_description_list_group_add($groups, cdm_occurrence_field_name_label('exactLocation'),
521
                array(
522
                  array('#markup' => $value->exactLocation->sexagesimalString),
523
                  array(
524
                    '#theme' => 'description_list',
525
                    '#groups' => $sub_dl_groups
526
                  ),
527
                )
528
              );
529
            }
530
            break;
531

    
532
          default:
533
            if (is_object($value) || is_array($value)) {
534
              drupal_set_message("Unhandled type in compose_cdm_specimenOrObservation() for field " . $field, "warning");
535
            } else {
536
              _description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value);
537
            }
538

    
539
        }
540

    
541
      }
542
    } // END of loop over $derivedUnitFacade fields
543

    
544
    // Extensions
545
    $extensions = cdm_ws_fetch_all(CDM_WS_PORTAL_OCCURRENCE . '/'  . $specimenOrObservation->uuid . '/extensions', array($specimenOrObservation->uuid));
546
    if ($extensions && count($extensions)) {
547

    
548
      $extensions_render_array = compose_extensions($extensions);
549
      @_description_list_group_add($groups, t('Extensions') . ':',
550
        $extensions_render_array,
551
        '', 100);
552
    }
553

    
554

    
555
    // template_preprocess_description_list() is not worting by weight so we do it right here
556
    uasort($groups, 'element_sort');
557

    
558
    $occurrence_elements = array(
559
        '#title' => $title,
560
        '#theme' => 'description_list',
561
        '#groups' => $groups,
562
        '#attributes' => array('class' => html_class_attribute_ref($specimenOrObservation)),
563
    );
564
    $derivatives[] = $occurrence_elements;
565
    // all footnotes which has been assembled so far (e.g. from typeDesignations) to here
566
    $foonote_li_elements = theme('cdm_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey(), 'enclosingTag' => 'span'));
567
    if (!empty($foonote_li_elements)) {
568
      $derivatives[] =  array(
569
          '#markup' =>  '<div class="footnotes">' . $foonote_li_elements . '</div>',
570
      );
571
    }
572

    
573
    // --- recurse into originals
574
    if (!isset($derivedFrom)) {
575
      $derivedFrom = cdm_ws_get(
576
          CDM_WS_OCCURRENCE,
577
          array($specimenOrObservation->uuid, 'derivedFrom')
578
        );
579
    }
580

    
581
    if (isset($derivedFrom)) {
582
      if (isset($derivedFrom->originals)) {
583
        $derived_from_label = t('derived');
584
        $preposition = t('from');
585
        if(isset($derivedFrom->type)){
586
          $derived_from_label = $derivedFrom->type->representation_L10n;
587
          if($derivedFrom->type->uuid == UUID_DERIVATIONEVENTTYPE_ACCESSIONING){
588
            $preposition = t('of');
589
          }
590
        }
591
        if (count($groups) > 0) {
592
          // TODO  annotations
593

    
594
          // only display the derived from information when the derivative has any element which will be diplayed
595
          $derivatives[] = array(
596
              '#markup' => '<div class="derived_from">' . $derived_from_label . ' ' . $preposition . ': </div>',
597
          );
598
        }
599
        foreach ($derivedFrom->originals as $original) {
600
          compose_cdm_specimenOrObservation($original, $derivatives);
601
        }
602
      }
603
    }
604

    
605
  } // END of $specimenOrObservation exists
606

    
607
  return $derivatives;
608
}
609

    
610

    
611
/**
612
 * Compose an render array from a CDM Sequence object.
613
 *
614
 * compose_hook() implementation
615
 *
616
 * @param object $sequence
617
 *   CDM instance of type Sequence
618
 * @return array
619
 *   A render array containing the fields of the supplied $sequence
620
 *
621
 * @ingroup compose
622
 */
623
function compose_cdm_sequence($sequence) {
624

    
625
  $exclude_sequence_fields = &drupal_static(__FUNCTION__);
626
  if (!isset($exclude_sequence_fields)) {
627
    $exclude_sequence_fields = array(
628
      'titleCache',
629
      'protectedTitleCache',
630
      'microReference',
631
      'created',
632
      'updated',
633
      'class',
634
    );
635
  }
636

    
637
  $groups = array();
638

    
639
  // -- retrieve additional data if neesscary
640
  // TODO below call disabled since sequences are not yet supported,
641
  //      see  #3347 (services and REST service controller for molecular classes implemented)
642
  //
643
  // cdm_load_annotations($sequence);
644

    
645
  foreach (get_object_vars($sequence) as $field => $value) {
646

    
647

    
648
    if (!in_array($field, $exclude_sequence_fields) && ($value && (!is_object($value) || isset($value->class)))) {
649
      switch ($field) {
650

    
651
        case 'geneticAccessionNumber';
652
          $dd_elements = array();
653
          foreach ($value as $accession) {
654
            if (isset($accession->uri) ){
655
              $dd_elements[] = l($accession->accessionNumber, $accession->uri);
656
            } else {
657
              $dd_elements[] = $accession->accessionNumber;
658
            }
659
          }
660
          @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),  $dd_elements, NULL, 1);
661
          break;
662

    
663

    
664
        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.
665
          if (isset($value->name)) {
666
            @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),  $value->name, NULL, 3);
667
          }
668
          if (isset($value->description)) {
669
            @_description_list_group_add($groups, cdm_occurrence_field_name_label($field) . ' ' . t('description') , $value->description, NULL, 4);
670
          }
671
          break;
672

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

    
688
         case 'dnaSample': // FIXME 3.3 implement
689
            break;
690
        case 'singleReads': // FIXME 3.3 implement
691
          break;
692
        case 'contigFile': // FIXME 3.3 implement - Media
693
            break;
694
        case 'pherograms': // FIXME 3.3 implement - Media
695
          break;
696
        case 'haplotype': // FIXME 3.3 implement
697
            break;
698
        case 'dateSequenced': // FIXME 3.3 now in SingelRead
699
          @_description_list_group_add($groups, t('Sequencing date'),  timePeriodToString($value), NULL, 6);
700
          break;
701

    
702
        case 'barcode': // boolean
703
          @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value ? 'Yes': 'No', NULL, 7);
704
          break;
705
        case 'barcodeSequencePart': // FIXME 3.3 implement, compose sequence
706
            break;
707

    
708
        case 'citation':
709
          @_description_list_group_add($groups,
710
            cdm_occurrence_field_name_label($field),
711
            theme('cdm_reference', array('reference' =>$value, 'microReference' => $sequence->microReference)),
712
            NULL,
713
            8
714
          );
715
          break;
716

    
717
        case 'publishedIn':
718
          @_description_list_group_add($groups,
719
            cdm_occurrence_field_name_label($field),
720
            theme('cdm_reference', array('reference'=>$value)),
721
            NULL,
722
            7
723
          );
724

    
725
        case 'rights':
726
          array_merge($groups, cdm_rights_as_dl_groups($value));
727
        break;
728

    
729
        case 'annotations':
730
          $dd_elements = array();
731
          foreach ($value as $annotation) {
732
            // TODO respect annotation type filter settings
733
            $dd_elements[] = $annotation->text;
734
          }
735
          @_description_list_group_add($groups, t('Notes'), $dd_elements, NULL, 9);
736
          break;
737

    
738
        case 'markers':
739
          $dd_elements = array();
740
          foreach ($value as $marker) {
741
            $dd_elements[] = compose_cdm_marker($marker);
742
          }
743
          @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements, NULL, 10);
744
          break;
745

    
746
        case 'chromatograms':
747
          @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),
748
              array(
749
                  '#markup'=>theme('cdm_media_gallerie', array('medialist'=>$value)),
750
              ),
751
              NULL,
752
              11);
753
          break;
754

    
755
        default:
756
          if(is_object($value) || is_array($value)){
757
            drupal_set_message("Unhandled type in compose_cdm_sequence() for field " . $field, "warning");
758
          } else {
759
            _description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 20);
760
          }
761
      }
762
    }
763
  }
764

    
765
  // template_preprocess_description_list() is not worting by weight so we do it right here
766
  uasort($groups, 'element_sort');
767

    
768
  $sequence_elements = array(
769
      '#theme' => 'description_list',
770
      '#groups' => $groups
771
  );
772

    
773
  return $sequence_elements;
774
}
775

    
776

    
(6-6/10)