src/Manager/RegionManager.php line 44

Open in your IDE?
  1. <?php
  2. namespace App\Manager;
  3. use App\Entity\Region;
  4. use App\Repository\RegionRepository;
  5. use App\Service\LocationIP\LocationIpInterface as LocationIP;
  6. use App\Service\Regionalization\Location;
  7. use Doctrine\ORM\EntityManagerInterface;
  8. use Symfony\Component\HttpFoundation\RequestStack;
  9. class RegionManager extends BaseManager
  10. {
  11.     private RequestStack $requestStack;
  12.     public function __construct(EntityManagerInterface $emRegionRepository $repositoryRequestStack $requestStack)
  13.     {
  14.         parent::__construct($em$repository);
  15.         $this->repository $repository;
  16.         $this->requestStack $requestStack;
  17.     }
  18.     public function create(): Region
  19.     {
  20.         return new Region();
  21.     }
  22.     public function bySlug(string $slug)
  23.     {
  24.         return $this->repository->bySlug($slug);
  25.     }
  26.     public function listInMap(?string $type)
  27.     {
  28.         if (is_null($type) or $type == '') {
  29.             return $this->listInMapSimple();
  30.         }
  31.         return $this->listInMapByType($type);
  32.     }
  33.     protected function listInMapSimple()
  34.     {
  35.         $city $this->requestStack->getSession()->get(LocationIP::REGION);
  36.         if (is_null($city)) {
  37.             return $this->repository->listInMap();
  38.         }
  39.         /** @var Location $city */
  40.         return $this->repository->listInMapBySlug($city->getRegion()->getSlug());
  41.     }
  42.     protected function listInMapByType($type)
  43.     {
  44.         $city $this->requestStack->getSession()->get(LocationIP::REGION);
  45.         if (is_null($city)) {
  46.             return $this->repository->listInMapByType($type);
  47.         }
  48.         /** @var Location $city */
  49.         return $this->repository->listInMapByTypeBySlug($city->getRegion()->getSlug(), $type);
  50.     }
  51. }