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.

47 lines
1.2KB

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