]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php
Jump to Symfony 3.1
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Form / Type / EntryFilterType.php
index dcdb3ab72965b3bbcea8920e4384c8d39d342988..bc59c9a1461ac86bb095246b78d1637fa671bf9f 100644 (file)
@@ -35,6 +35,20 @@ class EntryFilterType extends AbstractType
     {
         $builder
             ->add('readingTime', NumberRangeFilterType::class, [
+                'apply_filter' => function (QueryInterface $filterQuery, $field, $values) {
+                    $value = $values['value'];
+
+                    if (null === $value['left_number'][0] || null === $value['right_number'][0]) {
+                        return;
+                    }
+
+                    $min = (int) ($value['left_number'][0] * $this->user->getConfig()->getReadingSpeed());
+                    $max = (int) ($value['right_number'][0] * $this->user->getConfig()->getReadingSpeed());
+
+                    $expression = $filterQuery->getExpr()->between($field, $min, $max);
+
+                    return $filterQuery->createCondition($expression);
+                },
                 'label' => 'entry.filters.reading_time.label',
             ])
             ->add('createdAt', DateRangeFilterType::class, [
@@ -73,6 +87,18 @@ class EntryFilterType extends AbstractType
             ->add('isStarred', CheckboxFilterType::class, [
                 'label' => 'entry.filters.starred_label',
             ])
+            ->add('isUnread', CheckboxFilterType::class, [
+                'label' => 'entry.filters.unread_label',
+                'apply_filter' => function (QueryInterface $filterQuery, $field, $values) {
+                    if (false === $values['value']) {
+                        return;
+                    }
+
+                    $expression = $filterQuery->getExpr()->eq('e.isArchived', 'false');
+
+                    return $filterQuery->createCondition($expression);
+                },
+            ])
             ->add('previewPicture', CheckboxFilterType::class, [
                 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) {
                     if (false === $values['value']) {
@@ -87,7 +113,6 @@ class EntryFilterType extends AbstractType
             ])
             ->add('language', ChoiceFilterType::class, [
                 'choices' => array_flip($this->repository->findDistinctLanguageByUser($this->user->getId())),
-                'choices_as_values' => true,
                 'label' => 'entry.filters.language_label',
             ])
         ;