|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <?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;
- }
-
- }
|