Project

General

Profile

Download (8.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

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

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

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

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

    
74
/**
75
 * Creates the drupal form and returns it
76
 * 
77
 * @param unknown $form_state
78
 * @return multitype:string multitype:string  
79
 *          multitype:string multitype:string   
80
 *          Ambigous <A, string> multitype:NULL  
81
 *          multitype:string multitype: Ambigous <The, string, A, Optional>  The
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('name' => 'classification'),
90
  );
91

    
92
  $form['redListField'] = array(
93
      '#type' => 'fieldset',
94
      '#title'	=>t('Redlist Attributes'),
95
      '#collapsible' => TRUE,
96
      '#collapsed' => TRUE,
97
    );
98
  
99
  $form['redListField']['csvExportOptions'] = array(
100
      '#type'=>'checkboxes',
101
      '#options' => array(),
102
  );
103
    
104
   // ---- LAYOUT PER FEATURE ---- //
105
$feature_tree = get_profile_featureTree();
106
  if (isset($feature_tree->root->children)) {
107
    foreach ($feature_tree->root->children as $featureNode) {
108
      if (isset($featureNode->feature)) {
109

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

    
132
  $form['regionFilter'] = array(
133
    '#type' => 'fieldset',
134
    '#title' => t('Geographical filter'),
135
    '#collapsible' => TRUE,
136
    '#collapsed' => TRUE,
137
    );
138

    
139
  //TODO: #title value needs to be fetched from 'area_filter_country' 
140
  $form['regionFilter']['country'] = array (
141
    '#type' => 'checkbox',
142
    '#title' => 'Germany',
143
    '#attributes' => array('name' => 'area',
144
                            'id' => 'checkall',
145
                            'value' => variable_get('area_filter_country')
146
     ),
147
    );
148
  
149
  //GermanFederalStates
150
  $nameRelationshipTypeOptions = cdm_Vocabulary_as_option(variable_get('area_filter_state'));
151
  $form['regionFilter']['area'] = array(
152
    '#type' => 'checkboxes',
153
    '#description' =>t('Select an area to filter the list of taxa'),
154
    '#options' => $nameRelationshipTypeOptions,
155
    '#attributes' => array('name' => 'area',
156
                            'id' => 'area',
157
      ),
158
    );
159
  
160
  $form['button'] = array(
161
    '#type'  => 'submit',
162
    '#value' => 'Export',
163
    );
164
  
165
  $form['#action'] = url(variable_get('cdm_csv_export_webservice_url'));
166
  $form['#attributes'] = array('onsubmit' => 'return blockUIForDownload()');
167
  
168
  return $form;
169
}
170

    
171

    
172

    
173
/**
174
 * Implements Admin configuration hook_menu().
175
 */
176
function cdm_csv_export_menu() {
177
 $items = array();
178

    
179
 $items['admin/config/cdm_dataportal/csvexport'] = array(
180
   'title' => 'CDM CSV Export',
181
   'description' => 'Settings of CSV Export module.',
182
   'page callback' => 'drupal_get_form',
183
   'page arguments' => array('cdm_csv_export_admin'),
184
   'access arguments' => array('access administration pages'),
185
   'type' => MENU_NORMAL_ITEM,
186
 );
187

    
188
 return $items;
189
}
190

    
191
/**
192
 * Generate the HTML form for the CSV Export Settings.
193
 */
194
function cdm_csv_export_admin() {
195
 
196
 $form['cdm_csv_export_webservice'] = array(
197
   '#type' => 'fieldset',
198
   '#title' => t('CDM CSV Export web service'),
199
   '#collapsible' => TRUE,
200
   '#collapsed' => FALSE,
201
   '#description' => t('<em>CDM Server</em> makes the dialogue possible with
202
      <em>CDM Data Portal</em> thanks to its web services.'),
203
 );
204
 
205
 $form['cdm_csv_export_webservice']['cdm_csv_export_webservice_url'] = array(
206
   '#type' => 'textfield',
207
   '#title' => t('CSV Export web service URL') . ':',
208
   '#description' => t('This is the URL to the CDM-Server webservice exposing its controller
209
      e.g. <em>"http://localhost:8080/csv/exportRedlist"</em>'),
210
   '#default_value' => variable_get('cdm_csv_export_webservice_url', NULL),
211
 );
212
 
213
 // ---- Regional Filter ---- //
214
 $form['csv_export_area_filter'] = array(
215
   '#type' => 'fieldset',
216
   '#title' => t('CDM CSV Export Area Filter'),
217
   '#collapsible' => TRUE,
218
   '#collapsed' => FALSE,
219
   '#description' => t('The <em>Area Filter</em> can be freely configured to the need 
220
       of the specific <em>CDM Data Portal</em> and its catchment area. Right now it will 
221
       be only distinguished between two levels. If necessary it can be programmatically
222
       extended for a third level e.g. "continent level".'),
223
 );
224
 
225
 $form['csv_export_area_filter']['area_filter_country'] = array(
226
   '#type' => 'textfield',
227
   '#title' => t('Country Level') . ':',
228
   '#description' => t('This is the UUID for the country level, in order to be able to filter Germany,
229
      you should paste e.g. <em>"7b7c2db5-aa44-4302-bdec-6556fd74b0b9"</em> in the above text field'),
230
   '#default_value' => variable_get('area_filter_country', NULL),
231
 );
232
 
233
 $form['csv_export_area_filter']['area_filter_state'] = array(
234
   '#type' => 'textfield',
235
   '#title' => t('State Level') . ':',
236
   '#description' => t('This is the UUID for the state level, in order to be able to filter the german federal states,
237
      you should paste e.g. <em>"44a448f9-f4ca-49f6-b58c-d27d8a69efdb"</em> in the above text field'),
238
   '#default_value' => variable_get('area_filter_state', NULL),
239
 );
240
 
241
 // ---- FEATURE TREE ---- //
242
 $form['taxon_profile'] = array(
243
   '#type' => 'fieldset',
244
   '#title' => t('Features'),
245
   '#collapsible' => TRUE,
246
   '#collapsed' => FALSE,
247
   '#description' => t("This section covers settings related to the taxon's
248
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
249
      features such as description, distribution, common names, etc. that Drupal
250
      will render at the taxon profile page."),
251
 );
252
 
253
 $featureTrees = cdm_get_featureTrees_as_options(TRUE);
254
 $form['taxon_profile']['feature_trees'][CDM_PROFILE_FEATURETREE_UUID] = array(
255
   '#type' => 'radios',
256
   '#title' => t('Taxon profile sections') . ':',
257
   '#default_value' => variable_get(CDM_PROFILE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE),
258
   '#options' =>  $featureTrees['options'],
259
   // Comment @WA: because #options are sanitized in D7, it would
260
   // strip html like <fieldset>, so we put the fieldset in a suffix.
261
   '#field_suffix' => $featureTrees['treeRepresentations'],
262
   '#description' => t('Select the Feature Tree to be displayed at the taxon
263
      profile. Click "Show Details" to see the Feature Tree elements.'
264
   ),
265
 );
266

    
267
 return system_settings_form($form);
268
}
(2-2/2)