Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

SectionResolver.php 1.3KB

3 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. }