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.

51 lines
1.3KB

  1. <?php
  2. namespace Lc\SovBundle\Field\Filter;
  3. use EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto;
  4. /**
  5. * @author La clic ! <contact@laclic.fr>
  6. */
  7. trait FilterTrait
  8. {
  9. public function getFieldPropertySnake(string $fieldName): string
  10. {
  11. return str_replace('.', '_', $fieldName);
  12. }
  13. public function getFieldPropertyBase(string $fieldName): string
  14. {
  15. return str_replace('_', '.', $fieldName);
  16. }
  17. public function isRelationField(string $fieldName, string $needle = "."): bool
  18. {
  19. return strpos($fieldName, $needle) !== false;
  20. }
  21. public function getFieldPropertyWithoutRelation(string $fieldName, string $needle = '.'): string
  22. {
  23. return substr($fieldName, strpos($fieldName, $needle) + 1);
  24. }
  25. public function getFieldPropertyRelationAlias(string $fieldName, string $needle = '.'): string
  26. {
  27. return substr($fieldName, 0, strpos($fieldName, $needle));
  28. }
  29. public function getFieldProperty(FieldDto $fieldDto)
  30. {
  31. $property = $fieldDto->getProperty();
  32. //TODO pas forcément utile, à discuter
  33. // if ($fieldDto->getCustomOption('filter_on')) {
  34. // $property = $property . '.' . $fieldDto->getCustomOption('filter_on');
  35. // }
  36. return $property;
  37. }
  38. }