Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

69 lines
2.4KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Controller\Admin;
  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\Admin\AbstractCrudController as SovAbstractCrudController;
  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. abstract class AbstractCrudController extends SovAbstractCrudController
  20. {
  21. protected $session;
  22. protected $request;
  23. protected $merchantResolver;
  24. protected $sectionResolver;
  25. public function __construct(SessionInterface $session, RequestStack $request, EntityManager $em, TranslatorAdmin $translatorAdmin, SectionResolver $sectionResolver, MerchantResolver $merchantResolver)
  26. {
  27. parent::__construct($session, $request, $em, $translatorAdmin);
  28. $this->merchantResolver = $merchantResolver;
  29. $this->sectionResolver = $sectionResolver;
  30. }
  31. public function createIndexQueryBuilder(
  32. SearchDto $searchDto,
  33. EntityDto $entityDto,
  34. FieldCollection $fields,
  35. FilterCollection $filters
  36. ): QueryBuilder {
  37. $queryBuilder = parent::createIndexQueryBuilder(
  38. $searchDto,
  39. $entityDto,
  40. $fields,
  41. $filters
  42. );
  43. if ($this->isInstanceOf(FilterMerchantInterface::class)) {
  44. $queryBuilder->andWhere('entity.merchant = :merchant');
  45. $queryBuilder->setParameter('merchant', $this->merchantResolver->getCurrent());
  46. }
  47. if ($this->isInstanceOf(FilterSectionInterface::class)) {
  48. $queryBuilder->andWhere('entity.section = :section');
  49. $queryBuilder->setParameter('section', $this->merchantResolver->getCurrent());
  50. }
  51. return $queryBuilder;
  52. }
  53. }