Browse Source

Bon courage !

ideas
Simon Vieille 3 years ago
parent
commit
c2a750150c
6 changed files with 115 additions and 3 deletions
  1. +20
    -0
      Container/MyContainer.php
  2. +24
    -0
      Repository/AbstractRepositoryQuery.php
  3. +20
    -0
      Repository/Reminder/ReminderRepositoryQuery.php
  4. +32
    -0
      Repository/Reminder/ReminderStore.php
  5. +15
    -0
      Repository/RepositoryMerchantTrait.php
  6. +4
    -3
      Resolver/MerchantResolver.php

+ 20
- 0
Container/MyContainer.php View File

@@ -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;
}
}

+ 24
- 0
Repository/AbstractRepositoryQuery.php View File

@@ -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);
}
}

+ 20
- 0
Repository/Reminder/ReminderRepositoryQuery.php View File

@@ -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;
}

+ 32
- 0
Repository/Reminder/ReminderStore.php View File

@@ -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);
}
}

+ 15
- 0
Repository/RepositoryMerchantTrait.php View File

@@ -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);
}
}

+ 4
- 3
Resolver/MerchantResolver.php View File

@@ -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
);
}

}
}

Loading…
Cancel
Save