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 @ 8c72e82a

1
<?php
2

    
3
/**
4
 * @file
5
 * Base class defining the common methods available to exporters.
6
 */
7
class webform_exporter {
8
  public $options = array();
9
  public $export_wordrap;
10

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

    
22
  /**
23
   * Determines whether a cell is eligible for word-wrapping based upon
24
   * 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
   * @return boolean
38
   *   Whether the cell position is elegible for wordwrapping.
39
   */
40
  function wrappable($row, $column, $value) {
41
    return strpos($value, "\n") !== FALSE ||
42
      $this->export_wordwrap && ($row > 2 || $column > 0 || $this->options['header_keys'] < 0);
43
  }
44

    
45
  /**
46
   * Add a single row to the export file.
47
   *
48
   * @param $file_handle
49
   *   A PHP file handle to the export file.
50
   * @param array $data
51
   *   An array of formatted data for this row. One cell per item.
52
   * @param int $row_count
53
   *   The current number of rows in the export file.
54
   */
55
  function add_row(&$file_handle, $data, $row_count) {
56
  }
57

    
58
  /**
59
   * Provide headers to the page when an export file is being downloaded.
60
   *
61
   * @param $filename
62
   *   The name of the file being downloaded, for example, export.xls.
63
   */
64
  function set_headers($filename) {
65
    drupal_add_http_header('Content-Type', 'application/force-download');
66
    drupal_add_http_header('Pragma', 'public');
67
    drupal_add_http_header('Cache-Control', 'max-age=0');
68
  }
69

    
70
  /**
71
   * Write the start of the export file.
72
   *
73
   * @param $file_handle
74
   *   A PHP file handle to the export file.
75
   */
76
  function bof(&$file_handle) {
77
  }
78

    
79
  /**
80
   * Write the end of the export file.
81
   *
82
   * @param $file_handle
83
   *   A PHP file handle to the export file.
84
   */
85
  function eof(&$file_handle, $row_count, $col_count) {
86
  }
87

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