Project

General

Profile

Download (19.6 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
  RenderHints::pushToRenderStack('taxon_page_title');
30
  $referenceUri = '';
31
  $out = '';
32
  if (isset($taxon->name->nomenclaturalReference)) {
33
    $referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
34
  }
35

    
36
  $out .= render_taxon_or_name($taxon, NULL, $referenceUri, FALSE);
37
  RenderHints::popFromRenderStack();
38

    
39
  return '<span class="' . $taxon->class . '">' . $out . '</span>';
40
}
41

    
42
/**
43
 * Returns HTML for the default title of a specimen page.
44
 *  * The returned title is a the identifier of the specimen.
45
 *
46
 * @param array $variables
47
 *   An associative array containing:
48
 *   - specimen: The specimen being formatted for the title.
49
 *
50
 * @ingroup themeable
51
 */
52
function theme_cdm_specimen_page_title($variables) {
53
    $specimen = $variables['specimen'];
54
    RenderHints::pushToRenderStack('specimen_page_title');
55
    $referenceUri = '';
56
    $out = '';
57

    
58
    $title = "";
59
    if($specimen->accessionNumber){
60
        $title = $specimen->accessionNumber;
61
    }
62
    elseif($specimen->barcode){
63
        $title = $specimen->barcode;
64
    }
65
    elseif($specimen->catalogNumber) {
66
        $title = $specimen->catalogNumber;
67
    }
68

    
69

    
70
  $out .= $title;
71
  RenderHints::popFromRenderStack();
72

    
73
  return '<span class="' . $specimen->class . '">' . $out . '</span>';
74
}
75

    
76
/**
77
 * Returns HTML for the default title for a name page.
78
 *
79
 * The returned title is a formatted name.
80
 *
81
 * @param array $variables
82
 *   An associative array containing:
83
 *   - taxon_name: The taxon name object.
84
 *
85
 * @ingroup themeable
86
 */
87
function theme_cdm_name_page_title($variables) {
88
  $taxon_name = $variables['taxon_name'];
89
  RenderHints::pushToRenderStack('taxon_page_title');
90

    
91
  $referenceUri = NULL;
92
  if (isset($taxon_name->nomenclaturalReference)) {
93
    $referenceUri = url(path_to_reference($taxon_name->nomenclaturalReference->uuid));
94
  }
95

    
96
  $out = '<span class="' . $taxon_name->class . '">'
97
    . render_taxon_or_name($taxon_name, NULL, $referenceUri, FALSE)
98
    . '</span>';
99
  RenderHints::popFromRenderStack();
100
  return $out;
101
}
102

    
103

    
104

    
105

    
106

    
107
/**
108
 * Returns HTML containing the synonymy for the accepted taxon.
109
 *
110
 * Shows the whole synonymy for the accepted taxon.
111
 * The synonymy list is headed by the complete scientific name
112
 * of the accepted taxon with nomenclatural reference.
113
 *
114
 * @param array $variables
115
 *   An associative array containing:
116
 *   - taxon
117
 *   - addAcceptedTaxon
118
 *
119
 * @ingroup themeable
120
 */
121
function theme_cdm_taxon_page_synonymy($variables) {
122
  $taxon = $variables['taxon'];
123
  $addAcceptedTaxon = $variables['addAcceptedTaxon'];
124

    
125
  RenderHints::pushToRenderStack('taxon_page_synonymy');
126

    
127
  // footnote key for the homotypic group and accepted taxon,
128
  // both should have the same footnote key
129
  RenderHints::setFootnoteListKey(RenderHints::getRenderPath());
130

    
131
  $synomymie = cdm_ws_get(CDM_WS_PORTAL_TAXON_SYNONYMY, $taxon->uuid);
132
  $skip = array(
133
    UUID_NAMERELATIONSHIPTYPE_BASIONYM,
134
  );
135
  $out = '';
136

    
137
  // Render accepted taxon.
138
  //
139
  // foonotes of the accepted taxon will be rendered in the homotypic group section
140
  // even if there are not synonyms in the homotypic group
141
  // homotypic group and accepted taxon should have the same footnote key
142
  $referenceUri = '';
143
  if ($addAcceptedTaxon) {
144
    // remember the last part of the render path
145
    $synonymy_render_path = RenderHints::getRenderPath();
146
    // set new render path for the accepted taxon so
147
    // it can be styled differently via the name render part definitions
148
    RenderHints::pushToRenderStack('accepted_taxon');
149
    if (isset($taxon->name->nomenclaturalReference)) {
150
      $referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
151
    }
152

    
153
    $accepted_name = '<div class="accepted-name">';
154
    $accepted_name .= render_taxon_or_name($taxon, NULL, $referenceUri);
155

    
156
    $name_relationships = cdm_name_relationships_of($taxon);
157
    // Render relationships of accepted name.
158
    if($name_relationships){
159

    
160
      $accepted_name .= ' <span class="name_relationships">' . $name_relationships . '</span>';
161
    }
162

    
163
      // handle annotations of the name and taxon
164
    $special_annotations_array = array();
165
    $special_annotations_array[] = $taxon->name;
166
    $special_annotations_array[] = $taxon;
167
    $accepted_name .= theme('cdm_annotations_as_footnotekeys', array(
168
        'cdmBase_list' => $special_annotations_array,
169
        'footnote_list_key' => $synonymy_render_path . '-annotations')
170
      );
171
    $accepted_name .= '</div>';
172
    RenderHints::popFromRenderStack();
173
  }
174

    
175
  // --- Render homotypic synonymy group
176
  if (!empty($accepted_name)) {
177
    $out .= $accepted_name;
178
  }
179

    
180
  // Render the homotypicSynonymyGroup including the type information.
181
  $out .= theme(
182
      'cdm_homotypicSynonymyGroup',
183
      array(
184
          'synonymList' => $synomymie->homotypicSynonymsByHomotypicGroup,
185
          'accepted_taxon_name_uuid' => $taxon->name->uuid
186
      )
187
    );
188

    
189

    
190
  // Render accepted taxon heterotypic synonymy groups.
191
  if ($synomymie->heterotypicSynonymyGroups) {
192
    foreach ($synomymie->heterotypicSynonymyGroups as $homotypicalGroup) {
193
      $out .= theme('cdm_heterotypicSynonymyGroup', array('homotypicalGroup' => $homotypicalGroup));
194
    }
195
  }
196
  // Render taxon relationships.
197
  if (variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT)) {
198
    $taxonRelationships = cdm_ws_get(CDM_WS_PORTAL_TAXON_RELATIONS, $taxon->uuid);
199
    $out .= cdm_taxonRelationships($taxonRelationships, $taxon);
200
  }
201

    
202
  RenderHints::popFromRenderStack();
203

    
204
  return $out;
205
}
206

    
207

    
208
/**
209
 * Returns HTML for the given result page including a pager.
210
 *
211
 * @param array $variables
212
 *   An associative array containing:
213
 *   - pager: The cdmlib pager object containing the result set of cdm base
214
 *     objects (currently this function can only handle taxon instances =>
215
 *     TODO)
216
 *   - path: The target path for the pager links, this will usually point to
217
 *     'cdm_dataportal/search/results/taxon'
218
 *
219
 * @ingroup themeable
220
 */
221
function theme_cdm_search_results($variables)
222
{
223
  $pager = $variables['pager'];
224
  $path = $variables['path'];
225

    
226
  $freetextSearchResults = array();
227

    
228
  // If the pager contains records of SearchResults, extract the taxa and use
229
  // them as records instead.
230
  if (isset($pager->records[0]) && $pager->records[0]->class == "SearchResult") {
231
    $freetextSearchResults = $pager->records;
232
    $taxa = array();
233
    // $highlightedFragments = array();
234
    foreach ($pager->records as $searchResult) {
235
      $taxa[] = &$searchResult->entity;
236
      /*
237
       if(!isset($searchResult->fieldHighlightMap)){
238
      $searchResult->fieldHighlightMap = NULL;
239
      }
240
      $fragmentHighlighting[] = $searchResult->fieldHighlightMap;
241
      */
242
    }
243
    $pager->records = $taxa;
244
  }
245

    
246

    
247
  // Add thumbnails checkbox and refine search link.
248
  $out = '<div class="page_options">';
249
  if (isset($_REQUEST['ws'])) {
250
    if (cdm_dataportal_search_form_path_for_ws($_REQUEST['ws'])) {
251
      $out .= '<div id="backButton">' . l(t('Modify search'), cdm_dataportal_search_form_path_for_ws($_REQUEST['ws'])) . '</div>';
252
    }
253
  }
254
  if (variable_get(SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX, SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT)) {
255
    $out .= '<form name="pageoptions"><div id="showThumbnails"><input class="showThumbnails" type="checkbox" name="showThumbnails" ' . (do_showThumbnails() == 1 ? 'checked="checked"' : '') . '> ' . t('Display Image Thumbnails') . '</div></form>';
256
  }
257
  $out .= '</div>';
258

    
259
  $classification = cdm_dataportal_searched_in_classification();
260

    
261

    
262
  if (  count(cdm_ws_fetch_all(CDM_WS_PORTAL_TAXONOMY)) > 1 ) { // FIXME use a count REST method for this!!!
263
    $out .= '<div id="search-summary">' . t('results for') . ' ';
264
    if ($classification != NULL) {
265
      $out .=  $classification->titleCache ;
266
    } else {
267
     $out .= t('any classification');
268
    }
269
    $out .= ':</div>';
270
  }
271

    
272
  // List results.
273
  if (isset($pager->records) && count($pager->records) > 0) {
274
    $out .= '<div id="search_results">';
275
    $out .= drupal_render(compose_list_of_taxa($pager->records, $freetextSearchResults, $classification === NULL));
276
    $out .= '</div>';
277
    $out .= theme('cdm_pager', array(
278
        'pager' => $pager,
279
        'path' => $path,
280
        'parameters' => $_REQUEST,
281
    ));
282
  } else {
283
    $out .= '<h4 class="error">Sorry, no matching entries found.</h4>';
284
  }
285
  return $out;
286
}
287

    
288

    
289
/**
290
 * TODO Implementation of Hook taxon_image_gallery()
291
 *
292
 * @param unknown_type $taxon
293
 * @param unknown_type $media
294
 *
295
 * @return unknown_type
296
 */
297
function taxon_image_gallery_default($taxon, $media) {
298
  $hasImages = isset($media[0]);
299

    
300
  if ($hasImages) {
301

    
302
    $maxExtend = 150;
303
    $cols = 3;
304
    $maxRows = FALSE;
305
    $alternativeMediaUri = NULL;
306
    /* Comment @WA: was in D5:
307
    $captionElements = array(
308
      'title',
309
      'rights',
310
      '#uri' => t('open Image'),
311
    );
312
    */
313
    $captionElements = array(
314
      'title',
315
      'description',
316
      'artist',
317
      'location',
318
      'rights',
319
      '#uri' => t('open Image'),
320
    );
321
    $gallery_name = $taxon->uuid;
322
    $mediaLinkType = 'LIGHTBOX';
323

    
324
    // $gallery_settings = getGallerySettings(CDM_DATAPORTAL_MEDIA_GALLERY_NAME);
325

    
326
    $gallery_settings = getGallerySettings(CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB);
327

    
328
    $out = '<div class="image-gallerie">';
329
    $out .= theme('cdm_media_gallerie', array(
330
      'mediaList' => $media,
331
      'galleryName' => $gallery_name,
332
      'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
333
      'cols' => $gallery_settings['cdm_dataportal_media_cols'],
334
      'maxRows' => 0, // Ignore maxrows settings.
335
      'captionElements' => $captionElements,
336
      'mediaLinkType' => $mediaLinkType,
337
      'alternativeMediaUri' => NULL,
338
      'galleryLinkUri' => NULL,
339
      'showCaption' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
340
    ));
341
    $out .= '</div>';
342
  }
343
  else {
344
    $out = 'No images available.';
345
  }
346
  return $out;
347
}
348

    
349
/**
350
 * TODO Implementation of Hook taxon_image_gallery()
351
 *
352
 * @param unknown_type $taxon
353
 * @param unknown_type $media
354
 *
355
 * @return unknown_type
356
 */
357
function taxon_image_gallery_fsi($taxon, $media) {
358
  $flashLink = isset($media[0]);
359

    
360
  if ($flashLink) {
361

    
362
    if (module_exists("fsi_gallery")) {
363
      $out = theme("fsi_gallery", array('taxon' => $taxon, 'media' => $media));
364
    }
365
    else {
366
      $message = t('In order to use the FSI gallery you must enable the according ') . l(t("module"), "admin/modules");
367
      drupal_set_message($message, "error");
368
      $out = '<h3>' . $message . '</h3>';
369
    }
370
  }
371
  else {
372
    $out = 'No images available.';
373
  }
374
  return $out;
375
}
376

    
377
/**
378
 * Returns HTML for a single reference page.
379
 *
380
 * Renders a page with all data on a single reference.
381
 *
382
 * @param array $variables
383
 *   An associative array containing:
384
 *   - reference: Object.
385
 *
386
 * @ingroup themeable
387
 */
388
function theme_cdm_reference_page($variables) {
389
  $reference = $variables['reference'];
390

    
391
  $out = '';
392

    
393
  if (isset($reference->titleCache)) {
394
    drupal_set_title($reference->titleCache, PASS_THROUGH);
395
  }
396

    
397
  $field_order = array(
398
    "title",
399
    // "titleCache",
400
    // "citation",
401
    "authorship",
402
    "editor",
403
    "publisher",
404
    "placePublished",
405
    "datePublished",
406
    "year",
407
    "edition",// Class Book.
408
    "volume",// Class Article.
409
    "seriesPart",
410
    "inReference",
411
    "nomRefBase", // Class BookSection, Book, Article.
412
    "pages",// Class Article.
413
    "series",// Class Article, PrintSeries.
414
    "school",// Class Thesis.
415
    "institution",// Class Report.
416
    "organization",// Class Proceedings.
417
    "nextVersion",
418
    "previousVersion",
419
    "isbn",// Class Book.
420
    "issn",// Class Journal.
421
    "uri",
422
  );
423

    
424
  $header = array(
425
    t('Field'),
426
    t('Value'),
427
  );
428
  $table_rows = array();
429

    
430
  if (!isset($reference->authorship)) {
431
    $authorship = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $reference->uuid);
432
    $reference->authorship = isset($authorship->titleCache) ? $authorship->titleCache : '';
433
  }
434

    
435
  if (!isset($reference->inReference)) {
436
    $reference->inReference = cdm_ws_get(CDM_WS_REFERENCE, array(
437
      $reference->uuid,
438
      "inReference",
439
    ));
440
  }
441

    
442
  foreach ($field_order as $fieldname) {
443

    
444
    if (isset($reference->$fieldname)) {
445

    
446
      if ($fieldname == "datePublished") {
447
        $period = $reference->$fieldname;
448
        $datePublished = timePeriodToString($period);
449
        if (isset($datePublished) && $datePublished != '') {
450
          $table_rows[] = array(
451
            t(ucfirst(strtolower($fieldname))),
452
            $datePublished,
453
          );
454
        }
455
        // $datePublished = array(t(ucfirst(strtolower($fieldname))),
456
        // $datePublished);
457
      }
458
      elseif (is_object($reference->$fieldname)) {
459
        if ($fieldname == "authorship") {
460
          $dump = $reference->$fieldname;
461
          $teammembers = "teamMembers";
462
          $team = $dump->$teammembers;
463
          $nameArray = array();
464

    
465
          foreach ($team as $member) {
466
            if (strlen($member->lastname) > 0) {
467
              $nname = $member->lastname;
468
              $name = $nname;
469
              if (strlen($member->firstname) > 0) {
470
                $vname = $member->firstname;
471
                $name = $vname . " " . $nname;
472
              }
473
              $nameArray[] = $name;
474
            }
475
            else {
476
              if (strlen($member->titleCache) > 0) {
477
                $nameArray[] = $member->titleCache;
478
              }
479
            }
480
          }
481
          $value = join($nameArray, ", ");
482
        }
483
        elseif ($fieldname == "inReference") {
484
          $type = $reference->$fieldname->type;
485
          $value = l($reference->$fieldname->titleCache, path_to_reference($reference->$fieldname->uuid));
486
          switch ($type) {
487
            case "Book":
488
              $fieldname = "in book";
489
              break;
490
            case "Journal":
491
              $fieldname = "in journal";
492
              break;
493
            case "Proceedings":
494
              $fieldname = "in proceedings";
495
              break;
496
          }
497
        }
498
        else {
499
          $value = $reference->$fieldname->titleCache;
500
        }
501
        if (isset($value) && $value != '') {
502
          $table_rows[] = array(
503
            t(ucfirst(strtolower($fieldname))),
504
            $value,
505
          );
506
        }
507
      }
508
      else {
509
        if (isset($reference->$fieldname) && $reference->$fieldname != '') {
510
          $table_rows[] = array(
511
            t(ucfirst(strtolower($fieldname))),
512
            $reference->$fieldname,
513
          );
514
        }
515
      }
516
    }
517
  }
518

    
519
  $out = theme_table(array(
520
      'header' => array(),
521
      'rows' => $table_rows,
522
      'attributes' => array(),
523
      'caption' => NULL,
524
      'colgroups' => NULL,
525
      'sticky' => NULL,
526
     'empty' => NULL,
527
  ));
528

    
529
  // Annotations below the table.
530
  $annotations = cdm_ws_getAnnotationsFor($reference);
531
  $out .= theme("cdm_annotations", array('annotations' => $annotations));
532

    
533
  return $out;
534
}
535

    
536
/**
537
 * @todo Please document this function.
538
 * @see http://drupal.org/node/1354
539
 */
540
function theme_cdm_media_page($variables) {
541
  $media = $variables['media'];
542
  $mediarepresentation_uuid = $variables['mediarepresentation_uuid'];
543
  $partId = $variables['partId'];
544
  $out = '';
545
  // Determine which representation and which part to show.
546
  $representationIdx = 0;
547
  if ($mediarepresentation_uuid) {
548
    $i = 0;
549
    foreach ($media->representations as $representation) {
550
      if ($representation->uuid == $mediarepresentation_uuid) {
551
        $representationIdx = $i;
552
      }
553
      $i++;
554
    }
555
  }
556
  else {
557
    $mediarepresentation_uuid = $media->representations[0]->uuid;
558
  }
559

    
560
  $partIdx = 0;
561
  if (!is_numeric($partId)) {
562
    // Assuming it is an uuid.
563
    $i = 0;
564
    foreach ($media->representations[$representationIdx]->parts as $part) {
565
      if ($part->uuid == $partId) {
566
        $partIdx = $i;
567
      }
568
      $i++;
569
    }
570
  }
571
  else {
572
    // Assuming it is an index.
573
    $partIdx = $partId;
574
  }
575

    
576
  $media_metadata = read_media_metadata($media);
577
  // $title = $media->titleCache;
578
  $title = $media_metadata['title'];
579

    
580
  $imageMaxExtend = variable_get('image-page-maxextend', 400);
581

    
582
  if (!$title) {
583
    $title = 'Media ' . $media->uuid . '';
584
  }
585

    
586
  drupal_set_title($title, PASS_THROUGH);
587

    
588
  $out .= '<div class="media cdm_media_viewer_image">';
589

    
590
  $out .= theme('cdm_back_to_image_gallery_button', array());
591
  $out .= '<div class="viewer">';
592
  $out .= theme('cdm_openlayers_image', array('mediaRepresentationPart' => $media->representations[$representationIdx]->parts[$partIdx], 'maxExtend' => $imageMaxExtend));
593
  $out .= '</div>';
594

    
595
  // General media metadata.
596
  /*
597
  $media_metadata = cdm_ws_get(CDM_WS_MEDIA_METADATA, array($media->uuid));
598
  vardump("PRINTING MEDIA METADATA");
599
  vardump($media_metadata);
600
  vardump("PRINTING MEDIA");
601
  vardump($media);
602
  */
603
  $metadataToPrint = theme('cdm_media_caption', array('media' => $media));
604
  $out .= $metadataToPrint;
605

    
606
  // Tabs for the different representations.
607
  // ul.secondary
608
  $out .= '<ul class="primary">';
609
  foreach ($media->representations as $representation) {
610
    $out .= '<li>' . l($media->representations[$representationIdx]->mimeType, path_to_media($media->uuid, $mediarepresentation_uuid, $partIdx)) . '</li>';
611
  }
612
  $out .= '</ul>';
613

    
614
  // Representation(-part) specific metadata.
615
  $thumbnailMaxExtend = 100;
616
  $out .= '<table>';
617
  $i = 0;
618
  foreach ($media->representations[$representationIdx]->parts as $part) {
619
    $out .= '<tr><th>' . t('Part') . ' ' . ($i + 1) . '</th><td>';
620
    switch ($part->class) {
621
      case 'ImageFile':
622
        $out .= $part->width . ' x ' . $part->height . ' - ' . $part->size . 'k';
623
        break;
624
      case 'AudioFile':
625
      case 'MovieFile':
626
        $out .= t('Duration') . ': ' . $part->duration . 's - ' . $part->size . 'k';
627
        break;
628
      default:
629
        $out .= $part->size . 'k';
630
    }
631

    
632
    $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));
633
    $i++;
634
  }
635
  $out .= '</table>';
636
  $out .= '</div>';
637

    
638
  return $out;
639
}
640

    
641
/**
642
 * @todo Please document this function.
643
 * @see http://drupal.org/node/1354
644
 */
645
function theme_cdm_polytomousKey_page($variables) {
646
  $polytomousKey = $variables['polytomousKey'];
647
  drupal_set_title($polytomousKey->titleCache, PASS_THROUGH);
648

    
649
  $out = theme("cdm_IdentificationKey", array(
650
    'identificationKey' => $polytomousKey,
651
    'doLinkToKeyPage' => FALSE,
652
    'showIdentificationKeyTitle' => FALSE,
653
    ));
654

    
655
  // Key nodes in linked style.
656
  $out .= theme('cdm_polytomousKey', array('polytomousKey' => $polytomousKey));
657
  /*
658
   * FIXME implement node type for keys !!!
659
   * (wrapping the content in the cdm_dataportal.node becomes obsolete then).
660
   */
661
  return '<div id="identificationKey">' . $out . '</div>';
662
}
663

    
664
/**
665
 * Returns HTML for taxon page tabs.
666
 *
667
 * Allows theming of the taxon page tabs.
668
 *
669
 * @param array $variables
670
 *   An associative array containing:
671
 *   - tabname
672
 *
673
 * @ingroup themeable
674
 */
675
function theme_cdm_taxonpage_tab($variables) {
676
  $tabname = $variables['tabname'];
677
  // TODO replace by using translations or theme the menue tabs itself instead?
678
  switch ($tabname) {
679
    default:
680
      return t($tabname);
681
  }
682
}
(6-6/9)