Project

General

Profile

Download (30.9 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 $specimensOrObersvation) {
238
      $specimensOrObersvation->_fieldObjectMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array($specimensOrObersvation->uuid, 'fieldObjectMedia') );
239
      $specimensOrObersvation->_derivedUnitMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array($specimensOrObersvation->uuid, 'derivedUnitMedia') );
240
      //	  	$derivedUnitFacde = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array($descriptionElement->associatedSpecimenOrObservation->uuid) );
241
      //	  	$descriptionElement->_titleCache = $derivedUnitFacde->titleCache;
242
  }
243

    
244
  if(variable_get('cdm_dataportal_map_openlayers', 1)){
245
    $occurrenceQuery = cdm_ws_get(CDM_WS_GEOSERVICE_OCCURRENCEMAP, $taxon->uuid);
246
    $occurrenceQuery = $occurrenceQuery->String;
247
    $out .= get_openlayers_map(variable_get('cdm_dataportal_geoservice_display_width', false), $occurrenceQuery);
248
  }
249

    
250

    
251

    
252
  if($specimensOrObersvations){
253
    $out_specimenList = '<table class="specimens">';
254
    $i = 1;
255
    foreach($specimensOrObersvations as $specimensOrObersvation) {
256
      $i++;
257

    
258
        $mediaList = array();
259
        if(is_array($specimensOrObersvation->_fieldObjectMedia)){
260
          $mediaList = array_merge($mediaList, $specimensOrObersvation->_fieldObjectMedia);
261
        }
262
        if(is_array($specimensOrObersvation->_derivedUnitMedia)){
263
          $mediaList = array_merge($mediaList, $specimensOrObersvation->_derivedUnitMedia);
264
        }
265

    
266
        // --- render the title cache
267
        $out_row = '<tr class="descriptionElement descriptionElement_IndividualsAssociation '.($i%2?'odd':'even').'">';
268
        if($specimensOrObersvation->class != 'FieldObservation'){
269
          $label_html = cdm_dynabox($specimensOrObersvation->titleCache,
270
            cdm_compose_url('portal/'.CDM_WS_DERIVEDUNIT_FACADE, array($specimensOrObersvation->uuid)),
271
            'cdm_derivedUnitFacade',
272
            'Click for details',
273
            array('div', 'div'));
274
        } else {
275
          $label_html = $specimensOrObersvation->titleCache;
276
        }
277
        $out_row .= '<td>' . $label_html . '</td>';
278

    
279
        // --- render associated media
280
        if(count($mediaList) > 0){
281
          $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
282
          $gallery_name =  $specimensOrObersvation->uuid;
283
          $captionElements = array('#uri'=>t('open media'));
284
          $gallery_html = theme(
285
              'cdm_media_gallerie',
286
              $mediaList,
287
              $gallery_name ,
288
              $gallery_settings['cdm_dataportal_media_maxextend'],
289
              $gallery_settings['cdm_dataportal_media_cols'],
290
              $gallery_settings['cdm_dataportal_media_maxRows'],
291
              $captionElements, 'LIGHTBOX', null, null);
292
        } else {
293
          $gallery_html = '';
294
        }
295
        $out_row .= '<td>'.$gallery_html.'</td></tr>';
296
        $out_specimenList .= $out_row;
297
    }
298
    $out_specimenList .= '</table>';
299
  }
300

    
301
  $out .= $out_specimenList;
302

    
303

    
304
  RenderHints::popFromRenderStack();
305
  return $out;
306
}
307

    
308
function specimens_search_form() {
309

    
310
  //form select options
311
  $form['specimens_search_options'] = array(
312
    '#type' => 'value',
313
    '#value' => array(t('No sort'), t('Name'), t('CatalogNumber'), t('Gallery'))
314
  );
315

    
316
  //the form
317
  $form['specimens_search'] = array(
318
    '#title' => t('Speciments sort'),
319
    '#type' => 'fieldset',
320
    '#description' => t('Select your sort criteria.'),
321
    '#collapsible' => TRUE,
322
    '#collapsed' => FALSE
323
  );
324

    
325
  //criteria
326
  $form['specimens_search']['first_criteria'] = array(
327
    '#title' => t('First criteria'),
328
    '#type' => 'select',
329
    '#options' => $form['specimens_search_options']['#value']
330
  );
331
  $form['specimens_search']['second_criteria'] = array(
332
    '#title' => t('Second criteria'),
333
    '#type' => 'select',
334
    '#options' => $form['specimens_search_options']['#value']
335
  );
336
  $form['specimens_search']['third_criteria'] = array(
337
    '#title' => t('Third criteria'),
338
    '#type' => 'select',
339
    '#options' => $form['specimens_search_options']['#value']
340
  );
341

    
342
  //submit button
343
  $form['specimens_search']['submit'] = array(
344
    '#type' => 'submit',
345
    '#value' => t('Sort')
346
  );
347

    
348
  /*
349
  //from properties
350
  $form['#method'] = 'post';
351
  $form['#action'] = 'http://example.com/?q=foo/bar';
352
  $form['#attributes'] = array(
353
    'enctype' => 'multipart/form-data',
354
    'target' => 'name_of_target_frame'
355
  );
356
  $form['#prefix'] = '<div class="my-form-class">';
357
  $form['#suffix'] = '</div>';
358
  */
359

    
360
  //returning value
361
  return $form;
362
}
363

    
364
/**
365
 * Show whole synonymy for the accepted taxon. Synonymy list is headed by the complete scientific name
366
 * of the accepted taxon with nomenclatural reference.
367
 *
368
 */
369
function theme_cdm_taxon_page_synonymy($taxon, $addAcceptedTaxon){
370

    
371
  RenderHints::pushToRenderStack('taxon_page_synonymy');
372
  $synomymie = cdm_ws_get(CDM_WS_PORTAL_TAXON_SYNONYMY, $taxon->uuid);
373
  $skip = array(UUID_BASIONYM);
374

    
375
  //render accepted taxon
376
  if($addAcceptedTaxon){
377
    if(isset($taxon->name->nomenclaturalReference)){
378
      $referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
379
    }
380

    
381
    $accepted_name = '<span class="accepted-name">';
382
    $accepted_name .= theme('cdm_taxonName', $taxon->name, null, $referenceUri);
383
    $accepted_name .= '</span>';
384

    
385
    $special_annotations_array = array();
386
    $special_annotations_array[] = $taxon->name;
387
    $special_annotations_array[] = $taxon;
388
    $accepted_name .= theme('cdm_annotations_as_footnotekeys',
389
          $special_annotations_array,
390
          RenderHints::getRenderPath() . '-annotations');
391
          RenderHints::setFootnoteListKey(RenderHints::getRenderPath() . '-annotations');
392
  }
393

    
394

    
395
  //render homotypic synonymy group
396
  $hasHomotypicSynonyms = isset($synomymie->homotypicSynonymsByHomotypicGroup[0]->name->uuid);
397

    
398
  if($accepted_name){
399
    $out .= $accepted_name;
400
  }
401

    
402
  if (!$hasHomotypicSynonyms){
403
    //show typeDesignations even if the homotypic synonymy group is empty
404
    $typeDesignations = cdm_ws_get(CDM_WS_PORTAL_TAXON_NAMETYPEDESIGNATIONS, $taxon->uuid);
405
    if($typeDesignations){
406
      $out .= theme('cdm_typedesignations', $typeDesignations);
407
    }
408
    if($typeDesignations || $accepted_name){
409
      // add empty list for coherent layout
410
     $out .= '<ul class="homotypicSynonyms">' . '</ul>';
411
    }
412
  } else {
413
    // render the homotypicSynonymyGroup including the type information
414
    $out .= theme('cdm_homotypicSynonymyGroup', $synomymie->homotypicSynonymsByHomotypicGroup, $taxon->uuid);
415
  }
416

    
417
  //render accepted taxon heterotypic synonymy groups
418
  if($synomymie->heterotypicSynonymyGroups) {
419
    foreach($synomymie->heterotypicSynonymyGroups as $homotypicalGroup){
420
      $out .= theme('cdm_heterotypicSynonymyGroup', $homotypicalGroup);
421
    }
422
  }
423
  //render taxon relationships
424
  if(variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT)){
425
    $taxonRelationships = cdm_ws_get(CDM_WS_PORTAL_TAXON_RELATIONS, $taxon->uuid);
426
    $out .= theme('cdm_taxonRelationships', $taxonRelationships);
427
  }
428
  //render name relationships
429
  $name_rels_to_show = variable_get('name_relationships_to_show', null);
430
  $skip = array();
431
  if($name_rels_to_show){
432
    foreach ($name_rels_to_show as $key => $value){
433
      if ($value === 0){
434
        $skip[] = $key;
435
      }
436
    }
437
    if (sizeof($name_rels_to_show) != sizeof($skip)){
438
      $nameRelationships = cdm_ws_get(CDM_WS_PORTAL_TAXON_TO_NAMERELATIONS, $taxon->uuid);
439
      $out .= theme('cdm_nameRelationships', $nameRelationships, $skip);
440
    }
441
  }
442

    
443

    
444
  //render the annontations text for the accepted taxa
445
  if ($addAcceptedTaxon){
446
    $out .= theme('cdm_footnotes', RenderHints::getRenderPath() . '-annotations', 'li');
447
  }
448
  RenderHints::popFromRenderStack();
449

    
450
  return $out;
451
}
452

    
453
/**
454
 * TODO Implementation of Hook taxon_image_gallery()
455
 *
456
 * @param unknown_type $taxon
457
 * @param unknown_type $media
458
 * @return unknown_type
459
 */
460
function taxon_image_gallery_default($taxon, $media){
461

    
462
  $hasImages = isset($media[0]);
463

    
464
  if($hasImages){
465
    //
466
    $maxExtend = 150;
467
    $cols = 3;
468
    $maxRows = false;
469
    $alternativeMediaUri = null;
470
    $captionElements = array('title', 'rights', '#uri'=>t('open Image'));
471
    $gallery_name = $taxon->uuid;
472
    $mediaLinkType = 'LIGHTBOX';
473

    
474
    //$gallery_settings = getGallerySettings(CDM_DATAPORTAL_MEDIA_GALLERY_NAME);
475
    $gallery_settings = getGallerySettings(CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB);
476
    $out = '<div class="image-gallerie">';
477
    $out .= theme('cdm_media_gallerie',
478
      $media,
479
      $gallery_name,
480
      $gallery_settings['cdm_dataportal_media_maxextend'],
481
      $gallery_settings['cdm_dataportal_media_cols'],
482
      0, // ignore maxrows settings
483
      $captionElements,
484
      $mediaLinkType,
485
      null,
486
      null,
487
      $gallery_settings['cdm_dataportal_show_thumbnail_captions']);
488
      $out .= '</div>';
489
  }else{
490
    $out = 'No images available.';
491

    
492
  }
493
  return $out;
494

    
495
}
496

    
497
/**
498
 * TODO Implementation of Hook taxon_image_gallery()
499
 *
500
 * @param unknown_type $taxon
501
 * @param unknown_type $media
502
 * @return unknown_type
503
 */
504
function taxon_image_gallery_fsi($taxon, $media){
505

    
506
  $flashLink = isset($media[0]);
507

    
508
  if($flashLink){
509

    
510
    if(module_exists("fsi_gallery")){
511
    	$out = theme("fsi_gallery", $taxon, $media );
512
    } else {
513
    	$message = t('In order to use the FSI gallery you must enable the according ') . l(t("module"), "admin/build/modules");
514
    	drupal_set_message($message, "error");
515
    	$out = '<h3>' . $message . '</h3>';
516
    }
517

    
518
  }else{
519
    $out = 'No images available.';
520

    
521
  }
522
  return $out;
523

    
524
}
525
/**
526
 * Show a reference in it's atomized form
527
 */
528
function theme_cdm_reference_page($referenceTO){
529

    
530
  /*
531
   if($referenceTO->titleCache) {
532
    drupal_set_title($referenceTO->titleCache);
533
    } else {
534
    drupal_set_title($referenceTO->fullCitation);
535
    }
536
    */
537

    
538
  $field_order = array(
539
    "title",
540
  //"titleCache",
541
  //"citation",
542
    "authorTeam",
543
    "editor",
544
    "publisher",
545
    "placePublished",
546
    "datePublished",
547
    "year",
548
    "edition",      // class Book
549
    "volume",       // class Article
550
    "seriesPart",
551
    "inReference",
552
  //"inJournal",     // class Article
553
  //"inBook",        // class BookSection
554
    "nomRefBase",    // class BookSection, Book, Article
555
  //"inProceedings", // class InProceedings
556
    "pages",         // class Article
557
    "series",        // class Article, PrintSeries
558
    "school",        // class Thesis
559
    "institution",   // class Report
560
    "organization",  // class Proceedings
561
    "nextVersion",
562
    "previousVersion",
563
    "isbn",         // class Book
564
    "issn",         // class Journal
565
    "uri",
566
  );
567
  /*
568
   $table_rows = array();
569
   foreach($field_order as $fieldname){
570

    
571
    if(isset($referenceTO->$fieldname)){
572

    
573
    if($fieldname == "datePublished") {
574
    $partial = $referenceTO->$fieldname;
575
    $datePublished = '';
576
    if($partial->start){
577
    //var_dump ($partial->start);
578
    $datePublishedYear = substr($partial->start, 0, 4);
579
    $datePublishedMonth = substr($partial->start, 5, 2);
580

    
581
    if (!(preg_match('#[0-9]#',$datePublishedMonth))){
582
    $datePublishedMonth = '00';
583
    }
584

    
585
    $datePublishedDay = substr($partial->start, 7, 2);
586
    if (!(preg_match('#[0-9]#',$datePublishedDay))){
587
    $datePublishedDay = '00';
588
    }
589
    $datePublished = $datePublishedYear.'-'.$datePublishedMonth.'-'.$datePublishedDay;
590
    }
591
    if($partial->end){
592
    $datePublished = (strlen($datePublished) > 0 ? ' '.t('to').' ' : '').substr($partial->end, 0, 4).'-'.substr($partial->end, 4, 2).'-'.substr($partial->end, 6, 2);
593
    }
594
    $table_rows[] = array(t(ucfirst(strtolower($fieldname))), $datePublished);
595
    //$datePublished = array(t(ucfirst(strtolower($fieldname))), $datePublished);
596
    } else if(is_object($referenceTO->$fieldname)){
597
    if ($fieldname == "authorTeam"){
598
    $dump = $referenceTO->$fieldname;
599
    $teammembers = "teamMembers";
600
    $team = $dump->$teammembers;
601
    $nameArray = array();
602

    
603
    foreach($team as $member){
604
    if (strlen($member->lastname)> 0){
605
    $nname = $member->lastname;
606
    $name = $nname;
607
    if (strlen($member->firstname)> 0){
608
    $vname = $member->firstname;
609
    $name =$vname." ". $nname;
610
    }
611
    $nameArray[] =$name;
612
    }else{
613
    if (strlen($member->titleCache)> 0){
614
    $nameArray[] = $member->titleCache;
615
    }
616
    }
617
    }
618
    $names = join($nameArray, ", ");
619
    }else if ($fieldname == "inReference"){
620
    $type = $referenceTO ->$fieldname-> type;
621
    $names = $referenceTO-> $fieldname-> titleCache;
622
    switch ($type) {
623
    case "Book":
624
    $fieldname = "in book";
625
    break;
626
    case "Journal":
627
    $fieldname = "in journal";
628
    break;
629
    case "Proceedings":
630
    $fieldname = "in proceedings";
631
    break;
632
    }
633

    
634
    }else{
635
    $names = $referenceTO->$fieldname-> titleCache;
636
    }
637
    $table_rows[] = array(t(ucfirst(strtolower($fieldname))), $names);
638
    //$name = array(t(ucfirst(strtolower($fieldname))), $names);
639

    
640
    } else {
641
    $table_rows[] = array(t(ucfirst(strtolower($fieldname))), $referenceTO->$fieldname);
642
    //$name = array(t(ucfirst(strtolower($fieldname))), $referenceTO->$fieldname);
643
    }
644
    }
645
    }
646
    */
647

    
648
  //select the type of the reference and find the in Reference attribute
649

    
650
  $referenceData = array(
651
    "title" => NULL,
652
  //"titleCache",
653
  //"citation",
654
    "authorTeam" => NULL,
655
    "editor" => NULL,
656
    "publisher" => NULL,
657
    "placePublished" => NULL,
658
    "datePublished" => NULL,
659
    "year" => NULL,
660
    "edition" => NULL,      // class Book
661
    "volume" => NULL,       // class Article
662
    "seriesPart" => NULL,
663
    "inReference" => NULL,
664
  //"inJournal",     // class Article
665
  //"inBook",        // class BookSection
666
    "nomRefBase" => NULL,    // class BookSection, Book, Article
667
  //"inProceedings", // class InProceedings
668
    "pages" => NULL,         // class Article
669
    "series" => NULL,        // class Article, PrintSeries
670
    "school" => NULL,        // class Thesis
671
    "institution" => NULL,   // class Report
672
    "organization" => NULL,  // class Proceedings
673
    "nextVersion" => NULL,
674
    "previousVersion" => NULL,
675
    "isbn" => NULL,         // class Book
676
    "issn" => NULL,         // class Journal
677
    "uri" => NULL,
678
  );
679

    
680
  foreach($field_order as $fieldname){
681

    
682
    if(isset($referenceTO->$fieldname)){
683
      switch($fieldname){
684
        case "datePublished":
685
          $partial = $referenceTO->$fieldname;
686
          $datePublished = '';
687
          if($partial->start){
688
            $datePublishedYear = substr($partial->start, 0, 4);
689
            $datePublishedMonth = substr($partial->start, 5, 2);
690
            if (!(preg_match('#[0-9]#',$datePublishedMonth))){
691
              $datePublishedMonth = '00';
692
            }
693
            $datePublishedDay = substr($partial->start, 7, 2);
694
            if (!(preg_match('#[0-9]#',$datePublishedDay))){
695
              $datePublishedDay = '00';
696
            }
697
            $datePublished = $datePublishedYear.'-'.$datePublishedMonth.'-'.$datePublishedDay;
698
          }
699
          if($partial->end){
700
            $datePublished = (strlen($datePublished) > 0 ? ' '.t('to').' ' : '').substr($partial->end, 0, 4).'-'.substr($partial->end, 4, 2).'-'.substr($partial->end, 6, 2);
701
          }
702

    
703
          $referenceData[$fieldname] = $datePublishedYear;
704
          break;
705

    
706
        default:
707
          if(is_object($referenceTO->$fieldname)){
708
            if ($fieldname == "authorTeam"){
709
              $dump = $referenceTO->$fieldname;
710
              $teammembers = "teamMembers";
711
              $team = $dump->$teammembers;
712
              $nameArray = array();
713

    
714
              foreach($team as $member){
715
                if (strlen($member->lastname)> 0){
716
                  $nname = $member->lastname;
717
                  $name = $nname;
718
                  if (strlen($member->firstname)> 0){
719
                    $vname = $member->firstname;
720
                    $name =$vname." ". $nname;
721
                  }
722
                  $nameArray[] =$name;
723
                }else{
724
                  if (strlen($member->titleCache)> 0){
725
                    $nameArray[] = $member->titleCache;
726
                  }
727
                }
728
              }
729
              $names = join($nameArray, ", ");
730
              $referenceData[$fieldname] = $names;
731
            }else if ($fieldname == "inReference"){
732
              $names = $referenceTO->$fieldname->titleCache;
733
              $referenceData[$fieldname] = $names;
734
            }else{
735
              $names = $referenceTO->$fieldname->titleCache;
736
              $referenceData[$fieldname] = $names;
737
            }
738
          }else{
739
            $referenceData[$fieldname] = $referenceTO->$fieldname;
740
          }
741

    
742
      }
743
    }
744
  }
745
  $author_team =  cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $referenceTO->uuid);
746
  //return "" . ((strlen($referenceData["authorTeam"])>0) ? ($referenceData["authorTeam"] . '. ') : '')
747
  return "" . ((strlen($author_team->titleCache)>0) ? ($author_team->titleCache . '. ') : '')
748
  . ((strlen($referenceData["datePublished"])>0) ? ($referenceData["datePublished"] . '. ') : '')
749
  . ((strlen($referenceData["title"])>0) ? ($referenceData["title"] . '. ') : "")
750
  . ((strlen($referenceData["placePublished"])>0) ? ($referenceData["placePublished"] . '. ') : '')
751
  . ((strlen($referenceData["editor"])>0) ? ($referenceData["editor"] . '. ') : '')
752
  . ((strlen($referenceData["publisher"])>0) ? ($referenceData["publisher"] . '. ') : '')
753
  . ((strlen($referenceData["inReference"])>0) ? ($referenceData["inReference"] . '. ') : '')
754
  . ((strlen($referenceData["series"])>0) ? ($referenceData["series"] . '. ') : '')
755
  . ((strlen($referenceData["volume"])>0) ? ($referenceData["volume"] . '. ') : '')
756
  . ((strlen($referenceData["pages"])>0) ? ($referenceData["pages"] . '. ') : '')
757
  . ((strlen($referenceData["isbn"])>0) ? ($referenceData["isbn"] . '. ') : '')
758
  . ((strlen($referenceData["issn"])>0) ? ($referenceData["issn"] . '. ') : '')
759
  . ((strlen($referenceData["uri"])>0) ? ($referenceData["uri"] . '. ') : '');
760

    
761
}
762

    
763

    
764
function theme_cdm_media_page($media, $mediarepresentation_uuid = false, $partId = false){
765
  $out = '';
766
  // determine which reprresentation and which part to show
767
  $representationIdx = 0;
768
  if($mediarepresentation_uuid){
769
    $i = 0;
770
    foreach($media->representations as $representation) {
771
      if($representation->uuid == $mediarepresentation_uuid){
772
        $representationIdx = $i;
773
      }
774
      $i++;
775
    }
776
  } else {
777
    $mediarepresentation_uuid = $media->representations[0]->uuid;
778
  }
779

    
780
  $partIdx  = 0;
781
  if(!is_numeric($partId)){
782
    // assuming it is an uuid
783
    $i = 0;
784
    foreach($media->representations[$representationIdx]->parts as $part) {
785
      if($part->uuid == $partId){
786
        $partIdx = $i;
787
      }
788
      $i++;
789
    }
790
  } else {
791
    // assuming it is an index
792
    $partIdx = $partId;
793
  }
794

    
795
  $media_metadata = cdm_read_media_metadata($media);
796
  //$title = $media->titleCache;
797
  $title = $media_metadata['title'];
798

    
799
  $imageMaxExtend = variable_get('image-page-maxextend', 400);
800

    
801
  if(!$title){
802
    $title = 'Media '.$media->uuid.'';
803
  }
804

    
805
  drupal_set_title($title);
806

    
807

    
808
  $out .= '<div class="media">';
809

    
810
  //$out .= '<div class="viewer">';
811
  $out .= theme(cdm_back_to_image_gallery_button);
812
  $out .= '<div class="viewer">';
813
  //$out .= theme('cdm_media_gallerie_image', $representation->parts[$partIdx], $imageMaxExtend);
814
  $out .= theme('cdm_openlayers_image', $media->representations[$representationIdx]->parts[$partIdx], $imageMaxExtend);
815
  $out .= '</div>';
816

    
817
  // general media metadata
818
  //$media_metadata = cdm_ws_get(CDM_WS_MEDIA_METADATA, array($media->uuid));
819
  //vardump("PRINTING MEDIA METADATA");
820
  //vardump($media_metadata);
821
  //vardump("PRINTING MEDIA");
822
  //vardump($media);
823
  $metadataToPrint = theme('cdm_media_caption', $media);
824
  $out .= $metadataToPrint;
825

    
826

    
827
  //tabs for the different representations
828
  //ul.secondary
829
  $out .= '<ul class="primary">';
830
  foreach($media->representations as $representation){
831
    $out .= '<li>'.l($media->representations[$representationIdx]->mimeType, path_to_media($media->uuid, $mediarepresentation_uuid, $partIdx)).'</li>';
832
  }
833
  $out .= '</ul>';
834

    
835
  // representation(-part) specific metadata
836
  $thumbnailMaxExtend = 100;
837
  $out .= '<table>';
838
  //$out .= '<tr><th colspan="3">'.t('MimeType').': '.$media->representations[$representationIdx]->mimeType.'</th></tr>';
839
  $i = 0;
840
  foreach($media->representations[$representationIdx]->parts as $part){
841
    $out .= '<tr><th>'.t('Part').' '.($i + 1).'</th><td>';
842
    switch($part->class){
843
      case 'ImageFile': $out .= $part->width.' x '.$part->height.' - '.$part->size.'k'; break;
844
      case 'AudioFile':
845
      case 'MovieFile': $out .= t('Duration').': '.$part->duration.'s - '.$part->size.'k'; break;
846
      default: $out .= $part->size.'k';
847
    }
848
    $out .= '</td><td><a href="'.url(path_to_media($media->uuid, $mediarepresentation_uuid, $i)).'">'
849
      .theme('cdm_media_gallerie_image', $part, $thumbnailMaxExtend, true);'</a></td><tr>';
850
    $i++;
851
  }
852
  $out .= '</table>';
853
  $out .= '</div>';
854

    
855
  return $out;
856
}
857

    
858

    
859

    
860

    
861
function theme_cdm_polytomousKey_page($polytomousKey){
862

    
863
  drupal_set_title($polytomousKey->titleCache);
864

    
865
  $out = theme("cdm_IdentificationKey", $polytomousKey, false, false);
866

    
867
  // key nodes in linked style
868
  $out .= theme('cdm_polytomousKey', $polytomousKey);
869
  /* FIXME implement node type for keys !!!
870
   * (wrapping the content in the cdm_dataportal.node becomes obsolete then)
871
   */
872
  return '<div id="cdm_dataportal.node">' . $out . '</div>';
873
}
874

    
875
/**
876
 * Allows theming of the taxon page tabs
877
 *
878
 * @param $tabname
879
 * @return unknown_type
880
 */
881
function theme_cdm_taxonpage_tab($tabname){
882
  //TODO replace by using translations or theme the menue tabs itself instead?
883
  switch($tabname){
884
    default: return t($tabname);
885
  }
886
}
887

    
(6-6/8)