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.

45 lines
1.3KB

  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\SovBundle\Resolver\UrlResolver;
  10. use Symfony\Component\HttpFoundation\RequestStack;
  11. use Symfony\Component\Security\Core\Security;
  12. class SectionResolver
  13. {
  14. protected $sectionRepository;
  15. protected $merchantResolver;
  16. public function __construct(MerchantResolver $merchantResolver, EntityManagerInterface $em)
  17. {
  18. $this->em = $em;
  19. $this->merchantResolver = $merchantResolver;
  20. }
  21. public function getCurrent(): SectionInterface
  22. {
  23. $currentAdminSection = null;
  24. $userMerchant = $this->merchantResolver->getUserMerchant();
  25. if ($userMerchant !== null) {
  26. $currentAdminSection = $userMerchant->getCurrentAdminSection();
  27. }
  28. if ($currentAdminSection === null) {
  29. $currentAdminSection = $this->em->getRepository(SectionInterface::class)->findOneBy(array('isDefault' => true));
  30. if ($currentAdminSection === null) {
  31. throw new \ErrorException('Aucune section par défaut définie pour ce merchant');
  32. }
  33. }
  34. return $currentAdminSection;
  35. }
  36. }