瀏覽代碼

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

reduction
Guillaume 4 年之前
父節點
當前提交
d26ee00fab
共有 1 個文件被更改,包括 21 次插入3 次删除
  1. +21
    -3
      ShopBundle/Controller/Admin/AdminController.php

+ 21
- 3
ShopBundle/Controller/Admin/AdminController.php 查看文件

@@ -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…
取消
儲存