mirror of
https://github.com/wallabag/wallabag.git
synced 2024-11-27 11:31:05 +00:00
Handle only upper or only lower reading filter
When we select only one value in the reading time filter, we need to perform a query with only one value (greater than OR lower than).
This commit is contained in:
parent
d37bb05c88
commit
1bdbc39f02
1 changed files with 16 additions and 7 deletions
|
@ -36,16 +36,25 @@ class EntryFilterType extends AbstractType
|
|||
$builder
|
||||
->add('readingTime', NumberRangeFilterType::class, [
|
||||
'apply_filter' => function (QueryInterface $filterQuery, $field, $values) {
|
||||
$value = $values['value'];
|
||||
$lower = $values['value']['left_number'][0];
|
||||
$upper = $values['value']['right_number'][0];
|
||||
|
||||
if (null === $value['left_number'][0] || null === $value['right_number'][0]) {
|
||||
$min = (int) ($lower * $this->user->getConfig()->getReadingSpeed());
|
||||
$max = (int) ($upper * $this->user->getConfig()->getReadingSpeed());
|
||||
|
||||
if (null === $lower && null === $upper) {
|
||||
// no value? no filter
|
||||
return;
|
||||
}
|
||||
|
||||
$min = (int) ($value['left_number'][0] * $this->user->getConfig()->getReadingSpeed());
|
||||
$max = (int) ($value['right_number'][0] * $this->user->getConfig()->getReadingSpeed());
|
||||
|
||||
} else if (null === $lower && null !== $upper) {
|
||||
// only lower value is defined: query all entries with reading LOWER THAN this value
|
||||
$expression = $filterQuery->getExpr()->lte($field, $max);
|
||||
} else if (null !== $lower && null === $upper) {
|
||||
// only upper value is defined: query all entries with reading GREATER THAN this value
|
||||
$expression = $filterQuery->getExpr()->gte($field, $min);
|
||||
} else {
|
||||
// both value are defined, perform a between
|
||||
$expression = $filterQuery->getExpr()->between($field, $min, $max);
|
||||
}
|
||||
|
||||
return $filterQuery->createCondition($expression);
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue