|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
-
- namespace Lc\CaracoleBundle\Controller;
-
- use Doctrine\ORM\QueryBuilder;
- use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection;
- use EasyCorp\Bundle\EasyAdminBundle\Collection\FilterCollection;
- use EasyCorp\Bundle\EasyAdminBundle\Config\KeyValueStore;
- use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
- use Lc\CaracoleBundle\Doctrine\Extension\FilterMultipleMerchantsInterface;
- use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface;
- use Lc\CaracoleBundle\Factory\User\UserMerchantFactory;
- use Lc\CaracoleBundle\Resolver\MerchantResolver;
- use Lc\CaracoleBundle\Resolver\SectionResolver;
- use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
- use EasyCorp\Bundle\EasyAdminBundle\Dto\SearchDto;
- use Lc\SovBundle\Factory\User\UserFactory;
-
-
- trait AdminControllerTrait
- {
-
- public static function getSubscribedServices()
- {
- return array_merge(parent::getSubscribedServices(), [
- 'merchant_resolver' => MerchantResolver::class,
- 'section_resolver' => SectionResolver::class,
- 'user_factory' => UserFactory::class,
- 'user_merchant_factory' => UserMerchantFactory::class,
- ]);
- }
-
- public function configureResponseParameters(KeyValueStore $responseParameters): KeyValueStore
- {
- $responseParameters = parent::configureResponseParameters($responseParameters);
-
- // affichage du filtre sur section
- if($this->isInstanceOf(FilterSectionInterface::class)) {
- $responseParameters->set('display_switch_section', true);
- }
-
- return $responseParameters;
- }
-
- public function createIndexQueryBuilder(
- SearchDto $searchDto,
- EntityDto $entityDto,
- FieldCollection $fields,
- FilterCollection $filters
- ): QueryBuilder {
- $queryBuilder = parent::createIndexQueryBuilder(
- $searchDto,
- $entityDto,
- $fields,
- $filters
- );
-
- //TODO Gérer depuis les événements
-
- if ($this->isInstanceOf(FilterMerchantInterface::class)) {
- $queryBuilder->andWhere('entity.merchant = :merchant');
- $queryBuilder->setParameter('merchant', $this->get('merchant_resolver')->getCurrent());
- }
-
- if ($this->isInstanceOf(FilterMultipleMerchantsInterface::class)) {
- $queryBuilder->andWhere(':merchant MEMBER OF entity.merchants');
- $queryBuilder->setParameter('merchant', $this->get('merchant_resolver')->getCurrent());
- }
-
- if ($this->isInstanceOf(FilterSectionInterface::class)) {
- $queryBuilder->andWhere('entity.section = :section');
- $queryBuilder->setParameter('section', $this->get('section_resolver')->getCurrent());
- }
-
- return $queryBuilder;
- }
-
-
-
- }
-
|