1 |
aa7c7290
|
Andreas Kohlbecker
|
<?php
|
2 |
|
|
|
3 |
dd1c109a
|
Andreas Kohlbecker
|
/**
|
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 |
|
|
}
|
21 |
f19f47fa
|
Andreas Kohlbecker
|
}
|
22 |
dd1c109a
|
Andreas Kohlbecker
|
return implode(', ', $modifiers_strings);
|
23 |
aa7c7290
|
Andreas Kohlbecker
|
}
|
24 |
bf97c2e8
|
Andreas Kohlbecker
|
|
25 |
dd1c109a
|
Andreas Kohlbecker
|
/**
|
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){
|
42 |
19e097a3
|
Andreas Kohlbecker
|
|
43 |
dd1c109a
|
Andreas Kohlbecker
|
$computed_elements = array();
|
44 |
|
|
$other_elements = array();
|
45 |
19e097a3
|
Andreas Kohlbecker
|
|
46 |
dd1c109a
|
Andreas Kohlbecker
|
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 |
|
|
}
|
53 |
19e097a3
|
Andreas Kohlbecker
|
}
|
54 |
|
|
}
|
55 |
|
|
|
56 |
dd1c109a
|
Andreas Kohlbecker
|
if(count($computed_elements) > 0) {
|
57 |
|
|
return $computed_elements;
|
58 |
|
|
} else {
|
59 |
|
|
return $other_elements;
|
60 |
|
|
}
|
61 |
19e097a3
|
Andreas Kohlbecker
|
}
|
62 |
ae0a5060
|
Andreas Kohlbecker
|
|
63 |
dd1c109a
|
Andreas Kohlbecker
|
/**
|
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();
|
69 |
aa63dfb4
|
Andreas Kohlbecker
|
|
70 |
dd1c109a
|
Andreas Kohlbecker
|
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;
|
85 |
aa63dfb4
|
Andreas Kohlbecker
|
}
|
86 |
|
|
|
87 |
dd1c109a
|
Andreas Kohlbecker
|
/**
|
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');
|
97 |
aa63dfb4
|
Andreas Kohlbecker
|
|
98 |
dd1c109a
|
Andreas Kohlbecker
|
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 |
|
|
}
|
105 |
ae0a5060
|
Andreas Kohlbecker
|
}
|
106 |
|
|
}
|
107 |
|
|
}
|
108 |
bf97c2e8
|
Andreas Kohlbecker
|
|
109 |
dd1c109a
|
Andreas Kohlbecker
|
/**
|
110 |
9aff46e4
|
Andreas Kohlbecker
|
* Adds an entry to the end of the table of content items list
|
111 |
dd1c109a
|
Andreas Kohlbecker
|
*
|
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 |
9aff46e4
|
Andreas Kohlbecker
|
function cdm_toc_list_add_item($label, $class_attribute_suffix, $fragment = NULL, $as_first_element = FALSE){
|
125 |
dd1c109a
|
Andreas Kohlbecker
|
$toc_list_items = &cdm_toc_list();
|
126 |
|
|
|
127 |
|
|
if(!$fragment){
|
128 |
|
|
$fragment = $label;
|
129 |
bf97c2e8
|
Andreas Kohlbecker
|
}
|
130 |
9aff46e4
|
Andreas Kohlbecker
|
$fragment = generalizeString($fragment);
|
131 |
dd1c109a
|
Andreas Kohlbecker
|
|
132 |
|
|
$class_attributes = 'feature-toc-item-' . $class_attribute_suffix;
|
133 |
|
|
|
134 |
9aff46e4
|
Andreas Kohlbecker
|
$new_item = toc_list_item(
|
135 |
dd1c109a
|
Andreas Kohlbecker
|
theme(
|
136 |
|
|
'cdm_feature_name',
|
137 |
|
|
array('feature_name' => $label))
|
138 |
|
|
,
|
139 |
|
|
array('class' => $class_attributes),
|
140 |
|
|
$fragment
|
141 |
|
|
);
|
142 |
|
|
|
143 |
9aff46e4
|
Andreas Kohlbecker
|
if($as_first_element){
|
144 |
|
|
array_unshift($toc_list_items, $new_item);
|
145 |
|
|
} else {
|
146 |
|
|
$toc_list_items[] = $new_item;
|
147 |
|
|
}
|
148 |
|
|
|
149 |
bf97c2e8
|
Andreas Kohlbecker
|
}
|
150 |
|
|
|
151 |
dd1c109a
|
Andreas Kohlbecker
|
/**
|
152 |
|
|
* Returns the statically cached table of content items as render array
|
153 |
|
|
*
|
154 |
|
|
* @see see also cdm_toc_list_add_item()
|
155 |
|
|
*
|
156 |
|
|
* @return array
|
157 |
|
|
* a render array of table of content items suitable for theme_item_list()
|
158 |
|
|
*/
|
159 |
|
|
function &cdm_toc_list(){
|
160 |
|
|
$toc_list_items = &drupal_static('toc_list_items', array());
|
161 |
bf97c2e8
|
Andreas Kohlbecker
|
|
162 |
dd1c109a
|
Andreas Kohlbecker
|
return $toc_list_items;
|
163 |
|
|
}
|
164 |
1f11e206
|
Andreas Kohlbecker
|
|
165 |
f19f47fa
|
Andreas Kohlbecker
|
/**
|
166 |
|
|
* Prepares an empty Drupal block for displaying description elements of a specific CDM Feature.
|
167 |
|
|
*
|
168 |
|
|
* The block can also be used for pseudo Features like a bibliography. Pseudo features are
|
169 |
|
|
* derived from other data on the fly and so not exist as such in the cdm data. In case
|
170 |
|
|
* of pseudo features the $feature is left empty
|
171 |
|
|
*
|
172 |
|
|
* @param $feature_name
|
173 |
|
|
* A label describing the feature, usually the localized feature representation.
|
174 |
|
|
* @param $feature
|
175 |
|
|
* The CDM Feature for which the block is created. (optional)
|
176 |
|
|
* @return object
|
177 |
|
|
* A Drupal block object
|
178 |
|
|
*/
|
179 |
|
|
function feature_block($feature_name, $feature = null) {
|
180 |
|
|
$block = new stdclass(); // Empty object.
|
181 |
|
|
$block->module = 'cdm_dataportal';
|
182 |
|
|
$block->delta = generalizeString($feature_name);
|
183 |
|
|
$block->region = null;
|
184 |
|
|
$block->subject = '<a name="' . $block->delta . '"></a><span class="' . html_class_attribute_ref($feature) . '">'
|
185 |
|
|
. theme('cdm_feature_name', array('feature_name' => $feature_name))
|
186 |
|
|
. '</span>';
|
187 |
|
|
$block->module = "cdm_dataportal-feature";
|
188 |
|
|
$block->content = '';
|
189 |
|
|
return $block;
|
190 |
|
|
}
|
191 |
|
|
|
192 |
dd1c109a
|
Andreas Kohlbecker
|
/**
|
193 |
|
|
* Creates a list item for a table of content, suitable as data element for a themed list
|
194 |
|
|
*
|
195 |
|
|
* @see theme_list()
|
196 |
|
|
*
|
197 |
|
|
* @param $label
|
198 |
|
|
* @param $http_request_params
|
199 |
|
|
* @param $attributes
|
200 |
|
|
* @return array
|
201 |
|
|
*/
|
202 |
|
|
function toc_list_item($label, $attributes = array(), $fragment = null) {
|
203 |
|
|
|
204 |
|
|
// we better cache here since drupal_get_query_parameters has no internal static cache variable
|
205 |
|
|
$http_request_params = drupal_static('http_request_params', drupal_get_query_parameters());
|
206 |
|
|
|
207 |
|
|
$item = array(
|
208 |
|
|
'data' => l(
|
209 |
|
|
$label,
|
210 |
|
|
$_GET['q'],
|
211 |
|
|
array(
|
212 |
|
|
'attributes' => array('class' => array('toc')),
|
213 |
|
|
'fragment' => generalizeString($label),
|
214 |
|
|
'query' => $http_request_params
|
215 |
|
|
)
|
216 |
f19f47fa
|
Andreas Kohlbecker
|
)
|
217 |
dd1c109a
|
Andreas Kohlbecker
|
);
|
218 |
|
|
$item['attributes'] = $attributes;
|
219 |
|
|
return $item;
|
220 |
|
|
}
|
221 |
f19f47fa
|
Andreas Kohlbecker
|
|
222 |
dd1c109a
|
Andreas Kohlbecker
|
/**
|
223 |
|
|
* Creates the footnotes for the given CDM DescriptionElement instance.
|
224 |
|
|
*
|
225 |
44d445c0
|
Andreas Kohlbecker
|
* Footnotes are created for annotations and original sources,
|
226 |
|
|
* optionally the sources are put into a separate bibliography.
|
227 |
dd1c109a
|
Andreas Kohlbecker
|
*
|
228 |
|
|
* @param $descriptionElement
|
229 |
|
|
* A CDM DescriptionElement instance
|
230 |
|
|
* @param $separator
|
231 |
|
|
* Optional parameter. The separator string to concatenate the footnote ids, default is ','
|
232 |
|
|
* @param $footnote_list_key_suggestion
|
233 |
44d445c0
|
Andreas Kohlbecker
|
*
|
234 |
dd1c109a
|
Andreas Kohlbecker
|
* @return String
|
235 |
|
|
* The foot note keys
|
236 |
|
|
*/
|
237 |
|
|
function cdm_create_description_element_footnotes($description_element, $separator = ',', $footnote_list_key_suggestion = null){
|
238 |
|
|
|
239 |
|
|
|
240 |
|
|
// Annotations as footnotes.
|
241 |
|
|
$footNoteKeys = cdm_annotations_as_footnotekeys($description_element, $footnote_list_key_suggestion);
|
242 |
|
|
|
243 |
|
|
// Source references as footnotes.
|
244 |
|
|
$bibliography_settings = get_bibliography_settings();
|
245 |
|
|
$original_source_footnote_tag = $bibliography_settings['enabled'] == 1 ? 'div' : null; // otherwise the default
|
246 |
|
|
|
247 |
|
|
foreach ($description_element->sources as $source) {
|
248 |
|
|
if (_is_original_source_type($source)) {
|
249 |
|
|
$fn_key = FootnoteManager::addNewFootnote(
|
250 |
|
|
original_source_footnote_list_key($footnote_list_key_suggestion),
|
251 |
|
|
theme('cdm_OriginalSource', array(
|
252 |
|
|
'source' => $source,
|
253 |
|
|
'doLink' => FALSE,
|
254 |
|
|
)),
|
255 |
|
|
$original_source_footnote_tag
|
256 |
|
|
);
|
257 |
|
|
// Ensure uniqueness of the footnote keys.
|
258 |
|
|
cdm_add_footnote_to_array($footNoteKeys, $fn_key);
|
259 |
|
|
}
|
260 |
1f11e206
|
Andreas Kohlbecker
|
}
|
261 |
dd1c109a
|
Andreas Kohlbecker
|
// Sort and render footnote keys.
|
262 |
|
|
$footnoteKeyListStr = '';
|
263 |
|
|
asort($footNoteKeys);
|
264 |
|
|
foreach ($footNoteKeys as $footNoteKey) {
|
265 |
|
|
$footnoteKeyListStr .= theme('cdm_footnote_key',
|
266 |
|
|
array(
|
267 |
|
|
'footnoteKey' => $footNoteKey,
|
268 |
|
|
'separator' => ($footnoteKeyListStr ? $separator : '')));
|
269 |
|
|
}
|
270 |
|
|
return $footnoteKeyListStr;
|
271 |
1f11e206
|
Andreas Kohlbecker
|
}
|
272 |
aa63dfb4
|
Andreas Kohlbecker
|
|
273 |
dd1c109a
|
Andreas Kohlbecker
|
/**
|
274 |
|
|
*
|
275 |
|
|
* @return string the footnote_list_key
|
276 |
|
|
*/
|
277 |
|
|
function original_source_footnote_list_key($key_suggestion = null) {
|
278 |
|
|
if(!$key_suggestion){
|
279 |
|
|
$key_suggestion = RenderHints::getFootnoteListKey();
|
280 |
|
|
}
|
281 |
|
|
$bibliography_settings = get_bibliography_settings();
|
282 |
|
|
$footnote_list_key = $bibliography_settings['enabled'] == 1 ? 'BIBLIOGRAPHY' : $key_suggestion;
|
283 |
|
|
return $footnote_list_key;
|
284 |
f19f47fa
|
Andreas Kohlbecker
|
}
|