mirror of
https://github.com/ToxicCrack/PrintABrick.git
synced 2025-05-17 21:00:09 -07:00
Remove lexik filter
This commit is contained in:
parent
78ce9a9e64
commit
c10a2d8f17
@ -1,61 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace AppBundle\Form\Filter\Model;
|
|
||||||
|
|
||||||
use Doctrine\ORM\QueryBuilder;
|
|
||||||
use Lexik\Bundle\FormFilterBundle\Filter\FilterBuilderExecuterInterface;
|
|
||||||
use Lexik\Bundle\FormFilterBundle\Filter\Form\Type as Filters;
|
|
||||||
use Lexik\Bundle\FormFilterBundle\Filter\Query\QueryInterface;
|
|
||||||
use Symfony\Component\Form\AbstractType;
|
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
|
||||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
|
||||||
|
|
||||||
class ModelFilterType extends AbstractType
|
|
||||||
{
|
|
||||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
|
||||||
{
|
|
||||||
$builder->add('search', Filters\TextFilterType::class, [
|
|
||||||
'apply_filter' => [$this, 'modelSearchCallback'],
|
|
||||||
'label' => 'filter.model.search',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$builder->add('category', CategoryFilterType::class, [
|
|
||||||
'add_shared' => function (FilterBuilderExecuterInterface $builderExecuter) {
|
|
||||||
$builderExecuter->addOnce($builderExecuter->getAlias().'.category', 'c', function (QueryBuilder $filterBuilder, $alias, $joinAlias, $expr) {
|
|
||||||
$filterBuilder->leftJoin($alias.'.category', $joinAlias);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getBlockPrefix()
|
|
||||||
{
|
|
||||||
return 'filter';
|
|
||||||
}
|
|
||||||
|
|
||||||
public function configureOptions(OptionsResolver $resolver)
|
|
||||||
{
|
|
||||||
$resolver->setDefaults([
|
|
||||||
'csrf_protection' => false,
|
|
||||||
'validation_groups' => ['filtering'], // avoid NotBlank() constraint-related message
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function modelSearchCallback(QueryInterface $filterQuery, $field, $values)
|
|
||||||
{
|
|
||||||
if (empty($values['value']) || $values['value'] === '') {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$expr = $filterQuery->getExpr();
|
|
||||||
|
|
||||||
// expression that represent the condition
|
|
||||||
$expression = $expr->orX(
|
|
||||||
$expr->like('model.number', ':value'),
|
|
||||||
$expr->like('model.name', ':value')
|
|
||||||
//TODO filter by keywords
|
|
||||||
);
|
|
||||||
|
|
||||||
return $filterQuery->createCondition($expression, ['value' => '%'.$values['value'].'%']);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,66 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace AppBundle\Form\Filter\Set;
|
|
||||||
|
|
||||||
use Doctrine\ORM\QueryBuilder;
|
|
||||||
use Lexik\Bundle\FormFilterBundle\Filter\FilterBuilderExecuterInterface;
|
|
||||||
use Lexik\Bundle\FormFilterBundle\Filter\Form\Type as Filters;
|
|
||||||
use Lexik\Bundle\FormFilterBundle\Filter\Query\QueryInterface;
|
|
||||||
use Symfony\Component\Form\AbstractType;
|
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
|
||||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
|
||||||
|
|
||||||
class SetFilterType extends AbstractType
|
|
||||||
{
|
|
||||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
|
||||||
{
|
|
||||||
$builder->add('search', Filters\TextFilterType::class, [
|
|
||||||
'apply_filter' => [$this, 'setSearchCallback'],
|
|
||||||
'label' => 'filter.part.search',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$builder->add('partCount', Filters\NumberRangeFilterType::class, [
|
|
||||||
'label' => 'filter.part.partCount',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$builder->add('year', Filters\NumberRangeFilterType::class, [
|
|
||||||
'label' => 'filter.part.year',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$builder->add('theme', ThemeFilterType::class, [
|
|
||||||
'add_shared' => function (FilterBuilderExecuterInterface $builderExecuter) {
|
|
||||||
$builderExecuter->addOnce($builderExecuter->getAlias().'.theme', 't', function (QueryBuilder $filterBuilder, $alias, $joinAlias, $expr) {
|
|
||||||
$filterBuilder->leftJoin($alias.'.theme', $joinAlias);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getBlockPrefix()
|
|
||||||
{
|
|
||||||
return 'model_filter';
|
|
||||||
}
|
|
||||||
|
|
||||||
public function configureOptions(OptionsResolver $resolver)
|
|
||||||
{
|
|
||||||
$resolver->setDefaults([
|
|
||||||
'csrf_protection' => false,
|
|
||||||
'validation_groups' => ['filtering'], // avoid NotBlank() constraint-related message
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setSearchCallback(QueryInterface $filterQuery, $field, $values)
|
|
||||||
{
|
|
||||||
if (empty($values['value'])) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// expression that represent the condition
|
|
||||||
$expression = $filterQuery->getExpr()->orX(
|
|
||||||
$filterQuery->getExpr()->like('s.name', ':value'),
|
|
||||||
$filterQuery->getExpr()->like('s.number', ':value')
|
|
||||||
);
|
|
||||||
|
|
||||||
return $filterQuery->createCondition($expression, ['value' => '%'.$values['value'].'%']);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,66 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace AppBundle\Form\Filter\Set;
|
|
||||||
|
|
||||||
use AppBundle\Entity\Rebrickable\Theme;
|
|
||||||
use AppBundle\Repository\Rebrickable\ThemeRepository;
|
|
||||||
use Lexik\Bundle\FormFilterBundle\Filter\Form\Type as Filters;
|
|
||||||
use Symfony\Component\Form\AbstractType;
|
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
|
||||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
|
||||||
|
|
||||||
class ThemeFilterType extends AbstractType
|
|
||||||
{
|
|
||||||
private $themeRepository;
|
|
||||||
|
|
||||||
public function __construct(ThemeRepository $themeRepository)
|
|
||||||
{
|
|
||||||
$this->themeRepository = $themeRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
|
||||||
{
|
|
||||||
$builder->add('id', Filters\ChoiceFilterType::class, [
|
|
||||||
'choices' => $this->themeRepository->findAllMain(),
|
|
||||||
'choice_label' => function ($theme, $currentChoiceKey) {
|
|
||||||
if ($parent = $theme->getParent()) {
|
|
||||||
if ($parentParent = $parent->getParent()) {
|
|
||||||
if ($parentParentParent = $parentParent->getParent()) {
|
|
||||||
return $parentParentParent->getName().' > '.$parentParent->getName().' > '.$parent->getName().' > '.$theme->getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $parentParent->getName().' > '.$parent->getName().' > '.$theme->getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $parent->getName().' > '.$theme->getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $theme->getName();
|
|
||||||
},
|
|
||||||
'label' => 'filter.set.theme',
|
|
||||||
// 'attr' => [
|
|
||||||
// 'class' => 'ui dropdown search selection'
|
|
||||||
// ]
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getParent()
|
|
||||||
{
|
|
||||||
return Filters\SharedableFilterType::class; // this allow us to use the "add_shared" option
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getBlockPrefix()
|
|
||||||
{
|
|
||||||
return 'theme_filter';
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setDefaultOptions(OptionsResolver $resolver)
|
|
||||||
{
|
|
||||||
$resolver->setDefaults([
|
|
||||||
'data_class' => Theme::class,
|
|
||||||
'csrf_protection' => false,
|
|
||||||
'validation_groups' => ['filtering'], // avoid NotBlank() constraint-related message
|
|
||||||
'method' => 'GET',
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user