You are here

class ViewsDataExportJSONExporter in Views data export - JSON support 7.2

Exporter for creating TXT files.

Hierarchy

Expanded class hierarchy of ViewsDataExportJSONExporter

1 string reference to 'ViewsDataExportJSONExporter'
views_data_export_json_views_plugins in ./views_data_export_json.views.inc
Implementation of hook_views_plugins().

File

exporters/views_data_export_json_exporter.inc, line 6

View source
class ViewsDataExportJSONExporter extends ViewsDataExportExporter {
  function __construct($options) {
    $this->options = $options;
    parent::__construct($options);
  }

  /**
   * Tell the world whether we support Hide If Empty views option
   */
  function supports_hide_if_empty() {
    return TRUE;
  }

  /**
   * Set options fields and default values.
   *
   * @return
   * An array of options information.
   */
  function option_definition() {
    $options = array();
    return $options;
  }
  function add_row(&$file_handle, $data, $row_count, $field_titles) {
    $row = drupal_json_encode($data);
    $row .= ',' . PHP_EOL;
    fwrite($file_handle, $row);
  }
  function add_header(&$file_handle, $filename) {
    return 'file header';
  }
  function get_headers($filename) {
    $headers = parent::get_headers($filename);
    $extension = 'json';
    $content_type = 'application/json';
    $headers['Content-Type'] = $content_type;
    $headers['Content-Disposition'] = "attachment; filename={$filename}.{$extension}";
    return $headers;
  }

  /**
   * Write the start of the export file.
   *
   * @param $file_handle
   *   A PHP file handle to the export file.
   */
  function bof(&$file_handle) {
    $bof = '{"Views Data Export" : [';
    fwrite($file_handle, $bof);
  }

  /**
   * Write the end of the export file.
   *
   * @param $file_handle
   *   A PHP file handle to the export file.
   */
  function eof(&$file_handle, $row_count, $col_count) {
    fseek($file_handle, -2, SEEK_END);
    $eof = ']}';
    fwrite($file_handle, $eof);
  }

  /**
   * Allow final processing of the results.
   *
   * @param $results
   *   An array of result data, including:
   *   - file_name: The full file path of the generated file.
   *   - row_count: The final number of rows in the generated file.
   */
  function post_process(&$results) {
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ViewsDataExportExporter::$options public property
ViewsDataExportExporter::clean_xml_tag function
ViewsDataExportJSONExporter::add_header function
ViewsDataExportJSONExporter::add_row function Add a single row to the export file. Overrides ViewsDataExportExporter::add_row
ViewsDataExportJSONExporter::bof function Write the start of the export file. Overrides ViewsDataExportExporter::bof
ViewsDataExportJSONExporter::eof function Write the end of the export file. Overrides ViewsDataExportExporter::eof
ViewsDataExportJSONExporter::get_headers function Provide headers to the page when an export file is being downloaded. Overrides ViewsDataExportExporter::get_headers
ViewsDataExportJSONExporter::option_definition function Set options fields and default values. Overrides ViewsDataExportExporter::option_definition
ViewsDataExportJSONExporter::post_process function Allow final processing of the results. Overrides ViewsDataExportExporter::post_process
ViewsDataExportJSONExporter::supports_hide_if_empty function Tell the world whether we support Hide If Empty views option Overrides ViewsDataExportExporter::supports_hide_if_empty
ViewsDataExportJSONExporter::__construct function Constructor for views_data_export_exporter classes. Overrides ViewsDataExportExporter::__construct