1 |
a45e4bc1
|
Assos Assos
|
<?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 |
feca1e4a
|
Assos Assos
|
public function __construct($options) {
|
17 |
a45e4bc1
|
Assos Assos
|
$this->options = $options;
|
18 |
|
|
$this->export_wordwrap = webform_variable_get('webform_export_wordwrap');
|
19 |
|
|
}
|
20 |
|
|
|
21 |
|
|
/**
|
22 |
01f36513
|
Assos Assos
|
* Determines whether a cell is eligible for word-wrapping.
|
23 |
|
|
*
|
24 |
|
|
* This is based upon position in file and the contents of cell.
|
25 |
a45e4bc1
|
Assos Assos
|
*
|
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 |
feca1e4a
|
Assos Assos
|
*
|
38 |
|
|
* @return bool
|
39 |
|
|
* Whether the cell position is eligible for wordwrapping.
|
40 |
a45e4bc1
|
Assos Assos
|
*/
|
41 |
feca1e4a
|
Assos Assos
|
public function wrappable($row, $column, $value) {
|
42 |
a45e4bc1
|
Assos Assos
|
return strpos($value, "\n") !== FALSE ||
|
43 |
8c72e82a
|
Assos Assos
|
$this->export_wordwrap && ($row > 2 || $column > 0 || $this->options['header_keys'] < 0);
|
44 |
a45e4bc1
|
Assos Assos
|
}
|
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 |
01f36513
|
Assos Assos
|
public function add_row(&$file_handle, array $data, $row_count) {
|
57 |
a45e4bc1
|
Assos Assos
|
}
|
58 |
|
|
|
59 |
|
|
/**
|
60 |
|
|
* Provide headers to the page when an export file is being downloaded.
|
61 |
|
|
*
|
62 |
01f36513
|
Assos Assos
|
* @param string $filename
|
63 |
8c72e82a
|
Assos Assos
|
* The name of the file being downloaded, for example, export.xls.
|
64 |
a45e4bc1
|
Assos Assos
|
*/
|
65 |
feca1e4a
|
Assos Assos
|
public function set_headers($filename) {
|
66 |
a45e4bc1
|
Assos Assos
|
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 |
feca1e4a
|
Assos Assos
|
public function bof(&$file_handle) {
|
78 |
a45e4bc1
|
Assos Assos
|
}
|
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 |
01f36513
|
Assos Assos
|
* @param int $row_count
|
86 |
|
|
* @param int $col_count
|
87 |
a45e4bc1
|
Assos Assos
|
*/
|
88 |
feca1e4a
|
Assos Assos
|
public function eof(&$file_handle, $row_count, $col_count) {
|
89 |
a45e4bc1
|
Assos Assos
|
}
|
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 |
feca1e4a
|
Assos Assos
|
public function post_process(&$results) {
|
101 |
a45e4bc1
|
Assos Assos
|
}
|
102 |
feca1e4a
|
Assos Assos
|
|
103 |
a45e4bc1
|
Assos Assos
|
} |