Skip to content

Commit

Permalink
set default value for years; min() and max() return values, not arrays
Browse files Browse the repository at this point in the history
PHP Warning:  min(): Array must contain at least one element in …/classes/DateRangeParameter.php on line 37, referer: http://…/reports/
PHP Warning:  max(): Array must contain at least one element in …/classes/DateRangeParameter.php on line 38, referer: http://…/reports/
PHP Fatal error:  Uncaught InvalidArgumentException: invalid date range: 1/NULL -> 12/NULL in …/classes/DateRangeParameter.php:82
Stack trace:
#0 …/classes/DateRangeParameter.php(87): DateRangeParameter->validateRange(Array)
#1 …/classes/DateRangeParameter.php(49): DateRangeParameter->encode(Array)
#2 …/reports/report.php(41): DateRangeParameter->process()
#3 {main}
  thrown in …/classes/DateRangeParameter.php on line 82, referer: http://…/reports/
  • Loading branch information
t4k committed Jul 9, 2019
1 parent ff0b9b1 commit 3e7e771
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions classes/DateRangeParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ public function value() {
if ($this->reportID===null) {
return array('m0'=>null,'y0'=>null,'m1'=>null,'y1'=>null);
} else if (! isset($_REQUEST["prm_$this->id"])) {
$years = $this->getSelectValues($this->parentID);
// set a default value of the current year to avoid errors when
// there are no reports
$years = (!empty($this->getSelectValues($this->parentID)) ? $this->getSelectValues($this->parentID) : array(date('Y')));
$y0 = min($years);
$y1 = max($years);
return array('m0'=>1,'y0'=>$y0['val'],'m1'=>12,'y1'=>$y1['val']);
return array('m0' => 1, 'y0' => $y0, 'm1' => 12, 'y1' => $y1);
} else {
return $this->decode($_REQUEST["prm_$this->id"]);
}
Expand Down

0 comments on commit 3e7e771

Please sign in to comment.