Skip to content

Commit

Permalink
Fix range filter zero(falsy) value
Browse files Browse the repository at this point in the history
  • Loading branch information
K0nias authored and paveljanda committed Jun 25, 2020
1 parent c4e1a11 commit bd042d1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/NetteDatabaseDataSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,11 @@ protected function applyFilterRange(FilterRange $filter): void
$valueFrom = $conditions[$filter->getColumn()]['from'];
$valueTo = $conditions[$filter->getColumn()]['to'];

if ($valueFrom) {
if ($valueFrom !== null && $valueFrom !== '') {
$this->applyWhere($filter->getColumn(), $valueFrom, '>=');
}

if ($valueTo) {
if ($valueTo !== null && $valueTo !== '') {
$this->applyWhere($filter->getColumn(), $valueTo, '<=');
}
}
Expand Down
9 changes: 8 additions & 1 deletion tests/Cases/NetteDatabaseDataSourceTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,16 @@ final class NetteDatabaseDataSourceTest extends TestCase
$filter5 = new FilterDate($this->grid, 'date', 'Date', 'date');
$filter5->setValue('12. 12. 2012');

$filter6 = new FilterRange($this->grid, 'range', 'Range', 'id', 'To');
$filter6->setValue(['from' => '', 'to' => 0]);

$s->filter([
$filter1,
$filter2,
$filter3,
$filter4,
$filter5,
$filter6
]);

$q = $s->getQuery();
Expand All @@ -214,7 +218,9 @@ final class NetteDatabaseDataSourceTest extends TestCase
AND id >= ?
AND DATE(created) >= ?
AND DATE(created) <= ?
AND DATE(date) = ?';
AND DATE(date) = ?
AND id <= ?
';

Assert::same(trim(preg_replace('/\s+/', ' ', $expected_query)), $q[0]);

Expand All @@ -228,6 +234,7 @@ final class NetteDatabaseDataSourceTest extends TestCase
'2003-02-01',
'2149-12-03',
'2012-12-12',
0,
];

Assert::same($expectedParams, $q[1]);
Expand Down

0 comments on commit bd042d1

Please sign in to comment.