diff options
author | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-06-17 23:48:51 +0200 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-06-23 09:41:30 +0200 |
commit | 1bdbc39f021c2505865cebe828310c549f586826 (patch) | |
tree | 732f036b4bca4668756b2bf6ba9ef1dc391750de /src/Wallabag | |
parent | d37bb05c881bfdbeb1144b327edd4dcc2cbb163f (diff) | |
download | wallabag-1bdbc39f021c2505865cebe828310c549f586826.tar.gz wallabag-1bdbc39f021c2505865cebe828310c549f586826.tar.zst wallabag-1bdbc39f021c2505865cebe828310c549f586826.zip |
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).
Diffstat (limited to 'src/Wallabag')
-rw-r--r-- | src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php b/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php index bc59c9a1..9d63a8a9 100644 --- a/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php +++ b/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php | |||
@@ -36,17 +36,26 @@ class EntryFilterType extends AbstractType | |||
36 | $builder | 36 | $builder |
37 | ->add('readingTime', NumberRangeFilterType::class, [ | 37 | ->add('readingTime', NumberRangeFilterType::class, [ |
38 | 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) { | 38 | 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) { |
39 | $value = $values['value']; | 39 | $lower = $values['value']['left_number'][0]; |
40 | $upper = $values['value']['right_number'][0]; | ||
41 | |||
42 | $min = (int) ($lower * $this->user->getConfig()->getReadingSpeed()); | ||
43 | $max = (int) ($upper * $this->user->getConfig()->getReadingSpeed()); | ||
40 | 44 | ||
41 | if (null === $value['left_number'][0] || null === $value['right_number'][0]) { | 45 | if (null === $lower && null === $upper) { |
46 | // no value? no filter | ||
42 | return; | 47 | return; |
48 | } else if (null === $lower && null !== $upper) { | ||
49 | // only lower value is defined: query all entries with reading LOWER THAN this value | ||
50 | $expression = $filterQuery->getExpr()->lte($field, $max); | ||
51 | } else if (null !== $lower && null === $upper) { | ||
52 | // only upper value is defined: query all entries with reading GREATER THAN this value | ||
53 | $expression = $filterQuery->getExpr()->gte($field, $min); | ||
54 | } else { | ||
55 | // both value are defined, perform a between | ||
56 | $expression = $filterQuery->getExpr()->between($field, $min, $max); | ||
43 | } | 57 | } |
44 | 58 | ||
45 | $min = (int) ($value['left_number'][0] * $this->user->getConfig()->getReadingSpeed()); | ||
46 | $max = (int) ($value['right_number'][0] * $this->user->getConfig()->getReadingSpeed()); | ||
47 | |||
48 | $expression = $filterQuery->getExpr()->between($field, $min, $max); | ||
49 | |||
50 | return $filterQuery->createCondition($expression); | 59 | return $filterQuery->createCondition($expression); |
51 | }, | 60 | }, |
52 | 'label' => 'entry.filters.reading_time.label', | 61 | 'label' => 'entry.filters.reading_time.label', |