Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

82 lines
2.8KB

  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 EasyCorp\Bundle\EasyAdminBundle\Config\KeyValueStore;
  7. use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
  8. use Lc\CaracoleBundle\Doctrine\Extension\FilterMultipleMerchantsInterface;
  9. use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface;
  10. use Lc\CaracoleBundle\Factory\User\UserMerchantFactory;
  11. use Lc\CaracoleBundle\Resolver\MerchantResolver;
  12. use Lc\CaracoleBundle\Resolver\SectionResolver;
  13. use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
  14. use EasyCorp\Bundle\EasyAdminBundle\Dto\SearchDto;
  15. use Lc\SovBundle\Factory\User\UserFactory;
  16. trait AdminControllerTrait
  17. {
  18. public static function getSubscribedServices()
  19. {
  20. return array_merge(parent::getSubscribedServices(), [
  21. 'merchant_resolver' => MerchantResolver::class,
  22. 'section_resolver' => SectionResolver::class,
  23. 'user_factory' => UserFactory::class,
  24. 'user_merchant_factory' => UserMerchantFactory::class,
  25. ]);
  26. }
  27. public function configureResponseParameters(KeyValueStore $responseParameters): KeyValueStore
  28. {
  29. $responseParameters = parent::configureResponseParameters($responseParameters);
  30. // affichage du filtre sur section
  31. if($this->isInstanceOf(FilterSectionInterface::class)) {
  32. $responseParameters->set('display_switch_section', true);
  33. }
  34. return $responseParameters;
  35. }
  36. public function createIndexQueryBuilder(
  37. SearchDto $searchDto,
  38. EntityDto $entityDto,
  39. FieldCollection $fields,
  40. FilterCollection $filters
  41. ): QueryBuilder {
  42. $queryBuilder = parent::createIndexQueryBuilder(
  43. $searchDto,
  44. $entityDto,
  45. $fields,
  46. $filters
  47. );
  48. //TODO Gérer depuis les événements
  49. if ($this->isInstanceOf(FilterMerchantInterface::class)) {
  50. $queryBuilder->andWhere('entity.merchant = :merchant');
  51. $queryBuilder->setParameter('merchant', $this->get('merchant_resolver')->getCurrent());
  52. }
  53. if ($this->isInstanceOf(FilterMultipleMerchantsInterface::class)) {
  54. $queryBuilder->andWhere(':merchant MEMBER OF entity.merchants');
  55. $queryBuilder->setParameter('merchant', $this->get('merchant_resolver')->getCurrent());
  56. }
  57. if ($this->isInstanceOf(FilterSectionInterface::class)) {
  58. $queryBuilder->andWhere('entity.section = :section');
  59. $queryBuilder->setParameter('section', $this->get('section_resolver')->getCurrent());
  60. }
  61. return $queryBuilder;
  62. }
  63. }