Project

General

Profile

Download (31.6 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
// $Id$
3

    
4
/**
5
 * Copyright (C) 2007 EDIT
6
 * European Distributed Institute of Taxonomy
7
 * http://www.e-taxonomy.eu
8
 *
9
 * The contents of this file are subject to the Mozilla Public License Version 1.1
10
 * See http://www.mozilla.org/MPL/MPL-1.1.html for the full license terms.
11
 */
12

    
13
/**
14
 * default title for a taxon page
15
 *
16
 * @param NameTO $nameTO
17
 * @return the formatted taxon name
18
 */
19
function theme_cdm_taxon_page_title($taxon, $uuid){
20
  RenderHints::pushToRenderStack('taxon_page_title');
21
  if(isset($taxon->name->nomenclaturalReference)){
22
    $referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
23
  }
24
  $out = theme('cdm_taxonName', $taxon->name, null, $referenceUri, false);
25
  RenderHints::popFromRenderStack();
26

    
27
  return '<span class="'.$taxon->class.'">'.$out.'</span>';
28
}
29

    
30
/**
31
 * Default title for a name page
32
 * @param string $taxon_name The taxon name object
33
 * @return the formatted name title
34
 */
35
function theme_cdm_name_page_title($taxon_name){
36
  RenderHints::pushToRenderStack('taxon_page_title');
37
  if(isset($taxon_name->nomenclaturalReference)){
38
    $referenceUri = url(path_to_reference($taxon_name->nomenclaturalReference->uuid));
39
  }
40

    
41
  $out = '<span class="'.$taxon_name->class.'">'.theme('cdm_taxonName', $taxon_name, null, $referenceUri, false).'</span>';
42
  RenderHints::popFromRenderStack();
43
  return $out;
44
}
45

    
46
/**
47
 * A wrapper function that groups available information to show by default, when
48
 * a taxon page is requested by the browser.
49
 * Individual themeing has to decide what this page should include (see methods beneath)
50
 * and what information should go into tabs or should not be shown at all.
51
 *
52
 * It is headed by the name of the accepted taxon without author and reference.
53
 * @param $taxonTO the taxon object
54
 * @param $page_part name of the part to display,
55
 *         valid values are: 'description', 'images', 'synonymy', 'all'
56
 */
57
function theme_cdm_taxon_page($taxon, $page_part = 'description') {
58

    
59
  global $theme;
60

    
61
  $page_part = variable_get('cdm_dataportal_taxonpage_tabs', 1) ? $page_part : 'all';
62
  $hideTabs = array();
63

    
64

    
65
  // --- GET Images --- //
66

    
67
  $mediaQueryParameters = array("type"=>"ImageFile");
68

    
69
  $selectShowMedia = variable_get('cdm_dataportal_show_media', 0);
70
  if ($selectShowMedia == 0){
71
    $media = cdm_ws_get(CDM_WS_PORTAL_TAXON_MEDIA, array($taxon->uuid), queryString($mediaQueryParameters));
72
  }else{
73
    $media = cdm_ws_get(CDM_WS_PORTAL_TAXON_SUBTREE_MEDIA, array($taxon->uuid), queryString($mediaQueryParameters));
74
  }
75
  if(!isset($media[0])) {
76
    $hideTabs[] = theme('cdm_taxonpage_tab', 'Images');
77
  }
78
  // hideImage flag depending on administative preset
79
  $hideImages = false;
80
  if(variable_get('image_hide_rank', '0') != '0'){
81
    $rankCompare = rank_compare($taxon->name->rank->uuid, variable_get('image_hide_rank', '-99'));
82
    $hideImages =  ($rankCompare > -1);
83
  }
84

    
85
  // --- GET specimensOrObersvations --- //
86
  $specimensOrObersvations = cdm_ws_get(CDM_WS_TAXON, array($taxon->uuid, 'specimensOrObersvations') );
87
  $specimensOrObersvationsCount = is_array($specimensOrObersvations) ? count($specimensOrObersvations) : 0;
88
  if($specimensOrObersvationsCount == 0) {
89
    $hideTabs[] = theme('cdm_taxonpage_tab', 'Specimens');
90
  }
91

    
92
  // --- GET polytomousKeys --- //
93
  $polytomousKeysPager = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, null, "findByTaxonomicScope=$taxon->uuid");
94
  $identificationKeyCount = 0;
95
  if($polytomousKeysPager){
96
   $identificationKeyCount += $polytomousKeysPager->count;
97
  }
98
  if($identificationKeyCount == 0){
99
    $hideTabs[] = theme('cdm_taxonpage_tab', 'Keys');
100
  }
101
  // -------------------------------------------- //
102

    
103
  // hide tabs
104
  $tabhide_js = '';
105
  foreach($hideTabs as $tabText) {
106
    $tabhide_js .= "$('.tabs.primary').children('li').children('a:contains(\"$tabText\")').hide();\n";
107
  }
108
  drupal_add_js("
109
  $(document).ready(function(){
110
  $tabhide_js
111
    });", 'inline');
112

    
113
  $out = '';
114
  $out .= theme('cdm_back_to_search_result_button');
115
  //var_dump(variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR));
116
  if(variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR)){
117
    $out .= theme('cdm_acceptedFor', 'page_general');
118
  }
119

    
120
  // --- PAGE PART: DESCRIPTION --- //
121
  if($page_part == 'description' || $page_part == 'all'){
122

    
123
    $featureTree = cdm_ws_get(CDM_WS_FEATURETREE, variable_get(CDM_DATAPORTAL_DEFAULT_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE));
124
    $taxonDescriptions = cdm_ws_get(CDM_WS_PORTAL_TAXON_DESCRIPTIONS, $taxon->uuid); //retrieve all description for the taxon
125

    
126
    $nonStructuredDescriptions = array();
127
    if($taxonDescriptions != null){
128
      foreach ($taxonDescriptions as $taxonDescription) {
129
        // check if structured description
130
        $hasStructuredData = cdm_ws_get(CDM_WS_DESCRIPTION_HAS_STRUCTRURED_DATA, $taxonDescription->uuid);
131
        $hasStructuredData = $hasStructuredData->Boolean == 'true';
132
        if($hasStructuredData){
133
          $structured_description_featuretree_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, false);
134
          $naturallanguage_textData = cdm_ws_get(CDM_WS_DESCRIPTION_NATURALLANGUAGE_DESCRIPTION, array($taxonDescription->uuid, $structured_description_featuretree_uuid));
135
          if(!$naturallanguage_textData){
136
            drupal_set_message('The \'FeatureTree\' for the generation of natural language representations is not configured correctly, please select a \'FeatureTree\' in the '.l('CDM Dataportal Settings', 'admin/settings/cdm_dataportal/layout/taxon'), 'warning');
137
          }
138
          $taxonDescription->elements = null;
139
          $taxonDescription->elements = array($naturallanguage_textData);
140
        }
141
        $nonStructuredDescriptions[] = $taxonDescription;
142
      }
143
      $taxonDescriptions = null; // release memory
144
    }
145

    
146
    $mergedTrees = cdm_ws_descriptions_by_featuretree($featureTree, $nonStructuredDescriptions, variable_get('cdm_dataportal_descriptions_separated', FALSE));
147

    
148
    $out .= '<div id="general">';
149
    $out .= theme('cdm_taxon_page_profile', $taxon, $mergedTrees, $media, $hideImages);
150
    $out .= '</div>';
151
  }
152

    
153
  // --- PAGE PART: IMAGES --- //
154
  if(!$hideImages && $page_part == 'images' || $page_part == 'all'){
155
    $out .= '<div id="images">';
156
    if($page_part == 'all'){
157
      $out .= '<h2>'.t('Images').'</h2>';
158
    }
159

    
160
    // get the image gallery as configured by the admin
161
    $taxon_image_gallery = call_user_func_array( 'taxon_image_gallery_' . variable_get('image_gallery_viewer', 'default'),
162
         array($taxon, $media));
163
    $out .= $taxon_image_gallery;
164

    
165
    $out .= '</div>';
166
  }
167

    
168
  // --- PAGE PART: SYNONYMY --- //
169
  if($page_part == 'synonymy' || $page_part == 'all'){
170
    $out .= '<div id="synonymy">';
171
    if($page_part == 'all'){
172
      $out .= '<h2>'.t('Synonymy').'</h2>';
173
    }
174
    $addAcceptedTaxon = variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE);
175
    $out .= theme('cdm_taxon_page_synonymy', $taxon, $addAcceptedTaxon);
176

    
177
    $out .= '</div>';
178
  }
179

    
180
  // --- PAGE PART: SPECIMENS --- //
181
  if($specimensOrObersvationsCount > 0 && ($page_part == 'specimens' || $page_part == 'all') ){
182
    $out .= '<div id="specimens">';
183
    if($page_part == 'all'){
184
      $out .= '<h2>'.t('Specimens').'</h2>';
185
    }
186
    $out .= theme('cdm_taxon_page_specimens', $taxon);
187
    $out .= '</div>';
188
  }
189

    
190
  // --- PAGE PART: KEYS --- //
191
  if($identificationKeyCount > 0 && ($page_part == 'keys' || $page_part == 'all') ){
192
    $out .= '<div id="keys">';
193
        if($page_part == 'all'){
194
      $out .= '<h2>'.t('Keys').'</h2>';
195
    }
196
    $out .= theme('cdm_block_IdentificationKeys', $taxon->uuid);
197
    $out .= '</div>';
198
  }
199
  return $out;
200
}
201

    
202

    
203
/**
204
 * Outputs all descriptive data and shows the preferred picture of the
205
 * accepted taxon.
206
 *
207
 */
208
function theme_cdm_taxon_page_profile($taxon, $mergedTrees, $media = null, $hideImages = false){
209

    
210
  if( variable_get('cdm_dataportal_show_default_image', false) && !$hideImages){
211
    // preferred image
212
    // hardcoded for testing;
213
    $defaultRepresentationPart = false;
214
    $defaultRepresentationPart->width = 184;
215
    $defaultRepresentationPart->height = 144;
216
    $defaultRepresentationPart->uri = drupal_get_path('theme', 'palmweb_2').'/images/no_picture.png';
217

    
218
    // preferred image size 184px × 144
219
    $imageMaxExtend = 184;
220
    $out .= '<div id="taxonProfileImage">'.$defaultRepresentationPart->uri.theme('cdm_preferredImage', $media, $defaultRepresentationPart, $imageMaxExtend).'</div>';
221
  }
222
  // description TOC
223
  $out .= theme('cdm_featureTreeTOCs', $mergedTrees);
224
  // description
225
  $out .= theme('cdm_featureTrees', $mergedTrees, $taxon);
226
  return $out;
227
}
228

    
229

    
230
function theme_cdm_taxon_page_specimens($taxon){
231

    
232
  RenderHints::pushToRenderStack('taxon_page_specimens');
233

    
234
  $specimensOrObersvations = cdm_ws_get(CDM_WS_TAXON, array($taxon->uuid, 'specimensOrObersvations') );
235

    
236
  //collect media (fieldObjectMedia, derivedUnitMedia) and add as fields
237
   foreach($specimensOrObersvations as &$occurrence) {
238
      $occurrence->_fieldObjectMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array($occurrence->uuid, 'fieldObjectMedia') );
239
      $occurrence->_derivedUnitMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array($occurrence->uuid, 'derivedUnitMedia') );
240
      //	  	$derivedUnitFacde = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array($descriptionElement->associatedSpecimenOrObservation->uuid) );
241
      //	  	$descriptionElement->_titleCache = $derivedUnitFacde->titleCache;
242
  }
243

    
244
  if(count($specimensOrObersvations) > 0){
245

    
246
    $occurrenceQuery = cdm_ws_get(CDM_WS_GEOSERVICE_OCCURRENCEMAP, $taxon->uuid);
247
    $occurrenceQuery = $occurrenceQuery->String;
248

    
249
    if(variable_get('cdm_dataportal_map_openlayers', 1)){
250
      $out .= get_openlayers_map(
251
        variable_get('cdm_dataportal_geoservice_display_width', false),
252
        variable_get('cdm_dataportal_geoservice_bounding_box', false),
253
        $occurrenceQuery,
254
        null,
255
        $legendFormatQueryStr,
256
        variable_get('cdm_dataportal_geoservice_map_caption', '')
257
      );
258
    } else {
259
      //get_image_map($width, $occurrenceQuery = false, $distributionQuery = false, $legendFormatQuery = false, $map_caption = false )
260
      $out .= get_image_map(
261
        variable_get('cdm_dataportal_geoservice_display_width', false),
262
        variable_get('cdm_dataportal_geoservice_bounding_box', false),
263
        $occurrenceQuery,
264
        null,
265
        $legendFormatQueryStr,
266
        variable_get('cdm_dataportal_geoservice_map_caption', '')
267
      );
268
    }
269

    
270
  }
271

    
272

    
273

    
274
  if($specimensOrObersvations){
275
    $out_specimenList = '<table class="specimens">';
276
    $i = 1;
277
    foreach($specimensOrObersvations as $specimensOrObersvation) {
278
      $i++;
279

    
280
        $mediaList = array();
281
        if(is_array($specimensOrObersvation->_fieldObjectMedia)){
282
          $mediaList = array_merge($mediaList, $specimensOrObersvation->_fieldObjectMedia);
283
        }
284
        if(is_array($specimensOrObersvation->_derivedUnitMedia)){
285
          $mediaList = array_merge($mediaList, $specimensOrObersvation->_derivedUnitMedia);
286
        }
287

    
288
        // --- render the title cache
289
        $out_row = '<tr class="descriptionElement descriptionElement_IndividualsAssociation '.($i%2?'odd':'even').'">';
290
        if($specimensOrObersvation->class != 'FieldObservation'){
291
          $label_html = cdm_dynabox($specimensOrObersvation->titleCache,
292
            cdm_compose_url('portal/'.CDM_WS_DERIVEDUNIT_FACADE, array($specimensOrObersvation->uuid)),
293
            'cdm_derivedUnitFacade',
294
            'Click for details',
295
            array('div', 'div'));
296
        } else {
297
          $label_html = $specimensOrObersvation->titleCache;
298
        }
299
        $out_row .= '<td>' . $label_html . '</td>';
300

    
301
        // --- render associated media
302
        if(count($mediaList) > 0){
303
          $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
304
          $gallery_name =  $specimensOrObersvation->uuid;
305
          $captionElements = array('#uri'=>t('open media'));
306
          $gallery_html = theme(
307
              'cdm_media_gallerie',
308
              $mediaList,
309
              $gallery_name ,
310
              $gallery_settings['cdm_dataportal_media_maxextend'],
311
              $gallery_settings['cdm_dataportal_media_cols'],
312
              $gallery_settings['cdm_dataportal_media_maxRows'],
313
              $captionElements, 'LIGHTBOX', null, null);
314
        } else {
315
          $gallery_html = '';
316
        }
317
        $out_row .= '<td>'.$gallery_html.'</td></tr>';
318
        $out_specimenList .= $out_row;
319
    }
320
    $out_specimenList .= '</table>';
321
  }
322

    
323
  $out .= $out_specimenList;
324

    
325

    
326
  RenderHints::popFromRenderStack();
327
  return $out;
328
}
329

    
330
function specimens_search_form() {
331

    
332
  //form select options
333
  $form['specimens_search_options'] = array(
334
    '#type' => 'value',
335
    '#value' => array(t('No sort'), t('Name'), t('CatalogNumber'), t('Gallery'))
336
  );
337

    
338
  //the form
339
  $form['specimens_search'] = array(
340
    '#title' => t('Speciments sort'),
341
    '#type' => 'fieldset',
342
    '#description' => t('Select your sort criteria.'),
343
    '#collapsible' => TRUE,
344
    '#collapsed' => FALSE
345
  );
346

    
347
  //criteria
348
  $form['specimens_search']['first_criteria'] = array(
349
    '#title' => t('First criteria'),
350
    '#type' => 'select',
351
    '#options' => $form['specimens_search_options']['#value']
352
  );
353
  $form['specimens_search']['second_criteria'] = array(
354
    '#title' => t('Second criteria'),
355
    '#type' => 'select',
356
    '#options' => $form['specimens_search_options']['#value']
357
  );
358
  $form['specimens_search']['third_criteria'] = array(
359
    '#title' => t('Third criteria'),
360
    '#type' => 'select',
361
    '#options' => $form['specimens_search_options']['#value']
362
  );
363

    
364
  //submit button
365
  $form['specimens_search']['submit'] = array(
366
    '#type' => 'submit',
367
    '#value' => t('Sort')
368
  );
369

    
370
  /*
371
  //from properties
372
  $form['#method'] = 'post';
373
  $form['#action'] = 'http://example.com/?q=foo/bar';
374
  $form['#attributes'] = array(
375
    'enctype' => 'multipart/form-data',
376
    'target' => 'name_of_target_frame'
377
  );
378
  $form['#prefix'] = '<div class="my-form-class">';
379
  $form['#suffix'] = '</div>';
380
  */
381

    
382
  //returning value
383
  return $form;
384
}
385

    
386
/**
387
 * Show whole synonymy for the accepted taxon. Synonymy list is headed by the complete scientific name
388
 * of the accepted taxon with nomenclatural reference.
389
 *
390
 */
391
function theme_cdm_taxon_page_synonymy($taxon, $addAcceptedTaxon){
392

    
393
  RenderHints::pushToRenderStack('taxon_page_synonymy');
394
  $synomymie = cdm_ws_get(CDM_WS_PORTAL_TAXON_SYNONYMY, $taxon->uuid);
395
  $skip = array(UUID_BASIONYM);
396

    
397
  //render accepted taxon
398
  if($addAcceptedTaxon){
399
    if(isset($taxon->name->nomenclaturalReference)){
400
      $referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
401
    }
402

    
403
    $accepted_name = '<span class="accepted-name">';
404
    $accepted_name .= theme('cdm_taxonName', $taxon->name, null, $referenceUri);
405
    $accepted_name .= '</span>';
406

    
407
    $special_annotations_array = array();
408
    $special_annotations_array[] = $taxon->name;
409
    $special_annotations_array[] = $taxon;
410
    $accepted_name .= theme('cdm_annotations_as_footnotekeys',
411
          $special_annotations_array,
412
          RenderHints::getRenderPath() . '-annotations');
413
          RenderHints::setFootnoteListKey(RenderHints::getRenderPath() . '-annotations');
414
  }
415

    
416

    
417
  //render homotypic synonymy group
418
  $hasHomotypicSynonyms = isset($synomymie->homotypicSynonymsByHomotypicGroup[0]->name->uuid);
419

    
420
  if($accepted_name){
421
    $out .= $accepted_name;
422
  }
423

    
424
  if (!$hasHomotypicSynonyms){
425
    //show typeDesignations even if the homotypic synonymy group is empty
426
    $typeDesignations = cdm_ws_get(CDM_WS_PORTAL_TAXON_NAMETYPEDESIGNATIONS, $taxon->uuid);
427
    if($typeDesignations){
428
      $out .= theme('cdm_typedesignations', $typeDesignations);
429
    }
430
    if($typeDesignations || $accepted_name){
431
      // add empty list for coherent layout
432
     $out .= '<ul class="homotypicSynonyms">' . '</ul>';
433
    }
434
  } else {
435
    // render the homotypicSynonymyGroup including the type information
436
    $out .= theme('cdm_homotypicSynonymyGroup', $synomymie->homotypicSynonymsByHomotypicGroup, $taxon->uuid);
437
  }
438

    
439
  //render accepted taxon heterotypic synonymy groups
440
  if($synomymie->heterotypicSynonymyGroups) {
441
    foreach($synomymie->heterotypicSynonymyGroups as $homotypicalGroup){
442
      $out .= theme('cdm_heterotypicSynonymyGroup', $homotypicalGroup);
443
    }
444
  }
445
  //render taxon relationships
446
  if(variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT)){
447
    $taxonRelationships = cdm_ws_get(CDM_WS_PORTAL_TAXON_RELATIONS, $taxon->uuid);
448
    $out .= theme('cdm_taxonRelationships', $taxonRelationships, $taxon);
449
  }
450
  //render name relationships
451
  $name_rels_to_show = variable_get('name_relationships_to_show', null);
452
  $skip = array();
453
  if($name_rels_to_show){
454
    foreach ($name_rels_to_show as $key => $value){
455
      if ($value === 0){
456
        $skip[] = $key;
457
      }
458
    }
459
    if (sizeof($name_rels_to_show) != sizeof($skip)){
460
      $nameRelationships = cdm_ws_get(CDM_WS_PORTAL_TAXON_TO_NAMERELATIONS, $taxon->uuid);
461
      $out .= theme('cdm_nameRelationships', $nameRelationships, $skip);
462
    }
463
  }
464

    
465

    
466
  //render the annontations text for the accepted taxa
467
  if ($addAcceptedTaxon){
468
    $out .= theme('cdm_footnotes', RenderHints::getRenderPath() . '-annotations', 'li');
469
  }
470
  RenderHints::popFromRenderStack();
471

    
472
  return $out;
473
}
474

    
475
/**
476
 * TODO Implementation of Hook taxon_image_gallery()
477
 *
478
 * @param unknown_type $taxon
479
 * @param unknown_type $media
480
 * @return unknown_type
481
 */
482
function taxon_image_gallery_default($taxon, $media){
483

    
484
  $hasImages = isset($media[0]);
485

    
486
  if($hasImages){
487
    //
488
    $maxExtend = 150;
489
    $cols = 3;
490
    $maxRows = false;
491
    $alternativeMediaUri = null;
492
    $captionElements = array('title', 'rights', '#uri'=>t('open Image'));
493
    $gallery_name = $taxon->uuid;
494
    $mediaLinkType = 'LIGHTBOX';
495

    
496
    //$gallery_settings = getGallerySettings(CDM_DATAPORTAL_MEDIA_GALLERY_NAME);
497
    $gallery_settings = getGallerySettings(CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB);
498
    $out = '<div class="image-gallerie">';
499
    $out .= theme('cdm_media_gallerie',
500
      $media,
501
      $gallery_name,
502
      $gallery_settings['cdm_dataportal_media_maxextend'],
503
      $gallery_settings['cdm_dataportal_media_cols'],
504
      0, // ignore maxrows settings
505
      $captionElements,
506
      $mediaLinkType,
507
      null,
508
      null,
509
      $gallery_settings['cdm_dataportal_show_thumbnail_captions']);
510
      $out .= '</div>';
511
  }else{
512
    $out = 'No images available.';
513

    
514
  }
515
  return $out;
516

    
517
}
518

    
519
/**
520
 * TODO Implementation of Hook taxon_image_gallery()
521
 *
522
 * @param unknown_type $taxon
523
 * @param unknown_type $media
524
 * @return unknown_type
525
 */
526
function taxon_image_gallery_fsi($taxon, $media){
527

    
528
  $flashLink = isset($media[0]);
529

    
530
  if($flashLink){
531

    
532
    if(module_exists("fsi_gallery")){
533
    	$out = theme("fsi_gallery", $taxon, $media );
534
    } else {
535
    	$message = t('In order to use the FSI gallery you must enable the according ') . l(t("module"), "admin/build/modules");
536
    	drupal_set_message($message, "error");
537
    	$out = '<h3>' . $message . '</h3>';
538
    }
539

    
540
  }else{
541
    $out = 'No images available.';
542

    
543
  }
544
  return $out;
545

    
546
}
547
/**
548
 * Show a reference in it's atomized form
549
 */
550
function theme_cdm_reference_page($referenceTO){
551

    
552
  /*
553
   if($referenceTO->titleCache) {
554
    drupal_set_title($referenceTO->titleCache);
555
    } else {
556
    drupal_set_title($referenceTO->fullCitation);
557
    }
558
    */
559

    
560
  $field_order = array(
561
    "title",
562
  //"titleCache",
563
  //"citation",
564
    "authorTeam",
565
    "editor",
566
    "publisher",
567
    "placePublished",
568
    "datePublished",
569
    "year",
570
    "edition",      // class Book
571
    "volume",       // class Article
572
    "seriesPart",
573
    "inReference",
574
  //"inJournal",     // class Article
575
  //"inBook",        // class BookSection
576
    "nomRefBase",    // class BookSection, Book, Article
577
  //"inProceedings", // class InProceedings
578
    "pages",         // class Article
579
    "series",        // class Article, PrintSeries
580
    "school",        // class Thesis
581
    "institution",   // class Report
582
    "organization",  // class Proceedings
583
    "nextVersion",
584
    "previousVersion",
585
    "isbn",         // class Book
586
    "issn",         // class Journal
587
    "uri",
588
  );
589
  /*
590
   $table_rows = array();
591
   foreach($field_order as $fieldname){
592

    
593
    if(isset($referenceTO->$fieldname)){
594

    
595
    if($fieldname == "datePublished") {
596
    $partial = $referenceTO->$fieldname;
597
    $datePublished = '';
598
    if($partial->start){
599
    //var_dump ($partial->start);
600
    $datePublishedYear = substr($partial->start, 0, 4);
601
    $datePublishedMonth = substr($partial->start, 5, 2);
602

    
603
    if (!(preg_match('#[0-9]#',$datePublishedMonth))){
604
    $datePublishedMonth = '00';
605
    }
606

    
607
    $datePublishedDay = substr($partial->start, 7, 2);
608
    if (!(preg_match('#[0-9]#',$datePublishedDay))){
609
    $datePublishedDay = '00';
610
    }
611
    $datePublished = $datePublishedYear.'-'.$datePublishedMonth.'-'.$datePublishedDay;
612
    }
613
    if($partial->end){
614
    $datePublished = (strlen($datePublished) > 0 ? ' '.t('to').' ' : '').substr($partial->end, 0, 4).'-'.substr($partial->end, 4, 2).'-'.substr($partial->end, 6, 2);
615
    }
616
    $table_rows[] = array(t(ucfirst(strtolower($fieldname))), $datePublished);
617
    //$datePublished = array(t(ucfirst(strtolower($fieldname))), $datePublished);
618
    } else if(is_object($referenceTO->$fieldname)){
619
    if ($fieldname == "authorTeam"){
620
    $dump = $referenceTO->$fieldname;
621
    $teammembers = "teamMembers";
622
    $team = $dump->$teammembers;
623
    $nameArray = array();
624

    
625
    foreach($team as $member){
626
    if (strlen($member->lastname)> 0){
627
    $nname = $member->lastname;
628
    $name = $nname;
629
    if (strlen($member->firstname)> 0){
630
    $vname = $member->firstname;
631
    $name =$vname." ". $nname;
632
    }
633
    $nameArray[] =$name;
634
    }else{
635
    if (strlen($member->titleCache)> 0){
636
    $nameArray[] = $member->titleCache;
637
    }
638
    }
639
    }
640
    $names = join($nameArray, ", ");
641
    }else if ($fieldname == "inReference"){
642
    $type = $referenceTO ->$fieldname-> type;
643
    $names = $referenceTO-> $fieldname-> titleCache;
644
    switch ($type) {
645
    case "Book":
646
    $fieldname = "in book";
647
    break;
648
    case "Journal":
649
    $fieldname = "in journal";
650
    break;
651
    case "Proceedings":
652
    $fieldname = "in proceedings";
653
    break;
654
    }
655

    
656
    }else{
657
    $names = $referenceTO->$fieldname-> titleCache;
658
    }
659
    $table_rows[] = array(t(ucfirst(strtolower($fieldname))), $names);
660
    //$name = array(t(ucfirst(strtolower($fieldname))), $names);
661

    
662
    } else {
663
    $table_rows[] = array(t(ucfirst(strtolower($fieldname))), $referenceTO->$fieldname);
664
    //$name = array(t(ucfirst(strtolower($fieldname))), $referenceTO->$fieldname);
665
    }
666
    }
667
    }
668
    */
669

    
670
  //select the type of the reference and find the in Reference attribute
671

    
672
  $referenceData = array(
673
    "title" => NULL,
674
  //"titleCache",
675
  //"citation",
676
    "authorTeam" => NULL,
677
    "editor" => NULL,
678
    "publisher" => NULL,
679
    "placePublished" => NULL,
680
    "datePublished" => NULL,
681
    "year" => NULL,
682
    "edition" => NULL,      // class Book
683
    "volume" => NULL,       // class Article
684
    "seriesPart" => NULL,
685
    "inReference" => NULL,
686
  //"inJournal",     // class Article
687
  //"inBook",        // class BookSection
688
    "nomRefBase" => NULL,    // class BookSection, Book, Article
689
  //"inProceedings", // class InProceedings
690
    "pages" => NULL,         // class Article
691
    "series" => NULL,        // class Article, PrintSeries
692
    "school" => NULL,        // class Thesis
693
    "institution" => NULL,   // class Report
694
    "organization" => NULL,  // class Proceedings
695
    "nextVersion" => NULL,
696
    "previousVersion" => NULL,
697
    "isbn" => NULL,         // class Book
698
    "issn" => NULL,         // class Journal
699
    "uri" => NULL,
700
  );
701

    
702
  foreach($field_order as $fieldname){
703

    
704
    if(isset($referenceTO->$fieldname)){
705
      switch($fieldname){
706
        case "datePublished":
707
          $partial = $referenceTO->$fieldname;
708
          $datePublished = '';
709
          if($partial->start){
710
            $datePublishedYear = substr($partial->start, 0, 4);
711
            $datePublishedMonth = substr($partial->start, 5, 2);
712
            if (!(preg_match('#[0-9]#',$datePublishedMonth))){
713
              $datePublishedMonth = '00';
714
            }
715
            $datePublishedDay = substr($partial->start, 7, 2);
716
            if (!(preg_match('#[0-9]#',$datePublishedDay))){
717
              $datePublishedDay = '00';
718
            }
719
            $datePublished = $datePublishedYear.'-'.$datePublishedMonth.'-'.$datePublishedDay;
720
          }
721
          if($partial->end){
722
            $datePublished = (strlen($datePublished) > 0 ? ' '.t('to').' ' : '').substr($partial->end, 0, 4).'-'.substr($partial->end, 4, 2).'-'.substr($partial->end, 6, 2);
723
          }
724

    
725
          $referenceData[$fieldname] = $datePublishedYear;
726
          break;
727

    
728
        default:
729
          if(is_object($referenceTO->$fieldname)){
730
            if ($fieldname == "authorTeam"){
731
              $dump = $referenceTO->$fieldname;
732
              $teammembers = "teamMembers";
733
              $team = $dump->$teammembers;
734
              $nameArray = array();
735

    
736
              foreach($team as $member){
737
                if (strlen($member->lastname)> 0){
738
                  $nname = $member->lastname;
739
                  $name = $nname;
740
                  if (strlen($member->firstname)> 0){
741
                    $vname = $member->firstname;
742
                    $name =$vname." ". $nname;
743
                  }
744
                  $nameArray[] =$name;
745
                }else{
746
                  if (strlen($member->titleCache)> 0){
747
                    $nameArray[] = $member->titleCache;
748
                  }
749
                }
750
              }
751
              $names = join($nameArray, ", ");
752
              $referenceData[$fieldname] = $names;
753
            }else if ($fieldname == "inReference"){
754
              $names = $referenceTO->$fieldname->titleCache;
755
              $referenceData[$fieldname] = $names;
756
            }else{
757
              $names = $referenceTO->$fieldname->titleCache;
758
              $referenceData[$fieldname] = $names;
759
            }
760
          }else{
761
            $referenceData[$fieldname] = $referenceTO->$fieldname;
762
          }
763

    
764
      }
765
    }
766
  }
767
  $author_team =  cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $referenceTO->uuid);
768
  //return "" . ((strlen($referenceData["authorTeam"])>0) ? ($referenceData["authorTeam"] . '. ') : '')
769
  return "" . ((strlen($author_team->titleCache)>0) ? ($author_team->titleCache . '. ') : '')
770
  . ((strlen($referenceData["datePublished"])>0) ? ($referenceData["datePublished"] . '. ') : '')
771
  . ((strlen($referenceData["title"])>0) ? ($referenceData["title"] . '. ') : "")
772
  . ((strlen($referenceData["placePublished"])>0) ? ($referenceData["placePublished"] . '. ') : '')
773
  . ((strlen($referenceData["editor"])>0) ? ($referenceData["editor"] . '. ') : '')
774
  . ((strlen($referenceData["publisher"])>0) ? ($referenceData["publisher"] . '. ') : '')
775
  . ((strlen($referenceData["inReference"])>0) ? ($referenceData["inReference"] . '. ') : '')
776
  . ((strlen($referenceData["series"])>0) ? ($referenceData["series"] . '. ') : '')
777
  . ((strlen($referenceData["volume"])>0) ? ($referenceData["volume"] . '. ') : '')
778
  . ((strlen($referenceData["pages"])>0) ? ($referenceData["pages"] . '. ') : '')
779
  . ((strlen($referenceData["isbn"])>0) ? ($referenceData["isbn"] . '. ') : '')
780
  . ((strlen($referenceData["issn"])>0) ? ($referenceData["issn"] . '. ') : '')
781
  . ((strlen($referenceData["uri"])>0) ? ($referenceData["uri"] . '. ') : '');
782

    
783
}
784

    
785

    
786
function theme_cdm_media_page($media, $mediarepresentation_uuid = false, $partId = false){
787
  $out = '';
788
  // determine which reprresentation and which part to show
789
  $representationIdx = 0;
790
  if($mediarepresentation_uuid){
791
    $i = 0;
792
    foreach($media->representations as $representation) {
793
      if($representation->uuid == $mediarepresentation_uuid){
794
        $representationIdx = $i;
795
      }
796
      $i++;
797
    }
798
  } else {
799
    $mediarepresentation_uuid = $media->representations[0]->uuid;
800
  }
801

    
802
  $partIdx  = 0;
803
  if(!is_numeric($partId)){
804
    // assuming it is an uuid
805
    $i = 0;
806
    foreach($media->representations[$representationIdx]->parts as $part) {
807
      if($part->uuid == $partId){
808
        $partIdx = $i;
809
      }
810
      $i++;
811
    }
812
  } else {
813
    // assuming it is an index
814
    $partIdx = $partId;
815
  }
816

    
817
  $media_metadata = cdm_read_media_metadata($media);
818
  //$title = $media->titleCache;
819
  $title = $media_metadata['title'];
820

    
821
  $imageMaxExtend = variable_get('image-page-maxextend', 400);
822

    
823
  if(!$title){
824
    $title = 'Media '.$media->uuid.'';
825
  }
826

    
827
  drupal_set_title($title);
828

    
829

    
830
  $out .= '<div class="media">';
831

    
832
  //$out .= '<div class="viewer">';
833
  $out .= theme(cdm_back_to_image_gallery_button);
834
  $out .= '<div class="viewer">';
835
  //$out .= theme('cdm_media_gallerie_image', $representation->parts[$partIdx], $imageMaxExtend);
836
  $out .= theme('cdm_openlayers_image', $media->representations[$representationIdx]->parts[$partIdx], $imageMaxExtend);
837
  $out .= '</div>';
838

    
839
  // general media metadata
840
  //$media_metadata = cdm_ws_get(CDM_WS_MEDIA_METADATA, array($media->uuid));
841
  //vardump("PRINTING MEDIA METADATA");
842
  //vardump($media_metadata);
843
  //vardump("PRINTING MEDIA");
844
  //vardump($media);
845
  $metadataToPrint = theme('cdm_media_caption', $media);
846
  $out .= $metadataToPrint;
847

    
848

    
849
  //tabs for the different representations
850
  //ul.secondary
851
  $out .= '<ul class="primary">';
852
  foreach($media->representations as $representation){
853
    $out .= '<li>'.l($media->representations[$representationIdx]->mimeType, path_to_media($media->uuid, $mediarepresentation_uuid, $partIdx)).'</li>';
854
  }
855
  $out .= '</ul>';
856

    
857
  // representation(-part) specific metadata
858
  $thumbnailMaxExtend = 100;
859
  $out .= '<table>';
860
  //$out .= '<tr><th colspan="3">'.t('MimeType').': '.$media->representations[$representationIdx]->mimeType.'</th></tr>';
861
  $i = 0;
862
  foreach($media->representations[$representationIdx]->parts as $part){
863
    $out .= '<tr><th>'.t('Part').' '.($i + 1).'</th><td>';
864
    switch($part->class){
865
      case 'ImageFile': $out .= $part->width.' x '.$part->height.' - '.$part->size.'k'; break;
866
      case 'AudioFile':
867
      case 'MovieFile': $out .= t('Duration').': '.$part->duration.'s - '.$part->size.'k'; break;
868
      default: $out .= $part->size.'k';
869
    }
870
    $out .= '</td><td><a href="'.url(path_to_media($media->uuid, $mediarepresentation_uuid, $i)).'">'
871
      .theme('cdm_media_gallerie_image', $part, $thumbnailMaxExtend, true);'</a></td><tr>';
872
    $i++;
873
  }
874
  $out .= '</table>';
875
  $out .= '</div>';
876

    
877
  return $out;
878
}
879

    
880

    
881

    
882

    
883
function theme_cdm_polytomousKey_page($polytomousKey){
884

    
885
  drupal_set_title($polytomousKey->titleCache);
886

    
887
  $out = theme("cdm_IdentificationKey", $polytomousKey, false, false);
888

    
889
  // key nodes in linked style
890
  $out .= theme('cdm_polytomousKey', $polytomousKey);
891
  /* FIXME implement node type for keys !!!
892
   * (wrapping the content in the cdm_dataportal.node becomes obsolete then)
893
   */
894
  return '<div id="cdm_dataportal.node">' . $out . '</div>';
895
}
896

    
897
/**
898
 * Allows theming of the taxon page tabs
899
 *
900
 * @param $tabname
901
 * @return unknown_type
902
 */
903
function theme_cdm_taxonpage_tab($tabname){
904
  //TODO replace by using translations or theme the menue tabs itself instead?
905
  switch($tabname){
906
    default: return t($tabname);
907
  }
908
}
909

    
(6-6/8)