您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

46 行
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. }