1 |
1 |
<?php
|
2 |
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);
|
|
3 |
/**
|
|
4 |
* Returns the localized representations of the modifiers hold by the
|
|
5 |
* supplied cdm instance concatenated into one string.
|
|
6 |
*
|
|
7 |
* @param object $iModifieable
|
|
8 |
* cdm instance of an class implementing the interface IModifieable:
|
|
9 |
* DescriptionElementBase, StateDate, State
|
|
10 |
*
|
|
11 |
* @return String
|
|
12 |
* localized representations of the modifiers hold by the
|
|
13 |
* supplied cdm instance concatenated into one string
|
|
14 |
*/
|
|
15 |
function cdm_modifers_representations($iModifieable, $glue = ', ') {
|
|
16 |
$modifiers_strings = array();
|
|
17 |
if (isset($iModifieable->modifiers)) {
|
|
18 |
foreach ($iModifieable->modifiers as $modifier) {
|
|
19 |
$modifiers_strings[] = cdm_term_representation($modifier);
|
|
20 |
}
|
14 |
21 |
}
|
|
22 |
return implode(', ', $modifiers_strings);
|
15 |
23 |
}
|
16 |
|
return implode(', ', $modifiers_strings);
|
17 |
|
}
|
18 |
24 |
|
19 |
|
/**
|
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 |
|
* @deprecated this is replaced by the cdmlib DistributionUtil class!!!
|
30 |
|
*/
|
31 |
|
function cdm_description_elements_prefer_computed($description_elements){
|
|
25 |
/**
|
|
26 |
* Filters the given set of description elements and prefers
|
|
27 |
* computed elements over others. Computed description elements
|
|
28 |
* are identified by the MarkerType.COMPUTED()
|
|
29 |
*
|
|
30 |
* If the given set contains at least one computed element only
|
|
31 |
* the computed elements are returned.
|
|
32 |
*
|
|
33 |
* @param $description_elements
|
|
34 |
* An array of CDM DescriptionElementBase instances
|
|
35 |
*
|
|
36 |
* @return
|
|
37 |
* only the computed description elements otherwise all others.
|
|
38 |
*
|
|
39 |
* @deprecated this is replaced by the cdmlib DistributionUtil class!!!
|
|
40 |
*/
|
|
41 |
function cdm_description_elements_prefer_computed($description_elements){
|
32 |
42 |
|
33 |
|
$computed_elements = array();
|
34 |
|
$other_elements = array();
|
|
43 |
$computed_elements = array();
|
|
44 |
$other_elements = array();
|
35 |
45 |
|
36 |
|
if(!empty($description_elements)){
|
37 |
|
foreach ($description_elements as $element) {
|
38 |
|
if(cdm_entity_has_marker($element, UUID_MARKERTYPE_COMPUTED)){
|
39 |
|
$computed_elements[] = $element;
|
40 |
|
} else {
|
41 |
|
$other_elements[] = $element;
|
|
46 |
if(!empty($description_elements)){
|
|
47 |
foreach ($description_elements as $element) {
|
|
48 |
if(cdm_entity_has_marker($element, UUID_MARKERTYPE_COMPUTED)){
|
|
49 |
$computed_elements[] = $element;
|
|
50 |
} else {
|
|
51 |
$other_elements[] = $element;
|
|
52 |
}
|
42 |
53 |
}
|
43 |
54 |
}
|
44 |
|
}
|
45 |
55 |
|
46 |
|
if(count($computed_elements) > 0) {
|
47 |
|
return $computed_elements;
|
48 |
|
} else {
|
49 |
|
return $other_elements;
|
|
56 |
if(count($computed_elements) > 0) {
|
|
57 |
return $computed_elements;
|
|
58 |
} else {
|
|
59 |
return $other_elements;
|
|
60 |
}
|
50 |
61 |
}
|
51 |
|
}
|
52 |
62 |
|
53 |
|
function cdm_distribution_filter_query(){
|
54 |
|
$cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
|
55 |
|
$query = array();
|
|
63 |
/**
|
|
64 |
* @return array
|
|
65 |
*/
|
|
66 |
function cdm_distribution_filter_query(){
|
|
67 |
$cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
|
|
68 |
$query = array();
|
56 |
69 |
|
57 |
|
if($cdm_distribution_filter['filter_rules']['statusOrderPreference']){
|
58 |
|
$query['statusOrderPreference'] = 1;
|
59 |
|
}
|
60 |
|
if($cdm_distribution_filter['filter_rules']['subAreaPreference']){
|
61 |
|
$query['subAreaPreference'] = 1;
|
62 |
|
}
|
63 |
|
if(is_array($cdm_distribution_filter['hideMarkedAreas']) && count($cdm_distribution_filter['hideMarkedAreas']) > 0){
|
64 |
|
$query['hideMarkedAreas'] = '';
|
65 |
|
foreach ($cdm_distribution_filter['hideMarkedAreas'] as $marker_type => $enabled)
|
66 |
|
if($enabled){
|
67 |
|
$query['hideMarkedAreas'] .= ($query['hideMarkedAreas'] ? ',' : '') . $marker_type;
|
68 |
|
}
|
|
70 |
if($cdm_distribution_filter['filter_rules']['statusOrderPreference']){
|
|
71 |
$query['statusOrderPreference'] = 1;
|
|
72 |
}
|
|
73 |
if($cdm_distribution_filter['filter_rules']['subAreaPreference']){
|
|
74 |
$query['subAreaPreference'] = 1;
|
|
75 |
}
|
|
76 |
if(is_array($cdm_distribution_filter['hideMarkedAreas']) && count($cdm_distribution_filter['hideMarkedAreas']) > 0){
|
|
77 |
$query['hideMarkedAreas'] = '';
|
|
78 |
foreach ($cdm_distribution_filter['hideMarkedAreas'] as $marker_type => $enabled)
|
|
79 |
if($enabled){
|
|
80 |
$query['hideMarkedAreas'] .= ($query['hideMarkedAreas'] ? ',' : '') . $marker_type;
|
|
81 |
}
|
|
82 |
}
|
|
83 |
|
|
84 |
return $query;
|
69 |
85 |
}
|
70 |
86 |
|
71 |
|
return $query;
|
72 |
|
}
|
|
87 |
/**
|
|
88 |
* Merge the fields 'annotations', 'markers', 'sources', 'media' from the source CDM DescriptionElement into the target.
|
|
89 |
*
|
|
90 |
* @param $target
|
|
91 |
* The source CDM DescriptionElement
|
|
92 |
* @param $source
|
|
93 |
* The target CDM DescriptionElement
|
|
94 |
*/
|
|
95 |
function cdm_merge_description_elements(&$target, &$source){
|
|
96 |
static $fields_to_merge = array('annotations', 'markers', 'sources', 'media');
|
73 |
97 |
|
74 |
|
/**
|
75 |
|
* Merge the fields 'annotations', 'markers', 'sources', 'media' from the source CDM DescriptionElement into the target.
|
76 |
|
*
|
77 |
|
* @param $target
|
78 |
|
* The source CDM DescriptionElement
|
79 |
|
* @param $source
|
80 |
|
* The target CDM DescriptionElement
|
81 |
|
*/
|
82 |
|
function cdm_merge_description_elements(&$target, &$source){
|
83 |
|
static $fields_to_merge = array('annotations', 'markers', 'sources', 'media');
|
84 |
|
|
85 |
|
foreach ($fields_to_merge as $field){
|
86 |
|
if(is_array($source->$field)) {
|
87 |
|
if(!is_array($target->$field)){
|
88 |
|
$target->$field = $source->$field;
|
89 |
|
} else {
|
90 |
|
$target->$field = array_merge($target->$field, $source->$field);
|
|
98 |
foreach ($fields_to_merge as $field){
|
|
99 |
if(is_array($source->$field)) {
|
|
100 |
if(!is_array($target->$field)){
|
|
101 |
$target->$field = $source->$field;
|
|
102 |
} else {
|
|
103 |
$target->$field = array_merge($target->$field, $source->$field);
|
|
104 |
}
|
91 |
105 |
}
|
92 |
106 |
}
|
93 |
107 |
}
|
94 |
|
}
|
95 |
108 |
|
96 |
|
/**
|
97 |
|
* Prepares the items for a table of content list.
|
98 |
|
*
|
99 |
|
* see also hook_cdm_feature_node_toc_items_alter()
|
100 |
|
*
|
101 |
|
* @param $feature_nodes
|
102 |
|
* An array of CDM FeatureNode instances
|
103 |
|
*
|
104 |
|
* @return array
|
105 |
|
* The items array is an array suitable for theme_item_list().
|
106 |
|
*/
|
107 |
|
function cdm_feature_node_toc_items($feature_nodes) {
|
108 |
|
$items = array();
|
109 |
|
|
110 |
|
foreach ($feature_nodes as $node) {
|
111 |
|
|
112 |
|
if (isset($node->descriptionElements['#type']) || has_feature_node_description_elements($node)) {
|
113 |
|
|
114 |
|
$feature_name = isset($node->feature->representation_L10n) ? $node->feature->representation_L10n : 'Feature';
|
115 |
|
$class_attributes = 'feature-toc-item-' . $node->feature->uuid;
|
116 |
|
//TODO HACK to implement images for taxa, should be removed.
|
117 |
|
if ($node->feature->uuid != UUID_IMAGE) {
|
118 |
|
$items[] = toc_list_item(
|
119 |
|
theme(
|
120 |
|
'cdm_feature_name',
|
121 |
|
array('feature_name' => $feature_name))
|
122 |
|
,
|
123 |
|
array('class' => $class_attributes)
|
124 |
|
);
|
125 |
|
}
|
|
109 |
/**
|
|
110 |
* Creates a entry for the table of content items list
|
|
111 |
*
|
|
112 |
* The table of content items are crated internally by calling
|
|
113 |
* toc_list_item() the resulting item is added to the statically cached
|
|
114 |
* list of toc elements
|
|
115 |
*
|
|
116 |
* @param $label
|
|
117 |
* The label of toc entry
|
|
118 |
* @param $class_attribute_suffix
|
|
119 |
* The suffix to be appended to the class attribute prefix: "feature-toc-item-"
|
|
120 |
* @param $fragment
|
|
121 |
* Optional parameter to define a url fragment different from the $label,
|
|
122 |
* if the $fragment is not defined the $label will be used
|
|
123 |
*/
|
|
124 |
function cdm_toc_list_add_item($label, $class_attribute_suffix, $fragment = NULL){
|
|
125 |
$toc_list_items = &cdm_toc_list();
|
|
126 |
|
|
127 |
// TODO normalize $fragment if necesarry, check uri()
|
|
128 |
if(!$fragment){
|
|
129 |
$fragment = $label;
|
126 |
130 |
}
|
|
131 |
|
|
132 |
$class_attributes = 'feature-toc-item-' . $class_attribute_suffix;
|
|
133 |
|
|
134 |
$toc_list_items[] = toc_list_item(
|
|
135 |
theme(
|
|
136 |
'cdm_feature_name',
|
|
137 |
array('feature_name' => $label))
|
|
138 |
,
|
|
139 |
array('class' => $class_attributes),
|
|
140 |
$fragment
|
|
141 |
);
|
|
142 |
|
127 |
143 |
}
|
128 |
144 |
|
129 |
|
drupal_alter('cdm_feature_node_toc_items', $items);
|
|
145 |
/**
|
|
146 |
* Returns the statically cached table of content items as render array
|
|
147 |
*
|
|
148 |
* @see see also cdm_toc_list_add_item()
|
|
149 |
*
|
|
150 |
* @return array
|
|
151 |
* a render array of table of content items suitable for theme_item_list()
|
|
152 |
*/
|
|
153 |
function &cdm_toc_list(){
|
|
154 |
$toc_list_items = &drupal_static('toc_list_items', array());
|
130 |
155 |
|
131 |
|
return $items;
|
132 |
|
}
|
|
156 |
return $toc_list_items;
|
|
157 |
}
|
133 |
158 |
|
134 |
159 |
/**
|
135 |
160 |
* Prepares an empty Drupal block for displaying description elements of a specific CDM Feature.
|
... | ... | |
158 |
183 |
return $block;
|
159 |
184 |
}
|
160 |
185 |
|
161 |
|
/**
|
162 |
|
* Creates a list item for a table of content, suitable as data element for a themed list
|
163 |
|
*
|
164 |
|
* @see theme_list()
|
165 |
|
*
|
166 |
|
* @param $label
|
167 |
|
* @param $http_request_params
|
168 |
|
* @param $attributes
|
169 |
|
* @return array
|
170 |
|
*/
|
171 |
|
function toc_list_item($label, $attributes = array()) {
|
172 |
|
|
173 |
|
// we better cache here since drupal_get_query_parameters has no internal static cache variable
|
174 |
|
$http_request_params = drupal_static('http_request_params', drupal_get_query_parameters());
|
175 |
|
|
176 |
|
$item = array(
|
177 |
|
'data' => l(
|
178 |
|
$label,
|
179 |
|
$_GET['q'],
|
180 |
|
array(
|
181 |
|
'attributes' => array('class' => array('toc')),
|
182 |
|
'fragment' => generalizeString($label),
|
183 |
|
'query' => $http_request_params
|
|
186 |
/**
|
|
187 |
* Creates a list item for a table of content, suitable as data element for a themed list
|
|
188 |
*
|
|
189 |
* @see theme_list()
|
|
190 |
*
|
|
191 |
* @param $label
|
|
192 |
* @param $http_request_params
|
|
193 |
* @param $attributes
|
|
194 |
* @return array
|
|
195 |
*/
|
|
196 |
function toc_list_item($label, $attributes = array(), $fragment = null) {
|
|
197 |
|
|
198 |
// we better cache here since drupal_get_query_parameters has no internal static cache variable
|
|
199 |
$http_request_params = drupal_static('http_request_params', drupal_get_query_parameters());
|
|
200 |
|
|
201 |
$item = array(
|
|
202 |
'data' => l(
|
|
203 |
$label,
|
|
204 |
$_GET['q'],
|
|
205 |
array(
|
|
206 |
'attributes' => array('class' => array('toc')),
|
|
207 |
'fragment' => generalizeString($label),
|
|
208 |
'query' => $http_request_params
|
|
209 |
)
|
184 |
210 |
)
|
185 |
|
)
|
186 |
|
);
|
187 |
|
$item['attributes'] = $attributes;
|
188 |
|
return $item;
|
189 |
|
}
|
|
211 |
);
|
|
212 |
$item['attributes'] = $attributes;
|
|
213 |
return $item;
|
|
214 |
}
|
190 |
215 |
|
191 |
|
/**
|
192 |
|
* Creates the footnotes for the given CDM DescriptionElement instance.
|
193 |
|
*
|
194 |
|
* Footnotes are created for annotatins and original sources.
|
195 |
|
*
|
196 |
|
* @param $descriptionElement
|
197 |
|
* A CDM DescriptionElement instance
|
198 |
|
* @param $separator
|
199 |
|
* Optional parameter. The separator string to concatenate the footnote ids, default is ','
|
200 |
|
* @param $footnote_list_key_suggestion
|
201 |
|
* @return String
|
202 |
|
* The foot note keys
|
203 |
|
*/
|
204 |
|
function cdm_create_description_element_footnotes($description_element, $separator = ',', $footnote_list_key_suggestion = null){
|
205 |
|
|
206 |
|
|
207 |
|
// Annotations as footnotes.
|
208 |
|
$footNoteKeys = cdm_annotations_as_footnotekeys($description_element, $footnote_list_key_suggestion);
|
209 |
|
|
210 |
|
// Source references as footnotes.
|
211 |
|
$bibliography_settings = get_bibliography_settings();
|
212 |
|
$original_source_footnote_tag = $bibliography_settings['enabled'] == 1 ? 'div' : null; // otherwise the default
|
213 |
|
|
214 |
|
foreach ($description_element->sources as $source) {
|
215 |
|
if (_is_original_source_type($source)) {
|
216 |
|
$fn_key = FootnoteManager::addNewFootnote(
|
217 |
|
original_source_footnote_list_key($footnote_list_key_suggestion),
|
218 |
|
theme('cdm_OriginalSource', array(
|
219 |
|
'source' => $source,
|
220 |
|
'doLink' => FALSE,
|
221 |
|
)),
|
222 |
|
$original_source_footnote_tag
|
223 |
|
);
|
224 |
|
// Ensure uniqueness of the footnote keys.
|
225 |
|
cdm_add_footnote_to_array($footNoteKeys, $fn_key);
|
|
216 |
/**
|
|
217 |
* Creates the footnotes for the given CDM DescriptionElement instance.
|
|
218 |
*
|
|
219 |
* Footnotes are created for annotatins and original sources.
|
|
220 |
*
|
|
221 |
* @param $descriptionElement
|
|
222 |
* A CDM DescriptionElement instance
|
|
223 |
* @param $separator
|
|
224 |
* Optional parameter. The separator string to concatenate the footnote ids, default is ','
|
|
225 |
* @param $footnote_list_key_suggestion
|
|
226 |
* @return String
|
|
227 |
* The foot note keys
|
|
228 |
*/
|
|
229 |
function cdm_create_description_element_footnotes($description_element, $separator = ',', $footnote_list_key_suggestion = null){
|
|
230 |
|
|
231 |
|
|
232 |
// Annotations as footnotes.
|
|
233 |
$footNoteKeys = cdm_annotations_as_footnotekeys($description_element, $footnote_list_key_suggestion);
|
|
234 |
|
|
235 |
// Source references as footnotes.
|
|
236 |
$bibliography_settings = get_bibliography_settings();
|
|
237 |
$original_source_footnote_tag = $bibliography_settings['enabled'] == 1 ? 'div' : null; // otherwise the default
|
|
238 |
|
|
239 |
foreach ($description_element->sources as $source) {
|
|
240 |
if (_is_original_source_type($source)) {
|
|
241 |
$fn_key = FootnoteManager::addNewFootnote(
|
|
242 |
original_source_footnote_list_key($footnote_list_key_suggestion),
|
|
243 |
theme('cdm_OriginalSource', array(
|
|
244 |
'source' => $source,
|
|
245 |
'doLink' => FALSE,
|
|
246 |
)),
|
|
247 |
$original_source_footnote_tag
|
|
248 |
);
|
|
249 |
// Ensure uniqueness of the footnote keys.
|
|
250 |
cdm_add_footnote_to_array($footNoteKeys, $fn_key);
|
|
251 |
}
|
226 |
252 |
}
|
|
253 |
// Sort and render footnote keys.
|
|
254 |
$footnoteKeyListStr = '';
|
|
255 |
asort($footNoteKeys);
|
|
256 |
foreach ($footNoteKeys as $footNoteKey) {
|
|
257 |
$footnoteKeyListStr .= theme('cdm_footnote_key',
|
|
258 |
array(
|
|
259 |
'footnoteKey' => $footNoteKey,
|
|
260 |
'separator' => ($footnoteKeyListStr ? $separator : '')));
|
|
261 |
}
|
|
262 |
return $footnoteKeyListStr;
|
227 |
263 |
}
|
228 |
|
// Sort and render footnote keys.
|
229 |
|
$footnoteKeyListStr = '';
|
230 |
|
asort($footNoteKeys);
|
231 |
|
foreach ($footNoteKeys as $footNoteKey) {
|
232 |
|
$footnoteKeyListStr .= theme('cdm_footnote_key',
|
233 |
|
array(
|
234 |
|
'footnoteKey' => $footNoteKey,
|
235 |
|
'separator' => ($footnoteKeyListStr ? $separator : '')));
|
236 |
|
}
|
237 |
|
return $footnoteKeyListStr;
|
238 |
|
}
|
239 |
264 |
|
240 |
|
/**
|
241 |
|
*
|
242 |
|
* @return string the footnote_list_key
|
243 |
|
*/
|
244 |
|
function original_source_footnote_list_key($key_suggestion = null) {
|
245 |
|
if(!$key_suggestion){
|
246 |
|
$key_suggestion = RenderHints::getFootnoteListKey();
|
|
265 |
/**
|
|
266 |
*
|
|
267 |
* @return string the footnote_list_key
|
|
268 |
*/
|
|
269 |
function original_source_footnote_list_key($key_suggestion = null) {
|
|
270 |
if(!$key_suggestion){
|
|
271 |
$key_suggestion = RenderHints::getFootnoteListKey();
|
|
272 |
}
|
|
273 |
$bibliography_settings = get_bibliography_settings();
|
|
274 |
$footnote_list_key = $bibliography_settings['enabled'] == 1 ? 'BIBLIOGRAPHY' : $key_suggestion;
|
|
275 |
return $footnote_list_key;
|
247 |
276 |
}
|
248 |
|
$bibliography_settings = get_bibliography_settings();
|
249 |
|
$footnote_list_key = $bibliography_settings['enabled'] == 1 ? 'BIBLIOGRAPHY' : $key_suggestion;
|
250 |
|
return $footnote_list_key;
|
251 |
|
}
|
252 |
277 |
|
more flexible table of content creation, hook_cdm_feature_node_toc_items_alter() no longer needed