namespace Lc\CaracoleBundle\Repository; | namespace Lc\CaracoleBundle\Repository; | ||||
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; | use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; | ||||
use Lc\SovBundle\Repository\RepositoryQueryInterface; | |||||
use Lc\SovBundle\Repository\StoreInterface; | |||||
trait MerchantStoreTrait | trait MerchantStoreTrait | ||||
{ | { | ||||
return $this; | 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; | |||||
} | |||||
} | } |
->select('count(r.id) as total'); | ->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 | public function filterByUser(UserInterface $user): self | ||||
{ | { | ||||
return $this | return $this |
public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface | 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; | return $query; | ||||
} | } |
namespace Lc\CaracoleBundle\Repository; | namespace Lc\CaracoleBundle\Repository; | ||||
use Lc\CaracoleBundle\Model\Section\SectionInterface; | use Lc\CaracoleBundle\Model\Section\SectionInterface; | ||||
use Lc\SovBundle\Repository\RepositoryQueryInterface; | |||||
use Lc\SovBundle\Repository\StoreInterface; | |||||
trait SectionStoreTrait | trait SectionStoreTrait | ||||
{ | { | ||||
return $this; | 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() | public function getParents() | ||||
{ | { | ||||
$query = $this->query->create(); | $query = $this->query->create(); |