X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FForm%2FType%2FEntryFilterType.php;h=6a4c485f6d696f4525c354c1865ea3d7c0a6b3e4;hb=822c877949aff8ae57677671115f8f4fc69588d5;hp=a3e36fddd344304ed9c5630a38a905fba27f8bf8;hpb=a4de2351a0fbae735cad234ca8a50bdee7632b68;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php b/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php index a3e36fdd..6a4c485f 100644 --- a/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php +++ b/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php @@ -3,6 +3,7 @@ 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; @@ -11,6 +12,7 @@ use Lexik\Bundle\FormFilterBundle\Filter\Form\Type\CheckboxFilterType; use Lexik\Bundle\FormFilterBundle\Filter\Form\Type\ChoiceFilterType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; @@ -32,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; } } @@ -40,6 +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], + ], 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) { $lower = $values['value']['left_number'][0]; $upper = $values['value']['right_number'][0]; @@ -89,12 +99,27 @@ class EntryFilterType extends AbstractType if (strlen($value) <= 2 || empty($value)) { return; } - $expression = $filterQuery->getExpr()->like($field, $filterQuery->getExpr()->literal('%'.$value.'%')); + $expression = $filterQuery->getExpr()->like($field, $filterQuery->getExpr()->lower($filterQuery->getExpr()->literal('%'.$value.'%'))); return $filterQuery->createCondition($expression); }, 'label' => 'entry.filters.domain_label', ]) + ->add('httpStatus', TextFilterType::class, [ + 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) { + $value = $values['value']; + if (false === array_key_exists($value, Response::$statusTexts)) { + return; + } + + $paramName = sprintf('%s', str_replace('.', '_', $field)); + $expression = $filterQuery->getExpr()->eq($field, ':'.$paramName); + $parameters = array($paramName => $value); + + return $filterQuery->createCondition($expression, $parameters); + }, + 'label' => 'entry.filters.http_status_label', + ]) ->add('isArchived', CheckboxFilterType::class, [ 'label' => 'entry.filters.archived_label', ]) @@ -125,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',