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.

62 satır
2.0KB

  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\TextType;
  6. use Symfony\Component\Form\FormBuilderInterface;
  7. /**
  8. * @author La clic ! <contact@laclic.fr>
  9. */
  10. class TextFilter
  11. {
  12. use FilterTrait;
  13. public function buildProperty(FormBuilderInterface $builder, FieldDto $fieldDto, $options = array())
  14. {
  15. $builder->add(
  16. str_replace('.', '_', $fieldDto->getProperty()),
  17. TextType::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(RepositoryQueryInterface $repositoryQuery, FieldDto $fieldDto, string $filteredValue = null)
  28. {
  29. $fieldProperty = $this->getFieldProperty($fieldDto);
  30. if ($filteredValue !== null) {
  31. // if ($this->isRelationField($fieldProperty)) {
  32. //
  33. // $aliasRelation = $this->getFieldPropertyRelationAlias($fieldProperty);
  34. // if (array_search($aliasRelation, $repositoryQuery->getAllAliases()) === false) {
  35. // $repositoryQuery->innerJoin('entity.' . $aliasRelation, $aliasRelation);
  36. // }
  37. // $repositoryQuery->andWhere(
  38. // $fieldProperty . ' LIKE :' . $this->getFieldPropertySnake($fieldProperty) . ''
  39. // );
  40. // $repositoryQuery->setParameter(
  41. // $this->getFieldPropertySnake($fieldProperty),
  42. // '%' . $filteredValue . '%'
  43. // );
  44. // } else {
  45. $repositoryQuery->andWhere(
  46. '.' . $fieldProperty . ' LIKE :' . $fieldProperty . ''
  47. );
  48. $repositoryQuery->setParameter($fieldProperty, '%' . $filteredValue . '%');
  49. }
  50. }
  51. }