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.

56 line
1.5KB

  1. <?php
  2. namespace Lc\SovBundle\Field\Filter;
  3. use Doctrine\ORM\QueryBuilder;
  4. use EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto;
  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(QueryBuilder $queryBuilder, string $fieldProperty, $filteredValue = null)
  33. {
  34. if ($filteredValue !== null) {
  35. if($filteredValue === 1){
  36. $queryBuilder->andWhere(
  37. 'entity.' . $fieldProperty . ' IS NOT NULL'
  38. );
  39. }else{
  40. $queryBuilder->andWhere(
  41. 'entity.' . $fieldProperty . ' IS NULL'
  42. );
  43. }
  44. }
  45. }
  46. }