|
- <?php
-
- namespace Lc\CaracoleBundle\Repository;
-
- use Doctrine\ORM\EntityManagerInterface;
- use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
- use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface;
- use Lc\CaracoleBundle\Resolver\MerchantResolver;
- use Lc\CaracoleBundle\Resolver\SectionResolver;
- use Lc\SovBundle\Repository\AbstractRepository as SovAbstractRepository;
-
- trait RepositoryTrait
- {
- protected $merchantResolver;
- protected $sectionResolver;
-
- public function __construct(
- EntityManagerInterface $entityManager,
- SectionResolver $sectionResolver,
- MerchantResolver $merchantResolver
- ) {
- parent::__construct($entityManager);
- $this->merchantResolver = $merchantResolver;
- $this->sectionResolver = $sectionResolver;
- }
-
-
- protected function setCriteria(array $criteria) :array
- {
- $criteria = parent::setCriteria($criteria);
-
- $className = $this->getClassMetadata()->getName();
- $entity = new $className;
-
- if ($entity instanceof FilterMerchantInterface) {
- if (!isset($criteria['merchant'])) {
- $criteria['merchant'] = $this->merchantResolver->getCurrent();
- }
- if ($criteria['merchant'] === false) {
- unset($criteria['merchant']);
- }
- }
-
- if ($entity instanceof FilterSectionInterface) {
- if (!isset($criteria['section'])) {
- $criteria['section'] = $this->sectionResolver->getCurrent();
- }
- if ($criteria['section'] === false) {
- unset($criteria['section']);
- }
- }
- return $criteria;
- }
-
- }
|