class ViewsDataExportJSONExporter in Views data export - JSON support 7.2
Exporter for creating TXT files.
Hierarchy
- class \ViewsDataExportExporter implements ViewsDataExportExporterInterface
- class \ViewsDataExportJSONExporter
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) {
}
}