]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php
php-cs-fixer
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Form / Type / EntryFilterType.php
index 556578d1a7bf6cc896d2888a07dd70c503a85c26..702c7f7aa03d196939d8f51cd747b803794e34fa 100644 (file)
@@ -4,12 +4,12 @@ namespace Wallabag\CoreBundle\Form\Type;
 
 use Doctrine\ORM\EntityRepository;
 use Lexik\Bundle\FormFilterBundle\Filter\FilterOperands;
-use Lexik\Bundle\FormFilterBundle\Filter\Query\QueryInterface;
-use Lexik\Bundle\FormFilterBundle\Filter\Form\Type\NumberRangeFilterType;
-use Lexik\Bundle\FormFilterBundle\Filter\Form\Type\DateRangeFilterType;
-use Lexik\Bundle\FormFilterBundle\Filter\Form\Type\TextFilterType;
 use Lexik\Bundle\FormFilterBundle\Filter\Form\Type\CheckboxFilterType;
 use Lexik\Bundle\FormFilterBundle\Filter\Form\Type\ChoiceFilterType;
+use Lexik\Bundle\FormFilterBundle\Filter\Form\Type\DateRangeFilterType;
+use Lexik\Bundle\FormFilterBundle\Filter\Form\Type\NumberRangeFilterType;
+use Lexik\Bundle\FormFilterBundle\Filter\Form\Type\TextFilterType;
+use Lexik\Bundle\FormFilterBundle\Filter\Query\QueryInterface;
 use Symfony\Component\Form\AbstractType;
 use Symfony\Component\Form\FormBuilderInterface;
 use Symfony\Component\HttpFoundation\Response;
@@ -33,7 +33,7 @@ class EntryFilterType extends AbstractType
 
         $this->user = $tokenStorage->getToken() ? $tokenStorage->getToken()->getUser() : null;
 
-        if (null === $this->user || !is_object($this->user)) {
+        if (null === $this->user || !\is_object($this->user)) {
             return;
         }
     }
@@ -96,10 +96,10 @@ class EntryFilterType extends AbstractType
             ->add('domainName', TextFilterType::class, [
                 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) {
                     $value = $values['value'];
-                    if (strlen($value) <= 2 || empty($value)) {
+                    if (\strlen($value) <= 2 || empty($value)) {
                         return;
                     }
-                    $expression = $filterQuery->getExpr()->like($field, $filterQuery->getExpr()->lower($filterQuery->getExpr()->literal('%'.$value.'%')));
+                    $expression = $filterQuery->getExpr()->like($field, $filterQuery->getExpr()->lower($filterQuery->getExpr()->literal('%' . $value . '%')));
 
                     return $filterQuery->createCondition($expression);
                 },
@@ -113,8 +113,8 @@ class EntryFilterType extends AbstractType
                     }
 
                     $paramName = sprintf('%s', str_replace('.', '_', $field));
-                    $expression = $filterQuery->getExpr()->eq($field, ':'.$paramName);
-                    $parameters = array($paramName => $value);
+                    $expression = $filterQuery->getExpr()->eq($field, ':' . $paramName);
+                    $parameters = [$paramName => $value];
 
                     return $filterQuery->createCondition($expression, $parameters);
                 },
@@ -150,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',