|
- <?php
-
- namespace Lc\CaracoleBundle\Controller\Admin;
-
- use Doctrine\ORM\EntityManagerInterface;
- use Doctrine\ORM\QueryBuilder;
- use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection;
- use EasyCorp\Bundle\EasyAdminBundle\Collection\FilterCollection;
-
- 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\Controller\Admin\AbstractCrudController as SovAbstractCrudController;
- use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
- use EasyCorp\Bundle\EasyAdminBundle\Dto\SearchDto;
- use Lc\SovBundle\Doctrine\EntityManager;
- use Lc\SovBundle\Doctrine\Extension\TreeInterface;
- use Lc\SovBundle\Translation\TranslatorAdmin;
- use Symfony\Component\HttpFoundation\RequestStack;
- use Symfony\Component\HttpFoundation\Session\SessionInterface;
-
- abstract class AbstractCrudController extends SovAbstractCrudController
- {
- protected $session;
- protected $request;
- protected $merchantResolver;
- protected $sectionResolver;
-
- public function __construct(SessionInterface $session, RequestStack $request, EntityManager $em, TranslatorAdmin $translatorAdmin, SectionResolver $sectionResolver, MerchantResolver $merchantResolver)
- {
- parent::__construct($session, $request, $em, $translatorAdmin);
- $this->merchantResolver = $merchantResolver;
- $this->sectionResolver = $sectionResolver;
-
- }
-
- public function createIndexQueryBuilder(
- SearchDto $searchDto,
- EntityDto $entityDto,
- FieldCollection $fields,
- FilterCollection $filters
- ): QueryBuilder {
- $queryBuilder = parent::createIndexQueryBuilder(
- $searchDto,
- $entityDto,
- $fields,
- $filters
- );
-
-
- if ($this->isInstanceOf(FilterMerchantInterface::class)) {
- $queryBuilder->andWhere('entity.merchant = :merchant');
- $queryBuilder->setParameter('merchant', $this->merchantResolver->getCurrent());
- }
-
- if ($this->isInstanceOf(FilterSectionInterface::class)) {
- $queryBuilder->andWhere('entity.section = :section');
- $queryBuilder->setParameter('section', $this->merchantResolver->getCurrent());
- }
-
- return $queryBuilder;
- }
-
-
-
- }
|