Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

52 rindas
1.7KB

  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 getCurrent(): SectionInterface
  25. {
  26. $currentAdminSection = null;
  27. $userMerchant = $this->merchantResolver->getUserMerchant();
  28. if ($userMerchant !== null) {
  29. $currentAdminSection = $userMerchant->getCurrentAdminSection();
  30. }
  31. if ($currentAdminSection === null) {
  32. $currentAdminSection = $this->em->getRepository(SectionInterface::class)->findOneBy(array('isDefault' => true));
  33. $currentAdminSection = $this->sectionStore
  34. ->setMerchant($userMerchant->getMerchant())
  35. ->getOneDefault();
  36. if ($currentAdminSection === null) {
  37. throw new \ErrorException('Aucune section par défaut définie pour ce merchant');
  38. }
  39. }
  40. return $currentAdminSection;
  41. }
  42. }