]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php
manage assets through npm
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Form / Type / EntryFilterType.php
index ee10bc8b517135deac7303beea15fa7c00e2d11b..f3f848e9a6db0f667e5e80a0e9b308192a1dfc86 100644 (file)
@@ -34,25 +34,42 @@ class EntryFilterType extends AbstractType
     public function buildForm(FormBuilderInterface $builder, array $options)
     {
         $builder
-            ->add('readingTime', NumberRangeFilterType::class)
-            ->add('createdAt', DateRangeFilterType::class, array(
-                    'left_date_options' => array(
-                        'attr' => array(
+            ->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, [
+                    'left_date_options' => [
+                        'attr' => [
                             'placeholder' => 'dd/mm/yyyy',
-                        ),
+                        ],
                         'format' => 'dd/MM/yyyy',
                         'widget' => 'single_text',
-                    ),
-                    'right_date_options' => array(
-                        'attr' => array(
+                    ],
+                    'right_date_options' => [
+                        'attr' => [
                             'placeholder' => 'dd/mm/yyyy',
-                        ),
+                        ],
                         'format' => 'dd/MM/yyyy',
                         'widget' => 'single_text',
-                    ),
-                )
+                    ],
+                    'label' => 'entry.filters.created_at.label',
+                ]
             )
-            ->add('domainName', TextFilterType::class, array(
+            ->add('domainName', TextFilterType::class, [
                 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) {
                     $value = $values['value'];
                     if (strlen($value) <= 2 || empty($value)) {
@@ -62,10 +79,27 @@ class EntryFilterType extends AbstractType
 
                     return $filterQuery->createCondition($expression);
                 },
-            ))
-            ->add('isArchived', CheckboxFilterType::class)
-            ->add('isStarred', CheckboxFilterType::class)
-            ->add('previewPicture', CheckboxFilterType::class, array(
+                'label' => 'entry.filters.domain_label',
+            ])
+            ->add('isArchived', CheckboxFilterType::class, [
+                'label' => 'entry.filters.archived_label',
+            ])
+            ->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']) {
                         return;
@@ -75,11 +109,13 @@ class EntryFilterType extends AbstractType
 
                     return $filterQuery->createCondition($expression);
                 },
-            ))
-            ->add('language', ChoiceFilterType::class, array(
+                'label' => 'entry.filters.preview_picture_label',
+            ])
+            ->add('language', ChoiceFilterType::class, [
                 'choices' => array_flip($this->repository->findDistinctLanguageByUser($this->user->getId())),
                 'choices_as_values' => true,
-            ))
+                'label' => 'entry.filters.language_label',
+            ])
         ;
     }
 
@@ -90,9 +126,9 @@ class EntryFilterType extends AbstractType
 
     public function configureOptions(OptionsResolver $resolver)
     {
-        $resolver->setDefaults(array(
+        $resolver->setDefaults([
             'csrf_protection' => false,
-            'validation_groups' => array('filtering'),
-        ));
+            'validation_groups' => ['filtering'],
+        ]);
     }
 }