Project

General

Profile

Download (30.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($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 .= create_label("Specimen Scans") . $specimenScans . "<br>";
138
    }
139
    //specimen scan image gallery
140
    if($isSpecimenPage and isset($derivateDataDTO->specimenScanUuids) and !empty($derivateDataDTO->specimenScanUuids)) {
141
        $detail_html .= addImageGallery("Specimen scans", $derivateDataDTO->specimenScanUuids);
142
    }
143

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

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

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

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

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

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

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

    
210

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

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

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

    
257

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

    
263
  if (!isset($derivatives)) {
264
    $derivatives = array();
265
  }
266

    
267
  $descriptions = null;
268
  $derivedFrom = null;
269

    
270
  if (is_object($specimenOrObservation)) {
271

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

    
275

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

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

    
292
    $title = $type_label . ': '. $specimenOrObservation->titleCache;
293

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

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

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

    
315

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

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

    
332
          case 'definition':
333
            // TODO
334
            break;
335

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

    
346
          case 'determinations':
347
            $dd_elements = array();
348
            $glue = ', ';
349

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

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

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

    
402
            @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
403
            break;
404

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

    
413

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

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

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

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

    
440

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

    
450
            // TODO preservation
451
            // TODO exsiccatum
452

    
453

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

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

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

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

    
555
        }
556

    
557
      }
558
    } // END of loop over $derivedUnitFacade fields
559

    
560

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

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

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

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

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

    
611
  } // END of $specimenOrObservation exists
612

    
613
  return $derivatives;
614
}
615

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

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

    
642
  $groups = array();
643

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

    
650
  foreach (get_object_vars($sequence) as $field => $value) {
651

    
652

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

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

    
668

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

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

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

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

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

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

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

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

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

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

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

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

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

    
778
  return $sequence_elements;
779
}
780

    
781

    
(6-6/10)