Browse Source

Correctif sur les fitler

develop
Fab 3 years ago
parent
commit
e928c5d335
9 changed files with 34 additions and 23 deletions
  1. +2
    -1
      Field/Filter/AssociationFilter.php
  2. +2
    -1
      Field/Filter/CheckboxFilter.php
  3. +2
    -1
      Field/Filter/ChoiceFilter.php
  4. +2
    -1
      Field/Filter/DateFilter.php
  5. +7
    -16
      Field/Filter/FilterManager.php
  6. +13
    -0
      Field/Filter/FilterTrait.php
  7. +2
    -1
      Field/Filter/ImageFilter.php
  8. +2
    -1
      Field/Filter/IntegerFilter.php
  9. +2
    -1
      Field/Filter/TextFilter.php

+ 2
- 1
Field/Filter/AssociationFilter.php View File

); );
} }


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')) {

+ 2
- 1
Field/Filter/CheckboxFilter.php View File

)); ));
} }


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);

+ 2
- 1
Field/Filter/ChoiceFilter.php View File

); );
} }


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);

+ 2
- 1
Field/Filter/DateFilter.php View File

); );
} }


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'

+ 7
- 16
Field/Filter/FilterManager.php View File

} }
} }


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']
); );

+ 13
- 0
Field/Filter/FilterTrait.php View File

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;
}

} }

+ 2
- 1
Field/Filter/ImageFilter.php View File

} }




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(

+ 2
- 1
Field/Filter/IntegerFilter.php View File

); );
} }


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.''

+ 2
- 1
Field/Filter/TextFilter.php View File

); );
} }


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)) {

Loading…
Cancel
Save