Skip to content

Commit

Permalink
Use safe_get_object_vars() method that checks if $data is indeed object
Browse files Browse the repository at this point in the history
  • Loading branch information
nickdekruijk committed Aug 30, 2019
1 parent 69785c9 commit 73623cb
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Controllers/ReportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,23 @@ public function show($slug, $id)
return '<table class="report">'.$response.'</table>';
}

private function safe_get_object_vars($data)
{
if (is_array($data)) {
return $data;
} else {
return get_object_vars($data);
}
}

public function csv($slug, $id)
{
$this->checkSlug($slug, 'read');
$data = $this->getQueryData($slug, $id);
$out = fopen('php://memory', 'w');
fputcsv($out, array_keys(get_object_vars($data[0])));
fputcsv($out, array_keys($this->safe_get_object_vars($data[0])));
foreach($data as $line) {
fputcsv($out, get_object_vars($line), $this->module('download_csv_delimiter') ?: ',');
fputcsv($out, $this->safe_get_object_vars($line), $this->module('download_csv_delimiter') ?: ',');
}
rewind($out);
$csv = stream_get_contents($out);
Expand Down

0 comments on commit 73623cb

Please sign in to comment.