Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

68 lines
2.3KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Controller;
  3. use Doctrine\ORM\QueryBuilder;
  4. use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection;
  5. use EasyCorp\Bundle\EasyAdminBundle\Collection\FilterCollection;
  6. use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
  7. use Lc\CaracoleBundle\Doctrine\Extension\FilterMultipleMerchantsInterface;
  8. use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface;
  9. use Lc\CaracoleBundle\Factory\User\UserMerchantFactory;
  10. use Lc\CaracoleBundle\Resolver\MerchantResolver;
  11. use Lc\CaracoleBundle\Resolver\SectionResolver;
  12. use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
  13. use EasyCorp\Bundle\EasyAdminBundle\Dto\SearchDto;
  14. use Lc\SovBundle\Factory\User\UserFactory;
  15. trait AdminControllerTrait
  16. {
  17. public static function getSubscribedServices()
  18. {
  19. return array_merge(parent::getSubscribedServices(), [
  20. 'merchant_resolver' => MerchantResolver::class,
  21. 'section_resolver' => SectionResolver::class,
  22. 'user_factory' => UserFactory::class,
  23. 'user_merchant_factory' => UserMerchantFactory::class,
  24. ]);
  25. }
  26. public function createIndexQueryBuilder(
  27. SearchDto $searchDto,
  28. EntityDto $entityDto,
  29. FieldCollection $fields,
  30. FilterCollection $filters
  31. ): QueryBuilder {
  32. $queryBuilder = parent::createIndexQueryBuilder(
  33. $searchDto,
  34. $entityDto,
  35. $fields,
  36. $filters
  37. );
  38. //TODO Gérer depuis les événements
  39. if ($this->isInstanceOf(FilterMerchantInterface::class)) {
  40. $queryBuilder->andWhere('entity.merchant = :merchant');
  41. $queryBuilder->setParameter('merchant', $this->get('merchant_resolver')->getCurrent());
  42. }
  43. if ($this->isInstanceOf(FilterMultipleMerchantsInterface::class)) {
  44. $queryBuilder->andWhere(':merchant MEMBER OF entity.merchants');
  45. $queryBuilder->setParameter('merchant', $this->get('merchant_resolver')->getCurrent());
  46. }
  47. if ($this->isInstanceOf(FilterSectionInterface::class)) {
  48. $queryBuilder->andWhere('entity.section = :section');
  49. $queryBuilder->setParameter('section', $this->get('section_resolver')->getCurrent());
  50. }
  51. return $queryBuilder;
  52. }
  53. }