@@ -0,0 +1,20 @@ | |||
<?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; | |||
} | |||
} |
@@ -0,0 +1,24 @@ | |||
<?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); | |||
} | |||
} |
@@ -0,0 +1,20 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\Repository\Reminder; | |||
use Lc\CaracoleBundle\Repository\RepositoryMerchantTrait; | |||
use Lc\SovBundle\Repository\AbstractRepositoryQuery; | |||
use Knp\Component\Pager\PaginatorInterface; | |||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; | |||
use Lc\CaracoleBundle\Container\MyContainer; | |||
use Lc\SovBundle\Repository\Reminder\ReminderRepositoryQuery as BaseReminderRepositoryQuery; | |||
/** | |||
* class ReminderRepositoryQuery. | |||
* | |||
* @author Simon Vieille <simon@deblan.fr> | |||
*/ | |||
class ReminderRepositoryQuery extends AbstractRepositoryQuery | |||
{ | |||
use RepositoryMerchantTrait; | |||
} |
@@ -0,0 +1,32 @@ | |||
<?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); | |||
} | |||
} |
@@ -0,0 +1,15 @@ | |||
<?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); | |||
} | |||
} |
@@ -46,9 +46,10 @@ class MerchantResolver | |||
$request = $this->requestStack->getCurrentRequest(); | |||
$merchantRepository = $this->em->getRepository(MerchantInterface::class); | |||
$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) { | |||
if ($merchant->getId() == $_ENV['CURRENT_MERCHANT_LOCAL']) { | |||
$this->currentMerchant = $merchant; | |||
@@ -102,4 +103,4 @@ class MerchantResolver | |||
); | |||
} | |||
} | |||
} |