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.

73 lines
2.3KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Controller;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Doctrine\ORM\QueryBuilder;
  5. use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection;
  6. use EasyCorp\Bundle\EasyAdminBundle\Collection\FilterCollection;
  7. use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
  8. use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface;
  9. use Lc\CaracoleBundle\Resolver\MerchantResolver;
  10. use Lc\CaracoleBundle\Resolver\SectionResolver;
  11. use Lc\SovBundle\Controller\AbstractAdminController as SovAbstractAdminController;
  12. use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
  13. use EasyCorp\Bundle\EasyAdminBundle\Dto\SearchDto;
  14. use Lc\SovBundle\Doctrine\EntityManager;
  15. use Lc\SovBundle\Doctrine\Extension\TreeInterface;
  16. use Lc\SovBundle\Translation\TranslatorAdmin;
  17. use Symfony\Component\HttpFoundation\RequestStack;
  18. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  19. //TODO ce fichier ne devrait plus exister
  20. abstract class AbstractAdminController extends SovAbstractAdminController
  21. {
  22. protected $session;
  23. protected $request;
  24. protected $merchantResolver;
  25. protected $sectionResolver;
  26. public static function getSubscribedServices()
  27. {
  28. return array_merge(parent::getSubscribedServices(), [
  29. 'merchant_resolver' => MerchantResolver::class,
  30. 'section_resolver' => SectionResolver::class,
  31. ]);
  32. }
  33. public function createIndexQueryBuilder(
  34. SearchDto $searchDto,
  35. EntityDto $entityDto,
  36. FieldCollection $fields,
  37. FilterCollection $filters
  38. ): QueryBuilder {
  39. $queryBuilder = parent::createIndexQueryBuilder(
  40. $searchDto,
  41. $entityDto,
  42. $fields,
  43. $filters
  44. );
  45. //TODO Gérer depuis les événements
  46. if ($this->isInstanceOf(FilterMerchantInterface::class)) {
  47. $queryBuilder->andWhere('entity.merchant = :merchant');
  48. $queryBuilder->setParameter('merchant', $this->get('merchant_resolver')->getCurrent());
  49. }
  50. if ($this->isInstanceOf(FilterSectionInterface::class)) {
  51. $queryBuilder->andWhere('entity.section = :section');
  52. $queryBuilder->setParameter('section', $this->get('section_resolver')->getCurrent());
  53. }
  54. return $queryBuilder;
  55. }
  56. }