Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

cdm-dataportal / modules / cdm_dataportal / includes / occurrences.inc @ a5b11885

History | View | Annotate | Download (28.9 KB)

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

    
19

    
20
/**
21
 * Provides the HTML markup for a specimen page
22
 *
23
 * @param $specimen
24
 *
25
 * @return string
26
 *  The markup for a specimen page
27
 */
28
function render_cdm_specimen_page($specimen, $is_specimen_page = false)
29
{
30
    $detail_html = "";
31
    //link to specimen page
32
    $pathToSpecimen = path_to_specimen($specimen->uuid);
33
    if (!$is_specimen_page) {
34
        $specimenPageLink = l($specimen->accessionNumber, $pathToSpecimen, array('attributes' => array('target' => '_blank')));
35
        $detail_html .= "<strong>Specimen page: $specimenPageLink</strong><br>";
36
    }
37

    
38
    if($is_specimen_page) {
39
        if($specimen->citation){
40
            $detail_html .= "<br>".create_label("Citation") . $specimen->citation . "<br>";
41
        }
42
    }
43
    if($specimen->preferredStableUri){
44
        $stableIdentifierLink  = l($specimen->preferredStableUri, $specimen->preferredStableUri, array('attributes' => array('target' => '_blank')));
45
        $detail_html .= create_label("Preferred stable URI") . $stableIdentifierLink . "<br>";
46
    }
47
    if($is_specimen_page){
48
        // associated taxa
49
        if($specimen->associatedTaxa){
50
            $detail_html .= "<br>";
51
          $detail_html .= create_label("Associated with");
52
          if(sizeof($specimen->associatedTaxa)>1){
53
            $detail_html .= "<br>";
54
          }
55
          foreach($specimen->associatedTaxa as $associatedTaxon){
56
            $detail_html .= l($associatedTaxon->second, path_to_taxon($associatedTaxon->first, "specimens"));//$associatedTaxon->second."<br>";
57
          }
58
          $detail_html .= "<br>";
59
        }
60
    }
61
  // - type information
62
    $types = "";
63
    if (isset($specimen->types)) {
64
        //typed taxa
65
        foreach ($specimen->types as $typeStatus => $typedTaxa) {
66
            if($specimen->types){
67
                if($typeStatus == NULL){
68
                    $detail_html .= "<i>no type status set:</i> ";
69
                }
70
                else{
71
                    $detail_html .= "<i>".$typeStatus."</i> of ";
72
                }
73
                foreach($typedTaxa as $typedTaxon){
74
                    $detail_html .= $typedTaxon." ";
75
                }
76
                $detail_html .= "<br>";
77
            }
78
        }
79
    }
80
    $derivateDataDTO = $specimen->derivateDataDTO;
81
    // - specimen scans
82
    $specimenScans = create_html_links($derivateDataDTO->specimenScans, true);
83
    // - molecular data
84
    $molecularData = "";
85
    if ($derivateDataDTO->molecularDataList) {
86
        foreach ($derivateDataDTO->molecularDataList as $molecular) {
87
            //provider link
88
            if (isset($molecular->providerLink)) {
89
                $molecularData .= create_html_link($molecular->providerLink, true);
90
            } else {
91
                $molecularData .= "[no provider]";
92
            }
93
            //contig link
94
            if (isset($molecular->contigFiles)) {
95
                $molecularData .= "[";
96
                if (sizeof($molecular->contigFiles) > 0) {
97
                    foreach ($molecular->contigFiles as $contigFile) {
98
                        if (isset($contigFile->contigLink)) {
99
                            if (isset($contigFile->contigLink->uri) and $contigFile->contigLink->uri != null) {
100
                                $molecularData .= create_html_link($contigFile->contigLink, true) . " ";
101
                            }
102
                        }
103
                        else {
104
                            $molecularData .= "no contig ";
105
                        }
106
                        //primer links
107
                        if(isset($contigFile->primerLinks)) {
108
                            $molecularData .= create_html_links($contigFile->primerLinks, true);
109
                        }
110
                    }
111
                }
112
                $molecularData = rtrim($molecularData, " ");
113
                $molecularData .= "]";
114
            }
115
            //FIXME separate with comma (remove trailing comma)
116
        }
117
    }
118
    // - detail images
119
    $detailImages = create_html_links($derivateDataDTO->detailImages, true);
120

    
121
    if ($types) {
122
        $detail_html .= $is_specimen_page?"<br>":"";
123
        $detail_html .= create_label("Type(s)") . $types . "<br>";
124
    }
125
    if ($specimenScans and !$is_specimen_page) {
126
        $detail_html .= create_label("Specimen Scans") . $specimenScans . "<br>";
127
    }
128
    //specimen scan image gallery
129
    if($is_specimen_page and isset($derivateDataDTO->specimenScanUuids) and !empty($derivateDataDTO->specimenScanUuids)) {
130
        $detail_html .= addImageGallery("Specimen scans", $derivateDataDTO->specimenScanUuids);
131
    }
132

    
133
    if ($molecularData) {
134
        $detail_html .= $is_specimen_page?"<br>":"";
135
        $detail_html .= create_label("Molecular Data") . $molecularData . "<br>";
136
    }
137

    
138
    if ($detailImages and !$is_specimen_page) {
139
        $detail_html .= create_label("Detail Images") . $detailImages . "<br>";
140
    }
141

    
142
    //detail image gallery
143
    if($is_specimen_page and isset($derivateDataDTO->detailImageUuids) and !empty($derivateDataDTO->detailImageUuids)){
144
        $detail_html .= addImageGallery("Detail Images", $derivateDataDTO->detailImageUuids);
145
    }
146

    
147
    //character data
148
    if ($specimen->characterData) {
149
        $detail_html .= $is_specimen_page?"<br>":"";
150
        $detail_html .= create_label("Character Data");
151
        if($is_specimen_page) {
152
            $detail_html .= "<br>";
153
            foreach ($specimen->characterData as $characterStatePair) {
154
                $detail_html .= "<i>" . $characterStatePair->first . "</i>:" . $characterStatePair->second;
155
                $detail_html .= "<br>";
156
            }
157
        }
158
        else{
159
            $detail_html .= l("detail page", $pathToSpecimen,array('attributes' => array('target'=>'_blank')));
160
            $detail_html .= "<br>";
161
        }
162
    }
163
    return $detail_html;
164
}
165

    
166
function addImageGallery($galleryName, $imageUuids){
167
    $images = array();
168
    foreach ($imageUuids as $uuid) {
169
        $images[] = cdm_ws_get(CDM_WS_PORTAL_MEDIA, $uuid);
170
    }
171

    
172
    $gallery_html = '';
173
    if (count($imageUuids) > 0) {
174
        $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
175
        $captionElements = array(
176
            'title',
177
            'rights',
178
        );
179
        $alternativeMediaUris = array();
180
        foreach($images as $image){
181
          $mediaUri = getMediaUri($image);
182
          if($mediaUri){
183
            $alternativeMediaUris[] = $mediaUri;
184
          }
185
          else{
186
            $alternativeMediaUris[] = path_to_media($image->uuid);
187
          }
188
        }
189

    
190
        $gallery_html = compose_cdm_media_gallerie(array(
191
            'mediaList' => $images,
192
            'galleryName' => $galleryName,
193
            'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
194
            'cols' => $gallery_settings['cdm_dataportal_media_cols'],
195
            'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
196
            'captionElements' => $captionElements,
197
            'mediaLinkType' => 'LIGHTBOX',
198
            'alternativeMediaUri' => $alternativeMediaUris,
199
            'galleryLinkUri' => NULL,
200
        ));
201
    }
202
    return "<br>".create_label($galleryName)."<br>".$gallery_html;
203
}
204

    
205
function getMediaUri($media){
206
  if(isset($media->representations) && sizeof($media->representations)==1
207
    && isset($media->representations[0]->parts) &&
208
    sizeof($media->representations[0]->parts)==1) {
209
    return $media->representations[0]->parts[0]->uri;
210
  }
211
  return null;
212
}
213

    
214

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

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

    
244
  $exclude_occurrence_fields = &drupal_static(__FUNCTION__);
245
  if (!isset($exclude_occurrence_fields)) {
246
     $exclude_occurrence_fields = array(
247
        'derivationEvents',
248
        'titleCache',
249
        'protectedTitleCache',
250
        'derivedUnitMedia',
251
        'created',
252
        'publish',
253
        'updated',
254
        'class',
255
        'uuid',
256
       ''
257
    );
258
  }
259

    
260

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

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

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

    
273
  if (is_object($specimenOrObservation)) {
274

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

    
278

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

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

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

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

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

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

    
318

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

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

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

    
339
          case 'preferredStableUri':
340

    
341
            @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), array(array('#markup' => cdm_external_uri($value, false))));
342
            break;
343

    
344
          case 'specimenTypeDesignations':
345
            @_description_list_group_add(
346
              $groups,
347
              cdm_occurrence_field_name_label($field),
348
              array(
349
                '#markup' => theme('cdm_typedesignations', array('typeDesignations' => $value)),
350
              )
351
            );
352
            break;
353

    
354
          case 'determinations':
355
            $dd_elements = array();
356
            $glue = ', ';
357

    
358
            foreach ($value as $determinationEvent) {
359
              $timeperiod_string = NULL;
360
              if (isset($determinationEvent->timeperiod)) {
361
                $timeperiod_string = timePeriodToString($determinationEvent->timeperiod);
362
              }
363
              $weight = isset($determinationEvent->preferred) && $determinationEvent->preferred == 1 ? '0' : ($timeperiod_string ? $timeperiod_string : '1');
364
              // check key exists
365
              while (array_key_exists($weight, $dd_elements)) {
366
                $weight .= '0';
367
              }
368

    
369
              $taxon_name = '';
370
              $name_link = '';
371
              if ($determinationEvent->taxonName) {
372
                $taxon_name = $determinationEvent->taxonName;
373
              } else if ($determinationEvent->taxon) {
374
                $taxon_name = cdm_ws_get(CDM_WS_TAXON . '/$0/name', $determinationEvent->taxon->uuid);
375
                $name_link = path_to_taxon($determinationEvent->taxon->uuid);
376
              }
377
              if ($taxon_name) {
378
                $taxon_html = render_taxon_or_name($taxon_name, $name_link);
379
                $dd_elements[$weight] = $taxon_html;
380
              }
381
              if (isset($determinationEvent->modifier)) {
382
                $dd_elements[$weight] .= cdm_term_representation($determinationEvent->modifier);
383
              }
384
              if ($timeperiod_string) {
385
                $dd_elements[$weight] .= $glue . $timeperiod_string;
386
              }
387
              if (isset($determinationEvent->actor->titleCache)) {
388
                $dd_elements[$weight] .= $glue . $determinationEvent->actor->titleCache;
389
              }
390
              if (isset($determinationEvent->description)) {
391
                $dd_elements[$weight] .= $glue . $determinationEvent->description;
392
              }
393
            }
394
            ksort($dd_elements);
395
            @_description_list_group_add($groups, cdm_occurrence_field_name_label('determinations'), $dd_elements);
396
            break;
397

    
398
          case 'descriptions':
399
            $occurrence_featureTree = cdm_get_occurrence_featureTree();
400
            $dd_elements = array();
401

    
402
            foreach ($value as $description) {
403
              $description = cdm_ws_get(CDM_WS_PORTAL_DESCRIPTION, $description->uuid);
404
//               if($description->imageGallery == TRUE) {
405
//                 continue;
406
//               }
407
              $elements_by_feature = _mergeFeatureTreeDescriptions($occurrence_featureTree->root->childNodes, $description->elements);
408
              $description_render_elements = _block_get_renderable_array(make_feature_block_list($elements_by_feature, null));
409
              $dd_elements[] = $description_render_elements;
410
            }
411

    
412
            @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
413
            break;
414

    
415
          case 'sources':
416
            $dd_elements = array();
417
            foreach ($value as $identifiable_source) {
418
              $dd_elements[] = theme('cdm_OriginalSource', array('source' => $identifiable_source));
419
            }
420
            @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
421
            break;
422

    
423

    
424
          /* ---- DerivedUnitBase --- */
425
          case 'derivedFrom':
426
            $derivedFrom = $value;
427
            break;
428

    
429
          case 'collection':
430
            $sub_dl_groups = array();
431
            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('code'), $value->code, NULL, 1);
432
            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('codeStandard'), $value->codeStandard, NULL, 2);
433
            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('institute'), $value->institute, NULL, 3);
434
            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('townOrLocation'), $value->townOrLocation, NULL, 4);
435
            // TODO "superCollection"
436
            // TODO may have media
437

    
438
            @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),
439
              array(
440
                array('#markup' => $value->titleCache),
441
                array('#theme' => 'description_list', '#groups' => $sub_dl_groups)
442
              )
443
            );
444
            break;
445

    
446
          case 'storedUnder':
447
            @_description_list_group_add($groups, cdm_occurrence_field_name_label('storedUnder'), render_taxon_or_name($value));
448
            break;
449

    
450

    
451
          /* ---- Specimen --- */
452
          case 'sequences':
453
            $dd_elements = array();
454
            foreach ($value as $sequence) {
455
              $dd_elements[] = compose_cdm_sequence($sequence);
456
            }
457
            @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
458
            break;
459

    
460
          // TODO preservation
461
          // TODO exsiccatum
462

    
463

    
464
          /* ---- FieldObservation --- */
465
          case 'gatheringEvent':
466
            @_description_list_group_add($groups, cdm_occurrence_field_name_label('collector'), $value->actor->titleCache);
467
            @_description_list_group_add($groups, t('Gathering time'), timePeriodToString($value->timeperiod));
468
            @_description_list_group_add($groups, cdm_occurrence_field_name_label('description'), $value->description);
469
            @_description_list_group_add($groups, cdm_occurrence_field_name_label('locality'), $value->locality->text);
470
            @_description_list_group_add($groups, cdm_occurrence_field_name_label('country'), $value->country->representation_L10n);
471
            @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingMethod'), $value->collectingMethod);
472
            if (isset($value->absoluteElevation)) {
473
              $min_max_markup = min_max_measure($value, 'absoluteElevation');
474
              @_description_list_group_add($groups, cdm_occurrence_field_name_label('absoluteElevation'), $min_max_markup);
475
            }
476
            if (isset($value->distanceToGround)) {
477
              $min_max_markup = min_max_measure($value, 'distanceToGround');
478
              @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToGround'), $min_max_markup);
479
            }
480
            if (isset($value->distanceToWaterSurface)) {
481
              $min_max_markup = min_max_measure($value, 'distanceToWaterSurface');
482
              @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToWaterSurface'), $min_max_markup);
483
            }
484

    
485
            if (isset($value->collectingAreas) && count($value->collectingAreas) > 0) {
486
              $area_representations = array();
487
              foreach ($value->collectingAreas as $area) {
488
                $area_representations[] = l($area->representation_L10n, path_to_named_area($area->uuid));
489
              }
490
              @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingAreas'),
491
                array(
492
                  array('#markup' => implode(', ', $area_representations))
493
                )
494
              );
495
            }
496
            if (isset($value->exactLocation) && $value->exactLocation->sexagesimalString) {
497
              $sub_dl_groups = array();
498
              @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('errorRadius'), $value->exactLocation->errorRadius, ' m', 1);
499
              @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('longitude'), round($value->exactLocation->longitude, 7), '°', 2);
500
              @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('latitude'), round($value->exactLocation->latitude, 7), '°', 3);
501
              if (isset($value->exactLocation->referenceSystem)) {
502
                @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('referenceSystem'), $value->exactLocation->referenceSystem->representation_L10n, '', 4);
503
              }
504

    
505
              @_description_list_group_add($groups, cdm_occurrence_field_name_label('exactLocation'),
506
                array(
507
                  array('#markup' => $value->exactLocation->sexagesimalString),
508
                  array(
509
                    '#theme' => 'description_list',
510
                    '#groups' => $sub_dl_groups
511
                  ),
512
                )
513
              );
514
            }
515
            break;
516

    
517
          default:
518
            if (is_object($value) || is_array($value)) {
519
              drupal_set_message("Unhandled type in compose_cdm_specimen_or_observation() for field " . $field, "warning");
520
            } else {
521
              _description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value);
522
            }
523

    
524
        }
525

    
526
      }
527
    } // END of loop over $derivedUnitFacade fields
528

    
529
    // Extensions
530
    $extensions = cdm_ws_fetch_all(CDM_WS_PORTAL_OCCURRENCE . '/'  . $specimenOrObservation->uuid . '/extensions', array($specimenOrObservation->uuid));
531
    if ($extensions && count($extensions)) {
532

    
533
      $extensions_render_array = compose_extensions($extensions);
534
      @_description_list_group_add($groups, t('Extensions') . ':',
535
        $extensions_render_array,
536
        '', 100);
537
    }
538

    
539

    
540
    // template_preprocess_description_list() is not worting by weight so we do it right here
541
    uasort($groups, 'element_sort');
542

    
543
    $occurrence_elements = array(
544
        '#title' => $title,
545
        '#theme' => 'description_list',
546
        '#groups' => $groups,
547
        '#attributes' => array('class' => html_class_attribute_ref($specimenOrObservation)),
548
    );
549
    $derivatives[] = $occurrence_elements;
550
    // all footnotes which has been assembled so far (e.g. from typeDesignations) to here
551
    $foonote_li_elements = theme('cdm_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey(), 'enclosingTag' => 'span'));
552
    if (!empty($foonote_li_elements)) {
553
      $derivatives[] =  array(
554
          '#markup' =>  '<div class="footnotes">' . $foonote_li_elements . '</div>',
555
      );
556
    }
557

    
558
    // --- recurse into originals
559
    if (!isset($derivedFrom)) {
560
      $derivedFrom = cdm_ws_get(
561
          CDM_WS_OCCURRENCE,
562
          array($specimenOrObservation->uuid, 'derivedFrom')
563
        );
564
    }
565

    
566
    if (isset($derivedFrom)) {
567
      if (isset($derivedFrom->originals)) {
568
        $derived_from_label = t('derived');
569
        $preposition = t('from');
570
        if(isset($derivedFrom->type)){
571
          $derived_from_label = $derivedFrom->type->representation_L10n;
572
          if($derivedFrom->type->uuid == UUID_DERIVATIONEVENTTYPE_ACCESSIONING){
573
            $preposition = t('of');
574
          }
575
        }
576
        if (count($groups) > 0) {
577
          // TODO  annotations
578

    
579
          // only display the derived from information when the derivative has any element which will be diplayed
580
          $derivatives[] = array(
581
              '#markup' => '<div class="derived_from">' . $derived_from_label . ' ' . $preposition . ': </div>',
582
          );
583
        }
584
        foreach ($derivedFrom->originals as $original) {
585
          compose_cdm_specimen_or_observation($original, $derivatives);
586
        }
587
      }
588
    }
589

    
590
  } // END of $specimenOrObservation exists
591

    
592
  return $derivatives;
593
}
594

    
595

    
596
/**
597
 * Compose an render array from a CDM Sequence object.
598
 *
599
 * compose_hook() implementation
600
 *
601
 * @param object $sequence
602
 *   CDM instance of type Sequence
603
 * @return array
604
 *   A render array containing the fields of the supplied $sequence
605
 *
606
 * @ingroup compose
607
 */
608
function compose_cdm_sequence($sequence) {
609

    
610
  $exclude_sequence_fields = &drupal_static(__FUNCTION__);
611
  if (!isset($exclude_sequence_fields)) {
612
    $exclude_sequence_fields = array(
613
      'titleCache',
614
      'protectedTitleCache',
615
      'microReference',
616
      'created',
617
      'updated',
618
      'class',
619
    );
620
  }
621

    
622
  $groups = array();
623

    
624
  // -- retrieve additional data if neesscary
625
  // TODO below call disabled since sequences are not yet supported,
626
  //      see  #3347 (services and REST service controller for molecular classes implemented)
627
  //
628
  // cdm_load_annotations($sequence);
629

    
630
  foreach (get_object_vars($sequence) as $field => $value) {
631

    
632

    
633
    if (!in_array($field, $exclude_sequence_fields) && ($value && (!is_object($value) || isset($value->class)))) {
634
      switch ($field) {
635

    
636
        case 'geneticAccessionNumber';
637
          $dd_elements = array();
638
          foreach ($value as $accession) {
639
            if (isset($accession->uri) ){
640
              $dd_elements[] = l($accession->accessionNumber, $accession->uri);
641
            } else {
642
              $dd_elements[] = $accession->accessionNumber;
643
            }
644
          }
645
          @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),  $dd_elements, NULL, 1);
646
          break;
647

    
648

    
649
        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.
650
          if (isset($value->name)) {
651
            @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),  $value->name, NULL, 3);
652
          }
653
          if (isset($value->description)) {
654
            @_description_list_group_add($groups, cdm_occurrence_field_name_label($field) . ' ' . t('description') , $value->description, NULL, 4);
655
          }
656
          break;
657

    
658
        case 'consensusSequence':
659
          // format in genbank style, force linebreaks after each 70 nucleotites
660
          // see also http://stackoverflow.com/questions/499137/css-how-can-i-force-a-long-string-without-any-blank-to-be-wrapped-in-xul-and
661
          @_description_list_group_add(
662
            $groups,
663
            cdm_occurrence_field_name_label($field),
664
            array(
665
              array(
666
                '#markup' => '<div class="sequence-length">' . $value->length . ' ' . t('pb'). '</div><div>' . wordwrap($value->string, 70, '</br>', TRUE) . '</div>',
667
                '#wrapper_attributes' => array('class'=>'dna-sequence')
668
                )
669
              ),
670
            5);
671
          break;
672

    
673
         case 'dnaSample': // FIXME 3.3 implement
674
            break;
675
        case 'singleReads': // FIXME 3.3 implement
676
          break;
677
        case 'contigFile': // FIXME 3.3 implement - Media
678
            break;
679
        case 'pherograms': // FIXME 3.3 implement - Media
680
          break;
681
        case 'haplotype': // FIXME 3.3 implement
682
            break;
683
        case 'dateSequenced': // FIXME 3.3 now in SingelRead
684
          @_description_list_group_add($groups, t('Sequencing date'),  timePeriodToString($value), NULL, 6);
685
          break;
686

    
687
        case 'barcode': // boolean
688
          @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value ? 'Yes': 'No', NULL, 7);
689
          break;
690
        case 'barcodeSequencePart': // FIXME 3.3 implement, compose sequence
691
            break;
692

    
693
        case 'citation':
694
          @_description_list_group_add($groups,
695
            cdm_occurrence_field_name_label($field),
696
            theme('cdm_reference', array('reference' =>$value, 'microReference' => $sequence->microReference)),
697
            NULL,
698
            8
699
          );
700
          break;
701

    
702
        case 'publishedIn':
703
          @_description_list_group_add($groups,
704
            cdm_occurrence_field_name_label($field),
705
            theme('cdm_reference', array('reference'=>$value)),
706
            NULL,
707
            7
708
          );
709
          break;
710

    
711
        case 'rights':
712
          array_merge($groups, cdm_rights_as_dl_groups($value));
713
          break;
714

    
715
        case 'annotations':
716
          $dd_elements = array();
717
          foreach ($value as $annotation) {
718
            // TODO respect annotation type filter settings
719
            $dd_elements[] = $annotation->text;
720
          }
721
          @_description_list_group_add($groups, t('Notes'), $dd_elements, NULL, 9);
722
          break;
723

    
724
        case 'markers':
725
          $dd_elements = array();
726
          foreach ($value as $marker) {
727
            $dd_elements[] = compose_cdm_marker($marker);
728
          }
729
          @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements, NULL, 10);
730
          break;
731

    
732
        case 'chromatograms':
733
          @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),
734
              array(
735
                  '#markup'=>compose_cdm_media_gallerie(array('medialist'=>$value)),
736
              ),
737
              NULL,
738
              11);
739
          break;
740

    
741
        default:
742
          if(is_object($value) || is_array($value)){
743
            drupal_set_message("Unhandled type in compose_cdm_sequence() for field " . $field, "warning");
744
          } else {
745
            _description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value, NULL, 20);
746
          }
747
      }
748
    }
749
  }
750

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

    
754
  $sequence_elements = array(
755
      '#theme' => 'description_list',
756
      '#groups' => $groups
757
  );
758

    
759
  return $sequence_elements;
760
}
761

    
762

    
Add picture from clipboard (Maximum size: 40 MB)