Projet

Général

Profil

Paste
Télécharger (2,79 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / webform / includes / exporters / webform_exporter.inc @ e9f59ce0

1
<?php
2

    
3
/**
4
 * @file
5
 * Base class defining the common methods available to exporters.
6
 */
7

    
8
class webform_exporter {
9
  public $options = array();
10
  public $export_wordrap;
11

    
12
  /**
13
   * Constructor for webform_exporter classes.
14
   *
15
   * @param $options
16
   *   The array of export options as provided by the user-interface.
17
   */
18
  function __construct($options) {
19
    $this->options = $options;
20
    $this->export_wordwrap = webform_variable_get('webform_export_wordwrap');
21
  }
22

    
23
  /**
24
   * Determines whether a cell is eligible for word-wrapping based upon
25
   * position in file and the contents of cell.
26
   *
27
   * Return true when the global word-wrapping option is enabled and the cell
28
   * is anything other than the first column in either of the first two rows.
29
   * By default, these rows are long and are intended to overlap the columns
30
   * to the right. Also returns true when the cell contains a return character.
31
   *
32
   * @param int $row
33
   *   Row number, counting from 0.
34
   * @param int $column
35
   *   Column number, counting from 0.
36
   * @param string $value
37
   *   The value of the cell.
38
   * @return boolean
39
   *   Whether the cell position is elegible for wordwrapping.
40
   */
41
  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
  function add_row(&$file_handle, $data, $row_count) {
57
  }
58

    
59
  /**
60
   * Provide headers to the page when an export file is being downloaded.
61
   *
62
   * @param $filename
63
   *   The name of the file being downloaded. e.g. export.xls.
64
   */
65
  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
  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
   */
86
  function eof(&$file_handle, $row_count, $col_count) {
87
  }
88

    
89
  /**
90
   * Allow final processing of the results.
91
   *
92
   * @param $results
93
   *   An array of result data, including:
94
   *   - node: The node whose results are being downloaded.
95
   *   - file_name: The full file path of the generated file.
96
   *   - row_count: The final number of rows in the generated file.
97
   */
98
  function post_process(&$results) {
99
  }
100
}