1
|
<?php
|
2
|
/**
|
3
|
* @file
|
4
|
* Description 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
|
/**
|
18
|
* Theme function to alter the feature representation.
|
19
|
*
|
20
|
* It is highly questionable if this function should be completely removed.
|
21
|
* If a feature needs a different representation this should be edited directly
|
22
|
* in the cdm data but it should not be tweaked like this in the portal.
|
23
|
*
|
24
|
* Used in:
|
25
|
* - theme_cdm_feature_nodesTOC()
|
26
|
* - theme_cdm_feature_nodes()
|
27
|
* - theme_cdm_media_mime_application()
|
28
|
* - theme_cdm_media_mime_text()
|
29
|
*
|
30
|
* TODO delete this function? (a.kohlbecker feb 2013)
|
31
|
*
|
32
|
*/
|
33
|
function theme_cdm_feature_name($variables) {
|
34
|
$feature_name = $variables['feature_name'];
|
35
|
return t('@feature-name', array('@feature-name' => $feature_name));
|
36
|
}
|
37
|
|
38
|
|
39
|
/**
|
40
|
* @todo Please document this function.
|
41
|
* @see http://drupal.org/node/1354
|
42
|
*/
|
43
|
function theme_FeatureTree_hierarchy($variables) {
|
44
|
|
45
|
$feature_tree_uuid = $variables['FeatureTreeUuid'];
|
46
|
if (!is_uuid($feature_tree_uuid)) {
|
47
|
return NULL;
|
48
|
}
|
49
|
|
50
|
$out = '';
|
51
|
$feature_tree = cdm_ws_get(CDM_WS_FEATURETREE,
|
52
|
array(
|
53
|
$feature_tree_uuid,
|
54
|
)
|
55
|
);
|
56
|
|
57
|
if (isset($feature_tree) && isset($feature_tree->root)) {
|
58
|
$out = '<ul class="' . $feature_tree->class . '">';
|
59
|
$out .= theme('FeatureTree_hierarchy_children', array('node' => $feature_tree->root));
|
60
|
$out .= '</ul>';
|
61
|
}
|
62
|
return $out;
|
63
|
}
|
64
|
|
65
|
/**
|
66
|
* @todo Please document this function.
|
67
|
* @see http://drupal.org/node/1354
|
68
|
*/
|
69
|
function theme_FeatureTree_hierarchy_children($variables) {
|
70
|
|
71
|
$feature_node = $variables['node'];
|
72
|
$out = '';
|
73
|
if (isset($feature_node->childNodes)) {
|
74
|
|
75
|
foreach ($feature_node->childNodes as $child_feature_node) {
|
76
|
$out .= '<li>' . check_plain($child_feature_node->term->representation_L10n);
|
77
|
if (isset($child_feature_node->childNodes) && count($child_feature_node->childNodes) > 0) {
|
78
|
$out .= '<ul>' . theme('FeatureTree_hierarchy_children', array('node' => $child_feature_node)) . '</ul>';
|
79
|
}
|
80
|
$out .= '</li>';
|
81
|
}
|
82
|
}
|
83
|
return $out;
|
84
|
}
|
85
|
|
86
|
/**
|
87
|
* @todo Please document this function.
|
88
|
* @see http://drupal.org/node/1354
|
89
|
*/
|
90
|
function theme_cdm_IdentificationKey($variables) {
|
91
|
$out = '';
|
92
|
$identificationKey = $variables['identificationKey'];
|
93
|
$doLinkToKeyPage = $variables['doLinkToKeyPage'];
|
94
|
$showIdentificationKeyTitle = $variables['showIdentificationKeyTitle'];
|
95
|
$parentRenderPath = RenderHints::getRenderPath();
|
96
|
RenderHints::pushToRenderStack("IdentificationKey");
|
97
|
|
98
|
if ($showIdentificationKeyTitle) {
|
99
|
if ($doLinkToKeyPage) {
|
100
|
$out = l($identificationKey->titleCache, path_to_key($identificationKey->class, $identificationKey->uuid));
|
101
|
}
|
102
|
else {
|
103
|
$out = $identificationKey->titleCache;
|
104
|
}
|
105
|
}
|
106
|
if (isset($identificationKey->sources) && is_array($identificationKey->sources)) {
|
107
|
// order and display sources.
|
108
|
//TODO can the method handle_annotations_and_sources() be used here?
|
109
|
$sources = oder_and_render_original_sources($identificationKey->sources);
|
110
|
$out .= '<div class="sources">';
|
111
|
$out .= implode('', $sources);
|
112
|
$out .= '</div>';
|
113
|
}
|
114
|
// Display annotations.
|
115
|
$out .= theme('cdm_annotations', array('annotations' => cdm_fetch_visible_annotations($identificationKey), 'enclosingTag' => 'div'));
|
116
|
RenderHints::popFromRenderStack();
|
117
|
return $out;
|
118
|
}
|
119
|
|
120
|
/**
|
121
|
* @todo Please document this function.
|
122
|
* @see http://drupal.org/node/1354
|
123
|
*/
|
124
|
function theme_cdm_polytomousKey($variables) {
|
125
|
$polytomousKey = $variables['polytomousKey'];
|
126
|
|
127
|
// TODO settings needed.
|
128
|
// @see http://en.wikipedia.org/wiki/Single_access_key#Presentation_styles
|
129
|
// @see http://dev.e-taxonomy.eu/trac/ticket/2152
|
130
|
$keyStyle = "linkedStyle";
|
131
|
|
132
|
RenderHints::pushToRenderStack("polytomousKey");
|
133
|
// Key nodes in linked style.
|
134
|
$out = '<table class="polytomousKey polytomousKey_' . $keyStyle . '">';
|
135
|
$out .= theme('cdm_polytomousKey_' . $keyStyle . '_subgraph', array('polytomousKeyNode' => $polytomousKey->root));
|
136
|
$out .= '</table>';
|
137
|
RenderHints::popFromRenderStack();
|
138
|
return $out;
|
139
|
}
|
140
|
|
141
|
/**
|
142
|
* @todo Please document this function.
|
143
|
* @see http://drupal.org/node/1354
|
144
|
*/
|
145
|
function theme_cdm_polytomousKey_linkedStyle_subgraph($variables) {
|
146
|
$polytomousKeyNode = $variables['polytomousKeyNode'];
|
147
|
static $statementCountCharacter = '\'';
|
148
|
$out = "";
|
149
|
|
150
|
if (is_array($polytomousKeyNode->children)) {
|
151
|
$childIndex = 0;
|
152
|
|
153
|
// Render edges of the current node.
|
154
|
foreach ($polytomousKeyNode->children as &$child) {
|
155
|
|
156
|
if (!isset($child->statement) && isset($child->taxon->uuid)) {
|
157
|
// Skip node with empty statements (see below for explanation: "Special
|
158
|
// case").
|
159
|
// this skipping here happens always in the next deeper level of iteration
|
160
|
// the check below is node on the level above
|
161
|
continue;
|
162
|
}
|
163
|
|
164
|
/*
|
165
|
* Special case: Child nodes with empty statements but taxa as leaf are to
|
166
|
* treated as if all those taxa where direct children of the source node.
|
167
|
*/
|
168
|
$islinkToManyTaxa = !isset($child->children[0]->statement) && isset($child->children[0]->taxon->uuid);
|
169
|
$islinkToTaxon = isset($child->taxon->uuid);
|
170
|
$islinkToSubKey = isset($child->subkey->uuid);
|
171
|
$islinkToOtherNode = isset($child->otherNode);
|
172
|
// Either NULL or 0.
|
173
|
$islinkToNode = $child->nodeNumber && !$islinkToManyTaxa && !$islinkToOtherNode;
|
174
|
$hasQuestion = !empty($polytomousKeyNode->question->label_l10n);
|
175
|
$hasFeature = isset($polytomousKeyNode->feature);
|
176
|
|
177
|
// $indentEdge = $hasQuestion && $childIndex > 0;
|
178
|
// Question.
|
179
|
if ($hasQuestion && $childIndex == 0) {
|
180
|
// Place question, as extra table row.
|
181
|
$out .= '<tr class="question new_section">';
|
182
|
$out .= '<td class="nodeNumber">' . uuid_anchor($polytomousKeyNode->uuid, $polytomousKeyNode->nodeNumber) . "</td>";
|
183
|
$out .= '<td class="question">' . $polytomousKeyNode->question->label_l10n . '</td>';
|
184
|
$out .= '</tr>';
|
185
|
}
|
186
|
|
187
|
$out .= '<tr class="childCount_' . $childIndex . (!$hasQuestion && $childIndex == 0 ? ' new_section' : '') . '">';
|
188
|
|
189
|
if ($hasQuestion) {
|
190
|
$out .= '<td class="nodeNumber"></td>';
|
191
|
}
|
192
|
else {
|
193
|
$out .= '<td class="nodeNumber">' . uuid_anchor($polytomousKeyNode->uuid, $polytomousKeyNode->nodeNumber . str_pad("", $childIndex, $statementCountCharacter)) . "</td>";
|
194
|
}
|
195
|
|
196
|
$out .= '<td ' . RenderHints::getHtmlElementID($child) . ' class="edge' . ($hasQuestion ? ' edge-indent' : '') . '">';
|
197
|
|
198
|
// Feature.
|
199
|
if ($hasFeature) {
|
200
|
$out .= $polytomousKeyNode->feature->representation_L10n . ": ";
|
201
|
}
|
202
|
|
203
|
// Statement.
|
204
|
$out .= $child->statement->label_l10n;
|
205
|
|
206
|
// --- Links to nodes taxa and subkeys.
|
207
|
$out .= '<div class="nodeLink">';
|
208
|
|
209
|
// Link to a PolytomousKeyNode.
|
210
|
if ($islinkToNode) {
|
211
|
$out .= '<div class="nodeLinkToNode">';
|
212
|
if (isset($child->modifyingText)) {
|
213
|
$out .= theme('cdm_poytomousKeyNode_modifyingText', array('modifyingText' => $child->modifyingText));
|
214
|
}
|
215
|
$out .= l($child->nodeNumber, request_path(), array(
|
216
|
'attributes' => NULL,
|
217
|
'query' => NULL,
|
218
|
'fragment' => $child->uuid,
|
219
|
)) . '</div>';
|
220
|
}
|
221
|
|
222
|
// Link to a PolytomousKeyNode.
|
223
|
if ($islinkToOtherNode) {
|
224
|
$out .= '<div class="nodeLinkToOtherNode">';
|
225
|
if (isset($child->modifyingText)) {
|
226
|
$out .= theme('cdm_poytomousKeyNode_modifyingText', array('modifyingText' => $child->modifyingText));
|
227
|
}
|
228
|
$out .= l($child->otherNode->nodeNumber, $_REQUEST["q"], array(
|
229
|
'attributes' => NULL,
|
230
|
'query' => NULL,
|
231
|
'fragment' => $child->otherNode->uuid,
|
232
|
)) . '</div>';
|
233
|
}
|
234
|
|
235
|
// Link to one or many taxa.
|
236
|
if ($islinkToTaxon || $islinkToManyTaxa) {
|
237
|
|
238
|
if ($islinkToManyTaxa) {
|
239
|
$taxonChildren = $child->children;
|
240
|
}
|
241
|
else {
|
242
|
$taxonChildren = array(
|
243
|
$child,
|
244
|
);
|
245
|
}
|
246
|
|
247
|
foreach ($taxonChildren as $taxonChild) {
|
248
|
// TODO many taxa $child->children->taxon.
|
249
|
$out .= '<div class="nodeLinkToTaxon">';
|
250
|
if (isset($taxonChild->modifyingText)) {
|
251
|
$out .= theme('cdm_poytomousKeyNode_modifyingText', array('modifyingText' => $taxonChild->modifyingText));
|
252
|
}
|
253
|
$out .= render_taxon_or_name($taxonChild->taxon->name, url(path_to_taxon($taxonChild->taxon->uuid)));
|
254
|
$out .= '</div>';
|
255
|
}
|
256
|
|
257
|
// Link to a subkey.
|
258
|
if ($islinkToSubKey) {
|
259
|
$out .= '<div class="nodeLinkToSubkey">' . theme('cdm_IdentificationKey', array('identificationKey' => $child->subkey)) . '</div>';
|
260
|
}
|
261
|
}
|
262
|
|
263
|
$out .= '</div>'; // End node link.
|
264
|
$out .= '</td>'; // End edge.
|
265
|
$out .= '</tr>';
|
266
|
|
267
|
$childIndex++;
|
268
|
}
|
269
|
|
270
|
// Recurse into child nodes.
|
271
|
foreach ($polytomousKeyNode->children as &$child) {
|
272
|
$out .= theme('cdm_polytomousKey_linkedStyle_subgraph', array('polytomousKeyNode' => $child));
|
273
|
}
|
274
|
}
|
275
|
|
276
|
return $out;
|
277
|
}
|
278
|
|
279
|
/**
|
280
|
* @todo Please document this function.
|
281
|
* @see http://drupal.org/node/1354
|
282
|
*/
|
283
|
function theme_cdm_poytomousKeyNode_modifyingText($variables) {
|
284
|
$out = '';
|
285
|
$modifyingText = $variables['modifyingText'];
|
286
|
if (is_object($modifyingText)) {
|
287
|
$i = 0;
|
288
|
foreach (get_object_vars($modifyingText) as $lang => $languageString) {
|
289
|
$out .= ($i++ > 0 ? ', ' : '') . '<span class="modifyingText">' . $languageString->text . '</span> ';
|
290
|
}
|
291
|
}
|
292
|
return $out;
|
293
|
}
|
294
|
|
295
|
/**
|
296
|
* Returns HTML for a list of a specific type of IdentificationKeys.
|
297
|
*
|
298
|
* The list can be restricteded by a taxon.
|
299
|
*
|
300
|
* @param array $variables
|
301
|
* An associative array containing:
|
302
|
* - type: The simple name of the cdm class implementing the interface
|
303
|
* IdentificationKey, valid values are:
|
304
|
* PolytomousKey, MediaKey, MultiAccessKey
|
305
|
* - taxonUuid: If given, this parameter restrict the listed keys to those
|
306
|
* which have the taxon identified be this uuid in scope.
|
307
|
*
|
308
|
* @ingroup themeable
|
309
|
*/
|
310
|
function theme_cdm_list_IdentificationKeys($variables) {
|
311
|
$type = $variables['type'];
|
312
|
$taxonUuid = $variables['taxonUuid'];
|
313
|
$keyList = _list_IdentificationKeys($type, $taxonUuid);
|
314
|
if (!$keyList || count($keyList) == 0) {
|
315
|
return;
|
316
|
}
|
317
|
|
318
|
RenderHints::pushToRenderStack('list_IdentificationKeys');
|
319
|
$out = '<ul>';
|
320
|
foreach ($keyList as $key) {
|
321
|
$out .= '<li>';
|
322
|
$out .= theme('cdm_IdentificationKey', array('identificationKey' => $key));
|
323
|
$out .= '</li>';
|
324
|
}
|
325
|
$out .= '</ul>';
|
326
|
$out .= theme("cdm_annotation_footnotes", array('footnoteListKey' => RenderHints::getRenderPath()));
|
327
|
RenderHints::popFromRenderStack();
|
328
|
|
329
|
return $out;
|
330
|
}
|
331
|
|
332
|
/**
|
333
|
* @todo Please document this function.
|
334
|
* @see http://drupal.org/node/1354
|
335
|
*/
|
336
|
function theme_cdm_block_IdentificationKeys($variables) {
|
337
|
$taxonUuid = $variables['taxonUuid'];
|
338
|
static $types = array(
|
339
|
"PolytomousKey" => "Polytomous",
|
340
|
"MediaKey" => "Media",
|
341
|
"MultiAccessKey" => "Multiaccess",
|
342
|
);
|
343
|
RenderHints::pushToRenderStack('block_IdentificationKeys');
|
344
|
$out = '';
|
345
|
foreach ($types as $type => $label) {
|
346
|
$keylist = theme('cdm_list_IdentificationKeys', array('type' => $type, 'taxonUuid' => $taxonUuid));
|
347
|
if (!$keylist) {
|
348
|
continue;
|
349
|
}
|
350
|
$out .= '<div class="' . $type . '">';
|
351
|
$out .= '<h3>' . t('@label', array('@label' => $label)) . "</h3>";
|
352
|
$out .= $keylist;
|
353
|
$out .= '</div>';
|
354
|
}
|
355
|
RenderHints::popFromRenderStack();
|
356
|
return $out;
|
357
|
}
|
358
|
|
359
|
/**
|
360
|
* Composes block of USE_RECORD and USES feature elements for the given TaxonDescriptions.
|
361
|
*
|
362
|
* @param $descriptions
|
363
|
* The set of TaxonDescriptions
|
364
|
* @param $taxonUuid
|
365
|
* UUID of the taxon to which the descriptions belong
|
366
|
* @return array
|
367
|
* A Drupal render array
|
368
|
*
|
369
|
* @see cdm_block_use_description_content()
|
370
|
*
|
371
|
* @ingroup compose
|
372
|
*/
|
373
|
function compose_feature_block_items_use_records($descriptions, $taxonUuid, $feature) {
|
374
|
|
375
|
|
376
|
RenderHints::pushToRenderStack('block_Uses');
|
377
|
|
378
|
if ($descriptions == NULL) {
|
379
|
return null;
|
380
|
}
|
381
|
|
382
|
$feature_block_settings = get_feature_block_settings(UUID_USE_RECORD);
|
383
|
|
384
|
$on_current_taxon = array();
|
385
|
$on_other_taxa = array();
|
386
|
|
387
|
$currentTaxon = cdm_ws_get(CDM_WS_PORTAL_TAXON, $taxonUuid);
|
388
|
|
389
|
foreach ($descriptions as $description) {
|
390
|
$useSummary = '';
|
391
|
foreach ($description->elements as $element) {
|
392
|
|
393
|
if ($element->feature->uuid == UUID_USE && !(strlen($useSummary) > 0) && isset($element->multilanguageText_L10n)) {
|
394
|
$useSummary = $element->multilanguageText_L10n->text;
|
395
|
}
|
396
|
}
|
397
|
// uses will be ordered by source
|
398
|
foreach ($description->sources as $description_source) {
|
399
|
$originalTaxonUsedInSource = NULL;
|
400
|
$originalTaxonPager = NULL;
|
401
|
if ($description_source->originalNameString) {
|
402
|
$request_params = array();
|
403
|
$request_params['query'] = $description_source->originalNameString;
|
404
|
$request_params['matchMode'] = "EXACT";
|
405
|
$originalTaxonPager = cdm_ws_get(CDM_WS_PORTAL_NAME_FINDBYNAME, NULL, queryString($request_params));
|
406
|
if ($originalTaxonPager->count > 0) {
|
407
|
$originalTaxonUsedInSource = $originalTaxonPager->records[0];
|
408
|
}
|
409
|
else {
|
410
|
$originalTaxonUsedInSource = $currentTaxon->name;
|
411
|
}
|
412
|
}
|
413
|
else {
|
414
|
$originalTaxonUsedInSource = $currentTaxon->name;
|
415
|
}
|
416
|
|
417
|
$markup = '<li class="descriptionText DescriptionElement">';
|
418
|
$name_used_in_source_link_to_show_use = l(
|
419
|
$description_source->originalNameString,
|
420
|
path_to_name($originalTaxonUsedInSource->uuid, null, null, true),
|
421
|
array(
|
422
|
'absolute' => TRUE,
|
423
|
'html' => TRUE,
|
424
|
));
|
425
|
$markup .= $name_used_in_source_link_to_show_use . ': ';
|
426
|
$markup .= $useSummary;
|
427
|
foreach ($description->sources as $element_source) {
|
428
|
$markup .= " (" . render_original_source(
|
429
|
$element_source,
|
430
|
$feature_block_settings['link_to_reference'] == 1,
|
431
|
$feature_block_settings['link_to_name_used_in_source'] == 1) . ")";
|
432
|
}
|
433
|
$hasUseRecords = FALSE;
|
434
|
$descriptionUseRecordOut = '<div class="use-records"><table><th>Use Category</th><th>Use Sub Category</th><th>Plant Part</th><th>Human Group</th><th>Ethnic Group</th><th>Country</th>';
|
435
|
foreach ($description->elements as $descriptionElement) {
|
436
|
if ($descriptionElement->feature->uuid == UUID_USE_RECORD) {
|
437
|
$hasUseRecords = TRUE;
|
438
|
$useRecordTags = explode(';', $descriptionElement->modifyingText_l10n);
|
439
|
$descriptionUseRecordOut .= '<tr>';
|
440
|
$descriptionUseRecordOut .= '<td>' . $useRecordTags[0] . '</td>' . '<td>' . $useRecordTags[1] . '</td>' . '<td>' . $useRecordTags[3] . '</td>' . '<td>' . $useRecordTags[4] . '</td>' . '<td>' . $useRecordTags[5] . '</td>' . '<td>' . $useRecordTags[2] . '</td>';
|
441
|
$descriptionUseRecordOut .= '</tr>';
|
442
|
}
|
443
|
}
|
444
|
$descriptionUseRecordOut .= '</table></div>';
|
445
|
if ($hasUseRecords) {
|
446
|
$markup .= $descriptionUseRecordOut . '</li>';
|
447
|
}
|
448
|
|
449
|
$is_about_current_taxon_name = $currentTaxon->name->uuid == $originalTaxonUsedInSource->uuid;
|
450
|
if ($is_about_current_taxon_name) {
|
451
|
$on_current_taxon[] = markup_to_render_array($markup);
|
452
|
} else {
|
453
|
$on_other_taxa[] = markup_to_render_array($markup);
|
454
|
}
|
455
|
|
456
|
}
|
457
|
}
|
458
|
|
459
|
$render_array = compose_feature_block_wrap_elements(array_merge($on_current_taxon, $on_other_taxa), $feature, $feature_block_settings['glue']);
|
460
|
|
461
|
RenderHints::popFromRenderStack();
|
462
|
|
463
|
return $render_array;
|
464
|
}
|