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.

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