選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

59 行
1.8KB

  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. public function __construct(EntityManagerInterface $entityManager, MerchantResolver $merchantResolver, SectionStore $sectionStore)
  19. {
  20. $this->entityManager = $entityManager;
  21. $this->merchantResolver = $merchantResolver;
  22. $this->sectionStore = $sectionStore;
  23. }
  24. public function getCurrentFrontend()
  25. {
  26. return $this->sectionStore
  27. ->setMerchant($this->merchantResolver->getCurrent())
  28. ->getOneDefault();
  29. }
  30. public function getCurrent(): SectionInterface
  31. {
  32. $currentAdminSection = null;
  33. $userMerchant = $this->merchantResolver->getUserMerchant();
  34. if ($userMerchant !== null) {
  35. $currentAdminSection = $userMerchant->getCurrentAdminSection();
  36. }
  37. if ($currentAdminSection === null) {
  38. $currentAdminSection = $this->sectionStore
  39. ->setMerchant($userMerchant->getMerchant())
  40. ->getOneDefault();
  41. if ($currentAdminSection === null) {
  42. throw new \ErrorException('Aucune section par défaut définie pour ce merchant');
  43. }
  44. }
  45. return $currentAdminSection;
  46. }
  47. }