You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CheckboxFilter.php 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace Lc\SovBundle\Field\Filter;
  3. use EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto;
  4. use Lc\SovBundle\Repository\RepositoryQueryInterface;
  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(RepositoryQueryInterface $repositoryQuery, 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, $repositoryQuery->getAllAliases()) === false) {
  36. // $repositoryQuery->innerJoin('entity.'.$aliasRelation, $aliasRelation);
  37. // }
  38. // $repositoryQuery->andWhere(
  39. // $fieldProperty.' = :'.$this->getFieldPropertySnake($fieldProperty).''
  40. // );
  41. // $repositoryQuery->setParameter(
  42. // $this->getFieldPropertySnake($fieldProperty),
  43. // $filteredValue
  44. // );
  45. } else {
  46. $repositoryQuery->andWhere(
  47. '.'.$fieldProperty.' = :'.$fieldProperty.''
  48. );
  49. $repositoryQuery->setParameter($fieldProperty, $filteredValue);
  50. }
  51. }
  52. }
  53. }