Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

63 lines
2.1KB

  1. <?php
  2. namespace Lc\SovBundle\Field\Filter;
  3. use Doctrine\ORM\QueryBuilder;
  4. use EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto;
  5. use Lc\SovBundle\Translation\TranslatorAdmin;
  6. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  7. use Symfony\Component\Form\FormBuilderInterface;
  8. use function Symfony\Component\String\u;
  9. /**
  10. * @author La clic ! <contact@laclic.fr>
  11. */
  12. class CheckboxFilter
  13. {
  14. use FilterTrait;
  15. public function buildProperty(FormBuilderInterface $builder, FieldDto $fieldDto, $options = array())
  16. {
  17. $builder->add($fieldDto->getProperty(), ChoiceType::class, array(
  18. 'choices'=> array(
  19. 'Oui' => 1,
  20. 'Non' => 0,
  21. ),
  22. 'placeholder'=> '--',
  23. 'required'=>false,
  24. 'attr'=>array(
  25. 'class'=> 'select2 input-sm',
  26. 'form'=> 'filters-form'
  27. )
  28. ));
  29. }
  30. public function applyFilter(QueryBuilder $queryBuilder, string $fieldProperty, string $filteredValue= null)
  31. {
  32. if ($filteredValue !== null) {
  33. if ($this->isRelationField($fieldProperty)) {
  34. $aliasRelation = $this->getFieldPropertyRelationAlias($fieldProperty);
  35. if (array_search($aliasRelation, $queryBuilder->getAllAliases()) === false) {
  36. $queryBuilder->innerJoin('entity.'.$aliasRelation, $aliasRelation);
  37. }
  38. $queryBuilder->andWhere(
  39. $fieldProperty.' = :'.$this->getFieldPropertySnake($fieldProperty).''
  40. );
  41. $queryBuilder->setParameter(
  42. $this->getFieldPropertySnake($fieldProperty),
  43. '%'.$filteredValue.'%'
  44. );
  45. } else {
  46. $queryBuilder->andWhere(
  47. 'entity.'.$fieldProperty.' = :'.$fieldProperty.''
  48. );
  49. $queryBuilder->setParameter($fieldProperty, '%'.$filteredValue.'%');
  50. }
  51. dump($queryBuilder);
  52. }
  53. }
  54. }