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