1 |
6657531f
|
Andreas Kohlbecker
|
<?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 .= ' <a href="#TB_inline?tb_hack=1&width=300&height=330&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 |
|
|
'fieldNumber' => 'Collectors number',
|
110 |
|
|
'absoluteElevation' => 'Altitude',
|
111 |
|
|
'absoluteElevationMinimum' => 'Altitude maximum',
|
112 |
|
|
'absoluteElevationMaximum' => 'Altitude minimum',
|
113 |
|
|
'getGatheringPeriod' => 'Gathering period',
|
114 |
|
|
);
|
115 |
|
|
|
116 |
|
|
if (is_object($derivedUnitFacade)) {
|
117 |
|
|
$out = '<dl>';
|
118 |
|
|
foreach (get_object_vars($derivedUnitFacade) as $field => $value) {
|
119 |
|
|
if (!in_array($field, $excludeFields) && ($value && (!is_object($value) || isset($value->class)))) {
|
120 |
|
|
switch ($field) {
|
121 |
|
|
case 'locality':
|
122 |
|
|
$stringValue = $value->text;
|
123 |
|
|
break;
|
124 |
|
|
|
125 |
|
|
case 'country':
|
126 |
|
|
$stringValue = $value->representation_L10n;
|
127 |
|
|
break;
|
128 |
|
|
|
129 |
|
|
case 'collector':
|
130 |
|
|
$stringValue = $value->titleCache;
|
131 |
|
|
break;
|
132 |
|
|
|
133 |
|
|
case 'collection':
|
134 |
|
|
$stringValue = $value->titleCache;
|
135 |
|
|
break;
|
136 |
|
|
|
137 |
|
|
case 'exactLocation':
|
138 |
|
|
$stringValue = $value->sexagesimalString;
|
139 |
|
|
break;
|
140 |
|
|
|
141 |
|
|
case 'getGatheringPeriod':
|
142 |
|
|
$stringValue = timePeriodToString($value);
|
143 |
|
|
break;
|
144 |
|
|
|
145 |
|
|
default:
|
146 |
|
|
$stringValue = $value;
|
147 |
|
|
}
|
148 |
|
|
// Relabel field names.
|
149 |
|
|
if (isset($fieldLabels[$field])) {
|
150 |
|
|
$field = $fieldLabels[$field];
|
151 |
|
|
}
|
152 |
|
|
$field = preg_replace('/([a-z])([A-Z])/e', "'\\1 '.strtolower('\\2')", $field);
|
153 |
|
|
$values[] = '<dt>' . t(ucfirst($field)) . ':</dt><dd>' . $stringValue . '</dd>';
|
154 |
|
|
}
|
155 |
|
|
}
|
156 |
|
|
sort($values);
|
157 |
|
|
$out .= implode('', $values);
|
158 |
|
|
$out .= '</dl>';
|
159 |
|
|
}
|
160 |
|
|
return $out;
|
161 |
|
|
}
|