Project

General

Profile

Download (2.09 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
 * Implementation of hook_views_api()
32
 *
33
 * drupal will load dwca_export.views_default.inc when this hook is implemented
34
 */
35
function dwca_export_views_api() {
36
	return array('api' => 3.0);
37
}
38

    
39
/**
40
 * Form function, called by drupal_get_form()
41
 * in dwca_export_menu().
42
 */
43
function dwca_export_config_form($form, &$form_state) {
44

    
45
	$form['dwca_export_todo'] = array(
46
		'#markup' => '<p>No settings implemented yet.</p>'
47
	);
48

    
49
	return system_settings_form($form);
50
}
51

    
52

    
53
/**
54
 * menu callback
55
 */
56
function dwca_export_deliver_archive() {
57

    
58
	$tmp_archive_file_name = dwca_export_create_archive( _get_views_map() );
59

    
60
	if($tmp_archive_file_name){
61
		file_transfer($tmp_archive_file_name, array('Content-Type' => 'application/zip'));
62
	} else {
63
		print "ERROR";
64
	}
65
}
66

    
67
/**
68
 * Walks all view export paths defined in the $views_map.
69
 * Each file is downloaded to the tmp folder and a zip file
70
 * is bundeled of the resulting csv files plus the meta file.
71
 *
72
 * @param - $views_map maps a view paths to dwca filenames
73
 *
74
 * @return the path in the filesystem to the final archive,
75
 * or FALSE in case of an error.
76
 */
77
function dwca_export_create_archive($views_map) {
78

    
79
	$tmp_archive_file_name = drupal_tempnam("temporary://", "dwca_export_");
80

    
81
	return $tmp_archive_file_name;
82
}
83

    
84
/**
85
 * provides the settings which map a view path to
86
 * a dwca filename.
87
 *
88
 */
89
function _get_views_map() {
90

    
91
	return array(
92
		'dwca_export/classification/csv' => 'classification.txt'
93
	);
94
}
(2-2/3)