); | ); | ||||
} | } | ||||
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 ($filteredValue !== null) { | ||||
if ($fieldDto->getFormTypeOption('multiple')) { | if ($fieldDto->getFormTypeOption('multiple')) { |
)); | )); | ||||
} | } | ||||
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 ($filteredValue !== null) { | ||||
if ($this->isRelationField($fieldProperty)) { | if ($this->isRelationField($fieldProperty)) { | ||||
// $aliasRelation = $this->getFieldPropertyRelationAlias($fieldProperty); | // $aliasRelation = $this->getFieldPropertyRelationAlias($fieldProperty); |
); | ); | ||||
} | } | ||||
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 ($filteredValue !== null) { | ||||
// if ($this->isRelationField($fieldProperty)) { | // if ($this->isRelationField($fieldProperty)) { | ||||
// $aliasRelation = $this->getFieldPropertyRelationAlias($fieldProperty); | // $aliasRelation = $this->getFieldPropertyRelationAlias($fieldProperty); |
); | ); | ||||
} | } | ||||
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) { | if ($dateStart) { | ||||
$repositoryQuery->andWhere( | $repositoryQuery->andWhere( | ||||
'.' . $fieldProperty . ' >= :dateStart' | '.' . $fieldProperty . ' >= :dateStart' |
} | } | ||||
} | } | ||||
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) | public function applyFilter(RepositoryQueryInterface $repositoryQuery, FieldDto $fieldDto, array $filteredValue) | ||||
{ | { | ||||
$filterFqcn = $fieldDto->getCustomOption('filter_fqcn'); | $filterFqcn = $fieldDto->getCustomOption('filter_fqcn'); | ||||
$customFilter = new $filterFqcn; | $customFilter = new $filterFqcn; | ||||
$customFilter->applyFilter($repositoryQuery, $this->getFieldProperty($fieldDto), $filteredValue['value']); | |||||
$customFilter->applyFilter($repositoryQuery, $fieldDto, $filteredValue['value']); | |||||
} else { | } else { | ||||
switch ($this->guessFormType($fieldDto)) { | switch ($this->guessFormType($fieldDto)) { | ||||
case CheckboxType::class: | case CheckboxType::class: | ||||
$checkboxFilter = new CheckboxFilter(); | $checkboxFilter = new CheckboxFilter(); | ||||
$checkboxFilter->applyFilter($repositoryQuery, $this->getFieldProperty($fieldDto), $filteredValue['value']); | |||||
$checkboxFilter->applyFilter($repositoryQuery, $fieldDto, $filteredValue['value']); | |||||
break; | break; | ||||
case ChoiceType::class: | case ChoiceType::class: | ||||
$choiceFilter = new ChoiceFilter(); | $choiceFilter = new ChoiceFilter(); | ||||
$choiceFilter->applyFilter($repositoryQuery, $this->getFieldProperty($fieldDto), $filteredValue['value']); | |||||
$choiceFilter->applyFilter($repositoryQuery, $fieldDto, $filteredValue['value']); | |||||
break; | break; | ||||
case IntegerType::class: | case IntegerType::class: | ||||
$integerFilter = new IntegerFilter(); | $integerFilter = new IntegerFilter(); | ||||
$integerFilter->applyFilter($repositoryQuery, $this->getFieldProperty($fieldDto), $filteredValue['value']); | |||||
$integerFilter->applyFilter($repositoryQuery, $fieldDto, $filteredValue['value']); | |||||
break; | break; | ||||
case TextareaType::class: | case TextareaType::class: | ||||
case TextType::class: | case TextType::class: | ||||
$textFilter = new TextFilter(); | $textFilter = new TextFilter(); | ||||
$textFilter->applyFilter($repositoryQuery, $this->getFieldProperty($fieldDto), $filteredValue['value']); | |||||
$textFilter->applyFilter($repositoryQuery, $fieldDto, $filteredValue['value']); | |||||
break; | break; | ||||
case EntityType::class: | case EntityType::class: | ||||
$textFilter = new AssociationFilter(); | $textFilter = new AssociationFilter(); | ||||
$textFilter->applyFilter($repositoryQuery, $fieldDto, $this->getFieldProperty($fieldDto), $filteredValue['value']); | |||||
$textFilter->applyFilter($repositoryQuery, $fieldDto, $filteredValue['value']); | |||||
break; | break; | ||||
case DateTimeType::class: | case DateTimeType::class: | ||||
case DateType::class: | case DateType::class: | ||||
$textFilter = new DateFilter(); | $textFilter = new DateFilter(); | ||||
$textFilter->applyFilter( | $textFilter->applyFilter( | ||||
$repositoryQuery, | $repositoryQuery, | ||||
$this->getFieldProperty($fieldDto), | |||||
$fieldDto, | |||||
$filteredValue['dateStart'], | $filteredValue['dateStart'], | ||||
$filteredValue['dateEnd'] | $filteredValue['dateEnd'] | ||||
); | ); |
namespace Lc\SovBundle\Field\Filter; | namespace Lc\SovBundle\Field\Filter; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto; | |||||
/** | /** | ||||
* @author La clic ! <contact@laclic.fr> | * @author La clic ! <contact@laclic.fr> | ||||
*/ | */ | ||||
return substr($fieldName, 0, strpos($fieldName, $needle)); | 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; | |||||
} | |||||
} | } |
} | } | ||||
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 !== null) { | ||||
if($filteredValue === 1){ | if($filteredValue === 1){ | ||||
$repositoryQuery->andWhere( | $repositoryQuery->andWhere( |
); | ); | ||||
} | } | ||||
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 ($filteredValue !== null) { | ||||
$repositoryQuery->andWhere( | $repositoryQuery->andWhere( | ||||
'.'.$fieldProperty.' = :'.$fieldProperty.'' | '.'.$fieldProperty.' = :'.$fieldProperty.'' |
); | ); | ||||
} | } | ||||
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 ($filteredValue !== null) { | ||||
// if ($this->isRelationField($fieldProperty)) { | // if ($this->isRelationField($fieldProperty)) { |