Project

General

Profile

Download (31.7 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
        $markerTypesEmpty = array();
125
  $markerTypesEmpty['markerTypes'] = '';
126
    $taxonDescriptions = cdm_ws_get(CDM_WS_PORTAL_TAXON_DESCRIPTIONS, $taxon->uuid, queryString($markerTypesEmpty)); //retrieve all description for the taxon
127
	$nonStructuredDescriptions = array();
128
    if($taxonDescriptions != null){
129
      foreach ($taxonDescriptions as $taxonDescription) {
130
        // check if structured description
131
        $hasStructuredData = cdm_ws_get(CDM_WS_DESCRIPTION_HAS_STRUCTRURED_DATA, $taxonDescription->uuid);
132
        $hasStructuredData = $hasStructuredData->Boolean == 'true';
133
        if($hasStructuredData){
134
          $structured_description_featuretree_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, false);
135
          $naturallanguage_textData = cdm_ws_get(CDM_WS_DESCRIPTION_NATURALLANGUAGE_DESCRIPTION, array($taxonDescription->uuid, $structured_description_featuretree_uuid));
136
          if(!$naturallanguage_textData){
137
            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');
138
          }
139
          $taxonDescription->elements = null;
140
          $taxonDescription->elements = array($naturallanguage_textData);
141
        }
142
        $nonStructuredDescriptions[] = $taxonDescription;
143
      }
144
      $taxonDescriptions = null; // release memory
145
    }
146

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

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

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

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

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

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

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

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

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

    
203

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

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

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

    
230

    
231
function theme_cdm_taxon_page_specimens($taxon){
232

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

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

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

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

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

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

    
271
  }
272

    
273

    
274

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

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

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

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

    
324
  $out .= $out_specimenList;
325

    
326

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

    
331
function specimens_search_form() {
332

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

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

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

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

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

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

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

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

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

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

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

    
417

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

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

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

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

    
466

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

    
473
  return $out;
474
}
475

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

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

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

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

    
515
  }
516
  return $out;
517

    
518
}
519

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

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

    
531
  if($flashLink){
532

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

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

    
544
  }
545
  return $out;
546

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

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

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

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

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

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

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

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

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

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

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

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

    
703
  foreach($field_order as $fieldname){
704

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

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

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

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

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

    
784
}
785

    
786

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

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

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

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

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

    
828
  drupal_set_title($title);
829

    
830

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

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

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

    
849

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

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

    
878
  return $out;
879
}
880

    
881

    
882

    
883

    
884
function theme_cdm_polytomousKey_page($polytomousKey){
885

    
886
  drupal_set_title($polytomousKey->titleCache);
887

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

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

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

    
(6-6/8)