Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

cdm-dataportal / modules / cdm_dataportal / includes / occurrences.inc @ 2d6348e5

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

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

    
128
    if ($molecularData) {
129
        $detail_html .= $is_specimen_page?"<br>":"";
130
        $detail_html .= create_label("Molecular Data") . $molecularData . "<br>";
131
    }
132

    
133
    if ($detailImages and !$is_specimen_page) {
134
        $detail_html .= create_label("Detail Images") . $detailImages . "<br>";
135
    }
136

    
137
    //detail image gallery
138
    if($is_specimen_page and isset($derivateDataDTO->detailImageUuids) and !empty($derivateDataDTO->detailImageUuids)){
139
        $detail_html .= addImageGallery("Detail Images", $derivateDataDTO->detailImageUuids);
140
    }
141

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

    
161
function addImageGallery($galleryName, $imageUuids){
162
    $images = array();
163
    foreach ($imageUuids as $uuid) {
164
        $images[] = cdm_ws_get(CDM_WS_PORTAL_MEDIA, $uuid);
165
    }
166

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

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

    
200
function getMediaUri($media){
201
  if(isset($media->representations) && sizeof($media->representations)==1
202
    && isset($media->representations[0]->parts) &&
203
    sizeof($media->representations[0]->parts)==1) {
204
    return $media->representations[0]->parts[0]->uri;
205
  }
206
  return null;
207
}
208

    
209

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

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

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

    
255

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

    
261
  if (!isset($derivatives)) {
262
    $derivatives = array();
263
  }
264

    
265
  $descriptions = null;
266
  $derivedFrom = null;
267

    
268
  if (is_object($specimenOrObservation)) {
269

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

    
273

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

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

    
290
    $title = $type_label . ': ' . $specimenOrObservation->titleCache;
291

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

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

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

    
313

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

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

    
330
          case 'definition':
331
            // TODO
332
            break;
333

    
334
          case 'preferredStableUri':
335

    
336
            @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), array(array('#markup' => cdm_external_uri($value, false))));
337
            break;
338

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

    
349
          case 'determinations':
350
            $dd_elements = array();
351
            $glue = ', ';
352

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

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

    
393
          case 'descriptions':
394
            $occurrence_featureTree = cdm_get_occurrence_featureTree();
395
            $dd_elements = array();
396

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

    
407
            @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
408
            break;
409

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

    
418

    
419
          /* ---- DerivedUnitBase --- */
420
          case 'derivedFrom':
421
            $derivedFrom = $value;
422
            break;
423

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

    
433
            @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),
434
              array(
435
                array('#markup' => $value->titleCache),
436
                array('#theme' => 'description_list', '#groups' => $sub_dl_groups)
437
              )
438
            );
439
            break;
440

    
441
          case 'storedUnder':
442
            @_description_list_group_add($groups, cdm_occurrence_field_name_label('storedUnder'), render_taxon_or_name($value));
443
            break;
444

    
445

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

    
455
          // TODO preservation
456
          // TODO exsiccatum
457

    
458

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

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

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

    
512
          default:
513
            if (is_object($value) || is_array($value)) {
514
              drupal_set_message("Unhandled type in compose_cdm_specimen_or_observation() for field " . $field, "warning");
515
            } else {
516
              _description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value);
517
            }
518

    
519
        }
520

    
521
      }
522
    } // END of loop over $derivedUnitFacade fields
523

    
524
    // Extensions
525
    $extensions = cdm_ws_fetch_all(CDM_WS_PORTAL_OCCURRENCE . '/'  . $specimenOrObservation->uuid . '/extensions', array($specimenOrObservation->uuid));
526
    if ($extensions && count($extensions)) {
527

    
528
      $extensions_render_array = compose_extensions($extensions);
529
      @_description_list_group_add($groups, t('Extensions') . ':',
530
        $extensions_render_array,
531
        '', 100);
532
    }
533

    
534

    
535
    // template_preprocess_description_list() is not worting by weight so we do it right here
536
    uasort($groups, 'element_sort');
537

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

    
553
    // --- recurse into originals
554
    if (!isset($derivedFrom)) {
555
      $derivedFrom = cdm_ws_get(
556
          CDM_WS_OCCURRENCE,
557
          array($specimenOrObservation->uuid, 'derivedFrom')
558
        );
559
    }
560

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

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

    
585
  } // END of $specimenOrObservation exists
586

    
587
  return $derivatives;
588
}
589

    
590

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

    
605
  $exclude_sequence_fields = &drupal_static(__FUNCTION__);
606
  if (!isset($exclude_sequence_fields)) {
607
    $exclude_sequence_fields = array(
608
      'titleCache',
609
      'protectedTitleCache',
610
      'microReference',
611
      'created',
612
      'updated',
613
      'class',
614
    );
615
  }
616

    
617
  $groups = array();
618

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

    
625
  foreach (get_object_vars($sequence) as $field => $value) {
626

    
627

    
628
    if (!in_array($field, $exclude_sequence_fields) && ($value && (!is_object($value) || isset($value->class)))) {
629
      switch ($field) {
630

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

    
643

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

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

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

    
682
        case 'barcode': // boolean
683
          @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value ? 'Yes': 'No', NULL, 7);
684
          break;
685
        case 'barcodeSequencePart': // FIXME 3.3 implement, compose sequence
686
            break;
687

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

    
697
        case 'publishedIn':
698
          @_description_list_group_add($groups,
699
            cdm_occurrence_field_name_label($field),
700
            theme('cdm_reference', array('reference'=>$value)),
701
            NULL,
702
            7
703
          );
704
          break;
705

    
706
        case 'rights':
707
          array_merge($groups, cdm_rights_as_dl_groups($value));
708
          break;
709

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

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

    
727
        case 'chromatograms':
728
          @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),
729
              array(
730
                  '#markup'=>compose_cdm_media_gallerie(array('medialist'=>$value)),
731
              ),
732
              NULL,
733
              11);
734
          break;
735

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

    
746
  // template_preprocess_description_list() is not worting by weight so we do it right here
747
  uasort($groups, 'element_sort');
748

    
749
  $sequence_elements = array(
750
      '#theme' => 'description_list',
751
      '#groups' => $groups
752
  );
753

    
754
  return $sequence_elements;
755
}
756

    
757

    
Add picture from clipboard (Maximum size: 40 MB)