2015-08-07 20:20:30 +00:00
|
|
|
<?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;
|
2015-08-07 20:20:30 +00:00
|
|
|
|
|
|
|
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(
|
2015-08-20 05:53:55 +00:00
|
|
|
'placeholder' => 'dd/mm/yyyy',
|
|
|
|
),
|
2015-08-14 20:57:16 +00:00
|
|
|
'format' => 'dd/MM/yyyy',
|
2015-08-20 05:53:55 +00:00
|
|
|
'widget' => 'single_text',
|
2015-08-14 20:57:16 +00:00
|
|
|
),
|
|
|
|
'right_date_options' => array(
|
|
|
|
'attr' => array(
|
2015-08-20 05:53:55 +00:00
|
|
|
'placeholder' => 'dd/mm/yyyy',
|
|
|
|
),
|
2015-08-14 20:57:16 +00:00
|
|
|
'format' => 'dd/MM/yyyy',
|
2015-08-20 05:53:55 +00:00
|
|
|
'widget' => 'single_text',
|
2015-08-22 13:35:28 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
2015-08-18 15:28:12 +00:00
|
|
|
->add('domainName', 'filter_text', array(
|
2015-08-20 05:53:55 +00:00
|
|
|
'apply_filter' => function (QueryInterface $filterQuery, $field, $values) {
|
2015-08-18 15:28:12 +00:00
|
|
|
$value = $values['value'];
|
2015-08-24 18:43:58 +00:00
|
|
|
if (strlen($value) <= 2 || empty($value)) {
|
2015-08-20 05:53:55 +00:00
|
|
|
return;
|
2015-08-18 15:28:12 +00:00
|
|
|
}
|
|
|
|
$expression = $filterQuery->getExpr()->like($field, $filterQuery->getExpr()->literal('%'.$value.'%'));
|
2015-08-20 05:53:55 +00:00
|
|
|
|
2015-08-18 15:28:12 +00:00
|
|
|
return $filterQuery->createCondition($expression);
|
2015-09-12 15:08:12 +00:00
|
|
|
},
|
2015-08-20 13:59:47 +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);
|
|
|
|
},
|
|
|
|
));
|
2015-08-07 20:20:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
return 'entry_filter';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function configureOptions(OptionsResolver $resolver)
|
|
|
|
{
|
|
|
|
$resolver->setDefaults(array(
|
2015-08-20 05:53:55 +00:00
|
|
|
'csrf_protection' => false,
|
|
|
|
'validation_groups' => array('filtering'),
|
2015-08-07 20:20:30 +00:00
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|