You are here

class webform_exporter_delimited in Webform 6.2

Same name and namespace in other branches
  1. 5.2 webform_export.inc \webform_exporter_delimited
  2. 6.3 includes/webform.export.inc \webform_exporter_delimited
  3. 7.4 includes/exporters/webform_exporter_delimited.inc \webform_exporter_delimited
  4. 7.3 includes/webform.export.inc \webform_exporter_delimited

Hierarchy

Expanded class hierarchy of webform_exporter_delimited

1 string reference to 'webform_exporter_delimited'
webform_webform_exporters in ./webform_export.inc
Implementation of hook_webform_exporters().

File

./webform_export.inc, line 96
Provides several different handlers for exporting webform results.

View source
class webform_exporter_delimited extends webform_exporter {
  var $delimiter;
  function webform_exporter_delimited($options) {
    $this->delimiter = isset($options['delimiter']) ? $options['delimiter'] : ',';

    // Convert tabs.
    if ($this->delimiter == '\\t') {
      $this->delimiter = "\t";
    }
  }
  function bof(&$file_handle) {
    $output = '';

    // Include at BOM at the beginning of the file for Little Endian.
    // This makes tab-separated imports work correctly in MS Excel.
    if (function_exists('mb_convert_encoding') && $this->delimiter == '\\t') {
      $output = chr(255) . chr(254);
    }
    @fwrite($file_handle, $output);
  }
  function add_row(&$file_handle, $data) {
    foreach ($data as $key => $value) {

      // Escape inner quotes and wrap all contents in new quotes.
      $data[$key] = '"' . str_replace('"', '""', $value) . '"';
    }
    $row = implode($this->delimiter, $data) . "\n";
    if (function_exists('mb_convert_encoding')) {
      $row = mb_convert_encoding($row, 'UTF-16LE', 'UTF-8');
    }
    @fwrite($file_handle, $row);
  }
  function set_headers($filename) {
    parent::set_headers($filename);

    // Convert tabs.
    if ($this->delimiter == "\t") {
      $extension = 'tsv';
      $content_type = 'text/tab-separated-values';
    }
    else {
      $extension = 'csv';
      $content_type = 'text/csv';
    }
    drupal_set_header("Content-Type: {$content_type}");
    drupal_set_header("Content-Disposition: attachment; filename={$filename}.{$extension}");
  }

}

Members