<?php | |||||
namespace Lc\CaracoleBundle\Container; | |||||
use Lc\CaracoleBundle\Resolver\MerchantResolver; | |||||
/** | |||||
* class MyContainer. | |||||
* | |||||
* @author Simon Vieille <simon@deblan.fr> | |||||
*/ | |||||
class MyContainer | |||||
{ | |||||
public MerchantResolver $merchantResolver; | |||||
public function __construct(MerchantResolver $merchantResolver) | |||||
{ | |||||
$this->merchantResolver = $merchantResolver; | |||||
} | |||||
} |
<?php | |||||
namespace Lc\CaracoleBundle\Repository; | |||||
use Lc\SovBundle\Repository\AbstractRepositoryQuery as BaseAbstractRepositoryQuery; | |||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; | |||||
use Doctrine\ORM\QueryBuilder; | |||||
use Knp\Component\Pager\PaginatorInterface; | |||||
use Lc\CaracoleBundle\Container\MyContainer; | |||||
abstract class AbstractRepositoryQuery extends BaseAbstractRepositoryQuery | |||||
{ | |||||
public function __construct( | |||||
MyContainer $container, | |||||
ServiceEntityRepository $repository, | |||||
string $id, | |||||
PaginatorInterface $paginator = null | |||||
) | |||||
{ | |||||
$this->container = $container; | |||||
parent::__construct($repository, $id, $paginator); | |||||
} | |||||
} |
<?php | |||||
namespace Lc\CaracoleBundle\Repository\Reminder; | |||||
use Lc\CaracoleBundle\Repository\RepositoryTrait; | |||||
use Lc\SovBundle\Model\Reminder\ReminderInterface; | |||||
use Lc\SovBundle\Repository\Reminder\ReminderRepository as SovReminderRepository; | |||||
/** | |||||
* @method ReminderInterface|null find($id, $lockMode = null, $lockVersion = null) | |||||
* @method ReminderInterface|null findOneBy(array $criteria, array $orderBy = null) | |||||
* @method ReminderInterface[] findAll() | |||||
* @method ReminderInterface[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) | |||||
*/ | |||||
class ReminderRepository extends SovReminderRepository | |||||
{ | |||||
use RepositoryTrait; | |||||
} |
<?php | |||||
namespace Lc\CaracoleBundle\Repository\Reminder; | |||||
use Lc\CaracoleBundle\Repository\RepositoryMerchantTrait; | |||||
use Lc\SovBundle\Repository\Reminder\ReminderRepositoryQuery as SovReminderRepositoryQuery; | |||||
/** | |||||
* class ReminderRepositoryQuery. | |||||
* | |||||
* @author Simon Vieille <simon@deblan.fr> | |||||
*/ | |||||
class ReminderRepositoryQuery extends SovReminderRepositoryQuery | |||||
{ | |||||
use RepositoryMerchantTrait; | |||||
} |
<?php | |||||
namespace Lc\CaracoleBundle\Repository\Reminder; | |||||
use Lc\SovBundle\Repository\Reminder\ReminderStore as SovReminderStore; | |||||
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; | |||||
/** | |||||
* class ReminderStore. | |||||
* | |||||
* @author Simon Vieille <simon@deblan.fr> | |||||
*/ | |||||
class ReminderStore 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); | |||||
} | |||||
} |
<?php | |||||
namespace Lc\CaracoleBundle\Repository; | |||||
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; | |||||
trait RepositoryMerchantTrait | |||||
{ | |||||
public function filterByMerchant(MerchantInterface $merchant) | |||||
{ | |||||
return $this | |||||
->andWhere('.merchant = :merchant') | |||||
->setParameter(':merchant', $merchant); | |||||
} | |||||
} |
$request = $this->requestStack->getCurrentRequest(); | $request = $this->requestStack->getCurrentRequest(); | ||||
$merchantRepository = $this->em->getRepository(MerchantInterface::class); | $merchantRepository = $this->em->getRepository(MerchantInterface::class); | ||||
$merchants = $merchantRepository->findAll(); | $merchants = $merchantRepository->findAll(); | ||||
$isCli = php_sapi_name() === 'cli'; | |||||
if ($request) { | |||||
if ($this->urlResolver->isServerLocalhost()) { | |||||
if ($request || $isCli) { | |||||
if ($isCli || $this->urlResolver->isServerLocalhost()) { | |||||
foreach ($merchants as $merchant) { | foreach ($merchants as $merchant) { | ||||
if ($merchant->getId() == $_ENV['CURRENT_MERCHANT_LOCAL']) { | if ($merchant->getId() == $_ENV['CURRENT_MERCHANT_LOCAL']) { | ||||
$this->currentMerchant = $merchant; | $this->currentMerchant = $merchant; | ||||
); | ); | ||||
} | } | ||||
} | |||||
} |