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.

77 lines
2.6KB

  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 ChoiceFilter
  13. {
  14. use FilterTrait;
  15. protected $translatorAdmin;
  16. public function __construct(?TranslatorAdmin $translatorAdmin = null)
  17. {
  18. $this->translatorAdmin = $translatorAdmin;
  19. }
  20. public function buildProperty(FormBuilderInterface $builder, FieldDto $fieldDto, $options = array())
  21. {
  22. if($fieldDto->getCustomOption('choices')){
  23. $choices = $fieldDto->getCustomOption('choices');
  24. }else if($fieldDto->getFormTypeOption('choices') !=null){
  25. $choices = $fieldDto->getFormTypeOption('choices');
  26. }else{
  27. $choices = array();
  28. }
  29. $builder->add(
  30. $fieldDto->getProperty(),
  31. ChoiceType::class,
  32. array(
  33. 'required' => false,
  34. 'choices' => $choices,
  35. 'attr' => array(
  36. 'class' => 'select2 input-sm',
  37. 'form' => 'filters-form',
  38. ),
  39. )
  40. );
  41. }
  42. public function applyFilter(RepositoryQueryInterface $repositoryQuery , string $fieldProperty, string $filteredValue = null)
  43. {
  44. if ($filteredValue !== null) {
  45. // if ($this->isRelationField($fieldProperty)) {
  46. // $aliasRelation = $this->getFieldPropertyRelationAlias($fieldProperty);
  47. // if (array_search($aliasRelation, $repositoryQuery->getAllAliases()) === false) {
  48. // $repositoryQuery->innerJoin('entity.'.$aliasRelation, $aliasRelation);
  49. // }
  50. // $repositoryQuery->andWhere(
  51. // $fieldProperty.' LIKE :'.$this->getFieldPropertySnake($fieldProperty).''
  52. // );
  53. // $repositoryQuery->setParameter(
  54. // $this->getFieldPropertySnake($fieldProperty),
  55. // '%'.$filteredValue.'%'
  56. // );
  57. // } else {
  58. $repositoryQuery->andWhere(
  59. '.'.$fieldProperty.' LIKE :'.$fieldProperty.''
  60. );
  61. $repositoryQuery->setParameter($fieldProperty, '%'.$filteredValue.'%');
  62. }
  63. }
  64. }