Project

General

Profile

Download (5.37 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/**
3
 * @file
4
 * Occurrence 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 a specimen.
18
 *
19
 * @param array $variables
20
 *   An associative array containing:
21
 *   - specimenTypeDesignation: Object.
22
 *
23
 * @ingroup themeable
24
 */
25
function theme_cdm_specimen($variables) {
26
  $specimenTypeDesignation = $variables['specimenTypeDesignation'];
27

    
28
  // _add_js_thickbox();
29
  if (isset($specimenTypeDesignation->typeSpecimen)) {
30
    $derivedUnitFacade = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, $specimenTypeDesignation->typeSpecimen->uuid);
31
  }
32

    
33
  $out = '';
34
  if (isset($specimenTypeDesignation->media[0])) {
35

    
36
    $image_url = drupal_get_path('module', 'cdm_dataportal') . '/images/external_link.gif';
37
    // Thickbox has problems reading the first url parameter, so a litte hack is
38
    // needed here:
39
    // Adding a meaningless parameter &tb_hack=1& ....
40
    $out .= '&nbsp;<a href="#TB_inline?tb_hack=1&width=300&amp;height=330&amp;inlineId=specimen_media_' . $specimenTypeDesignation->uuid . '" class="thickbox">' . '<img src="' . $image_url . '" title="' . t('Show media') . '" /></a>';
41

    
42
    $out .= '<div id="specimen_media_' . $specimenTypeDesignation->uuid . '" class="tickbox_content"><table>';
43

    
44
    $media_row = '<tr class="media_data">';
45
    $meta_row = '<tr class="meta_data">';
46

    
47
    foreach ($specimenTypeDesignation->media as $media) {
48
      foreach ($media->representations as $representation) {
49

    
50
        // TODO this this is PART 2/2 of a HACK - select preferred
51
        // representation by mimetype and size.
52
        if (TRUE || $representation->mimeType == 'image/jpeg') {
53
          foreach ($representation->parts as $part) {
54
            // Get media uri conversion rules if the module is installed and
55
            // activated.
56
            if (module_exists('cdm_mediauri')) {
57
              $muris = cdm_mediauri_conversion($part->uri);
58
            }
59
            // --- Handle media preview rules.
60
            if (isset($muris['preview'])) {
61

    
62
              $a_child = '<img src="' . $muris['preview']['uri'] . '" class="preview" ' . ($muris['preview']['size_x'] ? 'width="' . $muris['preview']['size_x'] . '"' : '') . ($muris['preview']['size_y'] ? 'width="' . $muris['preview']['size_y'] . '"' : '') . '/>';
63
            }
64
            else {
65
              $a_child = '<img src="' . $part->uri . '" />';
66
            }
67

    
68
            // --- Handle web application rules.
69
            $webapp = '';
70
            if (isset($muris['webapp'])) {
71
              if ($muris['webapp']['embed_html']) {
72
                // Embed in same page.
73
                $webapp = $muris['webapp']['embed_html'];
74
              }
75
              else {
76
                $webapp = l(t('web application'), $muris['webapp']['uri']);
77
              }
78
            }
79
            $media_row .= '<td><a href="' . $part->uri . '" target="' . $part->uuid . '">' . $a_child . '</a></td>';
80
            $meta_row .= '<td><span class="label">' . check_plain($specimenTypeDesignation->titleCache) . '</span><div class="webapp">' . $webapp . '</div></td>';
81
          } // END parts.
82
          // TODO this is PART 2/2 of a hack.
83
          break;
84
        } // END representations.
85
      } // END media.
86
    }
87
    $out .= $media_row . '</tr>';
88
    $out .= $meta_row . '</tr>';
89

    
90
    $out .= '</div></table>';
91
  }
92
  return $out;
93
}
94

    
95
/**
96
 * @todo Please document this function.
97
 * @see http://drupal.org/node/1354
98
 */
99
function theme_cdm_derivedUnitFacade($variables) {
100
  $derivedUnitFacade = $variables['derivedUnitFacade'];
101
  $out = '';
102

    
103
  static $excludeFields = array(
104
    'class',
105
    'titleCache',
106
    'derivedUnitMedia',
107
  );
108
  static $fieldLabels = array(
109
    'type' => 'Basis of Record',
110
    'fieldNumber' => 'Collectors number',
111
    'absoluteElevation' => 'Altitude',
112
    'absoluteElevationMinimum' => 'Altitude maximum',
113
    'absoluteElevationMaximum' => 'Altitude minimum',
114
    'getGatheringPeriod' => 'Gathering period',
115
  );
116

    
117
  if (is_object($derivedUnitFacade)) {
118
    $out = '<dl>';
119
    foreach (get_object_vars($derivedUnitFacade) as $field => $value) {
120
      if (!in_array($field, $excludeFields) && ($value && (!is_object($value) || isset($value->class)))) {
121
        switch ($field) {
122
          case 'locality':
123
            $stringValue = $value->text;
124
            break;
125

    
126
          case 'country':
127
            $stringValue = $value->representation_L10n;
128
            break;
129

    
130
          case 'collector':
131
            $stringValue = $value->titleCache;
132
            break;
133

    
134
          case 'collection':
135
            $stringValue = $value->titleCache;
136
            break;
137

    
138
          case 'exactLocation':
139
            $stringValue = $value->sexagesimalString;
140
            break;
141

    
142
          case 'getGatheringPeriod':
143
            $stringValue = timePeriodToString($value);
144
            break;
145

    
146
          default:
147
            $stringValue = $value;
148
        }
149
        // Relabel field names.
150
        if (isset($fieldLabels[$field])) {
151
          $field = $fieldLabels[$field];
152
        }
153
        $field = preg_replace('/([a-z])([A-Z])/e', "'\\1 '.strtolower('\\2')", $field);
154
        $values[] = '<dt>' . t(ucfirst($field)) . ':</dt><dd>' . $stringValue . '</dd>';
155
      }
156
    }
157
    sort($values);
158
    $out .= implode('', $values);
159
    $out .= '</dl>';
160
  }
161
  return $out;
162
}
(6-6/9)