Skip to content

Commit

Permalink
Only create CSV headers if we have data in output_helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-unwin committed Feb 29, 2024
1 parent 30148ed commit 025217b
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions app/Helpers/output_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,18 +178,20 @@ function output_csv($instance)
}

// Our header line
$data_order_columns = array();
$count = count($instance->resp->data);
for ($i=0; $i < $count; $i++) {
foreach ($instance->resp->data[$i]->attributes as $key => $value) {
if (!in_array($key, $data_order_columns)) {
$data_order_columns[] = $key;
if (!empty($instance->resp->data)) {
$data_order_columns = array();
$count = count($instance->resp->data);
for ($i=0; $i < $count; $i++) {
foreach ($instance->resp->data[$i]->attributes as $key => $value) {
if (!in_array($key, $data_order_columns)) {
$data_order_columns[] = $key;
}
}
}
$instance->resp->meta->data_order = $data_order_columns;
$csv_header = $data_order_columns;
$output_csv = '"' . implode('","', $csv_header) . '"' . "\n";
}
$instance->resp->meta->data_order = $data_order_columns;
$csv_header = $data_order_columns;
$output_csv = '"' . implode('","', $csv_header) . '"' . "\n";

// Each individual data line
$output_escape_csv = @$instance->config->output_escape_csv;
Expand Down

0 comments on commit 025217b

Please sign in to comment.