Project

General

Profile

Download (27.9 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
  $media = _load_media_for_taxon($taxon);
109

    
110

    
111
  if (!isset($media[0]) || ($tabsToDisplay["Images"] == '0')) {
112
    taxon_page_tabs_hidden('images');
113
  }
114

    
115
  // HideImage flag depending on administative preset.
116
  $hideImages = FALSE;
117
  if (variable_get('image_hide_rank', '0') != '0' && isset($taxon->name->rank->uuid)) {
118
    $rankCompare = rank_compare($taxon->name->rank->uuid, variable_get('image_hide_rank', '-99'));
119
    $hideImages = ($rankCompare > -1);
120
  }
121

    
122
  // --- GET specimensOrObservations --- //
123
  $specimensOrObservations = cdm_ws_get(CDM_WS_TAXON, array( $taxon->uuid, 'specimensOrObservations'));
124

    
125
  $specimensOrObservationsCount = is_array($specimensOrObservations) ? count($specimensOrObservations) : 0;
126
  if ($specimensOrObservationsCount == 0 || ($tabsToDisplay["Specimens"] == '0')) {
127
    taxon_page_tabs_hidden('specimens');
128
  }
129

    
130
  // --- GET polytomousKeys --- //
131
  $polytomousKeysPager = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, NULL, "findByTaxonomicScope=$taxon->uuid");
132
  $identificationKeyCount = 0;
133
  if ($polytomousKeysPager) {
134
    $identificationKeyCount += $polytomousKeysPager->count;
135
  }
136
  if ($identificationKeyCount == 0 || ($tabsToDisplay["Keys"] == '0')) {
137
    taxon_page_tabs_hidden('keys');
138
  }
139

    
140
  if ($tabsToDisplay["Synonymy"] == '0') {
141
    taxon_page_tabs_hidden('synonymy');
142
  }
143

    
144
  // -------------------------------------------- //
145

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

    
148
  if (variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR)) {
149
    $render_array['accepted_for'] = theme('cdm_acceptedFor', 'page_general');
150
  }
151

    
152
  // --- PAGE PART: DESCRIPTION --- //
153
  if ($page_part == 'description' || $page_part == 'all') {
154

    
155
    $markerTypesEmpty = array();
156
    $markerTypesEmpty['markerTypes'] = '';
157
    $queryString = $markerTypesEmpty['markerTypes'] ? queryString($markerTypesEmpty) : '';
158
    // Retrieve all descriptions for the taxon.
159
    $taxonDescriptions = cdm_ws_get(CDM_WS_PORTAL_TAXON_DESCRIPTIONS, $taxon->uuid, $queryString);
160

    
161
    $nonStructuredDescriptions = array();
162
    if ($taxonDescriptions != NULL) {
163
      foreach ($taxonDescriptions as $taxonDescription) {
164
        // Check if structured description.
165
        $hasStructuredData = cdm_ws_get(CDM_WS_DESCRIPTION_HAS_STRUCTRURED_DATA, $taxonDescription->uuid);
166
        if (isset($hasStructuredData->Boolean)) {
167
          $hasStructuredData = $hasStructuredData->Boolean == 'TRUE';
168
        }
169
        if ($hasStructuredData) {
170
          $structured_description_featuretree_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, FALSE);
171
          if($structured_description_featuretree_uuid) {
172
            // if a feature tree for natural language generation has been defined use it,
173
            // otherwise natural language generation is skipped
174
            $naturallanguage_textData = cdm_ws_get(CDM_WS_DESCRIPTION_NATURALLANGUAGE_DESCRIPTION, array(
175
              $taxonDescription->uuid,
176
              $structured_description_featuretree_uuid,
177
            ));
178

    
179
            if (!isset($naturallanguage_textData)) {
180
              drupal_set_message(
181
                t(
182
                "The 'FeatureTree' for the generation of natural language representations is not configured correctly,"
183
                ." please select a 'FeatureTree' in the !settings",
184
                array(
185
                  '!settings' => l(t('CDM Dataportal Settings'), 'admin/config/cdm_dataportal/layout/taxon'))
186
                  ),
187
                'warning');
188
            } else {
189
              $taxonDescription->elements = NULL;
190
              $taxonDescription->elements = array(
191
                $naturallanguage_textData,
192
              );
193
            }
194
          }
195
        }
196
        $nonStructuredDescriptions[] = $taxonDescription;
197
      }
198
      // Release memory.
199
      $taxonDescriptions = NULL;
200
    }
201

    
202
    $mergedTrees = cdm_ws_descriptions_by_featuretree(get_profile_featureTree(), $nonStructuredDescriptions, variable_get('cdm_dataportal_descriptions_separated', FALSE));
203

    
204
    $profile_html = '<div id="general">';
205
    $profile_html .= theme('cdm_taxon_page_profile', array(
206
      'taxon' => $taxon,
207
      'mergedTrees' => $mergedTrees,
208
      'media' => $media,
209
      'hideImages' => $hideImages,
210
      ));
211
    $profile_html .= '</div>';
212
    $render_array['profile'] = markup_to_render_array($profile_html, $weight++);
213
  }
214

    
215
  // --- PAGE PART: IMAGES --- //
216
  if ((!$hideImages && $page_part == 'images' || $page_part == 'all')) {
217
    $images_html = '<div id="images">';
218
    if ($page_part == 'all') {
219
      $images_html .= '<h2>' . t('Images') . '</h2>';
220
    }
221
    // Get the image gallery as configured by the admin.
222
    $taxon_image_gallery = call_user_func_array('taxon_image_gallery_' . variable_get('image_gallery_viewer', 'default'), array(
223
      $taxon,
224
      $media,
225
    ));
226
    $images_html .= $taxon_image_gallery;
227
    $images_html .= '</div>';
228
    $render_array['images'] = markup_to_render_array($images_html, $weight++);
229
  }
230

    
231
  // --- PAGE PART: SYNONYMY --- //
232
  if (($page_part == 'synonymy' || $page_part == 'all')) {
233
    $synonymy_html = '<div id="synonymy">';
234
    if ($page_part == 'all') {
235
      $synonymy_html .= '<h2>' . t('Synonymy') . '</h2>';
236
    }
237
    $addAcceptedTaxon = variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE);
238
    $synonymy_html .= theme('cdm_taxon_page_synonymy', array('taxon' => $taxon, 'addAcceptedTaxon' => $addAcceptedTaxon));
239

    
240
    $synonymy_html .= '</div>';
241
    $render_array['synonymy'] = markup_to_render_array($synonymy_html, $weight++);
242
  }
243

    
244
  // --- PAGE PART: SPECIMENS --- //
245
  if ($specimensOrObservationsCount > 0 && ($page_part == 'specimens' || $page_part == 'all')) {
246
    $render_array['specimens'] = array(
247
        '#prefix' => '<div id="specimens">' . ($page_part == 'all' ? '<h2>' . t('Specimens') . '</h2>' : ''),
248
        'content' => cdm_dataportal_taxon_page_specimens($taxon), // returns render array
249
        '#suffix' => '</div>',
250
    );
251
  }
252

    
253
  // --- PAGE PART: KEYS --- //
254
  if ($identificationKeyCount > 0 && ($page_part == 'keys' || $page_part == 'all')) {
255
    $keys_html = '<div id="keys">';
256
    if ($page_part == 'all') {
257
      $keys_html .= '<h2>' . t('Keys') . '</h2>';
258
    }
259
    $keys_html .= theme('cdm_block_IdentificationKeys', array('taxonUuid' => $taxon->uuid));
260
    $keys_html .= '</div>';
261
    $render_array['keys'] = markup_to_render_array($keys_html, $weight++);
262
  }
263

    
264
  return $render_array;
265
}
266

    
267
/**
268
 * Returns HTML containing descriptive data and preferred picture.
269
 *
270
 * Outputs all descriptive data and shows the preferred picture of the
271
 * accepted taxon.
272
 *
273
 * @param array $variables
274
 *   An associative array containing:
275
 *   - taxon
276
 *   - mergedTrees
277
 *   - media:
278
 *   - hideImages
279
 *
280
 * @ingroup themeable
281
 */
282
function theme_cdm_taxon_page_profile($variables) {
283
  $taxon = $variables['taxon'];
284
  $mergedTrees = $variables['mergedTrees'];
285
  $media = $variables['media'];
286
  $hideImages = $variables['hideImages'];
287
  $out = '';
288
  if (variable_get('cdm_dataportal_show_default_image', FALSE) && !$hideImages) {
289

    
290
    // Preferred image hardcoded for testing.
291
    $defaultRepresentationPart = new stdClass();
292
    $defaultRepresentationPart->width = 184;
293
    $defaultRepresentationPart->height = 144;
294
    $defaultRepresentationPart->uri = base_path() .  drupal_get_path('module', 'cdm_dataportal') . '/images/no_picture.png';
295

    
296
    // Preferred image size 184px × 144.
297
    $imageMaxExtend = 184;
298
    $out .= '<div id="taxonProfileImage">' . theme('cdm_preferredImage', array(
299
      'media' => $media,
300
      'defaultRepresentationPart' => $defaultRepresentationPart,
301
      'imageMaxExtend' => $imageMaxExtend,
302
      )) . '</div>';
303
  }
304

    
305
  // Description TOC.
306
  $out .= theme('cdm_featureTreeTOCs', array('mergedTrees' => $mergedTrees));
307

    
308
  // Description.
309
  $out .= theme('cdm_featureTrees', array('mergedTrees' => $mergedTrees, 'taxon' => $taxon));
310

    
311
  return $out;
312
}
313

    
314

    
315

    
316
/**
317
 * Returns HTML containing the synonymy for the accepted taxon.
318
 *
319
 * Shows the whole synonymy for the accepted taxon.
320
 * The synonymy list is headed by the complete scientific name
321
 * of the accepted taxon with nomenclatural reference.
322
 *
323
 * @param array $variables
324
 *   An associative array containing:
325
 *   - taxon
326
 *   - addAcceptedTaxon
327
 *
328
 * @ingroup themeable
329
 */
330
function theme_cdm_taxon_page_synonymy($variables) {
331
  $taxon = $variables['taxon'];
332
  $addAcceptedTaxon = $variables['addAcceptedTaxon'];
333

    
334
  RenderHints::pushToRenderStack('taxon_page_synonymy');
335

    
336
  // footnote key for the homotypic group and accepted taxon,
337
  // both should have the same footnote key
338
  RenderHints::setFootnoteListKey(RenderHints::getRenderPath());
339

    
340
  $synomymie = cdm_ws_get(CDM_WS_PORTAL_TAXON_SYNONYMY, $taxon->uuid);
341
  $skip = array(
342
    UUID_BASIONYM,
343
  );
344
  $out = '';
345

    
346
  // Render accepted taxon.
347
  //
348
  // foonotes of the accepted taxon will be rendered in the homotypic group section
349
  // even if there are not synonyms in the homotypic group
350
  // homotypic group and accepted taxon should have the same footnote key
351
  $referenceUri = '';
352
  if ($addAcceptedTaxon) {
353
    if (isset($taxon->name->nomenclaturalReference)) {
354
      $referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
355
    }
356

    
357
    $accepted_name = '<span class="accepted-name">';
358
    $accepted_name .= theme('cdm_taxonName', array(
359
      'taxonName' => $taxon->name,
360
      'nameLink' => NULL,
361
      'refenceLink' => $referenceUri,
362
      ));
363
    $accepted_name .= '</span>';
364

    
365
    // handle annotations of the name and taxon
366
    $special_annotations_array = array();
367
    $special_annotations_array[] = $taxon->name;
368
    $special_annotations_array[] = $taxon;
369
    $accepted_name .= theme('cdm_annotations_as_footnotekeys', array(
370
        'cdmBase_list' => $special_annotations_array,
371
        'footnote_list_key' => RenderHints::getRenderPath() . '-annotations')
372
      );
373
  }
374

    
375
  // --- Render homotypic synonymy group
376
  if (!empty($accepted_name)) {
377
    $out .= $accepted_name;
378
  }
379

    
380
  // Render the homotypicSynonymyGroup including the type information.
381
  $out .= theme('cdm_homotypicSynonymyGroup', array('synonymList' => $synomymie->homotypicSynonymsByHomotypicGroup, 'accepted_taxon_uuid' => $taxon->uuid));
382

    
383

    
384
  // Render accepted taxon heterotypic synonymy groups.
385
  if ($synomymie->heterotypicSynonymyGroups) {
386
    foreach ($synomymie->heterotypicSynonymyGroups as $homotypicalGroup) {
387
      $out .= theme('cdm_heterotypicSynonymyGroup', array('homotypicalGroup' => $homotypicalGroup));
388
    }
389
  }
390
  // Render taxon relationships.
391
  if (variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT)) {
392
    $taxonRelationships = cdm_ws_get(CDM_WS_PORTAL_TAXON_RELATIONS, $taxon->uuid);
393
    $out .= theme('cdm_taxonRelationships', array('taxonRelationships' => $taxonRelationships, 'focusedTaxon' => $taxon));
394
  }
395
  // Render name relationships.
396
  $name_rels_to_show = variable_get('name_relationships_to_show', NULL);
397
  $skip = array();
398
  if ($name_rels_to_show) {
399
    foreach ($name_rels_to_show as $key => $value) {
400
      if ($value === 0) {
401
        $skip[] = $key;
402
      }
403
    }
404
    if (sizeof($name_rels_to_show) != sizeof($skip)) {
405
      $nameRelationships = cdm_ws_get(CDM_WS_PORTAL_TAXON_TO_NAMERELATIONS, $taxon->uuid);
406
      $out .= theme('cdm_nameRelationships', array('nameRelationships' => $nameRelationships, 'skipTypes' => $skip));
407
    }
408
  }
409

    
410
  RenderHints::popFromRenderStack();
411

    
412
  return $out;
413
}
414

    
415

    
416
/**
417
 * Returns HTML for the given result page including a pager.
418
 *
419
 * @param array $variables
420
 *   An associative array containing:
421
 *   - pager: The cdmlib pager object containing the result set of cdm base
422
 *     objects (currently this function can only handle taxon instances =>
423
 *     TODO)
424
 *   - path: The target path for the pager links, this will usually point to
425
 *     'cdm_dataportal/search/results/taxon'
426
 *
427
 * @ingroup themeable
428
 */
429
function theme_cdm_search_results($variables) {
430
  $pager = $variables['pager'];
431
  $path = $variables['path'];
432

    
433
  $freetextSearchResults = array();
434

    
435
  // The $query_parameters must not contain the 'q' parameter
436
  // since this would conflict with the desired target $path.
437
  // unset($search_params['q']);
438
  // If the pager contains records of SearchResults, extract the taxa and use
439
  // them as records instead.
440
  if (isset($pager->records[0]) && $pager->records[0]->class == "SearchResult") {
441
    $freetextSearchResults = $pager->records;
442
    $taxa = array();
443
    // $highlightedFragments = array();
444
    foreach ($pager->records as $searchResult) {
445
      $taxa[] = &$searchResult->entity;
446
      /*
447
       if(!isset($searchResult->fieldHighlightMap)){
448
      $searchResult->fieldHighlightMap = NULL;
449
      }
450
      $fragmentHighlighting[] = $searchResult->fieldHighlightMap;
451
      */
452
    }
453
    $pager->records = $taxa;
454
  }
455

    
456
  $out = '';
457
  // Add thumbnails checkbox and refine search link.
458
  $out = '<div class="page_options">';
459
  if (isset($_REQUEST['ws'])) {
460
    if (cdm_dataportal_search_form_path_for_ws($_REQUEST['ws'])) {
461
      $out .= '<div id="backButton">' . l(t('Modify search'), cdm_dataportal_search_form_path_for_ws($_REQUEST['ws'])) . '</div>';
462
    }
463
  }
464
  $out .= '<form name="pageoptions"><input id="showThumbnails" type="checkbox" name="showThumbnails" ' . (do_showThumbnails() == 1 ? 'checked="checked"' : '') . '> ' . t('Show Thumbnails') . '</form>';
465
  $out .= '</div>';
466
  $out .= '<div id="search-summary">' . t('results for') . ' ';
467
  $classification = cdm_dataportal_searched_in_classification();
468
  if ($classification != NULL) {
469
    $out .=  $classification->titleCache ;
470
  } else {
471
   $out .= t('any classification');
472
  }
473
  $out .= ':</div>';
474

    
475
  // List results.
476
  if (isset($pager->records) && count($pager->records) > 0) {
477
    $out .= '<div id="search_results">';
478
    $out .= theme('cdm_list_of_taxa',
479
        array(
480
          'records' => $pager->records,
481
          'freetextSearchResults' => $freetextSearchResults,
482
          'show_classification' => $classification === NULL
483
        )
484
      );
485
    $out .= '</div>';
486
    $out .= theme('cdm_pager', array(
487
        'pager' => $pager,
488
        'path' => $path,
489
        'parameters' => $_REQUEST,
490
    ));
491
  }
492
  else {
493
    $out .= '<h4 class="error">Sorry, no matching entries found.</h4>';
494
  }
495
  return $out;
496
}
497

    
498

    
499
/**
500
 * TODO Implementation of Hook taxon_image_gallery()
501
 *
502
 * @param unknown_type $taxon
503
 * @param unknown_type $media
504
 *
505
 * @return unknown_type
506
 */
507
function taxon_image_gallery_default($taxon, $media) {
508
  $hasImages = isset($media[0]);
509

    
510
  if ($hasImages) {
511

    
512
    $maxExtend = 150;
513
    $cols = 3;
514
    $maxRows = FALSE;
515
    $alternativeMediaUri = NULL;
516
    /* Comment @WA: was in D5:
517
    $captionElements = array(
518
      'title',
519
      'rights',
520
      '#uri' => t('open Image'),
521
    );
522
    */
523
    $captionElements = array(
524
      'title',
525
      'description',
526
      'artist',
527
      'location',
528
      'rights',
529
      '#uri' => t('open Image'),
530
    );
531
    $gallery_name = $taxon->uuid;
532
    $mediaLinkType = 'LIGHTBOX';
533

    
534
    // $gallery_settings = getGallerySettings(CDM_DATAPORTAL_MEDIA_GALLERY_NAME);
535

    
536
    $gallery_settings = getGallerySettings(CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB);
537

    
538
    $out = '<div class="image-gallerie">';
539
    $out .= theme('cdm_media_gallerie', array(
540
      'mediaList' => $media,
541
      'galleryName' => $gallery_name,
542
      'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
543
      'cols' => $gallery_settings['cdm_dataportal_media_cols'],
544
      'maxRows' => 0, // Ignore maxrows settings.
545
      'captionElements' => $captionElements,
546
      'mediaLinkType' => $mediaLinkType,
547
      'alternativeMediaUri' => NULL,
548
      'galleryLinkUri' => NULL,
549
      'showCaption' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
550
    ));
551
    $out .= '</div>';
552
  }
553
  else {
554
    $out = 'No images available.';
555
  }
556
  return $out;
557
}
558

    
559
/**
560
 * TODO Implementation of Hook taxon_image_gallery()
561
 *
562
 * @param unknown_type $taxon
563
 * @param unknown_type $media
564
 *
565
 * @return unknown_type
566
 */
567
function taxon_image_gallery_fsi($taxon, $media) {
568
  $flashLink = isset($media[0]);
569

    
570
  if ($flashLink) {
571

    
572
    if (module_exists("fsi_gallery")) {
573
      $out = theme("fsi_gallery", array('taxon' => $taxon, 'media' => $media));
574
    }
575
    else {
576
      $message = t('In order to use the FSI gallery you must enable the according ') . l(t("module"), "admin/modules");
577
      drupal_set_message($message, "error");
578
      $out = '<h3>' . $message . '</h3>';
579
    }
580
  }
581
  else {
582
    $out = 'No images available.';
583
  }
584
  return $out;
585
}
586

    
587
/**
588
 * Returns HTML for a single reference page.
589
 *
590
 * Renders a page with all data on a single reference.
591
 *
592
 * @param array $variables
593
 *   An associative array containing:
594
 *   - reference: Object.
595
 *
596
 * @ingroup themeable
597
 */
598
function theme_cdm_reference_page($variables) {
599
  $reference = $variables['reference'];
600

    
601
  $out = '';
602

    
603
  if (isset($reference->titleCache)) {
604
    drupal_set_title($reference->titleCache, PASS_THROUGH);
605
  }
606

    
607
  $field_order = array(
608
    "title",
609
    // "titleCache",
610
    // "citation",
611
    "authorTeam",
612
    "editor",
613
    "publisher",
614
    "placePublished",
615
    "datePublished",
616
    "year",
617
    "edition",// Class Book.
618
    "volume",// Class Article.
619
    "seriesPart",
620
    "inReference",
621
    "nomRefBase", // Class BookSection, Book, Article.
622
    "pages",// Class Article.
623
    "series",// Class Article, PrintSeries.
624
    "school",// Class Thesis.
625
    "institution",// Class Report.
626
    "organization",// Class Proceedings.
627
    "nextVersion",
628
    "previousVersion",
629
    "isbn",// Class Book.
630
    "issn",// Class Journal.
631
    "uri",
632
  );
633

    
634
  $header = array(
635
    t('Field'),
636
    t('Value'),
637
  );
638
  $table_rows = array();
639

    
640
  if (!isset($reference->authorTeam)) {
641
    $authorTeam = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $reference->uuid);
642
    $reference->authorTeam = isset($authorTeam->titleCache) ? $authorTeam->titleCache : '';
643
  }
644

    
645
  if (!isset($reference->inReference)) {
646
    $reference->inReference = cdm_ws_get(CDM_WS_REFERENCE, array(
647
      $reference->uuid,
648
      "inReference",
649
    ));
650
  }
651

    
652
  foreach ($field_order as $fieldname) {
653

    
654
    if (isset($reference->$fieldname)) {
655

    
656
      if ($fieldname == "datePublished") {
657
        $period = $reference->$fieldname;
658
        $datePublished = timePeriodToString($period);
659
        if (isset($datePublished) && $datePublished != '') {
660
          $table_rows[] = array(
661
            t(ucfirst(strtolower($fieldname))),
662
            $datePublished,
663
          );
664
        }
665
        // $datePublished = array(t(ucfirst(strtolower($fieldname))),
666
        // $datePublished);
667
      }
668
      elseif (is_object($reference->$fieldname)) {
669
        if ($fieldname == "authorTeam") {
670
          $dump = $reference->$fieldname;
671
          $teammembers = "teamMembers";
672
          $team = $dump->$teammembers;
673
          $nameArray = array();
674

    
675
          foreach ($team as $member) {
676
            if (strlen($member->lastname) > 0) {
677
              $nname = $member->lastname;
678
              $name = $nname;
679
              if (strlen($member->firstname) > 0) {
680
                $vname = $member->firstname;
681
                $name = $vname . " " . $nname;
682
              }
683
              $nameArray[] = $name;
684
            }
685
            else {
686
              if (strlen($member->titleCache) > 0) {
687
                $nameArray[] = $member->titleCache;
688
              }
689
            }
690
          }
691
          $value = join($nameArray, ", ");
692
        }
693
        elseif ($fieldname == "inReference") {
694
          $type = $reference->$fieldname->type;
695
          $value = l($reference->$fieldname->titleCache, path_to_reference($reference->$fieldname->uuid));
696
          switch ($type) {
697
            case "Book":
698
              $fieldname = "in book";
699
              break;
700
            case "Journal":
701
              $fieldname = "in journal";
702
              break;
703
            case "Proceedings":
704
              $fieldname = "in proceedings";
705
              break;
706
          }
707
        }
708
        else {
709
          $value = $reference->$fieldname->titleCache;
710
        }
711
        if (isset($value) && $value != '') {
712
          $table_rows[] = array(
713
            t(ucfirst(strtolower($fieldname))),
714
            $value,
715
          );
716
        }
717
      }
718
      else {
719
        if (isset($reference->$fieldname) && $reference->$fieldname != '') {
720
          $table_rows[] = array(
721
            t(ucfirst(strtolower($fieldname))),
722
            $reference->$fieldname,
723
          );
724
        }
725
      }
726
    }
727
  }
728

    
729
  $out = theme_table(array(
730
      'header' => array(),
731
      'rows' => $table_rows,
732
      'attributes' => array(),
733
      'caption' => NULL,
734
      'colgroups' => NULL,
735
      'sticky' => NULL,
736
     'empty' => NULL,
737
  ));
738

    
739
  // Annotations below the table.
740
  $annotations = cdm_ws_getAnnotationsFor($reference);
741
  $out .= theme("cdm_annotations", array('annotations' => $annotations));
742

    
743
  return $out;
744
}
745

    
746
/**
747
 * @todo Please document this function.
748
 * @see http://drupal.org/node/1354
749
 */
750
function theme_cdm_media_page($variables) {
751
  $media = $variables['media'];
752
  $mediarepresentation_uuid = $variables['mediarepresentation_uuid'];
753
  $partId = $variables['partId'];
754
  $out = '';
755
  // Determine which reprresentation and which part to show.
756
  $representationIdx = 0;
757
  if ($mediarepresentation_uuid) {
758
    $i = 0;
759
    foreach ($media->representations as $representation) {
760
      if ($representation->uuid == $mediarepresentation_uuid) {
761
        $representationIdx = $i;
762
      }
763
      $i++;
764
    }
765
  }
766
  else {
767
    $mediarepresentation_uuid = $media->representations[0]->uuid;
768
  }
769

    
770
  $partIdx = 0;
771
  if (!is_numeric($partId)) {
772
    // Assuming it is an uuid.
773
    $i = 0;
774
    foreach ($media->representations[$representationIdx]->parts as $part) {
775
      if ($part->uuid == $partId) {
776
        $partIdx = $i;
777
      }
778
      $i++;
779
    }
780
  }
781
  else {
782
    // Assuming it is an index.
783
    $partIdx = $partId;
784
  }
785

    
786
  $media_metadata = cdm_read_media_metadata($media);
787
  // $title = $media->titleCache;
788
  $title = $media_metadata['title'];
789

    
790
  $imageMaxExtend = variable_get('image-page-maxextend', 400);
791

    
792
  if (!$title) {
793
    $title = 'Media ' . $media->uuid . '';
794
  }
795

    
796
  drupal_set_title($title, PASS_THROUGH);
797

    
798
  $out .= '<div class="media cdm_media_viewer_image">';
799

    
800
  $out .= theme('cdm_back_to_image_gallery_button', array());
801
  $out .= '<div class="viewer">';
802
  $out .= theme('cdm_openlayers_image', array('mediaRepresentationPart' => $media->representations[$representationIdx]->parts[$partIdx], 'maxExtend' => $imageMaxExtend));
803
  $out .= '</div>';
804

    
805
  // General media metadata.
806
  /*
807
  $media_metadata = cdm_ws_get(CDM_WS_MEDIA_METADATA, array($media->uuid));
808
  vardump("PRINTING MEDIA METADATA");
809
  vardump($media_metadata);
810
  vardump("PRINTING MEDIA");
811
  vardump($media);
812
  */
813
  $metadataToPrint = theme('cdm_media_caption', array('media' => $media));
814
  $out .= $metadataToPrint;
815

    
816
  // Tabs for the different representations.
817
  // ul.secondary
818
  $out .= '<ul class="primary">';
819
  foreach ($media->representations as $representation) {
820
    $out .= '<li>' . l($media->representations[$representationIdx]->mimeType, path_to_media($media->uuid, $mediarepresentation_uuid, $partIdx)) . '</li>';
821
  }
822
  $out .= '</ul>';
823

    
824
  // Representation(-part) specific metadata.
825
  $thumbnailMaxExtend = 100;
826
  $out .= '<table>';
827
  $i = 0;
828
  foreach ($media->representations[$representationIdx]->parts as $part) {
829
    $out .= '<tr><th>' . t('Part') . ' ' . ($i + 1) . '</th><td>';
830
    switch ($part->class) {
831
      case 'ImageFile':
832
        $out .= $part->width . ' x ' . $part->height . ' - ' . $part->size . 'k';
833
        break;
834
      case 'AudioFile':
835
      case 'MovieFile':
836
        $out .= t('Duration') . ': ' . $part->duration . 's - ' . $part->size . 'k';
837
        break;
838
      default:
839
        $out .= $part->size . 'k';
840
    }
841

    
842
    $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));
843
    $i++;
844
  }
845
  $out .= '</table>';
846
  $out .= '</div>';
847

    
848
  return $out;
849
}
850

    
851
/**
852
 * @todo Please document this function.
853
 * @see http://drupal.org/node/1354
854
 */
855
function theme_cdm_polytomousKey_page($variables) {
856
  $polytomousKey = $variables['polytomousKey'];
857
  drupal_set_title($polytomousKey->titleCache, PASS_THROUGH);
858

    
859
  $out = theme("cdm_IdentificationKey", array(
860
    'identificationKey' => $polytomousKey,
861
    'doLinkToKeyPage' => FALSE,
862
    'showIdentificationKeyTitle' => FALSE,
863
    ));
864

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

    
874
/**
875
 * Returns HTML for taxon page tabs.
876
 *
877
 * Allows theming of the taxon page tabs.
878
 *
879
 * @param array $variables
880
 *   An associative array containing:
881
 *   - tabname
882
 *
883
 * @ingroup themeable
884
 */
885
function theme_cdm_taxonpage_tab($variables) {
886
  $tabname = $variables['tabname'];
887
  // TODO replace by using translations or theme the menue tabs itself instead?
888
  switch ($tabname) {
889
    default:
890
      return t($tabname);
891
  }
892
}
(7-7/10)