1 |
1d32c863
|
Alexander Oppermann
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Allows to export classifications into a flat csv file.
|
6 |
|
|
*
|
7 |
|
|
* @copyright
|
8 |
|
|
* (C) 2007-2012 EDIT
|
9 |
|
|
* European Distributed Institute of Taxonomy
|
10 |
|
|
* http://www.e-taxonomy.eu
|
11 |
|
|
*
|
12 |
|
|
* The contents of this module are subject to the Mozilla
|
13 |
|
|
* Public License Version 1.1.
|
14 |
|
|
* @see http://www.mozilla.org/MPL/MPL-1.1.html
|
15 |
|
|
*
|
16 |
|
|
* @author
|
17 |
|
|
* Oppermann, Alexander <a.oppermann@BGBM.org>
|
18 |
|
|
*
|
19 |
|
|
*/
|
20 |
|
|
|
21 |
eaf50304
|
Alexander Oppermann
|
define('CDM_WS_TERM', 'term/$0');
|
22 |
|
|
define('CDM_CSV_FEATURETREE_UUID', 'cdm_csv_featuretree_uuid');
|
23 |
|
|
|
24 |
|
|
|
25 |
|
|
|
26 |
1d32c863
|
Alexander Oppermann
|
/**
|
27 |
|
|
*
|
28 |
|
|
* @param unknown $path
|
29 |
|
|
* Which path of the site we're using to display help
|
30 |
|
|
* @param unknown $arg
|
31 |
|
|
* Array that holds the current path as returned from arg() function
|
32 |
|
|
* @return string
|
33 |
|
|
*/
|
34 |
|
|
function cdm_csv_export_help($path, $arg){
|
35 |
|
|
|
36 |
|
|
switch ($path) {
|
37 |
|
|
case "admin/help#cdm_csv_export":
|
38 |
|
|
return '<h1>'.t('CDM CSV Export Help'). '</h1>'. '<p>' . t("In order
|
39 |
|
|
to export the data with special export options, it is essential
|
40 |
|
|
to configure a feature tree with the desired features. Then set
|
41 |
|
|
this feature tree as the default feature tree for this portal."
|
42 |
|
|
) . '</p>';
|
43 |
|
|
break;
|
44 |
|
|
}
|
45 |
|
|
}
|
46 |
|
|
|
47 |
|
|
/**
|
48 |
|
|
* Implements hook_block_info()
|
49 |
|
|
*
|
50 |
|
|
* Prepares the content for the help menu
|
51 |
|
|
*
|
52 |
cdafd99f
|
Alexander Oppermann
|
* @return array
|
53 |
1d32c863
|
Alexander Oppermann
|
*/
|
54 |
|
|
function cdm_csv_export_block_info() {
|
55 |
|
|
$blocks['cdm_csv_export'] = array(
|
56 |
|
|
'info' => t('CDM CSV Export Module'), //The name that will appear in the block list.
|
57 |
|
|
'cache' => DRUPAL_CACHE_PER_ROLE, //Default
|
58 |
|
|
);
|
59 |
|
|
return $blocks;
|
60 |
|
|
}
|
61 |
|
|
|
62 |
|
|
/**
|
63 |
|
|
* Implements hook_block_view().
|
64 |
|
|
*
|
65 |
|
|
* Prepares the contents of the block.
|
66 |
|
|
*
|
67 |
|
|
* @param string $delta
|
68 |
cdafd99f
|
Alexander Oppermann
|
* @return array
|
69 |
1d32c863
|
Alexander Oppermann
|
*/
|
70 |
|
|
function cdm_csv_export_block_view($delta='') {
|
71 |
|
|
$block['subject'] = t('Export into CSV');
|
72 |
|
|
$block['content']= array(
|
73 |
|
|
drupal_get_form('cdm_csv_export_my_form'),
|
74 |
|
|
);
|
75 |
|
|
return $block;
|
76 |
|
|
}
|
77 |
|
|
|
78 |
|
|
/**
|
79 |
|
|
* Creates the drupal form and returns it
|
80 |
|
|
*
|
81 |
|
|
* @param unknown $form_state
|
82 |
cdafd99f
|
Alexander Oppermann
|
* @return array
|
83 |
|
|
*
|
84 |
1d32c863
|
Alexander Oppermann
|
*/
|
85 |
|
|
function cdm_csv_export_my_form($form_state) {
|
86 |
|
|
$form['combobox'] = array(
|
87 |
|
|
'#type' => 'select',
|
88 |
|
|
'#title' => t('Classification').':',
|
89 |
|
|
'#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
|
90 |
|
|
'#options' => cdm_get_taxontrees_as_options(),
|
91 |
b080c651
|
Alexander Oppermann
|
'#attributes' => array(
|
92 |
|
|
'name' => 'classification',
|
93 |
|
|
'onchange' => 'return validateForm()'),
|
94 |
1d32c863
|
Alexander Oppermann
|
);
|
95 |
|
|
|
96 |
14a85a42
|
Alexander Oppermann
|
$form['redListField'] = array(
|
97 |
|
|
'#type' => 'fieldset',
|
98 |
|
|
'#title' =>t('Redlist Attributes'),
|
99 |
|
|
'#collapsible' => TRUE,
|
100 |
|
|
'#collapsed' => TRUE,
|
101 |
|
|
);
|
102 |
|
|
|
103 |
|
|
$form['redListField']['csvExportOptions'] = array(
|
104 |
1d32c863
|
Alexander Oppermann
|
'#type'=>'checkboxes',
|
105 |
|
|
'#options' => array(),
|
106 |
|
|
);
|
107 |
|
|
|
108 |
|
|
// ---- LAYOUT PER FEATURE ---- //
|
109 |
eaf50304
|
Alexander Oppermann
|
$feature_tree = get_csv_featureTree();
|
110 |
1d32c863
|
Alexander Oppermann
|
if (isset($feature_tree->root->children)) {
|
111 |
|
|
foreach ($feature_tree->root->children as $featureNode) {
|
112 |
|
|
if (isset($featureNode->feature)) {
|
113 |
|
|
|
114 |
|
|
// Must not exceed 45 characters !!!
|
115 |
|
|
$subform_id = $featureNode->feature->uuid; //LAYOUT_SETTING_PREFIX .
|
116 |
|
|
$settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
|
117 |
|
|
$systemDefaults = unserialize(FEATURE_TREE_LAYOUT_DEFAULTS);
|
118 |
14a85a42
|
Alexander Oppermann
|
$form['redListField']['csvExportOptions'][$subform_id] = array(
|
119 |
1d32c863
|
Alexander Oppermann
|
'#type' => 'checkbox',
|
120 |
|
|
'#title' => $featureNode->feature->representation_L10n,
|
121 |
|
|
'#default_value' => $featureNode->feature->uuid,//$settings,
|
122 |
|
|
'#attributes' => array('value' => $featureNode->feature->uuid,
|
123 |
|
|
'name' => 'features'
|
124 |
|
|
),
|
125 |
|
|
);
|
126 |
|
|
}
|
127 |
|
|
}
|
128 |
|
|
}
|
129 |
cdafd99f
|
Alexander Oppermann
|
|
130 |
1d32c863
|
Alexander Oppermann
|
$form['downloadTokenValueId'] = array(
|
131 |
|
|
'#type' => 'hidden',
|
132 |
|
|
'#attributes' => array('name' => 'downloadTokenValueId',
|
133 |
|
|
'id' => 'downloadTokenValueId',
|
134 |
|
|
),
|
135 |
|
|
);
|
136 |
b080c651
|
Alexander Oppermann
|
|
137 |
|
|
$form['dialogMessage'] = array(
|
138 |
|
|
'#type' => 'hidden',
|
139 |
|
|
'#attributes' => array(
|
140 |
|
|
'name' => 'dialogMessage',
|
141 |
|
|
'id' => 'dialogMessage',
|
142 |
|
|
),
|
143 |
|
|
);
|
144 |
|
|
|
145 |
13d33727
|
Alexander Oppermann
|
$country = variable_get('area_filter_country');
|
146 |
|
|
$state = variable_get('area_filter_state');
|
147 |
|
|
if($country != null || $state != null){
|
148 |
14a85a42
|
Alexander Oppermann
|
$form['regionFilter'] = array(
|
149 |
|
|
'#type' => 'fieldset',
|
150 |
|
|
'#title' => t('Geographical filter'),
|
151 |
|
|
'#collapsible' => TRUE,
|
152 |
|
|
'#collapsed' => TRUE,
|
153 |
13d33727
|
Alexander Oppermann
|
);
|
154 |
|
|
}
|
155 |
14a85a42
|
Alexander Oppermann
|
|
156 |
13d33727
|
Alexander Oppermann
|
$term = cdm_ws_get(CDM_WS_TERM, $country);
|
157 |
606e1f53
|
Alexander Oppermann
|
$cdmRepresentationTitleCache = cdm_term_representation($term);
|
158 |
13d33727
|
Alexander Oppermann
|
if($country != null){
|
159 |
14a85a42
|
Alexander Oppermann
|
$form['regionFilter']['country'] = array (
|
160 |
|
|
'#type' => 'checkbox',
|
161 |
606e1f53
|
Alexander Oppermann
|
'#title' => t($cdmRepresentationTitleCache),
|
162 |
14a85a42
|
Alexander Oppermann
|
'#attributes' => array('name' => 'area',
|
163 |
|
|
'id' => 'checkall',
|
164 |
13d33727
|
Alexander Oppermann
|
'value' => $country
|
165 |
14a85a42
|
Alexander Oppermann
|
),
|
166 |
|
|
);
|
167 |
13d33727
|
Alexander Oppermann
|
}
|
168 |
14a85a42
|
Alexander Oppermann
|
|
169 |
|
|
//GermanFederalStates
|
170 |
13d33727
|
Alexander Oppermann
|
if($state != null){
|
171 |
|
|
$nameRelationshipTypeOptions = cdm_Vocabulary_as_option($state);
|
172 |
b71ad648
|
Alexander Oppermann
|
asort($nameRelationshipTypeOptions);
|
173 |
14a85a42
|
Alexander Oppermann
|
$form['regionFilter']['area'] = array(
|
174 |
|
|
'#type' => 'checkboxes',
|
175 |
|
|
'#description' =>t('Select an area to filter the list of taxa'),
|
176 |
|
|
'#options' => $nameRelationshipTypeOptions,
|
177 |
|
|
'#attributes' => array('name' => 'area',
|
178 |
|
|
'id' => 'area',
|
179 |
|
|
),
|
180 |
|
|
);
|
181 |
13d33727
|
Alexander Oppermann
|
}
|
182 |
14a85a42
|
Alexander Oppermann
|
|
183 |
1d32c863
|
Alexander Oppermann
|
$form['button'] = array(
|
184 |
|
|
'#type' => 'submit',
|
185 |
|
|
'#value' => 'Export',
|
186 |
|
|
);
|
187 |
|
|
|
188 |
14a85a42
|
Alexander Oppermann
|
$form['#action'] = url(variable_get('cdm_csv_export_webservice_url'));
|
189 |
b080c651
|
Alexander Oppermann
|
$form['#attributes'] = array(
|
190 |
|
|
'name' => 'exportForm',
|
191 |
|
|
'onsubmit' => 'return blockUIForDownload()');
|
192 |
13d33727
|
Alexander Oppermann
|
return $form;
|
193 |
1d32c863
|
Alexander Oppermann
|
}
|
194 |
14a85a42
|
Alexander Oppermann
|
|
195 |
|
|
|
196 |
|
|
|
197 |
|
|
/**
|
198 |
|
|
* Implements Admin configuration hook_menu().
|
199 |
cdafd99f
|
Alexander Oppermann
|
*
|
200 |
|
|
* @return array
|
201 |
14a85a42
|
Alexander Oppermann
|
*/
|
202 |
cdafd99f
|
Alexander Oppermann
|
|
203 |
14a85a42
|
Alexander Oppermann
|
function cdm_csv_export_menu() {
|
204 |
|
|
$items = array();
|
205 |
|
|
|
206 |
|
|
$items['admin/config/cdm_dataportal/csvexport'] = array(
|
207 |
|
|
'title' => 'CDM CSV Export',
|
208 |
|
|
'description' => 'Settings of CSV Export module.',
|
209 |
|
|
'page callback' => 'drupal_get_form',
|
210 |
|
|
'page arguments' => array('cdm_csv_export_admin'),
|
211 |
|
|
'access arguments' => array('access administration pages'),
|
212 |
|
|
'type' => MENU_NORMAL_ITEM,
|
213 |
|
|
);
|
214 |
|
|
return $items;
|
215 |
|
|
}
|
216 |
|
|
|
217 |
|
|
/**
|
218 |
eaf50304
|
Alexander Oppermann
|
* Generates the HTML form for the CSV Export Settings.
|
219 |
cdafd99f
|
Alexander Oppermann
|
*
|
220 |
|
|
* @return array
|
221 |
14a85a42
|
Alexander Oppermann
|
*/
|
222 |
|
|
function cdm_csv_export_admin() {
|
223 |
|
|
|
224 |
|
|
$form['cdm_csv_export_webservice'] = array(
|
225 |
|
|
'#type' => 'fieldset',
|
226 |
|
|
'#title' => t('CDM CSV Export web service'),
|
227 |
|
|
'#collapsible' => TRUE,
|
228 |
|
|
'#collapsed' => FALSE,
|
229 |
|
|
'#description' => t('<em>CDM Server</em> makes the dialogue possible with
|
230 |
|
|
<em>CDM Data Portal</em> thanks to its web services.'),
|
231 |
|
|
);
|
232 |
|
|
|
233 |
|
|
$form['cdm_csv_export_webservice']['cdm_csv_export_webservice_url'] = array(
|
234 |
|
|
'#type' => 'textfield',
|
235 |
|
|
'#title' => t('CSV Export web service URL') . ':',
|
236 |
|
|
'#description' => t('This is the URL to the CDM-Server webservice exposing its controller
|
237 |
|
|
e.g. <em>"http://localhost:8080/csv/exportRedlist"</em>'),
|
238 |
|
|
'#default_value' => variable_get('cdm_csv_export_webservice_url', NULL),
|
239 |
|
|
);
|
240 |
|
|
|
241 |
|
|
// ---- Regional Filter ---- //
|
242 |
|
|
$form['csv_export_area_filter'] = array(
|
243 |
|
|
'#type' => 'fieldset',
|
244 |
|
|
'#title' => t('CDM CSV Export Area Filter'),
|
245 |
|
|
'#collapsible' => TRUE,
|
246 |
|
|
'#collapsed' => FALSE,
|
247 |
|
|
'#description' => t('The <em>Area Filter</em> can be freely configured to the need
|
248 |
|
|
of the specific <em>CDM Data Portal</em> and its catchment area. Right now it will
|
249 |
|
|
be only distinguished between two levels. If necessary it can be programmatically
|
250 |
|
|
extended for a third level e.g. "continent level".'),
|
251 |
|
|
);
|
252 |
|
|
|
253 |
|
|
$form['csv_export_area_filter']['area_filter_country'] = array(
|
254 |
|
|
'#type' => 'textfield',
|
255 |
|
|
'#title' => t('Country Level') . ':',
|
256 |
|
|
'#description' => t('This is the UUID for the country level, in order to be able to filter Germany,
|
257 |
|
|
you should paste e.g. <em>"7b7c2db5-aa44-4302-bdec-6556fd74b0b9"</em> in the above text field'),
|
258 |
|
|
'#default_value' => variable_get('area_filter_country', NULL),
|
259 |
|
|
);
|
260 |
|
|
|
261 |
|
|
$form['csv_export_area_filter']['area_filter_state'] = array(
|
262 |
|
|
'#type' => 'textfield',
|
263 |
|
|
'#title' => t('State Level') . ':',
|
264 |
|
|
'#description' => t('This is the UUID for the state level, in order to be able to filter the german federal states,
|
265 |
|
|
you should paste e.g. <em>"44a448f9-f4ca-49f6-b58c-d27d8a69efdb"</em> in the above text field'),
|
266 |
|
|
'#default_value' => variable_get('area_filter_state', NULL),
|
267 |
|
|
);
|
268 |
|
|
|
269 |
|
|
// ---- FEATURE TREE ---- //
|
270 |
eaf50304
|
Alexander Oppermann
|
$form['feature_trees'] = array(
|
271 |
14a85a42
|
Alexander Oppermann
|
'#type' => 'fieldset',
|
272 |
|
|
'#title' => t('Features'),
|
273 |
|
|
'#collapsible' => TRUE,
|
274 |
|
|
'#collapsed' => FALSE,
|
275 |
|
|
'#description' => t("This section covers settings related to the taxon's
|
276 |
|
|
<em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
|
277 |
|
|
features such as description, distribution, common names, etc. that Drupal
|
278 |
|
|
will render at the taxon profile page."),
|
279 |
|
|
);
|
280 |
|
|
|
281 |
589a392b
|
Alexander Oppermann
|
$featureTrees = cdm_get_featureTrees_as_options(TRUE);
|
282 |
eaf50304
|
Alexander Oppermann
|
$form['feature_trees'][CDM_CSV_FEATURETREE_UUID] = array(
|
283 |
589a392b
|
Alexander Oppermann
|
'#type' => 'radios',
|
284 |
|
|
'#title' => t('CSV Export Feature Tree sections') . ':',
|
285 |
|
|
'#default_value' => variable_get(CDM_CSV_FEATURETREE_UUID, NULL),
|
286 |
|
|
'#options' => $featureTrees['options'],
|
287 |
|
|
'#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
|
288 |
|
|
'#options_suffixes' => $featureTrees['treeRepresentations'],
|
289 |
|
|
'#description' => t('Select the Feature Tree to be displayed at the taxon
|
290 |
|
|
profile. Click "Show Details" to see the Feature Tree elements.'
|
291 |
|
|
),
|
292 |
14a85a42
|
Alexander Oppermann
|
);
|
293 |
|
|
return system_settings_form($form);
|
294 |
|
|
}
|
295 |
eaf50304
|
Alexander Oppermann
|
|
296 |
|
|
/**
|
297 |
|
|
* Returns the chosen FeatureTree for the CSV Export Module.
|
298 |
|
|
*
|
299 |
|
|
* The returned CSV FeatureTree, has been set in the
|
300 |
|
|
* CSV Export Module settings (CDM CSV EXPORT -> FEATURES).
|
301 |
|
|
* If the chosen FeatureTree is not found in the database,
|
302 |
|
|
* the standard feature tree (UUID_DEFAULT_FEATURETREE) will be returned.
|
303 |
|
|
*
|
304 |
|
|
* @return mixed
|
305 |
|
|
* A cdm FeatureTree object.
|
306 |
|
|
*/
|
307 |
|
|
|
308 |
|
|
function get_csv_featureTree() {
|
309 |
|
|
static $csv_featureTree;
|
310 |
|
|
|
311 |
|
|
if($csv_featureTree == NULL) {
|
312 |
|
|
$csv_featureTree = cdm_ws_get(
|
313 |
|
|
CDM_WS_FEATURETREE,
|
314 |
|
|
variable_get(CDM_CSV_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE)
|
315 |
|
|
);
|
316 |
|
|
if (!$csv_featureTree) {
|
317 |
|
|
$csv_featureTree = cdm_ws_get(CDM_WS_FEATURETREE, UUID_DEFAULT_FEATURETREE);
|
318 |
|
|
}
|
319 |
|
|
}
|
320 |
|
|
return $csv_featureTree;
|
321 |
589a392b
|
Alexander Oppermann
|
}
|