Revision dc70e39a
Added by Niels Hoffmann over 11 years ago
7.x/modules/dwca_export/dwca_export.module | ||
---|---|---|
1 | 1 |
<?php |
2 | 2 |
|
3 |
define ("CSV_FILE_EXTENSION", ".txt"); |
|
4 |
// at the moment we are using a static meta.xml file |
|
5 |
define ("METADATA_FILE", "meta.xml"); |
|
6 |
|
|
7 |
define ("ARCHIVE_ROOT_DIR", "dwca_export/"); |
|
8 |
|
|
9 |
function _get_static_file_map(){ |
|
10 |
$static_file_map = array( |
|
11 |
'classification' => array( |
|
12 |
'view_name'=> 'dwca_export_classification', |
|
13 |
'display_id' => 'views_data_export_1', |
|
14 |
'out_file_url' => NULL |
|
15 |
), |
|
16 |
'typesandspecimen' => array( |
|
17 |
'view_name'=> 'view_test_specimen_export', |
|
18 |
'display_id' => 'views_data_export_1', |
|
19 |
'out_file_url' => NULL |
|
20 |
) |
|
21 |
); |
|
22 |
return $static_file_map; |
|
23 |
} |
|
24 |
|
|
25 |
|
|
3 | 26 |
/** |
4 | 27 |
* Implements hook_menu(). |
5 | 28 |
*/ |
... | ... | |
47 | 70 |
|
48 | 71 |
global $base_url; |
49 | 72 |
|
50 |
$form['dwca_export_todo'] = array( |
|
51 |
'#markup' => '<p><em>No settings implemented yet...</em></p>' |
|
52 |
.'<p>The DarwinCore Archive export is available at '. l('dwca_export', 'dwca_export').'</p>' |
|
53 |
.'<p>For general information on the DarwinCore Archive format please refer to ' |
|
73 |
$form['dwca_export_info'] = array( |
|
74 |
'#markup' => '<p>For general information on the DarwinCore Archive format please refer to ' |
|
54 | 75 |
. l('GBIF - Standards and Tools - Darwin Core Archives', 'http://www.gbif.org/informatics/standards-and-tools/publishing-data/data-standards/darwin-core-archives/') |
55 | 76 |
.'</p>' |
56 | 77 |
); |
57 | 78 |
|
58 |
$form['views'] = dwca_export_select_view_form(); |
|
79 |
$form['dwca_export_execute'] = array( |
|
80 |
'#markup' => '<p>The DarwinCore Archive export is available at '. l('dwca_export', 'dwca_export').'</p>' |
|
81 |
//'#type' => 'button', |
|
82 |
//'#value' => t('Export Scratchpad to DarwinCore Archive'), |
|
83 |
//'#weight' => 19, |
|
84 |
); |
|
85 |
|
|
86 |
$form['dwca_export_view_mapping'] = dwca_export_select_view_form(); |
|
87 |
|
|
88 |
|
|
59 | 89 |
|
60 | 90 |
$form['#submit'][] = 'dwca_export_config_form_submit'; |
61 | 91 |
return system_settings_form($form); |
... | ... | |
67 | 97 |
|
68 | 98 |
$views = array( |
69 | 99 |
'#type' => 'fieldset', |
70 |
'#title' => t('Select views'),
|
|
100 |
'#title' => t('View to file mapping'),
|
|
71 | 101 |
//'#tree' => TRUE, |
72 | 102 |
); |
73 | 103 |
|
74 |
$default_value = _dwca_export_archive_descriptor_file_map(); |
|
75 |
|
|
76 |
$views['classification_view'] = array( |
|
77 |
'#type' => 'textfield', |
|
78 |
'#title' => t('classification:'), |
|
79 |
'#default_value' => $default_value['classification.txt']['view_name'], |
|
80 |
'#size' => 60, |
|
81 |
'#maxlength' => 64, |
|
82 |
'#description' => t('specify view for classification.txt'), |
|
83 |
); |
|
84 |
|
|
85 |
$views['specimen_view'] = array( |
|
86 |
'#type' => 'textfield', |
|
87 |
'#title' => t('specimen:'), |
|
88 |
'#default_value' => variable_get('specimen.txt', 'dwca_export_specimen'), |
|
89 |
'#size' => 60, |
|
90 |
'#maxlength' => 64, |
|
91 |
'#description' => t('specify view for specimen.txt'), |
|
92 |
); |
|
93 |
|
|
94 |
$views['reference_view'] = array( |
|
95 |
'#type' => 'textfield', |
|
96 |
'#title' => t('reference:'), |
|
97 |
'#size' => 60, |
|
98 |
'#maxlength' => 64, |
|
99 |
'#description' => t('specify view for reference.txt'), |
|
100 |
); |
|
101 |
|
|
102 |
$views['description_view'] = array( |
|
103 |
'#type' => 'textfield', |
|
104 |
'#title' => t('description:'), |
|
105 |
'#size' => 60, |
|
106 |
'#maxlength' => 64, |
|
107 |
'#description' => t('specify view for description.txt'), |
|
108 |
); |
|
109 |
|
|
110 |
$views['distribution_view'] = array( |
|
111 |
'#type' => 'textfield', |
|
112 |
'#title' => t('distribution:'), |
|
113 |
'#size' => 60, |
|
114 |
'#maxlength' => 64, |
|
115 |
'#description' => t('specify view for distribution.txt'), |
|
116 |
); |
|
117 |
|
|
118 |
$views['image_view'] = array( |
|
119 |
'#type' => 'textfield', |
|
120 |
'#title' => t('image:'), |
|
121 |
'#size' => 60, |
|
122 |
'#maxlength' => 64, |
|
123 |
'#description' => t('specify view for image.txt'), |
|
124 |
); |
|
125 |
|
|
126 |
//variable_get('classification.txt', 'test'), |
|
127 |
//$views['submit'] = array('#type' => 'submit', '#value' => t('Save selected')); |
|
104 |
//$default_value = _dwca_export_archive_descriptor_file_map(); |
|
105 |
|
|
106 |
foreach(_dwca_export_archive_descriptor_file_map() as $dwca_filename => $view_data){ |
|
107 |
|
|
108 |
|
|
109 |
$views[$dwca_filename . '_view'] = array( |
|
110 |
'#type' => 'textfield', |
|
111 |
'#title' => t($dwca_filename), |
|
112 |
'#default_value' => $view_data['view_name'], |
|
113 |
'#size' => 60, |
|
114 |
'#maxlength' => 64, |
|
115 |
'#description' => t('specify view for ' . $dwca_filename . CSV_FILE_EXTENSION), |
|
116 |
); |
|
117 |
} |
|
128 | 118 |
|
129 | 119 |
return $views; |
130 | 120 |
} |
... | ... | |
160 | 150 |
* The 'out_file_url' is initailly empty and will be set when this function is called |
161 | 151 |
* with both parameters. |
162 | 152 |
* |
163 |
* @param unknown_type $file_name
|
|
164 |
* @param unknown_type $out_file_url
|
|
153 |
* @param String $file_name
|
|
154 |
* @param String $out_file_url
|
|
165 | 155 |
* |
166 | 156 |
* @return the archive_descriptor_file_map |
167 | 157 |
*/ |
... | ... | |
170 | 160 |
|
171 | 161 |
if(!isset($file_map)){ |
172 | 162 |
//TODO load from variables, consider using strongarm |
173 |
$file_map = array( |
|
174 |
'classification.txt' => array( |
|
175 |
'view_name'=> 'dwca_export_classification', |
|
176 |
'display_id' => 'views_data_export_1', |
|
177 |
'out_file_url' => NULL |
|
178 |
), |
|
179 |
'typesandspecimen.txt' => array( |
|
180 |
'view_name'=> 'view_test_specimen_export', |
|
181 |
'display_id' => 'views_data_export_1', |
|
182 |
'out_file_url' => NULL |
|
183 |
) |
|
184 |
); |
|
163 |
// current implementation uses a static filemap |
|
164 |
$file_map = _get_static_file_map(); |
|
185 | 165 |
} |
186 | 166 |
|
187 | 167 |
if($file_name && $out_file_url){ |
... | ... | |
221 | 201 |
} |
222 | 202 |
|
223 | 203 |
// all data is exported to temporary://dwca_export_* |
224 |
// now we can start bundeling the actual archive
|
|
204 |
// now we can start bundling the actual archive |
|
225 | 205 |
$tmp_archive_file_name = drupal_tempnam("temporary://", "dwca_export_archive_"); |
226 | 206 |
|
227 | 207 |
// Unfortunately we cannot use drupals ArchiverZip because there ís |
... | ... | |
236 | 216 |
// there might be a better way to get at this information |
237 | 217 |
$module_static_dir_absolute = realpath(drupal_get_path('module', 'dwca_export')) . "/static/"; |
238 | 218 |
|
239 |
// at the moment we are using a static meta.xml file |
|
240 |
$metadata = "meta.xml"; |
|
241 |
|
|
242 |
$zip_root_dir = "dwca_export/"; |
|
243 |
|
|
244 | 219 |
if ($result !== TRUE) { |
245 | 220 |
throw new Exception(t('Could not create zip_archive %tmp_archive_file_name', array('%tmp_archive_file_name' => $tmp_archive_file_name))); |
246 | 221 |
} |
247 |
|
|
222 |
|
|
248 | 223 |
|
249 | 224 |
// add metadata |
250 |
$zip->addFile($module_static_dir_absolute.$metadata, $zip_root_dir.$metadata);
|
|
225 |
$zip->addFile($module_static_dir_absolute.$metadata, ARCHIVE_ROOT_DIR.METADATA_FILE);
|
|
251 | 226 |
// add the csv data files |
252 | 227 |
foreach(_dwca_export_archive_descriptor_file_map() as $dwca_filename=>$view_data){ |
253 | 228 |
|
254 | 229 |
$view_temp_file = $view_data['out_file_url']; |
255 | 230 |
if($view_temp_file){ |
256 |
$zip->addFile(drupal_realpath($view_temp_file), $zip_root_dir.$dwca_filename);
|
|
231 |
$zip->addFile(drupal_realpath($view_temp_file), ARCHIVE_ROOT_DIR.$dwca_filename.CSV_FILE_EXTENSION);
|
|
257 | 232 |
}else{ |
258 |
throw new Exception(t('Cannot create %file', array('%file' => $dwca_filename))); |
|
233 |
throw new Exception(t('Cannot create %file', array('%file' => $dwca_filename.CSV_FILE_EXTENSION)));
|
|
259 | 234 |
} |
260 | 235 |
} |
261 | 236 |
|
262 | 237 |
$zip->close(); |
263 | 238 |
|
264 | 239 |
return $tmp_archive_file_name; |
265 |
|
|
266 |
|
|
267 | 240 |
} |
268 | 241 |
|
269 | 242 |
/** |
Also available in: Unified diff
refactoring