Parcourir la source

Correction de l'erreur générée lors de la recherche (lié à currentMerchant dans dqlFilter)

reduction
Guillaume il y a 4 ans
Parent
révision
d26ee00fab
1 fichiers modifiés avec 21 ajouts et 3 suppressions
  1. +21
    -3
      ShopBundle/Controller/Admin/AdminController.php

+ 21
- 3
ShopBundle/Controller/Admin/AdminController.php Voir le fichier

@@ -60,7 +60,7 @@ class AdminController extends EasyAdminController
]) ;
}

protected function createListQueryBuilder($entityClass, $sortDirection, $sortField = null, $dqlFilter = null)
protected function commonDqlFilterQueryBuilder($entityClass, $dqlFilter)
{
if ($pos = strpos($dqlFilter, 'currentMerchant')) {
$dqlFilter = sprintf(str_replace('currentMerchant', $this->getUser()->getMerchant()->getId(), $dqlFilter));
@@ -71,14 +71,32 @@ class AdminController extends EasyAdminController
else $dqlFilter .= sprintf(' entity.status > = 0');
}

$queryBuilder = parent::createListQueryBuilder($entityClass, $sortDirection, $sortField, $dqlFilter);
return $dqlFilter;
}

protected function commonQueryFilter($entityClass, $queryBuilder)
{
if ($entityClass == 'App\Entity\PointSale') {
$queryBuilder->andWhere(':currentMerchant MEMBER OF entity.merchant')
->setParameter(':currentMerchant', $this->getUser()->getMerchant()->getId());
}

return $queryBuilder;
}

protected function createSearchQueryBuilder($entityClass, $searchQuery, array $searchableFields, $sortField = null, $sortDirection = null, $dqlFilter = null)
{
$dqlFilter = $this->commonDqlFilterQueryBuilder($entityClass, $dqlFilter) ;
$queryBuilder = parent::createSearchQueryBuilder($entityClass, $searchQuery, $searchableFields, $sortField, $sortDirection, $dqlFilter) ;
$this->commonQueryFilter($entityClass, $queryBuilder) ;
return $queryBuilder ;
}

protected function createListQueryBuilder($entityClass, $sortDirection, $sortField = null, $dqlFilter = null)
{
$dqlFilter = $this->commonDqlFilterQueryBuilder($entityClass, $dqlFilter) ;
$queryBuilder = parent::createListQueryBuilder($entityClass, $sortDirection, $sortField, $dqlFilter);
$this->commonQueryFilter($entityClass, $queryBuilder) ;
return $queryBuilder ;
}



Chargement…
Annuler
Enregistrer