Skip to content

Commit

Permalink
Merge pull request #65 from sparkison/master
Browse files Browse the repository at this point in the history
fix required param after optional for PHP 8+; add option for CSV save to disk
  • Loading branch information
Jimmy-JS authored Aug 25, 2021
2 parents d6fd6a8 + bcb342b commit 6130ad1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/ReportGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct()
$this->applyFlush = (bool) Config::get('report-generator.flush', true);
}

public function of($title, Array $meta = [], $query, Array $columns)
public function of($title, Array $meta, $query, Array $columns)
{
$this->headers = [
'title' => $title,
Expand Down
19 changes: 15 additions & 4 deletions src/ReportMedia/CSVReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ class CSVReport extends ReportGenerator
{
protected $showMeta = false;

public function download($filename)
public function download($filename, $save = false)
{
if (!class_exists(Writer::class)) {
throw new Exception('Please install league/csv to generate CSV Report!');
}

$csv = Writer::createFromFileObject(new \SplTempFileObject());
if ($save) {
$csv = Writer::createFromPath($filename, 'w');
} else {
$csv = Writer::createFromFileObject(new \SplTempFileObject());
}

if ($this->showMeta) {
foreach ($this->headers['meta'] as $key => $value) {
Expand Down Expand Up @@ -48,7 +52,14 @@ public function download($filename)
$ctr++;
}

$csv->output($filename . '.csv');
if (!$save) {
$csv->output($filename . '.csv');
}
}

public function store($filename)
{
$this->download($filename, true);
}

private function formatRow($result)
Expand Down Expand Up @@ -77,4 +88,4 @@ private function formatRow($result)

return $rows;
}
}
}

0 comments on commit 6130ad1

Please sign in to comment.