wallabag/src/Wallabag/CoreBundle/Filter/EntryFilterType.php

72 lines
2.5 KiB
PHP
Raw Normal View History

<?php
namespace Wallabag\CoreBundle\Filter;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
2015-08-18 15:28:12 +00:00
use Lexik\Bundle\FormFilterBundle\Filter\Query\QueryInterface;
class EntryFilterType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
2015-08-14 20:57:16 +00:00
$builder
->add('readingTime', 'filter_number_range')
->add('createdAt', 'filter_date_range', array(
'left_date_options' => array(
'attr' => array(
'placeholder' => 'dd/mm/yyyy',
),
2015-08-14 20:57:16 +00:00
'format' => 'dd/MM/yyyy',
'widget' => 'single_text',
2015-08-14 20:57:16 +00:00
),
'right_date_options' => array(
'attr' => array(
'placeholder' => 'dd/mm/yyyy',
),
2015-08-14 20:57:16 +00:00
'format' => 'dd/MM/yyyy',
'widget' => 'single_text',
2015-08-22 13:35:28 +00:00
),
)
)
2015-08-18 15:28:12 +00:00
->add('domainName', 'filter_text', array(
'apply_filter' => function (QueryInterface $filterQuery, $field, $values) {
2015-08-18 15:28:12 +00:00
$value = $values['value'];
if (strlen($value) <= 2 || empty($value)) {
return;
2015-08-18 15:28:12 +00:00
}
$expression = $filterQuery->getExpr()->like($field, $filterQuery->getExpr()->literal('%'.$value.'%'));
2015-08-18 15:28:12 +00:00
return $filterQuery->createCondition($expression);
2015-09-12 15:08:12 +00:00
},
))
->add('isArchived', 'filter_checkbox')
2015-09-12 15:08:12 +00:00
->add('isStarred', 'filter_checkbox')
->add('previewPicture', 'filter_checkbox', array(
'apply_filter' => function (QueryInterface $filterQuery, $field, $values) {
2015-09-13 07:57:35 +00:00
if (false === $values['value']) {
2015-09-13 06:43:15 +00:00
return;
}
2015-09-12 15:08:12 +00:00
$expression = $filterQuery->getExpr()->isNotNull($field);
return $filterQuery->createCondition($expression);
},
));
}
public function getName()
{
return 'entry_filter';
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'csrf_protection' => false,
'validation_groups' => array('filtering'),
));
}
}