namespace Lc\CaracoleBundle\Repository\Reminder; | namespace Lc\CaracoleBundle\Repository\Reminder; | ||||
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; | |||||
use Lc\CaracoleBundle\Model\Section\SectionInterface; | |||||
use Lc\CaracoleBundle\Repository\MerchantStoreTrait; | use Lc\CaracoleBundle\Repository\MerchantStoreTrait; | ||||
use Lc\CaracoleBundle\Repository\SectionStoreTrait; | use Lc\CaracoleBundle\Repository\SectionStoreTrait; | ||||
use Lc\SovBundle\Model\User\UserInterface; | use Lc\SovBundle\Model\User\UserInterface; |
<?php | |||||
namespace Lc\CaracoleBundle\Repository\Reminder; | |||||
use Lc\SovBundle\Repository\Reminder\ReminderStore as SovReminderStore; | |||||
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; | |||||
class TicketStore extends SovReminderStore | |||||
{ | |||||
protected MerchantInterface $merchant; | |||||
public function setMerchant(MerchantInterface $merchant) | |||||
{ | |||||
$this->merchant = $merchant; | |||||
} | |||||
public function getFoo($query = null) | |||||
{ | |||||
$query = $this->query->create(); | |||||
if ($this->merchant) { | |||||
$query->filterByMerchant($this->merchant); | |||||
} | |||||
return parent::getFoo($query); | |||||
} | |||||
} |
class TicketRepositoryQuery extends SovTicketRepositoryQuery | class TicketRepositoryQuery extends SovTicketRepositoryQuery | ||||
{ | { | ||||
use MerchantRepositoryQueryTrait; | use MerchantRepositoryQueryTrait; | ||||
} | } |
<?php | |||||
namespace Lc\CaracoleBundle\Repository\Ticket; | |||||
use Lc\CaracoleBundle\Repository\MerchantStoreTrait; | |||||
use Lc\SovBundle\Repository\Ticket\TicketStore as SovTicketStore; | |||||
class TicketStore extends SovTicketStore | |||||
{ | |||||
use MerchantStoreTrait; | |||||
public function getByUser($user, $query = null): array | |||||
{ | |||||
if (is_null($query)) { | |||||
$query = $this->query->create(); | |||||
} | |||||
if ($this->merchant) { | |||||
$query->filterByMerchant($this->merchant); | |||||
} | |||||
return parent::getByUser($user, $query); | |||||
} | |||||
public function getAllOpen(int $limit = 0, $query = null): array | |||||
{ | |||||
if (is_null($query)) { | |||||
$query = $this->query->create(); | |||||
} | |||||
if ($this->merchant) { | |||||
$query->filterByMerchant($this->merchant); | |||||
} | |||||
return parent::getAllOpen($limit, $query); | |||||
} | |||||
public function countAllOpen($query = null): array | |||||
{ | |||||
if (is_null($query)) { | |||||
$query = $this->query->create(); | |||||
} | |||||
if ($this->merchant) { | |||||
$query->filterByMerchant($this->merchant); | |||||
} | |||||
return parent::countAllOpen($query); | |||||
} | |||||
} |
<?php | |||||
namespace Lc\CaracoleBundle\Repository\User; | |||||
use App\Entity\Merchant\Merchant; | |||||
use Lc\CaracoleBundle\Repository\MerchantRepositoryQueryTrait; | |||||
use Lc\SovBundle\Repository\User\UserRepositoryQuery as SovUserRepositoryQuery; | |||||
class UserRepositoryQuery extends SovUserRepositoryQuery | |||||
{ | |||||
use MerchantRepositoryQueryTrait; | |||||
protected $isJoinUserMerchants = false; | |||||
public function joinUserMerchants(): self | |||||
{ | |||||
if (!$this->isJoinUserMerchants) { | |||||
$this->isJoinUserMerchants = true; | |||||
return $this | |||||
->innerJoin('.userMerchants', 'um'); | |||||
} | |||||
return $this; | |||||
} | |||||
public function filterMerchantIsActive(): self | |||||
{ | |||||
$this->joinUserMerchants(); | |||||
return $this | |||||
->andWhere('um.active = 1'); | |||||
} | |||||
public function filterByUserMerchant(Merchant $merchant): self | |||||
{ | |||||
$this->joinUserMerchants(); | |||||
return $this | |||||
->andWhere('um.merchant = :merchant') | |||||
->setParameter('merchant', $merchant); | |||||
} | |||||
} |
<?php | |||||
namespace Lc\CaracoleBundle\Repository\User; | |||||
use App\Entity\Newsletter\Newsletter; | |||||
use Lc\CaracoleBundle\Repository\MerchantStoreTrait; | |||||
use Lc\SovBundle\Repository\User\UserStore as SovUserStore; | |||||
class UserStore extends SovUserStore | |||||
{ | |||||
use MerchantStoreTrait; | |||||
public function getByNewsletter(Newsletter $newsletter, $query = null): array | |||||
{ | |||||
if (is_null($query)) { | |||||
$query = $this->query->create(); | |||||
} | |||||
if ($this->merchant) { | |||||
$query | |||||
->filterByUserMerchant($this->merchant) | |||||
->filterMerchantIsActive(); | |||||
} | |||||
return parent::getByNewsletter($newsletter, $query); | |||||
} | |||||
} |