]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/CoreBundle/Filter/EntryFilterType.php
Merge pull request #1372 from wallabag/v2-assign-tags
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Filter / EntryFilterType.php
CommitLineData
26864574
NL
1<?php
2
3namespace Wallabag\CoreBundle\Filter;
4
5use Symfony\Component\Form\AbstractType;
6use Symfony\Component\Form\FormBuilderInterface;
7use Symfony\Component\OptionsResolver\OptionsResolver;
443cecd2 8use Lexik\Bundle\FormFilterBundle\Filter\Query\QueryInterface;
26864574
NL
9
10class 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
JB
29 'widget' => 'single_text',
30 ),
31 ))
443cecd2 32 ->add('domainName', 'filter_text', array(
8ce32af6 33 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) {
443cecd2
NL
34 $value = $values['value'];
35 if (strlen($value) <= 3 || empty($value)) {
8ce32af6 36 return;
443cecd2
NL
37 }
38 $expression = $filterQuery->getExpr()->like($field, $filterQuery->getExpr()->literal('%'.$value.'%'));
8ce32af6 39
443cecd2 40 return $filterQuery->createCondition($expression);
8ce32af6 41 },
89659c9e
NL
42 ))
43 ->add('isArchived', 'filter_checkbox')
44 ->add('isStarred', 'filter_checkbox');
26864574
NL
45 }
46
47 public function getName()
48 {
49 return 'entry_filter';
50 }
51
52 public function configureOptions(OptionsResolver $resolver)
53 {
54 $resolver->setDefaults(array(
8ce32af6
JB
55 'csrf_protection' => false,
56 'validation_groups' => array('filtering'),
26864574
NL
57 ));
58 }
59}