1
|
<?php
|
2
|
|
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
|
}
|
21
|
}
|
22
|
return implode(', ', $modifiers_strings);
|
23
|
}
|
24
|
|
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){
|
42
|
|
43
|
$computed_elements = array();
|
44
|
$other_elements = array();
|
45
|
|
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
|
}
|
53
|
}
|
54
|
}
|
55
|
|
56
|
if(count($computed_elements) > 0) {
|
57
|
return $computed_elements;
|
58
|
} else {
|
59
|
return $other_elements;
|
60
|
}
|
61
|
}
|
62
|
|
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();
|
69
|
|
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;
|
85
|
}
|
86
|
|
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');
|
97
|
|
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
|
}
|
105
|
}
|
106
|
}
|
107
|
}
|
108
|
|
109
|
/**
|
110
|
* Adds an entry to the end of 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, $as_first_element = FALSE){
|
125
|
$toc_list_items = &cdm_toc_list();
|
126
|
|
127
|
if(!$fragment){
|
128
|
$fragment = $label;
|
129
|
}
|
130
|
$fragment = generalizeString($fragment);
|
131
|
|
132
|
$class_attributes = 'feature-toc-item-' . $class_attribute_suffix;
|
133
|
|
134
|
$new_item = toc_list_item(
|
135
|
theme(
|
136
|
'cdm_feature_name',
|
137
|
array('feature_name' => $label))
|
138
|
,
|
139
|
array('class' => $class_attributes),
|
140
|
$fragment
|
141
|
);
|
142
|
|
143
|
if($as_first_element){
|
144
|
array_unshift($toc_list_items, $new_item);
|
145
|
} else {
|
146
|
$toc_list_items[] = $new_item;
|
147
|
}
|
148
|
|
149
|
}
|
150
|
|
151
|
/**
|
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
|
|
162
|
return $toc_list_items;
|
163
|
}
|
164
|
|
165
|
/**
|
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
|
/**
|
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
|
)
|
217
|
);
|
218
|
$item['attributes'] = $attributes;
|
219
|
return $item;
|
220
|
}
|
221
|
|
222
|
/**
|
223
|
* Creates the footnotes for the given CDM DescriptionElement instance.
|
224
|
*
|
225
|
* Footnotes are created for annotatins and original sources.
|
226
|
*
|
227
|
* @param $descriptionElement
|
228
|
* A CDM DescriptionElement instance
|
229
|
* @param $separator
|
230
|
* Optional parameter. The separator string to concatenate the footnote ids, default is ','
|
231
|
* @param $footnote_list_key_suggestion
|
232
|
* @return String
|
233
|
* The foot note keys
|
234
|
*/
|
235
|
function cdm_create_description_element_footnotes($description_element, $separator = ',', $footnote_list_key_suggestion = null){
|
236
|
|
237
|
|
238
|
// Annotations as footnotes.
|
239
|
$footNoteKeys = cdm_annotations_as_footnotekeys($description_element, $footnote_list_key_suggestion);
|
240
|
|
241
|
// Source references as footnotes.
|
242
|
$bibliography_settings = get_bibliography_settings();
|
243
|
$original_source_footnote_tag = $bibliography_settings['enabled'] == 1 ? 'div' : null; // otherwise the default
|
244
|
|
245
|
foreach ($description_element->sources as $source) {
|
246
|
if (_is_original_source_type($source)) {
|
247
|
$fn_key = FootnoteManager::addNewFootnote(
|
248
|
original_source_footnote_list_key($footnote_list_key_suggestion),
|
249
|
theme('cdm_OriginalSource', array(
|
250
|
'source' => $source,
|
251
|
'doLink' => FALSE,
|
252
|
)),
|
253
|
$original_source_footnote_tag
|
254
|
);
|
255
|
// Ensure uniqueness of the footnote keys.
|
256
|
cdm_add_footnote_to_array($footNoteKeys, $fn_key);
|
257
|
}
|
258
|
}
|
259
|
// Sort and render footnote keys.
|
260
|
$footnoteKeyListStr = '';
|
261
|
asort($footNoteKeys);
|
262
|
foreach ($footNoteKeys as $footNoteKey) {
|
263
|
$footnoteKeyListStr .= theme('cdm_footnote_key',
|
264
|
array(
|
265
|
'footnoteKey' => $footNoteKey,
|
266
|
'separator' => ($footnoteKeyListStr ? $separator : '')));
|
267
|
}
|
268
|
return $footnoteKeyListStr;
|
269
|
}
|
270
|
|
271
|
/**
|
272
|
*
|
273
|
* @return string the footnote_list_key
|
274
|
*/
|
275
|
function original_source_footnote_list_key($key_suggestion = null) {
|
276
|
if(!$key_suggestion){
|
277
|
$key_suggestion = RenderHints::getFootnoteListKey();
|
278
|
}
|
279
|
$bibliography_settings = get_bibliography_settings();
|
280
|
$footnote_list_key = $bibliography_settings['enabled'] == 1 ? 'BIBLIOGRAPHY' : $key_suggestion;
|
281
|
return $footnote_list_key;
|
282
|
}
|
283
|
|