From b0b893eafd3c1d66b8681a4a6420603af42ec084 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Wed, 20 Jan 2016 16:24:48 +0100 Subject: [#1604] First draft to fix SensioLabsInsight report --- .../CoreBundle/Form/Type/EditEntryType.php | 5 -- .../CoreBundle/Form/Type/EntryFilterType.php | 98 ++++++++++++++++++++++ 2 files changed, 98 insertions(+), 5 deletions(-) create mode 100644 src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php (limited to 'src/Wallabag/CoreBundle/Form') diff --git a/src/Wallabag/CoreBundle/Form/Type/EditEntryType.php b/src/Wallabag/CoreBundle/Form/Type/EditEntryType.php index 0cb29881..2b1e1ef4 100644 --- a/src/Wallabag/CoreBundle/Form/Type/EditEntryType.php +++ b/src/Wallabag/CoreBundle/Form/Type/EditEntryType.php @@ -16,11 +16,6 @@ class EditEntryType extends AbstractType $builder ->add('title', TextType::class, array('required' => true)) ->add('is_public', CheckboxType::class, array('required' => false)) - // @todo: add autocomplete - // ->add('tags', 'entity', array( - // 'class' => 'Wallabag\CoreBundle\Entity\Tag', - // 'choice_translation_domain' => true, - // )) ->add('save', SubmitType::class) ; } diff --git a/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php b/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php new file mode 100644 index 00000000..ee10bc8b --- /dev/null +++ b/src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php @@ -0,0 +1,98 @@ +repository = $entryRepository; + $this->user = $token->getToken()->getUser(); + } + + public function buildForm(FormBuilderInterface $builder, array $options) + { + $builder + ->add('readingTime', NumberRangeFilterType::class) + ->add('createdAt', DateRangeFilterType::class, array( + 'left_date_options' => array( + 'attr' => array( + 'placeholder' => 'dd/mm/yyyy', + ), + 'format' => 'dd/MM/yyyy', + 'widget' => 'single_text', + ), + 'right_date_options' => array( + 'attr' => array( + 'placeholder' => 'dd/mm/yyyy', + ), + 'format' => 'dd/MM/yyyy', + 'widget' => 'single_text', + ), + ) + ) + ->add('domainName', TextFilterType::class, array( + 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) { + $value = $values['value']; + if (strlen($value) <= 2 || empty($value)) { + return; + } + $expression = $filterQuery->getExpr()->like($field, $filterQuery->getExpr()->literal('%'.$value.'%')); + + return $filterQuery->createCondition($expression); + }, + )) + ->add('isArchived', CheckboxFilterType::class) + ->add('isStarred', CheckboxFilterType::class) + ->add('previewPicture', CheckboxFilterType::class, array( + 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) { + if (false === $values['value']) { + return; + } + + $expression = $filterQuery->getExpr()->isNotNull($field); + + return $filterQuery->createCondition($expression); + }, + )) + ->add('language', ChoiceFilterType::class, array( + 'choices' => array_flip($this->repository->findDistinctLanguageByUser($this->user->getId())), + 'choices_as_values' => true, + )) + ; + } + + public function getBlockPrefix() + { + return 'entry_filter'; + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults(array( + 'csrf_protection' => false, + 'validation_groups' => array('filtering'), + )); + } +} -- cgit v1.2.3