1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* Base class defining the common methods available to exporters.
|
5
|
*/
|
6
|
class webform_exporter {
|
7
|
public $options = array();
|
8
|
public $export_wordrap;
|
9
|
|
10
|
/**
|
11
|
* Constructor for webform_exporter classes.
|
12
|
*
|
13
|
* @param $options
|
14
|
* The array of export options as provided by the user-interface.
|
15
|
*/
|
16
|
public function __construct($options) {
|
17
|
$this->options = $options;
|
18
|
$this->export_wordwrap = webform_variable_get('webform_export_wordwrap');
|
19
|
}
|
20
|
|
21
|
/**
|
22
|
* Determines whether a cell is eligible for word-wrapping.
|
23
|
*
|
24
|
* This is based upon position in file and the contents of cell.
|
25
|
*
|
26
|
* Return true when the global word-wrapping option is enabled and the cell
|
27
|
* is anything other than the first column in either of the first two rows.
|
28
|
* By default, these rows are long and are intended to overlap the columns
|
29
|
* to the right. Also returns true when the cell contains a return character.
|
30
|
*
|
31
|
* @param int $row
|
32
|
* Row number, counting from 0.
|
33
|
* @param int $column
|
34
|
* Column number, counting from 0.
|
35
|
* @param string $value
|
36
|
* The value of the cell.
|
37
|
*
|
38
|
* @return bool
|
39
|
* Whether the cell position is eligible for wordwrapping.
|
40
|
*/
|
41
|
public function wrappable($row, $column, $value) {
|
42
|
return strpos($value, "\n") !== FALSE ||
|
43
|
$this->export_wordwrap && ($row > 2 || $column > 0 || $this->options['header_keys'] < 0);
|
44
|
}
|
45
|
|
46
|
/**
|
47
|
* Add a single row to the export file.
|
48
|
*
|
49
|
* @param $file_handle
|
50
|
* A PHP file handle to the export file.
|
51
|
* @param array $data
|
52
|
* An array of formatted data for this row. One cell per item.
|
53
|
* @param int $row_count
|
54
|
* The current number of rows in the export file.
|
55
|
*/
|
56
|
public function add_row(&$file_handle, array $data, $row_count) {
|
57
|
}
|
58
|
|
59
|
/**
|
60
|
* Provide headers to the page when an export file is being downloaded.
|
61
|
*
|
62
|
* @param string $filename
|
63
|
* The name of the file being downloaded, for example, export.xls.
|
64
|
*/
|
65
|
public function set_headers($filename) {
|
66
|
drupal_add_http_header('Content-Type', 'application/force-download');
|
67
|
drupal_add_http_header('Pragma', 'public');
|
68
|
drupal_add_http_header('Cache-Control', 'max-age=0');
|
69
|
}
|
70
|
|
71
|
/**
|
72
|
* Write the start of the export file.
|
73
|
*
|
74
|
* @param $file_handle
|
75
|
* A PHP file handle to the export file.
|
76
|
*/
|
77
|
public function bof(&$file_handle) {
|
78
|
}
|
79
|
|
80
|
/**
|
81
|
* Write the end of the export file.
|
82
|
*
|
83
|
* @param $file_handle
|
84
|
* A PHP file handle to the export file.
|
85
|
* @param int $row_count
|
86
|
* @param int $col_count
|
87
|
*/
|
88
|
public function eof(&$file_handle, $row_count, $col_count) {
|
89
|
}
|
90
|
|
91
|
/**
|
92
|
* Allow final processing of the results.
|
93
|
*
|
94
|
* @param $results
|
95
|
* An array of result data, including:
|
96
|
* - node: The node whose results are being downloaded.
|
97
|
* - file_name: The full file path of the generated file.
|
98
|
* - row_count: The final number of rows in the generated file.
|
99
|
*/
|
100
|
public function post_process(&$results) {
|
101
|
}
|
102
|
|
103
|
}
|