X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FForm%2FType%2FEntryFilterType.php;h=61ad99a8656c0b28f9a8fea472c05226d63fb36c;hb=8ee7b1603d23297a6c183105f79b1290ce9828bf;hp=7b02f85c35e336671d3ee19f87f22ef8be677aec;hpb=68003139e133835805b143b62c4407f19b495dab;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php b/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php index 7b02f85c..61ad99a8 100644 --- a/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php +++ b/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php @@ -3,12 +3,13 @@ namespace Wallabag\CoreBundle\Form\Type; use Doctrine\ORM\EntityRepository; -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\FilterOperands; 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; @@ -22,9 +23,6 @@ class EntryFilterType extends AbstractType /** * Repository & user are used to get a list of language entries for this user. - * - * @param EntityRepository $entryRepository - * @param TokenStorageInterface $tokenStorage */ public function __construct(EntityRepository $entryRepository, TokenStorageInterface $tokenStorage) { @@ -32,8 +30,8 @@ class EntryFilterType extends AbstractType $this->user = $tokenStorage->getToken() ? $tokenStorage->getToken()->getUser() : null; - if (null === $this->user || !is_object($this->user)) { - return null; + if (null === $this->user || !\is_object($this->user)) { + return; } } @@ -41,12 +39,20 @@ 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]; - $min = (int) ($lower * $this->user->getConfig()->getReadingSpeed()); - $max = (int) ($upper * $this->user->getConfig()->getReadingSpeed()); + $min = (int) ($lower * $this->user->getConfig()->getReadingSpeed() / 200); + $max = (int) ($upper * $this->user->getConfig()->getReadingSpeed() / 200); if (null === $lower && null === $upper) { // no value? no filter @@ -67,30 +73,29 @@ class EntryFilterType extends AbstractType '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', + 'left_date_options' => [ + 'attr' => [ + 'placeholder' => 'yyyy-mm-dd', ], - 'right_date_options' => [ - 'attr' => [ - 'placeholder' => 'dd/mm/yyyy', - ], - 'format' => 'dd/MM/yyyy', - 'widget' => 'single_text', + 'format' => 'yyyy-MM-dd', + 'widget' => 'single_text', + ], + 'right_date_options' => [ + 'attr' => [ + 'placeholder' => 'yyyy-mm-dd', ], - 'label' => 'entry.filters.created_at.label', - ] - ) + 'format' => 'yyyy-MM-dd', + 'widget' => 'single_text', + ], + 'label' => 'entry.filters.created_at.label', + ]) ->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()->literal('%'.$value.'%')); + $expression = $filterQuery->getExpr()->like($field, $filterQuery->getExpr()->lower($filterQuery->getExpr()->literal('%' . $value . '%'))); return $filterQuery->createCondition($expression); }, @@ -99,13 +104,13 @@ class EntryFilterType extends AbstractType ->add('httpStatus', TextFilterType::class, [ 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) { $value = $values['value']; - if (false === array_key_exists($value, Response::$statusTexts)) { + 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); + $expression = $filterQuery->getExpr()->eq($field, ':' . $paramName); + $parameters = [$paramName => $value]; return $filterQuery->createCondition($expression, $parameters); }, @@ -141,6 +146,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',