|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- /**
- * @author La clic ! <contact@laclic.fr>
- */
-
- namespace Lc\CaracoleBundle\Resolver;
-
- use Doctrine\ORM\EntityManagerInterface;
- use Lc\CaracoleBundle\Model\Section\SectionInterface;
- use Lc\CaracoleBundle\Repository\Section\SectionRepository;
- use Lc\CaracoleBundle\Repository\Section\SectionStore;
- use Lc\SovBundle\Resolver\UrlResolver;
- use Symfony\Component\HttpFoundation\RequestStack;
- use Symfony\Component\Security\Core\Security;
-
- class SectionResolver
- {
- protected EntityManagerInterface $entityManager;
- protected MerchantResolver $merchantResolver;
- protected SectionStore $sectionStore;
-
- public function __construct(EntityManagerInterface $entityManager, MerchantResolver $merchantResolver, SectionStore $sectionStore)
- {
- $this->entityManager = $entityManager;
- $this->merchantResolver = $merchantResolver;
- $this->sectionStore = $sectionStore;
- }
-
- public function getCurrentFrontend()
- {
- return $this->sectionStore
- ->setMerchant($this->merchantResolver->getCurrent())
- ->getOneDefault();
- }
-
- public function getCurrent(): SectionInterface
- {
- $currentAdminSection = null;
- $userMerchant = $this->merchantResolver->getUserMerchant();
-
- if ($userMerchant !== null) {
- $currentAdminSection = $userMerchant->getCurrentAdminSection();
- }
-
- if ($currentAdminSection === null) {
- $currentAdminSection = $this->sectionStore
- ->setMerchant($userMerchant->getMerchant())
- ->getOneDefault();
-
- if ($currentAdminSection === null) {
- throw new \ErrorException('Aucune section par défaut définie pour ce merchant');
- }
- }
-
- return $currentAdminSection;
- }
-
-
- }
|