Project

General

Profile

Download (1.89 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2

    
3
/**
4
 * Implements hook_menu().
5
 */
6
function dwca_export_menu() {
7

    
8
	$items = array();
9

    
10
	$items['admin/config/system/dwca_export/settings'] = array(
11

    
12
		'title' => t('DarwinCore-Archive export'),
13
		'page callback' => 'drupal_get_form',
14
		'page arguments' => array('dwca_export_config_form'),
15
		'access arguments' => array('access administration pages'),
16
		'type' => MENU_LOCAL_TASK,
17
		//'file' => 'dwca_export.admin.inc'
18
	);
19

    
20
	$items['dwca_export'] = array(
21
		'page callback' => 'dwca_export_deliver_archive',
22
		'access arguments' => TRUE,
23
		'type' => MENU_CALLBACK
24
	);
25

    
26

    
27
	return $items;
28
}
29

    
30
/**
31
 * Form function, called by drupal_get_form()
32
 * in dwca_export_menu().
33
 */
34
function dwca_export_config_form($form, &$form_state) {
35

    
36
	$form['dwca_export_todo'] = array(
37
		'#markup' => '<p>No settings implemented yet.</p>'
38
	);
39

    
40
	return system_settings_form($form);
41
}
42

    
43

    
44
/**
45
 * menu callback
46
 */
47
function dwca_export_deliver_archive() {
48

    
49
	$tmp_archive_file_name = dwca_export_create_archive( _get_views_map() );
50

    
51
	if($tmp_archive_file_name){
52
		file_transfer($tmp_archive_file_name, array('Content-Type' => 'application/zip'));
53
	} else {
54
		print "ERROR";
55
	}
56
}
57

    
58
/**
59
 * Walks all view export paths defined in the $views_map.
60
 * Each file is downloaded to the tmp folder and a zip file
61
 * is bundeled of the resulting csv files plus the meta file.
62
 *
63
 * @param - $views_map maps a view paths to dwca filenames
64
 *
65
 * @return the path in the filesystem to the final archive,
66
 * or FALSE in case of an error.
67
 */
68
function dwca_export_create_archive($views_map) {
69

    
70
	$tmp_archive_file_name = drupal_tempnam("temporary://", "dwca_export_");
71

    
72
	return $tmp_archive_file_name;
73
}
74

    
75
/**
76
 * provides the settings which map a view path to
77
 * a dwca filename.
78
 *
79
 */
80
function _get_views_map() {
81

    
82
	return array(
83
		'taxon' => 'taxon.txt',
84
		'extension' => 'extension.txt'
85
	);
86
}
(2-2/2)