Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

AdminControllerTrait.php 2.6KB

3 lat temu
3 lat temu
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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->andWhereMerchant('entity', $this->get('merchant_resolver')->getCurrent());
  51. }
  52. if ($this->isInstanceOf(FilterMultipleMerchantsInterface::class)) {
  53. $queryBuilder->andWhere(':merchant MEMBER OF entity.merchants');
  54. $queryBuilder->setParameter('merchant', $this->get('merchant_resolver')->getCurrent());
  55. }
  56. if ($this->isInstanceOf(FilterSectionInterface::class)) {
  57. $queryBuilder->andWhereSection('entity', $this->get('section_resolver')->getCurrent());
  58. }
  59. return $queryBuilder;
  60. }
  61. }