@@ -3,6 +3,8 @@ | |||
namespace Lc\CaracoleBundle\Repository; | |||
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; | |||
use Lc\SovBundle\Repository\RepositoryQueryInterface; | |||
use Lc\SovBundle\Repository\StoreInterface; | |||
trait MerchantStoreTrait | |||
{ | |||
@@ -14,4 +16,49 @@ trait MerchantStoreTrait | |||
return $this; | |||
} | |||
public function isMerchantDefined(): bool | |||
{ | |||
return isset($this->merchant) && $this->merchant; | |||
} | |||
public function addFilterByMerchantOptionnal(RepositoryQueryInterface $query): StoreInterface | |||
{ | |||
if($this->isMerchantDefined()) { | |||
$query->filterByMerchant($this->merchant); | |||
} | |||
return $this; | |||
} | |||
public function addFilterByMerchantRequired(RepositoryQueryInterface $query): StoreInterface | |||
{ | |||
$this->addFilterByMerchantOptionnal($query); | |||
if(!$this->isMerchantDefined()) { | |||
throw new \ErrorException('Le Merchant doit être définie dans '.get_class($this)); | |||
} | |||
return $this; | |||
} | |||
public function addFilterByMerchantViaSectionOptionnal(RepositoryQueryInterface $query): StoreInterface | |||
{ | |||
if($this->isMerchantDefined()) { | |||
$query->filterByMerchantViaSection($this->merchant); | |||
} | |||
return $this; | |||
} | |||
public function addFilterByMerchantViaSectionRequired(RepositoryQueryInterface $query): StoreInterface | |||
{ | |||
$this->addFilterByMerchantOptionnal($query); | |||
if(!$this->isMerchantDefined()) { | |||
throw new \ErrorException('Le Merchant doit être définie dans '.get_class($this)); | |||
} | |||
return $this; | |||
} | |||
} |
@@ -49,13 +49,6 @@ class OrderShopRepositoryQuery extends AbstractRepositoryQuery | |||
->select('count(r.id) as total'); | |||
} | |||
public function filterByMerchant(MerchantInterface $merchant) | |||
{ | |||
$this->joinMerchant(); | |||
return $this->andWhere('s.merchant = :merchant') | |||
->setParameter('merchant', $merchant); | |||
} | |||
public function filterByUser(UserInterface $user): self | |||
{ | |||
return $this |
@@ -88,13 +88,9 @@ class OrderShopStore extends AbstractStore | |||
public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface | |||
{ | |||
if(isset($this->section) && $this->section) { | |||
$query->filterBySection($this->section); | |||
} | |||
if(isset($this->merchant) && $this->merchant) { | |||
$query->filterByMerchant($this->merchant); | |||
} | |||
$this | |||
->addFilterBySectionOptionnal($query) | |||
->addFilterByMerchantViaSectionOptionnal($query); | |||
return $query; | |||
} |
@@ -3,6 +3,8 @@ | |||
namespace Lc\CaracoleBundle\Repository; | |||
use Lc\CaracoleBundle\Model\Section\SectionInterface; | |||
use Lc\SovBundle\Repository\RepositoryQueryInterface; | |||
use Lc\SovBundle\Repository\StoreInterface; | |||
trait SectionStoreTrait | |||
{ | |||
@@ -15,6 +17,31 @@ trait SectionStoreTrait | |||
return $this; | |||
} | |||
public function isSectionDefined(): bool | |||
{ | |||
return isset($this->section) && $this->section; | |||
} | |||
public function addFilterBySectionOptionnal(RepositoryQueryInterface $query): StoreInterface | |||
{ | |||
if($this->isSectionDefined()) { | |||
$query->filterBySection($this->section); | |||
} | |||
return $this; | |||
} | |||
public function addFilterBySectionRequired(RepositoryQueryInterface $query): StoreInterface | |||
{ | |||
$this->addFilterBySectionOptionnal($query); | |||
if(!$this->isSectionDefined()) { | |||
throw new \ErrorException('La Section doit être définie dans '.get_class($this)); | |||
} | |||
return $this; | |||
} | |||
public function getParents() | |||
{ | |||
$query = $this->query->create(); |