Project

General

Profile

Download (4.91 KB) Statistics
| Branch: | Tag: | Revision:
1
<?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

    
74
  if(!isset($reference->authorTeam)){
75
    $author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $reference->uuid);
76
  } else {
77
    $author_team = $reference->authorTeam;
78
  }
79

    
80
  if ($referenceStyle == "zoology") {
81
    $year = '';
82
    if (isset($reference->datePublished->start)) {
83
      $year = partialToYear($reference->datePublished->start);
84
    }
85
    $citation = $author_team->titleCache . (!empty($year) ? '. ' . $year : '');
86
  }
87
  else {
88
    $citation = $reference->titleCache;
89
  }
90

    
91
  if (isset($doLink) && $doLink === TRUE) {
92
    $out = '<span class="reference">';
93
    $out .= l($citation, path_to_reference($reference->uuid), array(
94
      'attributes' => array(
95
        "class" => "reference",
96
      ),
97
      'absolute' => TRUE,
98
      'html' => TRUE,
99
    ));
100
    $out .= '</span>';
101
  }
102
  else {
103
    $out = '<span class="reference">' . $citation . '</span>';
104
  }
105

    
106
  if (!empty($microReference)) {
107
    $out .= ": " . $microReference;
108
  }
109

    
110
  return $out;
111
}
112

    
113
/**
114
 * @todo Please document this function.
115
 * @see http://drupal.org/node/1354
116
 */
117
function _short_form_of_author_team($author_team) {
118
  $number_of_authors = substr_count($author_team, ' & ') + 1;
119
  // var_dump($author_team);
120
  // var_dump($number_of_authors);
121
  switch ($number_of_authors) {
122
    case 1:
123
      $result = $author_team;
124
      break;
125

    
126
    case 2:
127
      $result = str_replace(' & ', ' and ', $author_team);
128
      break;
129

    
130
    default:
131
      $result_parts = explode(' & ', $author_team);
132
      $result = $result_parts[0] . ' et al.';
133
  }
134
  return $result;
135
}
136

    
137
/**
138
 * @todo Please document this function.
139
 * @see http://drupal.org/node/1354
140
 */
141
function theme_cdm_OriginalSource($variables) {
142
  $out = '';
143
  $source = $variables['source'];
144
  $doLink = $variables['doLink'];
145

    
146
  if (isset($source->citation)) {
147
    $out = theme('cdm_reference', array(
148
        'reference' => $source->citation,
149
        'microReference' => $source->citationMicroReference,
150
        'doLink' => $doLink,
151
    ));
152

    
153
    $name_in_source = '';
154
    if (isset($source->nameUsedInSource)) {
155
      $name_in_source = theme('cdm_taxonName', array(
156
          'taxonName' => $source->nameUsedInSource
157
      ));
158
    } else if (isset($source->originalNameString) && !empty($source->originalNameString)) {
159
      // the name used in source can not be expressed as valid taxon name,
160
      // so the editor has chosen to put the freetext name into ReferencedEntityBase.originalNameString
161
      // field
162
      // using the originalNameString as key to avoid duplicate entries
163
      $name_in_source = $source->originalNameString;
164
    }
165
    if($name_in_source) {
166
      $out .=  ' <span class="nameUsedInSource">(' . t('as') . ' ' . $name_in_source . ')</span>';
167
    }
168

    
169
    $id_with_namespace = '';
170
    if( isset($source->idNamespace) && $source->idNamespace ) {
171
      $id_with_namespace = $source->idNamespace . '/';
172
    }
173
    if( isset($source->idInSource) && $source->idInSource ) {
174
      $id_with_namespace .= $source->idInSource;
175
    } else {
176
      $id_with_namespace = NULL;
177
    }
178

    
179
    if($id_with_namespace){
180
      $out .=  ' <span class="idInSource">[' . $id_with_namespace . ']</span>';
181
    }
182
  }
183
  return $out;
184
}
(7-7/9)