]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | namespace Wallabag\CoreBundle\Filter; | |
4 | ||
5 | use Symfony\Component\Form\AbstractType; | |
6 | use Symfony\Component\Form\FormBuilderInterface; | |
7 | use Symfony\Component\OptionsResolver\OptionsResolver; | |
8 | use Lexik\Bundle\FormFilterBundle\Filter\Query\QueryInterface; | |
9 | ||
10 | class EntryFilterType extends AbstractType | |
11 | { | |
12 | public function buildForm(FormBuilderInterface $builder, array $options) | |
13 | { | |
14 | $builder | |
15 | ->add('readingTime', 'filter_number_range') | |
16 | ->add('createdAt', 'filter_date_range', array( | |
17 | 'left_date_options' => array( | |
18 | 'attr' => array( | |
19 | 'placeholder' => 'dd/mm/yyyy', | |
20 | ), | |
21 | 'format' => 'dd/MM/yyyy', | |
22 | 'widget' => 'single_text', | |
23 | ), | |
24 | 'right_date_options' => array( | |
25 | 'attr' => array( | |
26 | 'placeholder' => 'dd/mm/yyyy', | |
27 | ), | |
28 | 'format' => 'dd/MM/yyyy', | |
29 | 'widget' => 'single_text', | |
30 | ), | |
31 | ) | |
32 | ) | |
33 | ->add('domainName', 'filter_text', array( | |
34 | 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) { | |
35 | $value = $values['value']; | |
36 | if (strlen($value) <= 2 || empty($value)) { | |
37 | return; | |
38 | } | |
39 | $expression = $filterQuery->getExpr()->like($field, $filterQuery->getExpr()->literal('%'.$value.'%')); | |
40 | ||
41 | return $filterQuery->createCondition($expression); | |
42 | }, | |
43 | )) | |
44 | ->add('isArchived', 'filter_checkbox') | |
45 | ->add('isStarred', 'filter_checkbox') | |
46 | ->add('previewPicture', 'filter_checkbox', array( | |
47 | 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) { | |
48 | if (false === $values['value']) { | |
49 | return; | |
50 | } | |
51 | ||
52 | $expression = $filterQuery->getExpr()->isNotNull($field); | |
53 | ||
54 | return $filterQuery->createCondition($expression); | |
55 | }, | |
56 | )); | |
57 | } | |
58 | ||
59 | public function getName() | |
60 | { | |
61 | return 'entry_filter'; | |
62 | } | |
63 | ||
64 | public function configureOptions(OptionsResolver $resolver) | |
65 | { | |
66 | $resolver->setDefaults(array( | |
67 | 'csrf_protection' => false, | |
68 | 'validation_groups' => array('filtering'), | |
69 | )); | |
70 | } | |
71 | } |