]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php
Merge pull request #2683 from wallabag/credentials-in-db
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Form / Type / EntryFilterType.php
index ab27ec8e3407486671a151b8bf69110d34d0cffd..6a4c485f6d696f4525c354c1865ea3d7c0a6b3e4 100644 (file)
@@ -34,7 +34,7 @@ class EntryFilterType extends AbstractType
         $this->user = $tokenStorage->getToken() ? $tokenStorage->getToken()->getUser() : null;
 
         if (null === $this->user || !is_object($this->user)) {
-            return null;
+            return;
         }
     }
 
@@ -42,8 +42,14 @@ class EntryFilterType extends AbstractType
     {
         $builder
             ->add('readingTime', NumberRangeFilterType::class, [
-                'left_number_options' => ['condition_operator' => FilterOperands::OPERATOR_GREATER_THAN_EQUAL, 'attr' => ['min' => 0]],
-                'right_number_options' => ['condition_operator' => FilterOperands::OPERATOR_LOWER_THAN_EQUAL, 'attr' => ['min' => 0]],
+                'left_number_options' => [
+                    'condition_operator' => FilterOperands::OPERATOR_GREATER_THAN_EQUAL,
+                    'attr' => ['min' => 0],
+                ],
+                'right_number_options' => [
+                    'condition_operator' => FilterOperands::OPERATOR_LOWER_THAN_EQUAL,
+                    'attr' => ['min' => 0],
+                ],
                 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) {
                     $lower = $values['value']['left_number'][0];
                     $upper = $values['value']['right_number'][0];
@@ -144,6 +150,20 @@ class EntryFilterType extends AbstractType
                 },
                 'label' => 'entry.filters.preview_picture_label',
             ])
+            ->add('isPublic', CheckboxFilterType::class, [
+                'apply_filter' => function (QueryInterface $filterQuery, $field, $values) {
+                    if (false === $values['value']) {
+                        return;
+                    }
+
+                    // is_public isn't a real field
+                    // we should use the "uid" field to determine if the entry has been made public
+                    $expression = $filterQuery->getExpr()->isNotNull($values['alias'].'.uid');
+
+                    return $filterQuery->createCondition($expression);
+                },
+                'label' => 'entry.filters.is_public_label',
+            ])
             ->add('language', ChoiceFilterType::class, [
                 'choices' => array_flip($this->repository->findDistinctLanguageByUser($this->user->getId())),
                 'label' => 'entry.filters.language_label',