1 |
aa7c7290
|
Andreas Kohlbecker
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* Returns the localized representations of the modifiers hold by the supplied cdm instance concatenated into one string.
|
5 |
|
|
*
|
6 |
|
|
* @param object $iModifieable
|
7 |
|
|
* cdm instance of an class implementing the interface IModifieable: DescriptionElementBase, StateDate, State
|
8 |
|
|
*/
|
9 |
|
|
function cdm_modifers_representations($iModifieable, $glue = ', ') {
|
10 |
|
|
$modifiers_strings = array();
|
11 |
|
|
if (isset($iModifieable->modifiers)) {
|
12 |
|
|
foreach ($iModifieable->modifiers as $modifier) {
|
13 |
|
|
$modifiers_strings[] = cdm_term_representation($modifier);
|
14 |
|
|
}
|
15 |
|
|
}
|
16 |
|
|
return implode(', ', $modifiers_strings);
|
17 |
19e097a3
|
Andreas Kohlbecker
|
}
|
18 |
bf97c2e8
|
Andreas Kohlbecker
|
|
19 |
19e097a3
|
Andreas Kohlbecker
|
/**
|
20 |
|
|
* Filters the given set of description elements and prefers computed elements over
|
21 |
|
|
* others. Computed description elements are identified by the MarkerType.COMPUTED()
|
22 |
|
|
*
|
23 |
|
|
* If the given set contains at least one computed element only the computed elements
|
24 |
|
|
* returned.
|
25 |
|
|
*
|
26 |
|
|
* @param $description_elements
|
27 |
|
|
* An array of CDM DescriptionElementBase instances
|
28 |
|
|
* @return only the computed description elements otherwise all others.
|
29 |
|
|
*/
|
30 |
|
|
function cdm_description_elements_prefer_computed($description_elements){
|
31 |
|
|
|
32 |
|
|
$computed_elements = array();
|
33 |
|
|
$other_elements = array();
|
34 |
|
|
|
35 |
|
|
if(!empty($description_elements)){
|
36 |
|
|
foreach ($description_elements as $element) {
|
37 |
|
|
if(cdm_entity_has_marker($element, UUID_MARKERTYPE_COMPUTED)){
|
38 |
|
|
$computed_elements[] = $element;
|
39 |
|
|
} else {
|
40 |
|
|
$other_elements[] = $element;
|
41 |
|
|
}
|
42 |
|
|
}
|
43 |
|
|
}
|
44 |
|
|
|
45 |
|
|
if(count($computed_elements) > 0) {
|
46 |
|
|
return $computed_elements;
|
47 |
|
|
} else {
|
48 |
|
|
return $other_elements;
|
49 |
|
|
}
|
50 |
ae0a5060
|
Andreas Kohlbecker
|
}
|
51 |
|
|
|
52 |
|
|
/**
|
53 |
|
|
* Merge the fields 'annotations', 'markers', 'sources', 'media' from the source CDM DescriptionElement into the target.
|
54 |
|
|
*
|
55 |
|
|
* @param $target
|
56 |
|
|
* The source CDM DescriptionElement
|
57 |
|
|
* @param $source
|
58 |
|
|
* The target CDM DescriptionElement
|
59 |
|
|
*/
|
60 |
|
|
function cdm_merge_description_elements(&$target, &$source){
|
61 |
|
|
static $fields_to_merge = array('annotations', 'markers', 'sources', 'media');
|
62 |
|
|
|
63 |
|
|
foreach ($fields_to_merge as $field){
|
64 |
|
|
if(is_array($source->$field)) {
|
65 |
|
|
if(!is_array($target->$field)){
|
66 |
|
|
$target->$field = $source->$field;
|
67 |
|
|
} else {
|
68 |
|
|
$target->$field = array_merge($target->$field, $source->$field);
|
69 |
|
|
}
|
70 |
|
|
}
|
71 |
|
|
}
|
72 |
bf97c2e8
|
Andreas Kohlbecker
|
}
|
73 |
|
|
|
74 |
|
|
/**
|
75 |
|
|
* Prepares the items for a table of content list.
|
76 |
|
|
*
|
77 |
|
|
* see also hook_cdm_feature_node_toc_items_alter()
|
78 |
|
|
*
|
79 |
|
|
* @param $feature_nodes
|
80 |
|
|
* An array of CDM FeatureNode instances
|
81 |
|
|
*
|
82 |
|
|
* @return array
|
83 |
|
|
* The items array is an array suitable for theme_item_list().
|
84 |
|
|
*/
|
85 |
|
|
function cdm_feature_node_toc_items($feature_nodes) {
|
86 |
|
|
$items = array();
|
87 |
|
|
|
88 |
|
|
// we better cache here since drupal_get_query_parameters has no internal static cache variable
|
89 |
|
|
$http_request_params = drupal_get_query_parameters();
|
90 |
|
|
|
91 |
|
|
foreach ($feature_nodes as $node) {
|
92 |
|
|
|
93 |
|
|
if (hasFeatureNodeDescriptionElements($node)) {
|
94 |
|
|
|
95 |
|
|
$featureRepresentation = isset($node->feature->representation_L10n) ? $node->feature->representation_L10n : 'Feature';
|
96 |
|
|
//TODO HACK to implement images for taxa, should be removed.
|
97 |
|
|
if ($node->feature->uuid != UUID_IMAGE) {
|
98 |
|
|
$items[] = array(
|
99 |
|
|
l(
|
100 |
|
|
theme('cdm_feature_name', array('feature_name' => $featureRepresentation)),
|
101 |
|
|
$_GET['q'],
|
102 |
|
|
array(
|
103 |
|
|
'attributes' => array('class' => array('toc')),
|
104 |
|
|
'fragment' => generalizeString($featureRepresentation),
|
105 |
|
|
'query' => $http_request_params
|
106 |
|
|
)
|
107 |
|
|
)
|
108 |
|
|
);
|
109 |
|
|
}
|
110 |
|
|
}
|
111 |
|
|
}
|
112 |
|
|
|
113 |
1be93be6
|
Andreas Kohlbecker
|
drupal_alter('cdm_feature_node_toc_items', $items);
|
114 |
bf97c2e8
|
Andreas Kohlbecker
|
|
115 |
|
|
return $items;
|
116 |
aa7c7290
|
Andreas Kohlbecker
|
}
|