1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Provides several different handlers for exporting webform results.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Implements hook_webform_exporters().
|
10
|
*
|
11
|
* Defines the exporters this module implements.
|
12
|
*
|
13
|
* @return array
|
14
|
* An "array of arrays", keyed by content-types. The 'handler' slot
|
15
|
* should point to the PHP class implementing this flag.
|
16
|
*/
|
17
|
function webform_webform_exporters() {
|
18
|
$exporters = array(
|
19
|
'delimited' => array(
|
20
|
'title' => t('Delimited text'),
|
21
|
'description' => t('A plain text file delimited by commas, tabs, or other characters.'),
|
22
|
'handler' => 'webform_exporter_delimited',
|
23
|
'file' => drupal_get_path('module', 'webform') . '/includes/exporters/webform_exporter_delimited.inc',
|
24
|
'weight' => 10,
|
25
|
),
|
26
|
'excel' => array(
|
27
|
'title' => t('Microsoft Excel'),
|
28
|
'description' => t('A file readable by Microsoft Excel.'),
|
29
|
'handler' => 'webform_exporter_excel_xlsx',
|
30
|
'file' => drupal_get_path('module', 'webform') . '/includes/exporters/webform_exporter_excel_xlsx.inc',
|
31
|
'weight' => -1,
|
32
|
// Tells the options to use consistent dates instead of user-defined
|
33
|
// formats.
|
34
|
'options' => array(
|
35
|
'iso8601_time' => TRUE,
|
36
|
'iso8601_date' => TRUE,
|
37
|
),
|
38
|
),
|
39
|
'excel_legacy' => array(
|
40
|
'title' => t('Microsoft Excel (older versions)'),
|
41
|
'description' => t('A file readable by older versions of Microsoft Excel.'),
|
42
|
'handler' => 'webform_exporter_excel_delimited',
|
43
|
'file' => drupal_get_path('module', 'webform') . '/includes/exporters/webform_exporter_excel_delimited.inc',
|
44
|
'weight' => 0,
|
45
|
),
|
46
|
);
|
47
|
|
48
|
// The new Excel exporter is only available if ZipArchive is available.
|
49
|
if (!class_exists('ZipArchive')) {
|
50
|
unset($exporters['excel']);
|
51
|
}
|
52
|
// By default the legacy Excel exporter is disabled.
|
53
|
if (!webform_variable_get('webform_excel_legacy_exporter')) {
|
54
|
unset($exporters['excel_legacy']);
|
55
|
}
|
56
|
|
57
|
return $exporters;
|
58
|
}
|
59
|
|
60
|
/**
|
61
|
* Return a list of exporters suitable for display in a select list.
|
62
|
*/
|
63
|
function webform_export_list() {
|
64
|
$exporters = webform_export_fetch_definition();
|
65
|
$list = array();
|
66
|
foreach ($exporters as $name => $exporter) {
|
67
|
$list[$name] = $exporter['title'];
|
68
|
}
|
69
|
return $list;
|
70
|
}
|
71
|
|
72
|
/**
|
73
|
* Returns a Webform exporter definition.
|
74
|
*/
|
75
|
function webform_export_fetch_definition($format = NULL) {
|
76
|
static $cache;
|
77
|
if (!isset($cache)) {
|
78
|
$cache = module_invoke_all('webform_exporters');
|
79
|
drupal_alter('webform_exporters', $cache);
|
80
|
foreach ($cache as $key => $exporter) {
|
81
|
$cache[$key] += array('weight' => 0);
|
82
|
$cache[$key]['name'] = $key; // Used in sorting.
|
83
|
}
|
84
|
uasort($cache, '_webform_components_sort');
|
85
|
}
|
86
|
|
87
|
if (isset($format)) {
|
88
|
if (isset($cache[$format])) {
|
89
|
return $cache[$format];
|
90
|
}
|
91
|
}
|
92
|
else {
|
93
|
return $cache;
|
94
|
}
|
95
|
}
|
96
|
|
97
|
/**
|
98
|
* Instantiates a new Webform handler based on the format.
|
99
|
*/
|
100
|
function webform_export_create_handler($format, $options) {
|
101
|
$definition = webform_export_fetch_definition($format);
|
102
|
if (isset($definition['file'])) {
|
103
|
include_once $definition['file'];
|
104
|
}
|
105
|
if (isset($definition)) {
|
106
|
$handler = new $definition['handler']($options);
|
107
|
}
|
108
|
else {
|
109
|
// TODO: Create a default broken exporter.
|
110
|
$handler = new webform_exporter_broken($options);
|
111
|
}
|
112
|
|
113
|
return $handler;
|
114
|
}
|