Browse Source

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

reduction
Guillaume 4 years ago
parent
commit
d26ee00fab
1 changed files with 21 additions and 3 deletions
  1. +21
    -3
      ShopBundle/Controller/Admin/AdminController.php

+ 21
- 3
ShopBundle/Controller/Admin/AdminController.php View File

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



Loading…
Cancel
Save