<?php
namespace App\Manager;
use App\Entity\Region;
use App\Repository\RegionRepository;
use App\Service\LocationIP\LocationIpInterface as LocationIP;
use App\Service\Regionalization\Location;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
class RegionManager extends BaseManager
{
private RequestStack $requestStack;
public function __construct(EntityManagerInterface $em, RegionRepository $repository, RequestStack $requestStack)
{
parent::__construct($em, $repository);
$this->repository = $repository;
$this->requestStack = $requestStack;
}
public function create(): Region
{
return new Region();
}
public function bySlug(string $slug)
{
return $this->repository->bySlug($slug);
}
public function listInMap(?string $type)
{
if (is_null($type) or $type == '') {
return $this->listInMapSimple();
}
return $this->listInMapByType($type);
}
protected function listInMapSimple()
{
$city = $this->requestStack->getSession()->get(LocationIP::REGION);
if (is_null($city)) {
return $this->repository->listInMap();
}
/** @var Location $city */
return $this->repository->listInMapBySlug($city->getRegion()->getSlug());
}
protected function listInMapByType($type)
{
$city = $this->requestStack->getSession()->get(LocationIP::REGION);
if (is_null($city)) {
return $this->repository->listInMapByType($type);
}
/** @var Location $city */
return $this->repository->listInMapByTypeBySlug($city->getRegion()->getSlug(), $type);
}
}