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.

58 lines
1.6KB

  1. <?php
  2. namespace Lc\SovBundle\Field\Filter;
  3. use EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto;
  4. use Lc\SovBundle\Repository\RepositoryQueryInterface;
  5. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  6. use Symfony\Component\Form\FormBuilderInterface;
  7. /**
  8. * @author La clic ! <contact@laclic.fr>
  9. */
  10. class ImageFilter
  11. {
  12. use FilterTrait;
  13. public function buildProperty(FormBuilderInterface $builder, FieldDto $fieldDto, $options = array())
  14. {
  15. $targetEntity = $options['entity_dto']->getPropertyMetadata($fieldDto->getProperty())->get('targetEntity');
  16. $builder->add(
  17. $fieldDto->getProperty(),
  18. ChoiceType::class,
  19. array(
  20. 'required' => false,
  21. 'choices' => array(
  22. 'Sans image' => 0,
  23. 'Avec image' => 1,
  24. ),
  25. 'attr' => array(
  26. 'class' => 'select2 input-sm',
  27. 'form' => 'filters-form',
  28. ),
  29. )
  30. );
  31. }
  32. public function applyFilter(RepositoryQueryInterface $repositoryQuery, FieldDto $fieldDto, $filteredValue = null)
  33. {
  34. $fieldProperty = $this->getFieldProperty($fieldDto);
  35. if ($filteredValue !== null) {
  36. if($filteredValue === 1){
  37. $repositoryQuery->andWhere(
  38. '.' . $fieldProperty . ' IS NOT NULL'
  39. );
  40. }else{
  41. $repositoryQuery->andWhere(
  42. '.' . $fieldProperty . ' IS NULL'
  43. );
  44. }
  45. }
  46. }
  47. }