function views_data_export_plugin_style_export::render_body in Views data export 7.4
Same name and namespace in other branches
- 6.3 plugins/views_data_export_plugin_style_export.inc \views_data_export_plugin_style_export::render_body()
- 6 plugins/views_data_export_plugin_style_export.inc \views_data_export_plugin_style_export::render_body()
- 6.2 plugins/views_data_export_plugin_style_export.inc \views_data_export_plugin_style_export::render_body()
- 7 plugins/views_data_export_plugin_style_export.inc \views_data_export_plugin_style_export::render_body()
- 7.3 plugins/views_data_export_plugin_style_export.inc \views_data_export_plugin_style_export::render_body()
1 call to views_data_export_plugin_style_export::render_body()
- views_data_export_plugin_style_export::render in plugins/
views_data_export_plugin_style_export.inc - Render the display in this style.
File
- plugins/
views_data_export_plugin_style_export.inc, line 340 - Plugin include file for export style plugin.
Class
- views_data_export_plugin_style_export
- Generalized style plugin for export plugins.
Code
function render_body($file = null) {
// Return a value if we haven't been given a file to write to.
$return_a_value = is_null($file);
if ($return_a_value) {
// Write to our own memory stream.
$file = fopen('php://memory', 'w+');
}
if ($this
->uses_row_plugin() && empty($this->row_plugin)) {
vpr('views_plugin_style_default: Missing row plugin');
return;
}
$view = $this->view;
$fields =& $view->field;
$field_labels = $this->display->handler
->get_field_labels();
// Group the rows according to the grouping field, if specified.
$sets = $this
->render_grouping($this->view->result, $this->options['grouping']);
// Render each group separately and concatenate. Plugins may override this
// method if they wish some other way of handling grouping.
$output = '';
// $file = fopen('php://memory', 'w+');
$exporter = $this
->get_exporter();
$row_count = 0;
foreach ($sets as $title => $records) {
if ($this
->uses_row_plugin()) {
$rows = array();
foreach ($records as $row_index => $row) {
$this->view->row_index = $row_index;
$rows[] = $this->row_plugin
->render($row);
}
}
else {
$rows = $records;
}
$hide_empty_support = $exporter
->supports_hide_if_empty();
$themed_rows = array();
$keys = array_keys($fields);
foreach ($rows as $num => $row) {
$themed_rows[$num] = array();
foreach ($keys as $id) {
if (empty($fields[$id]->options['exclude'])) {
$content = $view->style_plugin->rendered_fields[$num][$id];
if ($hide_empty_support && !empty($fields[$id]->options['hide_empty'])) {
if ($fields[$id]
->is_value_empty($content, $fields[$id]->options['empty_zero'])) {
continue;
}
}
$themed_rows[$num][$id] = $content;
}
}
}
foreach ($themed_rows as $row) {
$exporter
->add_row($file, $row, $row_count, $field_labels);
$row_count++;
}
}
unset($this->view->row_index);
// Return a value if we haven't been given a file to write to.
if ($return_a_value) {
// Read from file and verify contents.
fseek($file, 0);
$contents = '';
while (!feof($file)) {
$contents .= fread($file, 8192);
}
// Close up the file stream.
fclose($file);
// Return the contents.
return $contents;
}
}