@@ -54,8 +54,9 @@ class AssociationFilter | |||
); | |||
} | |||
public function applyFilter(RepositoryQueryInterface $repositoryQuery, FieldDto $fieldDto, string $fieldProperty, $filteredValue = null) | |||
public function applyFilter(RepositoryQueryInterface $repositoryQuery, FieldDto $fieldDto, $filteredValue = null) | |||
{ | |||
$fieldProperty = $this->getFieldProperty($fieldDto); | |||
if ($filteredValue !== null) { | |||
if ($fieldDto->getFormTypeOption('multiple')) { |
@@ -35,8 +35,9 @@ class CheckboxFilter | |||
)); | |||
} | |||
public function applyFilter(RepositoryQueryInterface $repositoryQuery, string $fieldProperty, string $filteredValue= null) | |||
public function applyFilter(RepositoryQueryInterface $repositoryQuery, FieldDto $fieldDto, string $filteredValue= null) | |||
{ | |||
$fieldProperty = $this->getFieldProperty($fieldDto); | |||
if ($filteredValue !== null) { | |||
if ($this->isRelationField($fieldProperty)) { | |||
// $aliasRelation = $this->getFieldPropertyRelationAlias($fieldProperty); |
@@ -49,8 +49,9 @@ class ChoiceFilter | |||
); | |||
} | |||
public function applyFilter(RepositoryQueryInterface $repositoryQuery , string $fieldProperty, string $filteredValue = null) | |||
public function applyFilter(RepositoryQueryInterface $repositoryQuery , FieldDto $fieldDto, string $filteredValue = null) | |||
{ | |||
$fieldProperty = $this->getFieldProperty($fieldDto); | |||
if ($filteredValue !== null) { | |||
// if ($this->isRelationField($fieldProperty)) { | |||
// $aliasRelation = $this->getFieldPropertyRelationAlias($fieldProperty); |
@@ -44,8 +44,9 @@ class DateFilter | |||
); | |||
} | |||
public function applyFilter(RepositoryQueryInterface $repositoryQuery, string $fieldProperty, \DateTime $dateStart = null, \DateTime $dateEnd = null) | |||
public function applyFilter(RepositoryQueryInterface $repositoryQuery, FieldDto $fieldDto, \DateTime $dateStart = null, \DateTime $dateEnd = null) | |||
{ | |||
$fieldProperty = $this->getFieldProperty($fieldDto); | |||
if ($dateStart) { | |||
$repositoryQuery->andWhere( | |||
'.' . $fieldProperty . ' >= :dateStart' |
@@ -78,15 +78,6 @@ class FilterManager | |||
} | |||
} | |||
public function getFieldProperty(FieldDto $fieldDto) | |||
{ | |||
$property = $fieldDto->getProperty(); | |||
//TODO pas forcément utile, à discuter | |||
if ($fieldDto->getCustomOption('filter_on')) { | |||
$property = $property . '.' . $fieldDto->getCustomOption('filter_on'); | |||
} | |||
return $property; | |||
} | |||
public function applyFilter(RepositoryQueryInterface $repositoryQuery, FieldDto $fieldDto, array $filteredValue) | |||
{ | |||
@@ -94,38 +85,38 @@ class FilterManager | |||
$filterFqcn = $fieldDto->getCustomOption('filter_fqcn'); | |||
$customFilter = new $filterFqcn; | |||
$customFilter->applyFilter($repositoryQuery, $this->getFieldProperty($fieldDto), $filteredValue['value']); | |||
$customFilter->applyFilter($repositoryQuery, $fieldDto, $filteredValue['value']); | |||
} else { | |||
switch ($this->guessFormType($fieldDto)) { | |||
case CheckboxType::class: | |||
$checkboxFilter = new CheckboxFilter(); | |||
$checkboxFilter->applyFilter($repositoryQuery, $this->getFieldProperty($fieldDto), $filteredValue['value']); | |||
$checkboxFilter->applyFilter($repositoryQuery, $fieldDto, $filteredValue['value']); | |||
break; | |||
case ChoiceType::class: | |||
$choiceFilter = new ChoiceFilter(); | |||
$choiceFilter->applyFilter($repositoryQuery, $this->getFieldProperty($fieldDto), $filteredValue['value']); | |||
$choiceFilter->applyFilter($repositoryQuery, $fieldDto, $filteredValue['value']); | |||
break; | |||
case IntegerType::class: | |||
$integerFilter = new IntegerFilter(); | |||
$integerFilter->applyFilter($repositoryQuery, $this->getFieldProperty($fieldDto), $filteredValue['value']); | |||
$integerFilter->applyFilter($repositoryQuery, $fieldDto, $filteredValue['value']); | |||
break; | |||
case TextareaType::class: | |||
case TextType::class: | |||
$textFilter = new TextFilter(); | |||
$textFilter->applyFilter($repositoryQuery, $this->getFieldProperty($fieldDto), $filteredValue['value']); | |||
$textFilter->applyFilter($repositoryQuery, $fieldDto, $filteredValue['value']); | |||
break; | |||
case EntityType::class: | |||
$textFilter = new AssociationFilter(); | |||
$textFilter->applyFilter($repositoryQuery, $fieldDto, $this->getFieldProperty($fieldDto), $filteredValue['value']); | |||
$textFilter->applyFilter($repositoryQuery, $fieldDto, $filteredValue['value']); | |||
break; | |||
case DateTimeType::class: | |||
case DateType::class: | |||
$textFilter = new DateFilter(); | |||
$textFilter->applyFilter( | |||
$repositoryQuery, | |||
$this->getFieldProperty($fieldDto), | |||
$fieldDto, | |||
$filteredValue['dateStart'], | |||
$filteredValue['dateEnd'] | |||
); |
@@ -3,6 +3,8 @@ | |||
namespace Lc\SovBundle\Field\Filter; | |||
use EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto; | |||
/** | |||
* @author La clic ! <contact@laclic.fr> | |||
*/ | |||
@@ -34,4 +36,15 @@ trait FilterTrait | |||
return substr($fieldName, 0, strpos($fieldName, $needle)); | |||
} | |||
public function getFieldProperty(FieldDto $fieldDto) | |||
{ | |||
$property = $fieldDto->getProperty(); | |||
//TODO pas forcément utile, à discuter | |||
if ($fieldDto->getCustomOption('filter_on')) { | |||
$property = $property . '.' . $fieldDto->getCustomOption('filter_on'); | |||
} | |||
return $property; | |||
} | |||
} |
@@ -37,8 +37,9 @@ class ImageFilter | |||
} | |||
public function applyFilter(RepositoryQueryInterface $repositoryQuery, string $fieldProperty, $filteredValue = null) | |||
public function applyFilter(RepositoryQueryInterface $repositoryQuery, FieldDto $fieldDto, $filteredValue = null) | |||
{ | |||
$fieldProperty = $this->getFieldProperty($fieldDto); | |||
if ($filteredValue !== null) { | |||
if($filteredValue === 1){ | |||
$repositoryQuery->andWhere( |
@@ -31,8 +31,9 @@ class IntegerFilter | |||
); | |||
} | |||
public function applyFilter(RepositoryQueryInterface $repositoryQuery, string $fieldProperty, string $filteredValue= null) | |||
public function applyFilter(RepositoryQueryInterface $repositoryQuery, FieldDto $fieldDto, string $filteredValue= null) | |||
{ | |||
$fieldProperty = $this->getFieldProperty($fieldDto); | |||
if ($filteredValue !== null) { | |||
$repositoryQuery->andWhere( | |||
'.'.$fieldProperty.' = :'.$fieldProperty.'' |
@@ -31,8 +31,9 @@ class TextFilter | |||
); | |||
} | |||
public function applyFilter(RepositoryQueryInterface $repositoryQuery, string $fieldProperty, string $filteredValue = null) | |||
public function applyFilter(RepositoryQueryInterface $repositoryQuery, FieldDto $fieldDto, string $filteredValue = null) | |||
{ | |||
$fieldProperty = $this->getFieldProperty($fieldDto); | |||
if ($filteredValue !== null) { | |||
// if ($this->isRelationField($fieldProperty)) { |