Project

General

Profile

Download (9.68 KB) Statistics
| Branch: | Tag: | Revision:
1
<?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
define('CDM_CSV_FEATURETREE_UUID', 'cdm_csv_featuretree_uuid');
22

    
23

    
24
/**
25
 *
26
 * @param unknown $path
27
 *  Which path of the site we're using to display help
28
 * @param unknown $arg
29
 *  Array that holds the current path as returned from arg() function
30
 * @return string
31
 */
32
function cdm_csv_export_help($path, $arg){
33

    
34
switch ($path) {
35
  case "admin/help#cdm_csv_export":
36
  return '<h1>'.t('CDM CSV Export Help'). '</h1>'. '<p>' . t("In order
37
    to export the data with special export options, it is essential
38
    to configure a feature tree with the desired features. Then set
39
    this feature tree as the default feature tree for this portal."
40
    ) . '</p>';
41
  break;
42
  }
43
}
44

    
45
/**
46
 * Implements hook_block_info()
47
 *
48
 * Prepares the content for the help menu
49
 *
50
 * @return array
51
 */
52
function cdm_csv_export_block_info() {
53
  $blocks['cdm_csv_export'] = array(
54
    'info' => t('CDM CSV Export Module'), //The name that will appear in the block list.
55
    'cache' => DRUPAL_CACHE_PER_ROLE, //Default
56
  );
57
  return $blocks;
58
}
59

    
60
/**
61
 * Implements hook_block_view().
62
 *
63
 * Prepares the contents of the block.
64
 *
65
 * @param string $delta
66
 * @return array
67
 */
68
function cdm_csv_export_block_view($delta='') {
69
  $block['subject'] = t('Export into CSV');
70
  $block['content']= array(
71
      drupal_get_form('cdm_csv_export_my_form'),
72
  );
73
  return $block;
74
}
75

    
76
/**
77
 * Creates the drupal form and returns it
78
 *
79
 * @param unknown $form_state
80
 * @return array
81
 *
82
 */
83
function cdm_csv_export_my_form($form_state) {
84
  $form['combobox'] = array(
85
    '#type' => 'select',
86
    '#title' => t('Classification').':',
87
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
88
    '#options' => cdm_get_taxontrees_as_options(),
89
    '#attributes' => array(
90
         'name' => 'classification',
91
          'onchange' => 'return validateForm()'),
92
  );
93

    
94
  $form['redListField'] = array(
95
      '#type' => 'fieldset',
96
      '#title'	=>t('Redlist Attributes'),
97
      '#collapsible' => TRUE,
98
      '#collapsed' => TRUE,
99
    );
100

    
101
  $form['redListField']['csvExportOptions'] = array(
102
      '#type'=>'checkboxes',
103
      '#options' => array(),
104
  );
105

    
106
   // ---- LAYOUT PER FEATURE ---- //
107
$feature_tree = get_csv_featureTree();
108
  if (isset($feature_tree->root->childNodes)) {
109
    foreach ($feature_tree->root->childNodes as $featureNode) {
110
      if (isset($featureNode->feature)) {
111

    
112
       // Must not exceed 45 characters !!!
113
        $subform_id =  $featureNode->feature->uuid; //LAYOUT_SETTING_PREFIX .
114
//        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
115
//        $systemDefaults = unserialize(FEATURE_TREE_LAYOUT_DEFAULTS);
116
        $form['redListField']['csvExportOptions'][$subform_id] = array(
117
          '#type' => 'checkbox',
118
          '#title' => $featureNode->feature->representation_L10n,
119
          '#default_value' => $featureNode->feature->uuid,//$settings,
120
          '#attributes' => array('value' => $featureNode->feature->uuid,
121
                                  'name' => 'features'
122
            ),
123
        );
124
      }
125
    }
126
  }
127

    
128
  $form['downloadTokenValueId'] = array(
129
    '#type' => 'hidden',
130
    '#attributes' => array('name' => 'downloadTokenValueId',
131
                           'id' => 'downloadTokenValueId',
132
      ),
133
    );
134

    
135
  $form['dialogMessage'] = array(
136
    '#type' => 'hidden',
137
    '#attributes' => array(
138
      'name' => 'dialogMessage',
139
      'id' => 'dialogMessage',
140
    ),
141
  );
142

    
143
  $country = variable_get('area_filter_country');
144
  $state = variable_get('area_filter_state');
145
if($country != null || $state != null){
146
  $form['regionFilter'] = array(
147
    '#type' => 'fieldset',
148
    '#title' => t('Geographical filter'),
149
    '#collapsible' => TRUE,
150
    '#collapsed' => TRUE,
151
  );
152
 }
153

    
154
  $term = cdm_ws_get(CDM_WS_TERM, $country);
155
  $representation_title_cache = cdm_term_representation($term);
156
  if($country != null){
157
  $form['regionFilter']['country'] = array (
158
    '#type' => 'checkbox',
159
    '#title' => t('@representation-title-cache', array('@representation-title-cache' => $representation_title_cache)),
160
    '#attributes' => array('name' => 'area',
161
                            'id' => 'checkall',
162
                            'value' =>  $country
163
     ),
164
    );
165
  }
166

    
167
  //GermanFederalStates
168
  if($state != null){
169
  $nameRelationshipTypeOptions = cdm_vocabulary_as_option($state);
170
  asort($nameRelationshipTypeOptions);
171
  $form['regionFilter']['area'] = array(
172
    '#type' => 'checkboxes',
173
    '#description' =>t('Select an area to filter the list of taxa'),
174
    '#options' => $nameRelationshipTypeOptions,
175
    '#attributes' => array('name' => 'area',
176
                            'id' => 'area',
177
      ),
178
    );
179
  }
180

    
181
  $form['button'] = array(
182
    '#type'  => 'submit',
183
    '#value' => 'Export',
184
    );
185

    
186
  $form['#action'] = url(variable_get('cdm_csv_export_webservice_url'));
187
  $form['#attributes'] = array(
188
                 'name' => 'exportForm',
189
                 'onsubmit' => 'return blockUIForDownload()');
190
 return $form;
191
}
192

    
193

    
194

    
195
/**
196
 * Implements Admin configuration hook_menu().
197
 *
198
 * @return array
199
 */
200

    
201
function cdm_csv_export_menu() {
202
 $items = array();
203

    
204
 $items['admin/config/cdm_dataportal/csvexport'] = array(
205
   'title' => 'CDM CSV Export',
206
   'description' => 'Settings of CSV Export module.',
207
   'page callback' => 'drupal_get_form',
208
   'page arguments' => array('cdm_csv_export_admin'),
209
   'access arguments' => array('access administration pages'),
210
   'type' => MENU_NORMAL_ITEM,
211
 );
212
 return $items;
213
}
214

    
215
/**
216
 * Generates the HTML form for the CSV Export Settings.
217
 *
218
 * @return array
219
 */
220
function cdm_csv_export_admin() {
221

    
222
 $form['cdm_csv_export_webservice'] = array(
223
   '#type' => 'fieldset',
224
   '#title' => t('CDM CSV Export web service'),
225
   '#collapsible' => TRUE,
226
   '#collapsed' => FALSE,
227
   '#description' => t('<em>CDM Server</em> makes the dialogue possible with
228
      <em>CDM Data Portal</em> thanks to its web services.'),
229
 );
230

    
231
 $form['cdm_csv_export_webservice']['cdm_csv_export_webservice_url'] = array(
232
   '#type' => 'textfield',
233
   '#title' => t('CSV Export web service URL') . ':',
234
   '#description' => t('This is the URL to the CDM-Server webservice exposing its controller
235
      e.g. <em>"http://localhost:8080/csv/exportRedlist"</em>'),
236
   '#default_value' => variable_get('cdm_csv_export_webservice_url', NULL),
237
 );
238

    
239
 // ---- Regional Filter ---- //
240
 $form['csv_export_area_filter'] = array(
241
   '#type' => 'fieldset',
242
   '#title' => t('CDM CSV Export Area Filter'),
243
   '#collapsible' => TRUE,
244
   '#collapsed' => FALSE,
245
   '#description' => t('The <em>Area Filter</em> can be freely configured to the need
246
       of the specific <em>CDM Data Portal</em> and its catchment area. Right now it will
247
       be only distinguished between two levels. If necessary it can be programmatically
248
       extended for a third level e.g. "continent level".'),
249
 );
250

    
251
 $form['csv_export_area_filter']['area_filter_country'] = array(
252
   '#type' => 'textfield',
253
   '#title' => t('Country Level') . ':',
254
   '#description' => t('This is the UUID for the country level, in order to be able to filter Germany,
255
      you should paste e.g. <em>"7b7c2db5-aa44-4302-bdec-6556fd74b0b9"</em> in the above text field'),
256
   '#default_value' => variable_get('area_filter_country', NULL),
257
 );
258

    
259
 $form['csv_export_area_filter']['area_filter_state'] = array(
260
   '#type' => 'textfield',
261
   '#title' => t('State Level') . ':',
262
   '#description' => t('This is the UUID for the state level, in order to be able to filter the german federal states,
263
      you should paste e.g. <em>"44a448f9-f4ca-49f6-b58c-d27d8a69efdb"</em> in the above text field'),
264
   '#default_value' => variable_get('area_filter_state', NULL),
265
 );
266

    
267
 // ---- FEATURE TREE ---- //
268
 $form['feature_trees'] = array(
269
   '#type' => 'fieldset',
270
   '#title' => t('Features'),
271
   '#collapsible' => TRUE,
272
   '#collapsed' => FALSE,
273
   '#description' => t("This section covers settings related to the taxon's
274
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
275
      features such as description, distribution, common names, etc. that Drupal
276
      will render at the taxon profile page."),
277
 );
278

    
279
 $featureTrees = cdm_get_featureTrees_as_options(TRUE);
280
 $form['feature_trees'][CDM_CSV_FEATURETREE_UUID] = array(
281
     '#type' => 'radios',
282
     '#title' => t('CSV Export Feature Tree sections') . ':',
283
  '#default_value' => variable_get(CDM_CSV_FEATURETREE_UUID, NULL),
284
   '#options' =>  $featureTrees['options'],
285
   '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
286
   '#options_suffixes' => $featureTrees['treeRepresentations'],
287
  '#description' => t('Select the Feature Tree to be displayed at the taxon
288
      profile. Click "Show Details" to see the Feature Tree elements.'
289
   ),
290
 );
291
 return system_settings_form($form);
292
}
293

    
294
/**
295
 * Returns the chosen FeatureTree for the CSV Export Module.
296
 *
297
 * The returned CSV FeatureTree, has been set in the
298
 * CSV Export Module settings (CDM CSV EXPORT -> FEATURES).
299
 * If the chosen FeatureTree is not found in the database,
300
 * the standard feature tree (UUID_DEFAULT_FEATURETREE) will be returned.
301
 *
302
 * @return mixed
303
 *   A cdm FeatureTree object.
304
 */
305

    
306
function get_csv_featureTree() {
307
 static $csv_featureTree;
308

    
309
 if($csv_featureTree == NULL) {
310
  $csv_featureTree = cdm_ws_get(
311
    CDM_WS_FEATURETREE,
312
    variable_get(CDM_CSV_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE)
313
  );
314
  if (!$csv_featureTree) {
315
   $csv_featureTree = cdm_ws_get(CDM_WS_FEATURETREE, UUID_DEFAULT_FEATURETREE);
316
  }
317
 }
318
 return $csv_featureTree;
319
}
(2-2/2)