Project

General

Profile

Download (28.8 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
 * 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>".$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){
68
                    $detail_html .= "<i>".$typeStatus."</i> of ";
69
                } else {
70
                    $detail_html .= "<i>no type status set:</i> ";
71
                }
72
                foreach($typedTaxa as $typedTaxon){
73
                    $detail_html .= $typedTaxon." ";
74
                }
75
                $detail_html .= "<br>";
76
            }
77
        }
78
    }
79
    $derivateDataDTO = $specimen->derivateDataDTO;
80
    // - specimen scans
81
    $specimenScans = create_html_links($derivateDataDTO->specimenScans, true);
82
    // - molecular data
83
    $molecularData = "";
84
    if ($derivateDataDTO->molecularDataList) {
85
        foreach ($derivateDataDTO->molecularDataList as $molecular) {
86
            //provider link
87
            if (isset($molecular->providerLink)) {
88
                $molecularData .= create_html_link($molecular->providerLink, true);
89
            } else {
90
                $molecularData .= "[no provider]";
91
            }
92
            //contig link
93
            if (isset($molecular->contigFiles)) {
94
                $molecularData .= "[";
95
                if (sizeof($molecular->contigFiles) > 0) {
96
                    foreach ($molecular->contigFiles as $contigFile) {
97
                        if (isset($contigFile->contigLink)) {
98
                            if (isset($contigFile->contigLink->uri) and $contigFile->contigLink->uri != null) {
99
                                $molecularData .= create_html_link($contigFile->contigLink, true) . " ";
100
                            }
101
                        }
102
                        else {
103
                            $molecularData .= "no contig ";
104
                        }
105
                        //primer links
106
                        if(isset($contigFile->primerLinks)) {
107
                            $molecularData .= create_html_links($contigFile->primerLinks, true);
108
                        }
109
                    }
110
                }
111
                $molecularData = rtrim($molecularData, " ");
112
                $molecularData .= "]";
113
            }
114
            //FIXME separate with comma (remove trailing comma)
115
        }
116
    }
117
    // - detail images
118
    $detailImages = create_html_links($derivateDataDTO->detailImages, true);
119

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

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

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

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

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

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

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

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

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

    
213

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

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

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

    
259

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

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

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

    
272
  if (is_object($specimenOrObservation)) {
273

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

    
277

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

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

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

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

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

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

    
317

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

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

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

    
338
          case 'preferredStableUri':
339

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

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

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

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

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

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

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

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

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

    
422

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

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

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

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

    
449

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

    
459
          // TODO preservation
460
          // TODO exsiccatum
461

    
462

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

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

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

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

    
523
        }
524

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

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

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

    
538

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

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

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

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

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

    
589
  } // END of $specimenOrObservation exists
590

    
591
  return $derivatives;
592
}
593

    
594

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

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

    
621
  $groups = array();
622

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

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

    
631

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

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

    
647

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

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

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

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

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

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

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

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

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

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

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

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

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

    
758
  return $sequence_elements;
759
}
760

    
761

    
(6-6/10)