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