You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 satır
2.0KB

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