Project

General

Profile

Download (3.23 KB) Statistics
| Branch: | Tag: | Revision:
1 6657531f Andreas Kohlbecker
<?php
2
/**
3
 * @file
4
 * Reference 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
 * @todo Please document this function.
18
 * @see http://drupal.org/node/1354
19
 */
20
function theme_cdm_reference_pager($variables) {
21
  $referencePager = $variables['referencePager'];
22
  $path = $variables['path'];
23
  $parameters = $variables['parameters'];
24
  drupal_set_title(t('Bibliographic index'), PASS_THROUGH);
25
  $out = '';
26
  if (count($referencePager->records) > 0) {
27
    $out .= '<ul>';
28
    foreach ($referencePager->records as $reference) {
29
      // FIXME remove hack.
30
      $reference->fullCitation = $reference->titleCache;
31
      // For matching cdm entity to STO.
32
      $out .= '<li>' . theme('cdm_reference', array(
33
        'reference' => $reference,
34
        'microReference' => NULL,
35
        'doLink' => TRUE,
36
        )) . '</li>';
37
    }
38
    $out .= '</ul>';
39
    $out .= theme('cdm_pager', array(
40
      'pager' => $referencePager,
41
      'path' => $path,
42
      'parameters' => $parameters,
43
    ));
44
  }
45
  else {
46
    $out = '<h4 class="error">Sorry, this page contains not entries.</h4>';
47
  }
48
  return $out;
49
}
50
51
/**
52
 * Returns HTML for a reference.
53
 *
54
 * Used by:
55
 * - theme_cdm_typedesignations
56
 * - theme_cdm_reference_pager
57
 * - theme_cdm_taxonRelationships
58
 *
59
 * @param array $variables
60
 *   An associative array containing:
61
 *   - reference
62
 *   - microReference
63
 *   - doLink
64
 *   - referenceStyle
65
 *
66
 * @ingroup themeable
67
 */
68
function theme_cdm_reference($variables) {
69
  $reference = $variables['reference'];
70
  $microReference = $variables['microReference'];
71
  $doLink = $variables['doLink'];
72
  $referenceStyle = $variables['referenceStyle'];
73
  $author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $reference->uuid);
74
75
  if ($referenceStyle == "zoology") {
76
    $year = '';
77
    if (isset($reference->datePublished->start)) {
78
      $year = partialToYear($reference->datePublished->start);
79
    }
80
    $citation = $author_team->titleCache . (!empty($year) ? '. ' . $year : '');
81
  }
82
  else {
83
    $citation = $reference->titleCache;
84
  }
85
86
  if (isset($doLink) && $doLink === TRUE) {
87
    $out = '<span class="reference">';
88
    $out .= l($citation, path_to_reference($reference->uuid), array(
89
      'attributes' => array(
90
        "class" => "reference",
91
      ),
92
      'absolute' => TRUE,
93
      'html' => TRUE,
94
    ));
95
    $out .= '</span>';
96
  }
97
  else {
98
    $out = '<span class="reference">' . $citation . '</span>';
99
  }
100
101
  if (!empty($microReference)) {
102
    $out .= ": " . $microReference;
103
  }
104
105
  return $out;
106
}
107
108
/**
109
 * @todo Please document this function.
110
 * @see http://drupal.org/node/1354
111
 */
112
function _short_form_of_author_team($author_team) {
113
  $number_of_authors = substr_count($author_team, ' & ') + 1;
114
  // var_dump($author_team);
115
  // var_dump($number_of_authors);
116
  switch ($number_of_authors) {
117
    case 1:
118
      $result = $author_team;
119
      break;
120
121
    case 2:
122
      $result = str_replace(' & ', ' and ', $author_team);
123
      break;
124
125
    default:
126
      $result_parts = explode(' & ', $author_team);
127
      $result = $result_parts[0] . ' et al.';
128
  }
129
  return $result;
130
}