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.

SectionResolver.php 2.1KB

пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. }