diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Form/Type')
-rw-r--r-- | src/Wallabag/CoreBundle/Form/Type/EditEntryType.php | 5 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php | 98 |
2 files changed, 98 insertions, 5 deletions
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 | |||
16 | $builder | 16 | $builder |
17 | ->add('title', TextType::class, array('required' => true)) | 17 | ->add('title', TextType::class, array('required' => true)) |
18 | ->add('is_public', CheckboxType::class, array('required' => false)) | 18 | ->add('is_public', CheckboxType::class, array('required' => false)) |
19 | // @todo: add autocomplete | ||
20 | // ->add('tags', 'entity', array( | ||
21 | // 'class' => 'Wallabag\CoreBundle\Entity\Tag', | ||
22 | // 'choice_translation_domain' => true, | ||
23 | // )) | ||
24 | ->add('save', SubmitType::class) | 19 | ->add('save', SubmitType::class) |
25 | ; | 20 | ; |
26 | } | 21 | } |
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 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Form\Type; | ||
4 | |||
5 | use Doctrine\ORM\EntityRepository; | ||
6 | use Lexik\Bundle\FormFilterBundle\Filter\Query\QueryInterface; | ||
7 | use Lexik\Bundle\FormFilterBundle\Filter\Form\Type\NumberRangeFilterType; | ||
8 | use Lexik\Bundle\FormFilterBundle\Filter\Form\Type\DateRangeFilterType; | ||
9 | use Lexik\Bundle\FormFilterBundle\Filter\Form\Type\TextFilterType; | ||
10 | use Lexik\Bundle\FormFilterBundle\Filter\Form\Type\CheckboxFilterType; | ||
11 | use Lexik\Bundle\FormFilterBundle\Filter\Form\Type\ChoiceFilterType; | ||
12 | use Symfony\Component\Form\AbstractType; | ||
13 | use Symfony\Component\Form\FormBuilderInterface; | ||
14 | use Symfony\Component\OptionsResolver\OptionsResolver; | ||
15 | use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; | ||
16 | |||
17 | class EntryFilterType extends AbstractType | ||
18 | { | ||
19 | private $user; | ||
20 | private $repository; | ||
21 | |||
22 | /** | ||
23 | * Repository & user are used to get a list of language entries for this user. | ||
24 | * | ||
25 | * @param EntityRepository $entryRepository | ||
26 | * @param TokenStorage $token | ||
27 | */ | ||
28 | public function __construct(EntityRepository $entryRepository, TokenStorage $token) | ||
29 | { | ||
30 | $this->repository = $entryRepository; | ||
31 | $this->user = $token->getToken()->getUser(); | ||
32 | } | ||
33 | |||
34 | public function buildForm(FormBuilderInterface $builder, array $options) | ||
35 | { | ||
36 | $builder | ||
37 | ->add('readingTime', NumberRangeFilterType::class) | ||
38 | ->add('createdAt', DateRangeFilterType::class, array( | ||
39 | 'left_date_options' => array( | ||
40 | 'attr' => array( | ||
41 | 'placeholder' => 'dd/mm/yyyy', | ||
42 | ), | ||
43 | 'format' => 'dd/MM/yyyy', | ||
44 | 'widget' => 'single_text', | ||
45 | ), | ||
46 | 'right_date_options' => array( | ||
47 | 'attr' => array( | ||
48 | 'placeholder' => 'dd/mm/yyyy', | ||
49 | ), | ||
50 | 'format' => 'dd/MM/yyyy', | ||
51 | 'widget' => 'single_text', | ||
52 | ), | ||
53 | ) | ||
54 | ) | ||
55 | ->add('domainName', TextFilterType::class, array( | ||
56 | 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) { | ||
57 | $value = $values['value']; | ||
58 | if (strlen($value) <= 2 || empty($value)) { | ||
59 | return; | ||
60 | } | ||
61 | $expression = $filterQuery->getExpr()->like($field, $filterQuery->getExpr()->literal('%'.$value.'%')); | ||
62 | |||
63 | return $filterQuery->createCondition($expression); | ||
64 | }, | ||
65 | )) | ||
66 | ->add('isArchived', CheckboxFilterType::class) | ||
67 | ->add('isStarred', CheckboxFilterType::class) | ||
68 | ->add('previewPicture', CheckboxFilterType::class, array( | ||
69 | 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) { | ||
70 | if (false === $values['value']) { | ||
71 | return; | ||
72 | } | ||
73 | |||
74 | $expression = $filterQuery->getExpr()->isNotNull($field); | ||
75 | |||
76 | return $filterQuery->createCondition($expression); | ||
77 | }, | ||
78 | )) | ||
79 | ->add('language', ChoiceFilterType::class, array( | ||
80 | 'choices' => array_flip($this->repository->findDistinctLanguageByUser($this->user->getId())), | ||
81 | 'choices_as_values' => true, | ||
82 | )) | ||
83 | ; | ||
84 | } | ||
85 | |||
86 | public function getBlockPrefix() | ||
87 | { | ||
88 | return 'entry_filter'; | ||
89 | } | ||
90 | |||
91 | public function configureOptions(OptionsResolver $resolver) | ||
92 | { | ||
93 | $resolver->setDefaults(array( | ||
94 | 'csrf_protection' => false, | ||
95 | 'validation_groups' => array('filtering'), | ||
96 | )); | ||
97 | } | ||
98 | } | ||