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ů.

SectionResolver.php 2.5KB

před 3 roky
před 3 roky
před 3 roky
před 3 roky
před 3 roky
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. protected UrlResolver $urlResolver;
  20. public function __construct(
  21. EntityManagerInterface $entityManager,
  22. MerchantResolver $merchantResolver,
  23. SectionStore $sectionStore,
  24. RequestStack $requestStack,
  25. UrlResolver $urlResolver
  26. ) {
  27. $this->entityManager = $entityManager;
  28. $this->merchantResolver = $merchantResolver;
  29. $this->sectionStore = $sectionStore;
  30. $this->requestStack = $requestStack;
  31. $this->urlResolver = $urlResolver;
  32. }
  33. public function getCurrent()
  34. {
  35. $requestAttributesArray = $this->requestStack->getMainRequest()->attributes->all();
  36. // admin
  37. if (isset($requestAttributesArray['easyadmin_context'])) {
  38. $currentAdminSection = null;
  39. $userMerchant = $this->merchantResolver->getUserMerchant();
  40. if ($userMerchant !== null) {
  41. $currentAdminSection = $userMerchant->getCurrentAdminSection();
  42. }
  43. if ($currentAdminSection === null) {
  44. $currentAdminSection = $this->sectionStore
  45. ->setMerchant($userMerchant->getMerchant())
  46. ->getOneDefault();
  47. if ($currentAdminSection === null) {
  48. throw new \ErrorException('Aucune section par défaut définie pour ce merchant');
  49. }
  50. }
  51. return $currentAdminSection;
  52. } // front
  53. else {
  54. $sectionStore = $this->sectionStore->setMerchant($this->merchantResolver->getCurrent());
  55. $sectionCurrent = null;
  56. $sectionDefault = $sectionStore->getOneDefault();
  57. if(isset($requestAttributesArray['section'])) {
  58. $sectionCurrent = $sectionStore->getOneBySlug($requestAttributesArray['section']);
  59. }
  60. return $sectionCurrent ?: $sectionDefault;
  61. }
  62. }
  63. }