Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

65 lines
2.1KB

  1. <?php
  2. /**
  3. * @author La clic ! <contact@laclic.fr>
  4. */
  5. namespace Lc\CaracoleBundle\Resolver;
  6. use Doctrine\ORM\EntityManagerInterface;
  7. use Lc\CaracoleBundle\Model\Section\SectionInterface;
  8. use Lc\CaracoleBundle\Repository\Section\SectionRepository;
  9. use Lc\CaracoleBundle\Repository\Section\SectionStore;
  10. use Lc\SovBundle\Resolver\UrlResolver;
  11. use Symfony\Component\HttpFoundation\RequestStack;
  12. use Symfony\Component\Security\Core\Security;
  13. class SectionResolver
  14. {
  15. protected EntityManagerInterface $entityManager;
  16. protected MerchantResolver $merchantResolver;
  17. protected SectionStore $sectionStore;
  18. protected RequestStack $requestStack;
  19. public function __construct(EntityManagerInterface $entityManager, MerchantResolver $merchantResolver, SectionStore $sectionStore, RequestStack $requestStack)
  20. {
  21. $this->entityManager = $entityManager;
  22. $this->merchantResolver = $merchantResolver;
  23. $this->sectionStore = $sectionStore;
  24. $this->requestStack = $requestStack;
  25. }
  26. public function getCurrent()
  27. {
  28. $requestAttributesArray = $this->requestStack->getMainRequest()->attributes->all();
  29. // admin
  30. if(isset($requestAttributesArray['easyadmin_context'])) {
  31. $currentAdminSection = null;
  32. $userMerchant = $this->merchantResolver->getUserMerchant();
  33. if ($userMerchant !== null) {
  34. $currentAdminSection = $userMerchant->getCurrentAdminSection();
  35. }
  36. if ($currentAdminSection === null) {
  37. $currentAdminSection = $this->sectionStore
  38. ->setMerchant($userMerchant->getMerchant())
  39. ->getOneDefault();
  40. if ($currentAdminSection === null) {
  41. throw new \ErrorException('Aucune section par défaut définie pour ce merchant');
  42. }
  43. }
  44. return $currentAdminSection;
  45. }
  46. // front
  47. else {
  48. return $this->sectionStore
  49. ->setMerchant($this->merchantResolver->getCurrent())
  50. ->getOneDefault();
  51. }
  52. }
  53. }