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.

65 satır
2.1KB

  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, FieldDto $fieldDto, string $filteredValue= null)
  31. {
  32. $fieldProperty = $this->getFieldProperty($fieldDto);
  33. if ($filteredValue !== null) {
  34. if ($this->isRelationField($fieldProperty)) {
  35. // $aliasRelation = $this->getFieldPropertyRelationAlias($fieldProperty);
  36. // if (array_search($aliasRelation, $repositoryQuery->getAllAliases()) === false) {
  37. // $repositoryQuery->innerJoin('entity.'.$aliasRelation, $aliasRelation);
  38. // }
  39. // $repositoryQuery->andWhere(
  40. // $fieldProperty.' = :'.$this->getFieldPropertySnake($fieldProperty).''
  41. // );
  42. // $repositoryQuery->setParameter(
  43. // $this->getFieldPropertySnake($fieldProperty),
  44. // $filteredValue
  45. // );
  46. } else {
  47. $repositoryQuery->andWhere(
  48. '.'.$fieldProperty.' = :'.$fieldProperty.''
  49. );
  50. $repositoryQuery->setParameter($fieldProperty, $filteredValue);
  51. }
  52. }
  53. }
  54. }