Skip to content

Commit

Permalink
More gracefully handle no response->data from a Report in the Reports…
Browse files Browse the repository at this point in the history
… controller.
  • Loading branch information
mark-unwin committed Feb 2, 2024
1 parent e490e4d commit f780c19
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions app/Controllers/Reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ public function execute($id)

$breadcrumb = new stdClass();
$breadcrumb->url = url_to('reportsExecute', $this->resp->meta->id);
$breadcrumb->name = $this->resp->meta->name ;
$breadcrumb->name = (!empty($this->resp->meta->name)) ? $this->resp->meta->name : '';
$this->resp->meta->breadcrumbs[] = $breadcrumb;
$this->resp->data = format_data($this->resp->data, 'devices');
$this->resp->data = (!empty($this->resp->data)) ? format_data($this->resp->data, 'devices') : array();

$this->resp->meta->total = count($this->resp->data);
$this->resp->meta->filtered = count($this->resp->data);
Expand All @@ -83,7 +83,11 @@ public function execute($id)
return true;
}
if (empty($this->resp->data)) {
\Config\Services::session()->setFlashdata('error', 'No data returned when running report.');
if (empty($this->resp->errors)) {
\Config\Services::session()->setFlashdata('error', 'No data returned when running report.');
} else {
\Config\Services::session()->setFlashdata('error', $this->resp->errors);
}
return redirect()->route('devicesCollection');
}
if ($this->resp->meta->filtered === $this->resp->meta->limit) {
Expand Down

0 comments on commit f780c19

Please sign in to comment.