Project

General

Profile

Download (26.4 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/**
3
 * @file
4
 * Page theming functions.
5
 *
6
 * @copyright
7
 *   (C) 2007-2012 EDIT
8
 *   European Distributed Institute of Taxonomy
9
 *   http://www.e-taxonomy.eu
10
 *
11
 *   The contents of this module are subject to the Mozilla
12
 *   Public License Version 1.1.
13
 * @see http://www.mozilla.org/MPL/MPL-1.1.html
14
 */
15

    
16
/**
17
 * Returns HTML for the default title of a taxon page.
18
 *  * The returned title is a formatted taxon name.
19
 *
20
 * @param array $variables
21
 *   An associative array containing:
22
 *   - taxon: The taxon name being formatted for the title.
23
 *   - uuid: UUID for the taxon.
24
 *
25
 * @ingroup themeable
26
 */
27
function theme_cdm_taxon_page_title($variables) {
28
  $taxon = $variables['taxon'];
29
  $uuid = $variables['uuid'];
30
  RenderHints::pushToRenderStack('taxon_page_title');
31
  $referenceUri = '';
32
  $out = '';
33
  if (isset($taxon->name->nomenclaturalReference)) {
34
    $referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
35
  }
36

    
37
  $out .= theme('cdm_taxonName', array(
38
    'taxonName' => $taxon->name,
39
    'nameLink' => NULL,
40
    'refenceLink' => $referenceUri,
41
    'show_annotations' => FALSE,
42
  ));
43
  RenderHints::popFromRenderStack();
44

    
45
  return '<span class="' . $taxon->class . '">' . $out . '</span>';
46
}
47

    
48
/**
49
 * Returns HTML for the default title for a name page.
50
 *
51
 * The returned title is a formatted name.
52
 *
53
 * @param array $variables
54
 *   An associative array containing:
55
 *   - taxon_name: The taxon name object.
56
 *
57
 * @ingroup themeable
58
 */
59
function theme_cdm_name_page_title($variables) {
60
  $taxon_name = $variables['taxon_name'];
61
  RenderHints::pushToRenderStack('taxon_page_title');
62
  if (isset($taxon_name->nomenclaturalReference)) {
63
    $referenceUri = url(path_to_reference($taxon_name->nomenclaturalReference->uuid));
64
  }
65

    
66
  $out = '<span class="' . $taxon_name->class . '">' . theme('cdm_taxonName', array(
67
    'taxonName' => $taxon_name,
68
    'nameLink' => NULL,
69
    'refenceLink' => $referenceUri,
70
    'show_annotations' => FALSE,
71
  )) . '</span>';
72
  RenderHints::popFromRenderStack();
73
  return $out;
74
}
75

    
76
/**
77
 * Returns HTML for a taxon page.
78
 *
79
 * A wrapper function that groups available information to show by default,
80
 * when a taxon page is requested by the browser.
81
 * Individual themeing has to decide what this page should include (see methods
82
 * beneath) and what information should go into tabs or should not be shown
83
 * at all.
84
 *
85
 * It is headed by the name of the accepted taxon without author and reference.
86
 *
87
 * @param array $variables
88
 *   An associative array containing:
89
 *   - taxon: The taxon object for which to theme the page.
90
 *   - page_part: Name of the part to display, valid values are:
91
 *   'description', 'images', 'synonymy', 'all'.
92
 *
93
 * @ingroup themeable
94
 */
95
function theme_cdm_taxon_page($variables) {
96

    
97
  $taxon = $variables['taxon'];
98
  $page_part = $variables['page_part'];
99
  global $theme;
100

    
101
  $render_array = array();
102
  $weight = 0; // the weight for the render array elements
103

    
104
  $tabsToDisplay = variable_get('cdm_taxonpage_tabs_visibility', unserialize(TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT));
105

    
106
  $page_part = variable_get('cdm_dataportal_taxonpage_tabs', 1) ? $page_part : 'all';
107

    
108
  $hideTabs = array();
109

    
110
  // --- GET Images --- //
111
  $mediaQueryParameters = array(
112
    "type" => "ImageFile",
113
  );
114

    
115
  $selectShowMedia = variable_get('cdm_dataportal_show_media', 0);
116
  if ($selectShowMedia == 0) {
117
    $media = cdm_ws_get(CDM_WS_PORTAL_TAXON_MEDIA, array(
118
      $taxon->uuid,
119
    ), queryString($mediaQueryParameters));
120
  }
121
  else {
122
    $media = cdm_ws_get(CDM_WS_PORTAL_TAXON_SUBTREE_MEDIA, array(
123
      $taxon->uuid,
124
    ), queryString($mediaQueryParameters));
125
  }
126
  if (!isset($media[0]) || ($tabsToDisplay["Images"] == '0')) {
127
    $hideTabs[] = theme('cdm_taxonpage_tab', array('tabname' => 'Images'));
128
  }
129
  // HideImage flag depending on administative preset.
130
  $hideImages = FALSE;
131
  if (variable_get('image_hide_rank', '0') != '0' && isset($taxon->name->rank->uuid)) {
132
    $rankCompare = rank_compare($taxon->name->rank->uuid, variable_get('image_hide_rank', '-99'));
133
    $hideImages = ($rankCompare > -1);
134
  }
135

    
136
  // --- GET specimensOrObservations --- //
137
  $specimensOrObservations = cdm_ws_get(CDM_WS_TAXON, array( $taxon->uuid, 'specimensOrObservations'));
138

    
139
  $specimensOrObservationsCount = is_array($specimensOrObservations) ? count($specimensOrObservations) : 0;
140
  if ($specimensOrObservationsCount == 0 || ($tabsToDisplay["Specimens"] == '0')) {
141
    $hideTabs[] = theme('cdm_taxonpage_tab', array('tabname' => 'Specimens'));
142
  }
143

    
144
  // --- GET polytomousKeys --- //
145
  $polytomousKeysPager = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, NULL, "findByTaxonomicScope=$taxon->uuid");
146
  $identificationKeyCount = 0;
147
  if ($polytomousKeysPager) {
148
    $identificationKeyCount += $polytomousKeysPager->count;
149
  }
150
  if ($identificationKeyCount == 0 || ($tabsToDisplay["Keys"] == '0')) {
151
    $hideTabs[] = theme('cdm_taxonpage_tab', array('tabname' => 'Keys'));
152
  }
153

    
154
  if ($tabsToDisplay["Synonymy"] == '0') {
155
    $hideTabs[] = theme('cdm_taxonpage_tab', array('tabname' => 'Synonymy'));
156
  }
157

    
158
  // -------------------------------------------- //
159
  // Hide tabs.
160
  $tabhide_js = '';
161
  foreach ($hideTabs as $tabText) {
162
    $tabhide_js .= "jQuery('.tabs.primary').children('li').children('a:contains(\"$tabText\")').hide();\n";
163
  }
164
  drupal_add_js("
165
  jQuery(document).ready(function(){
166
  $tabhide_js
167
    });", array('type' => 'inline'));
168

    
169

    
170
  $render_array['back_to_search'] = markup_to_render_array(theme('cdm_back_to_search_result_button'), $weight++);
171

    
172
  // var_dump(variable_get('cdm_dataportal_display_is_accepted_for',
173
  // CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR));
174
  if (variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR)) {
175
    $out .= theme('cdm_acceptedFor', 'page_general');
176
  }
177

    
178
  // --- PAGE PART: DESCRIPTION --- //
179
  if ($page_part == 'description' || $page_part == 'all') {
180

    
181
    $markerTypesEmpty = array();
182
    $markerTypesEmpty['markerTypes'] = '';
183
    // Retrieve all descriptions for the taxon.
184
    $taxonDescriptions = cdm_ws_get(CDM_WS_PORTAL_TAXON_DESCRIPTIONS, $taxon->uuid, queryString($markerTypesEmpty));
185

    
186
    $nonStructuredDescriptions = array();
187
    if ($taxonDescriptions != NULL) {
188
      foreach ($taxonDescriptions as $taxonDescription) {
189
        // Check if structured description.
190
        $hasStructuredData = cdm_ws_get(CDM_WS_DESCRIPTION_HAS_STRUCTRURED_DATA, $taxonDescription->uuid);
191
        if (isset($hasStructuredData->Boolean)) {
192
          $hasStructuredData = $hasStructuredData->Boolean == 'TRUE';
193
        }
194
        if ($hasStructuredData) {
195
          $structured_description_featuretree_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, FALSE);
196
          if($structured_description_featuretree_uuid) {
197
            // if a feature tree for natural language generation has been defined use it,
198
            // otherwise natural language generation is skipped
199
            $naturallanguage_textData = cdm_ws_get(CDM_WS_DESCRIPTION_NATURALLANGUAGE_DESCRIPTION, array(
200
              $taxonDescription->uuid,
201
              $structured_description_featuretree_uuid,
202
            ));
203

    
204
            if (!isset($naturallanguage_textData)) {
205
              drupal_set_message(
206
                t(
207
                "The 'FeatureTree' for the generation of natural language representations is not configured correctly,"
208
                ." please select a 'FeatureTree' in the !settings",
209
                array(
210
              		'!settings' => l(t('CDM Dataportal Settings'), 'admin/config/cdm_dataportal/layout/taxon'))
211
              		),
212
              	'warning');
213
            } else {
214
              $taxonDescription->elements = NULL;
215
              $taxonDescription->elements = array(
216
                $naturallanguage_textData,
217
              );
218
            }
219
          }
220
        }
221
        $nonStructuredDescriptions[] = $taxonDescription;
222
      }
223
      // Release memory.
224
      $taxonDescriptions = NULL;
225
    }
226

    
227
    $mergedTrees = cdm_ws_descriptions_by_featuretree(get_profile_featureTree(), $nonStructuredDescriptions, variable_get('cdm_dataportal_descriptions_separated', FALSE));
228

    
229
    $profile_html = '<div id="general">';
230
    $profile_html .= theme('cdm_taxon_page_profile', array(
231
      'taxon' => $taxon,
232
      'mergedTrees' => $mergedTrees,
233
      'media' => $media,
234
      'hideImages' => $hideImages,
235
      ));
236
    $profile_html .= '</div>';
237
    $render_array['profile'] = markup_to_render_array($profile_html, $weight++);
238
  }
239

    
240
  // --- PAGE PART: IMAGES --- //
241
  if ((!$hideImages && $page_part == 'images' || $page_part == 'all')) {
242
    $images_html = '<div id="images">';
243
    if ($page_part == 'all') {
244
      $images_html .= '<h2>' . t('Images') . '</h2>';
245
    }
246
    // Get the image gallery as configured by the admin.
247
    $taxon_image_gallery = call_user_func_array('taxon_image_gallery_' . variable_get('image_gallery_viewer', 'default'), array(
248
      $taxon,
249
      $media,
250
    ));
251
    $images_html .= $taxon_image_gallery;
252
    $images_html .= '</div>';
253
    $render_array['images'] = markup_to_render_array($images_html, $weight++);
254
  }
255

    
256
  // --- PAGE PART: SYNONYMY --- //
257
  if (($page_part == 'synonymy' || $page_part == 'all')) {
258
    $synonymy_html = '<div id="synonymy">';
259
    if ($page_part == 'all') {
260
      $synonymy_html .= '<h2>' . t('Synonymy') . '</h2>';
261
    }
262
    $addAcceptedTaxon = variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE);
263
    $synonymy_html .= theme('cdm_taxon_page_synonymy', array('taxon' => $taxon, 'addAcceptedTaxon' => $addAcceptedTaxon));
264

    
265
    $synonymy_html .= '</div>';
266
    $render_array['synonymy'] = markup_to_render_array($synonymy_html, $weight++);
267
  }
268

    
269
  // --- PAGE PART: SPECIMENS --- //
270
  if ($specimensOrObservationsCount > 0 && ($page_part == 'specimens' || $page_part == 'all')) {
271
    $render_array['specimens'] = array(
272
        '#prefix' => '<div id="specimens">' . ($page_part == 'all' ? '<h2>' . t('Specimens') . '</h2>' : ''),
273
        'content' => cdm_dataportal_taxon_page_specimens($taxon), // returns render array
274
        '#suffix' => '</div>',
275
    );
276
  }
277

    
278
  // --- PAGE PART: KEYS --- //
279
  if ($identificationKeyCount > 0 && ($page_part == 'keys' || $page_part == 'all')) {
280
    $keys_html = '<div id="keys">';
281
    if ($page_part == 'all') {
282
      $keys_html .= '<h2>' . t('Keys') . '</h2>';
283
    }
284
    $keys_html .= theme('cdm_block_IdentificationKeys', array('taxonUuid' => $taxon->uuid));
285
    $keys_html .= '</div>';
286
    $render_array['keys'] = markup_to_render_array($keys_html, $weight++);
287
  }
288

    
289
  return $render_array;
290
}
291

    
292
/**
293
 * Returns HTML containing descriptive data and preferred picture.
294
 *
295
 * Outputs all descriptive data and shows the preferred picture of the
296
 * accepted taxon.
297
 *
298
 * @param array $variables
299
 *   An associative array containing:
300
 *   - taxon
301
 *   - mergedTrees
302
 *   - media:
303
 *   - hideImages
304
 *
305
 * @ingroup themeable
306
 */
307
function theme_cdm_taxon_page_profile($variables) {
308
  $taxon = $variables['taxon'];
309
  $mergedTrees = $variables['mergedTrees'];
310
  $media = $variables['media'];
311
  $hideImages = $variables['hideImages'];
312
  $out = '';
313
  if (variable_get('cdm_dataportal_show_default_image', FALSE) && !$hideImages) {
314

    
315
    // Preferred image hardcoded for testing.
316
    $defaultRepresentationPart = new stdClass();
317
    $defaultRepresentationPart->width = 184;
318
    $defaultRepresentationPart->height = 144;
319
    $defaultRepresentationPart->uri = drupal_get_path('theme', 'palmweb_2') . '/images/no_picture.png';
320

    
321
    // Preferred image size 184px × 144.
322
    $imageMaxExtend = 184;
323
    $out .= '<div id="taxonProfileImage">' . theme('cdm_preferredImage', array(
324
      'media' => $media,
325
      'defaultRepresentationPart' => $defaultRepresentationPart,
326
      'imageMaxExtend' => $imageMaxExtend,
327
      )) . '</div>';
328
  }
329

    
330
  // Description TOC.
331
  $out .= theme('cdm_featureTreeTOCs', array('mergedTrees' => $mergedTrees));
332

    
333
  // Description.
334
  $out .= theme('cdm_featureTrees', array('mergedTrees' => $mergedTrees, 'taxon' => $taxon));
335

    
336
  return $out;
337
}
338

    
339

    
340

    
341
/**
342
 * Returns HTML containing the synonymy for the accepted taxon.
343
 *
344
 * Shows the whole synonymy for the accepted taxon.
345
 * The synonymy list is headed by the complete scientific name
346
 * of the accepted taxon with nomenclatural reference.
347
 *
348
 * @param array $variables
349
 *   An associative array containing:
350
 *   - taxon
351
 *   - addAcceptedTaxon
352
 *
353
 * @ingroup themeable
354
 */
355
function theme_cdm_taxon_page_synonymy($variables) {
356
  $taxon = $variables['taxon'];
357
  $addAcceptedTaxon = $variables['addAcceptedTaxon'];
358
  RenderHints::pushToRenderStack('taxon_page_synonymy');
359
  $synomymie = cdm_ws_get(CDM_WS_PORTAL_TAXON_SYNONYMY, $taxon->uuid);
360
  $skip = array(
361
    UUID_BASIONYM,
362
  );
363
  $out = '';
364

    
365
  // Render accepted taxon.
366
  $referenceUri = '';
367
  if ($addAcceptedTaxon) {
368
    if (isset($taxon->name->nomenclaturalReference)) {
369
      $referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
370
    }
371

    
372
    $accepted_name = '<span class="accepted-name">';
373
    $accepted_name .= theme('cdm_taxonName', array(
374
      'taxonName' => $taxon->name,
375
      'nameLink' => NULL,
376
      'refenceLink' => $referenceUri,
377
      ));
378
    $accepted_name .= '</span>';
379

    
380
    $special_annotations_array = array();
381
    $special_annotations_array[] = $taxon->name;
382
    $special_annotations_array[] = $taxon;
383
    $accepted_name .= theme('cdm_annotations_as_footnotekeys', array('cdmBase_list' => $special_annotations_array, 'footnote_list_key' => RenderHints::getRenderPath() . '-annotations'));
384
    RenderHints::setFootnoteListKey(RenderHints::getRenderPath() . '-annotations');
385
  }
386

    
387
  // Render homotypic synonymy group.
388
  $hasHomotypicSynonyms = isset($synomymie->homotypicSynonymsByHomotypicGroup[0]->name->uuid);
389

    
390
  if (!empty($accepted_name)) {
391
    $out .= $accepted_name;
392
  }
393

    
394
  if (!$hasHomotypicSynonyms) {
395
    // Show typeDesignations even if the homotypic synonymy group is empty.
396
    $typeDesignations = cdm_ws_get(CDM_WS_PORTAL_TAXON_NAMETYPEDESIGNATIONS, $taxon->uuid);
397
    if ($typeDesignations) {
398
      $out .= theme('cdm_typedesignations', array('typeDesignations' => $typeDesignations));
399
    }
400
    if (!empty($typeDesignations) || !empty($accepted_name)) {
401
      // Add empty list for coherent layout.
402
      $out .= '<ul class="homotypicSynonyms"></ul>';
403
    }
404
  }
405
  else {
406
    // Render the homotypicSynonymyGroup including the type information.
407
    $out .= theme('cdm_homotypicSynonymyGroup', array('synonymList' => $synomymie->homotypicSynonymsByHomotypicGroup, 'accepted_taxon_uuid' => $taxon->uuid));
408
  }
409

    
410
  // Render accepted taxon heterotypic synonymy groups.
411
  if ($synomymie->heterotypicSynonymyGroups) {
412
    foreach ($synomymie->heterotypicSynonymyGroups as $homotypicalGroup) {
413
      $out .= theme('cdm_heterotypicSynonymyGroup', array('homotypicalGroup' => $homotypicalGroup));
414
    }
415
  }
416
  // Render taxon relationships.
417
  if (variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT)) {
418
    $taxonRelationships = cdm_ws_get(CDM_WS_PORTAL_TAXON_RELATIONS, $taxon->uuid);
419
    $out .= theme('cdm_taxonRelationships', array('taxonRelationships' => $taxonRelationships, 'focusedTaxon' => $taxon));
420
  }
421
  // Render name relationships.
422
  $name_rels_to_show = variable_get('name_relationships_to_show', NULL);
423
  $skip = array();
424
  if ($name_rels_to_show) {
425
    foreach ($name_rels_to_show as $key => $value) {
426
      if ($value === 0) {
427
        $skip[] = $key;
428
      }
429
    }
430
    if (sizeof($name_rels_to_show) != sizeof($skip)) {
431
      $nameRelationships = cdm_ws_get(CDM_WS_PORTAL_TAXON_TO_NAMERELATIONS, $taxon->uuid);
432
      $out .= theme('cdm_nameRelationships', array('nameRelationships' => $nameRelationships, 'skipTypes' => $skip));
433
    }
434
  }
435

    
436
  // Render the annontations text for the accepted taxa.
437
  if ($addAcceptedTaxon) {
438
    $out .= theme('cdm_footnotes', array('footnoteListKey' => RenderHints::getRenderPath() . '-annotations', 'enclosingTag' => 'li'));
439
  }
440
  RenderHints::popFromRenderStack();
441

    
442
  return $out;
443
}
444

    
445
/**
446
 * TODO Implementation of Hook taxon_image_gallery()
447
 *
448
 * @param unknown_type $taxon
449
 * @param unknown_type $media
450
 *
451
 * @return unknown_type
452
 */
453
function taxon_image_gallery_default($taxon, $media) {
454
  $hasImages = isset($media[0]);
455

    
456
  if ($hasImages) {
457

    
458
    $maxExtend = 150;
459
    $cols = 3;
460
    $maxRows = FALSE;
461
    $alternativeMediaUri = NULL;
462
    /* Comment @WA: was in D5:
463
    $captionElements = array(
464
      'title',
465
      'rights',
466
      '#uri' => t('open Image'),
467
    );
468
    */
469
    $captionElements = array(
470
      'title',
471
      'description',
472
      'artist',
473
      'location',
474
      'rights',
475
      '#uri' => t('open Image'),
476
    );
477
    $gallery_name = $taxon->uuid;
478
    $mediaLinkType = 'LIGHTBOX';
479

    
480
    // $gallery_settings = getGallerySettings(CDM_DATAPORTAL_MEDIA_GALLERY_NAME);
481

    
482
    $gallery_settings = getGallerySettings(CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB);
483

    
484
    $out = '<div class="image-gallerie">';
485
    $out .= theme('cdm_media_gallerie', array(
486
      'mediaList' => $media,
487
      'galleryName' => $gallery_name,
488
      'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
489
      'cols' => $gallery_settings['cdm_dataportal_media_cols'],
490
      'maxRows' => 0, // Ignore maxrows settings.
491
      'captionElements' => $captionElements,
492
      'mediaLinkType' => $mediaLinkType,
493
      'alternativeMediaUri' => NULL,
494
      'galleryLinkUri' => NULL,
495
      'showCaption' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
496
    ));
497
    $out .= '</div>';
498
  }
499
  else {
500
    $out = 'No images available.';
501
  }
502
  return $out;
503
}
504

    
505
/**
506
 * TODO Implementation of Hook taxon_image_gallery()
507
 *
508
 * @param unknown_type $taxon
509
 * @param unknown_type $media
510
 *
511
 * @return unknown_type
512
 */
513
function taxon_image_gallery_fsi($taxon, $media) {
514
  $flashLink = isset($media[0]);
515

    
516
  if ($flashLink) {
517

    
518
    if (module_exists("fsi_gallery")) {
519
      $out = theme("fsi_gallery", array('taxon' => $taxon, 'media' => $media));
520
    }
521
    else {
522
      $message = t('In order to use the FSI gallery you must enable the according ') . l(t("module"), "admin/modules");
523
      drupal_set_message($message, "error");
524
      $out = '<h3>' . $message . '</h3>';
525
    }
526
  }
527
  else {
528
    $out = 'No images available.';
529
  }
530
  return $out;
531
}
532

    
533
/**
534
 * Returns HTML for a single reference page.
535
 *
536
 * Renders a page with all data on a single reference.
537
 *
538
 * @param array $variables
539
 *   An associative array containing:
540
 *   - reference: Object.
541
 *
542
 * @ingroup themeable
543
 */
544
function theme_cdm_reference_page($variables) {
545
  $reference = $variables['reference'];
546

    
547
  $out = '';
548

    
549
  if (isset($reference->titleCache)) {
550
    drupal_set_title($reference->titleCache, PASS_THROUGH);
551
  }
552

    
553
  $field_order = array(
554
    "title",
555
    // "titleCache",
556
    // "citation",
557
    "authorTeam",
558
    "editor",
559
    "publisher",
560
    "placePublished",
561
    "datePublished",
562
    "year",
563
    "edition",// Class Book.
564
    "volume",// Class Article.
565
    "seriesPart",
566
    "inReference",
567
    "nomRefBase", // Class BookSection, Book, Article.
568
    "pages",// Class Article.
569
    "series",// Class Article, PrintSeries.
570
    "school",// Class Thesis.
571
    "institution",// Class Report.
572
    "organization",// Class Proceedings.
573
    "nextVersion",
574
    "previousVersion",
575
    "isbn",// Class Book.
576
    "issn",// Class Journal.
577
    "uri",
578
  );
579

    
580
  $header = array(
581
    t('Field'),
582
    t('Value'),
583
  );
584
  $table_rows = array();
585

    
586
  if (!isset($reference->authorTeam)) {
587
    $authorTeam = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $reference->uuid);
588
    $reference->authorTeam = isset($authorTeam->titleCache) ? $authorTeam->titleCache : '';
589
  }
590

    
591
  if (!isset($reference->inReference)) {
592
    $reference->inReference = cdm_ws_get(CDM_WS_REFERENCE, array(
593
      $reference->uuid,
594
      "inReference",
595
    ));
596
  }
597

    
598
  foreach ($field_order as $fieldname) {
599

    
600
    if (isset($reference->$fieldname)) {
601

    
602
      if ($fieldname == "datePublished") {
603
        $period = $reference->$fieldname;
604
        $datePublished = timePeriodToString($period);
605
        if (isset($datePublished) && $datePublished != '') {
606
          $table_rows[] = array(
607
            t(ucfirst(strtolower($fieldname))),
608
            $datePublished,
609
          );
610
        }
611
        // $datePublished = array(t(ucfirst(strtolower($fieldname))),
612
        // $datePublished);
613
      }
614
      elseif (is_object($reference->$fieldname)) {
615
        if ($fieldname == "authorTeam") {
616
          $dump = $reference->$fieldname;
617
          $teammembers = "teamMembers";
618
          $team = $dump->$teammembers;
619
          $nameArray = array();
620

    
621
          foreach ($team as $member) {
622
            if (strlen($member->lastname) > 0) {
623
              $nname = $member->lastname;
624
              $name = $nname;
625
              if (strlen($member->firstname) > 0) {
626
                $vname = $member->firstname;
627
                $name = $vname . " " . $nname;
628
              }
629
              $nameArray[] = $name;
630
            }
631
            else {
632
              if (strlen($member->titleCache) > 0) {
633
                $nameArray[] = $member->titleCache;
634
              }
635
            }
636
          }
637
          $value = join($nameArray, ", ");
638
        }
639
        elseif ($fieldname == "inReference") {
640
          $type = $reference->$fieldname->type;
641
          $value = l($reference->$fieldname->titleCache, path_to_reference($reference->$fieldname->uuid));
642
          switch ($type) {
643
            case "Book":
644
              $fieldname = "in book";
645
              break;
646
            case "Journal":
647
              $fieldname = "in journal";
648
              break;
649
            case "Proceedings":
650
              $fieldname = "in proceedings";
651
              break;
652
          }
653
        }
654
        else {
655
          $value = $reference->$fieldname->titleCache;
656
        }
657
        if (isset($value) && $value != '') {
658
          $table_rows[] = array(
659
            t(ucfirst(strtolower($fieldname))),
660
            $value,
661
          );
662
        }
663
      }
664
      else {
665
        if (isset($reference->$fieldname) && $reference->$fieldname != '') {
666
          $table_rows[] = array(
667
            t(ucfirst(strtolower($fieldname))),
668
            $reference->$fieldname,
669
          );
670
        }
671
      }
672
    }
673
  }
674

    
675
  $out = theme_table(array(
676
      'header' => array(),
677
      'rows' => $table_rows,
678
      'attributes' => array(),
679
      'caption' => NULL,
680
      'colgroups' => NULL,
681
      'sticky' => NULL,
682
     'empty' => NULL,
683
  ));
684

    
685
  // Annotations below the table.
686
  $annotations = cdm_ws_getAnnotationsFor($reference);
687
  $out .= theme("cdm_annotations", array('annotations' => $annotations));
688

    
689
  return $out;
690
}
691

    
692
/**
693
 * @todo Please document this function.
694
 * @see http://drupal.org/node/1354
695
 */
696
function theme_cdm_media_page($variables) {
697
  $media = $variables['media'];
698
  $mediarepresentation_uuid = $variables['mediarepresentation_uuid'];
699
  $partId = $variables['partId'];
700
  $out = '';
701
  // Determine which reprresentation and which part to show.
702
  $representationIdx = 0;
703
  if ($mediarepresentation_uuid) {
704
    $i = 0;
705
    foreach ($media->representations as $representation) {
706
      if ($representation->uuid == $mediarepresentation_uuid) {
707
        $representationIdx = $i;
708
      }
709
      $i++;
710
    }
711
  }
712
  else {
713
    $mediarepresentation_uuid = $media->representations[0]->uuid;
714
  }
715

    
716
  $partIdx = 0;
717
  if (!is_numeric($partId)) {
718
    // Assuming it is an uuid.
719
    $i = 0;
720
    foreach ($media->representations[$representationIdx]->parts as $part) {
721
      if ($part->uuid == $partId) {
722
        $partIdx = $i;
723
      }
724
      $i++;
725
    }
726
  }
727
  else {
728
    // Assuming it is an index.
729
    $partIdx = $partId;
730
  }
731

    
732
  $media_metadata = cdm_read_media_metadata($media);
733
  // $title = $media->titleCache;
734
  $title = $media_metadata['title'];
735

    
736
  $imageMaxExtend = variable_get('image-page-maxextend', 400);
737

    
738
  if (!$title) {
739
    $title = 'Media ' . $media->uuid . '';
740
  }
741

    
742
  drupal_set_title($title, PASS_THROUGH);
743

    
744
  $out .= '<div class="media cdm_media_viewer_image">';
745

    
746
  $out .= theme('cdm_back_to_image_gallery_button', array());
747
  $out .= '<div class="viewer">';
748
  $out .= theme('cdm_openlayers_image', array('mediaRepresentationPart' => $media->representations[$representationIdx]->parts[$partIdx], 'maxExtend' => $imageMaxExtend));
749
  $out .= '</div>';
750

    
751
  // General media metadata.
752
  /*
753
  $media_metadata = cdm_ws_get(CDM_WS_MEDIA_METADATA, array($media->uuid));
754
  vardump("PRINTING MEDIA METADATA");
755
  vardump($media_metadata);
756
  vardump("PRINTING MEDIA");
757
  vardump($media);
758
  */
759
  $metadataToPrint = theme('cdm_media_caption', array('media' => $media));
760
  $out .= $metadataToPrint;
761

    
762
  // Tabs for the different representations.
763
  // ul.secondary
764
  $out .= '<ul class="primary">';
765
  foreach ($media->representations as $representation) {
766
    $out .= '<li>' . l($media->representations[$representationIdx]->mimeType, path_to_media($media->uuid, $mediarepresentation_uuid, $partIdx)) . '</li>';
767
  }
768
  $out .= '</ul>';
769

    
770
  // Representation(-part) specific metadata.
771
  $thumbnailMaxExtend = 100;
772
  $out .= '<table>';
773
  $i = 0;
774
  foreach ($media->representations[$representationIdx]->parts as $part) {
775
    $out .= '<tr><th>' . t('Part') . ' ' . ($i + 1) . '</th><td>';
776
    switch ($part->class) {
777
      case 'ImageFile':
778
        $out .= $part->width . ' x ' . $part->height . ' - ' . $part->size . 'k';
779
        break;
780
      case 'AudioFile':
781
      case 'MovieFile':
782
        $out .= t('Duration') . ': ' . $part->duration . 's - ' . $part->size . 'k';
783
        break;
784
      default:
785
        $out .= $part->size . 'k';
786
    }
787

    
788
    $out .= '</td><td><a href="' . url(path_to_media($media->uuid, $mediarepresentation_uuid, $i)) . '">' . theme('cdm_media_gallerie_image', array('mediaRepresentationPart' => $part, 'maxExtend' => $thumbnailMaxExtend, 'addPassePartout' => TRUE));
789
    $i++;
790
  }
791
  $out .= '</table>';
792
  $out .= '</div>';
793

    
794
  return $out;
795
}
796

    
797
/**
798
 * @todo Please document this function.
799
 * @see http://drupal.org/node/1354
800
 */
801
function theme_cdm_polytomousKey_page($variables) {
802
  $polytomousKey = $variables['polytomousKey'];
803
  drupal_set_title($polytomousKey->titleCache, PASS_THROUGH);
804

    
805
  $out = theme("cdm_IdentificationKey", array(
806
    'identificationKey' => $polytomousKey,
807
    'doLinkToKeyPage' => FALSE,
808
    'showIdentificationKeyTitle' => FALSE,
809
    ));
810

    
811
  // Key nodes in linked style.
812
  $out .= theme('cdm_polytomousKey', array('polytomousKey' => $polytomousKey));
813
  /*
814
  FIXME implement node type for keys !!! (wrapping the content in the
815
  cdm_dataportal.node becomes obsolete then).
816
  */
817
  return '<div id="cdm_dataportal.node">' . $out . '</div>';
818
}
819

    
820
/**
821
 * Returns HTML for taxon page tabs.
822
 *
823
 * Allows theming of the taxon page tabs.
824
 *
825
 * @param array $variables
826
 *   An associative array containing:
827
 *   - tabname
828
 *
829
 * @ingroup themeable
830
 */
831
function theme_cdm_taxonpage_tab($variables) {
832
  $tabname = $variables['tabname'];
833
  // TODO replace by using translations or theme the menue tabs itself instead?
834
  switch ($tabname) {
835
    default:
836
      return t($tabname);
837
  }
838
}
(7-7/9)