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.

IntegerFilter.php 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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\IntegerType;
  6. use Symfony\Component\Form\FormBuilderInterface;
  7. /**
  8. * @author La clic ! <contact@laclic.fr>
  9. */
  10. class IntegerFilter
  11. {
  12. use FilterTrait;
  13. public function buildProperty(FormBuilderInterface $builder, FieldDto $fieldDto, $options = array())
  14. {
  15. $builder->add(
  16. str_replace('.', '_', $fieldDto->getProperty()),
  17. IntegerType::class,
  18. array(
  19. 'required' => false,
  20. 'attr' => array(
  21. 'class' => ' input-sm',
  22. 'form' => 'filters-form',
  23. ),
  24. )
  25. );
  26. }
  27. public function applyFilter(QueryBuilder $queryBuilder, string $fieldProperty, string $filteredValue= null)
  28. {
  29. if ($filteredValue !== null) {
  30. $queryBuilder->andWhere(
  31. 'entity.'.$fieldProperty.' = :'.$fieldProperty.''
  32. );
  33. $queryBuilder->setParameter($fieldProperty, $filteredValue);
  34. }
  35. }
  36. }