<?php
namespace App\Controller;
use App\Entity\Otpusk\City;
use App\Entity\Otpusk\Country;
use App\Entity\Otpusk\Rubric;
use App\Entity\Otpusk\Selection;
use App\Repository\Otpusk\GeoSeoUrlRepository;
use App\Services\PageGenerator;
use App\Services\PageService;
use Doctrine\ORM\EntityManager;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpKernel\EventListener\AbstractSessionListener;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;
class GeoController extends AbstractController
{
private $months = [
1 => 'january',
2 => 'february',
3 => 'march',
4 => 'april',
5 => 'may',
6 => 'june',
7 => 'july',
8 => 'august',
9 => 'september',
10 => 'october',
11 => 'november',
12 => 'december'
];
private $em;
private $generator;
/**
* @var \App\Repository\Otpusk\GeoSeoUrlRepository
*/
private $geoSeoUrlRepository;
private $page;
public function __construct(EntityManager $entityManager, PageGenerator $generator, GeoSeoUrlRepository $geoSeoUrlRepository, PageService $page)
{
$this->em = $entityManager;
$this->generator = $generator;
$this->geoSeoUrlRepository = $geoSeoUrlRepository;
$this->page = $page;
}
/**
* @Route(
* "/search/{country}/{city}/{season}/",
* name="app_city_search_season",
* methods={"GET"},
* requirements={
* "season"="september|october|november|december|january|february|march|april|may|june|july|august|summer|autumn|winter|spring"
* })
*/
public function citySearchSeason(Request $request, $country, $city, $season)
{
$market = $request->getSession()->get('market');
$countryObj = $this->em->getRepository(Country::class)->findOneBy(['fNameTr' => $country]);
if (is_null($countryObj)) throw new NotFoundHttpException('This page not found.');
$cityObj = $this->em->getRepository(City::class)->findOneBy(['fNameTr' => $city]);
if (is_null($cityObj)) throw new NotFoundHttpException('This page not found.');
$locale = $request->getLocale();
$cities = $this->page->getCities($countryObj->getRecId(), $cityObj->getId(), $locale);
if ($key = array_search($season, $this->months)) {
$page = $this->generator->getLandingPage($market, $country, $city, $key, null, null, null, null, $locale);
} else {
$page = $this->generator->getLandingPage($market, $country, $city, null, $season, null, null, null, $locale);
}
$seo = $this->generator->getTourSeasonSeoAction($market, $country, $season, $city, null, $locale);
$dates = $this->generator->seasonDates[$season];
$seoUrls = $this->geoSeoUrlRepository->findByCity($cityObj->getId());
$countries = $this->getCountriesHP($market, $page);
$hotels = $this->getCountriesHP($market, $page, 'hotels', 'city', $cityObj->getId(), $locale);
$response = $this->render('geo/city-search-season.html.twig', [
'cities' => $cities,
'page' => $page,
'seo' => $seo,
'country' => $country,
'season' => $season,
'countryId' => $countryObj->getId(),
'cityId' => $cityObj->getId(),
'city' => $city,
'dates' => $dates,
'type' => (in_array($season, $this->months)) ? 'search_resort_month' : 'search_resort_season',
'seoUrls' => $seoUrls,
'countries' => $countries,
'hotels' => $hotels,
]);
$response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER, 'true');
return $response;
}
/**
* @Route(
* "/search/{country}/{season}/",
* name="app_country_search_season",
* methods={"GET"},
* requirements={
* "season"="september|october|november|december|january|february|march|april|may|june|july|august|summer|autumn|winter|spring"
* })
*/
public function countrySearchSeason(Request $request, $country, $season)
{
$market = $request->getSession()->get('market');
$countryObj = $this->em->getRepository(Country::class)->findOneBy(['fNameTr' => $country]);
if (is_null($countryObj)) throw new NotFoundHttpException('This page not found.');
$locale = $request->getLocale();
$cities = $this->page->getCities($countryObj->getRecId(), null, $locale);
if ($key = array_search($season, $this->months)) {
$page = $this->generator->getLandingPage($market, $country, null, $key, null, null, null, null, $locale);
} else {
$page = $this->generator->getLandingPage($market, $country, null, null, $season, null, null, null, $locale);
}
$seo = $this->generator->getTourSeasonSeoAction($market, $country, $season, null, null, $locale);
$dates = $this->generator->seasonDates[$season];
$seoUrls = $this->geoSeoUrlRepository->findByCountry($countryObj->getRecId());
$countries = $this->getCountriesHP($market, $page);
$hotels = $this->getCountriesHP($market, $page, 'hotels', 'country', $countryObj->getRecId(), $locale);
$response = $this->render('geo/country-search-season.html.twig', [
'cities' => $cities,
'page' => $page,
'seo' => $seo,
'country' => $country,
'season' => $season,
'countryId' => $countryObj->getRecId(),
'dates' => $dates,
'seoUrls' => $seoUrls,
'type' => (in_array($season, $this->months)) ? 'search_country_month' : 'search_country_season',
'countries' => $countries,
'hotels' => $hotels,
]);
$response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER, 'true');
return $response;
}
/**
* @Route(
* "/search/{country}/from-{departureCity}/",
* name="app_country_search_departure_city",
* methods={"GET"}
* )
*/
public function countrySearchDepartureCity(Request $request, $country, $departureCity)
{
$market = $request->getSession()->get('market');
$countryObj = $this->em->getRepository(Country::class)->findOneBy(['fNameTr' => $country]);
if (is_null($countryObj)) throw new NotFoundHttpException('This page not found.');
$locale = $request->getLocale();
$departureCityObj = $this->em->getRepository(City::class)->checkDepartureCity($departureCity, $locale);
if (is_null($departureCityObj)) throw new NotFoundHttpException('This page not found.');
$cities = $this->page->getCities($countryObj->getRecId(), null, $locale);
$page = $this->generator->getLandingPage($market, $country, null, null, null, null, null, $departureCityObj['id'], $locale, true);
$seo = $this->generator->getTourSeoAction($market, $country, null, null, null, $departureCityObj['id'], $locale, true);
$seoUrls = $this->geoSeoUrlRepository->findByCountry($countryObj->getRecId());
$hotels = $this->getCountriesHP($market, $page, 'hotels', 'country', $countryObj->getRecId(), $locale);
$response = $this->render('geo/country-search.html.twig', [
'cities' => $cities,
'page' => $page,
'seo' => $seo,
'country' => $country,
'countryId' => $countryObj->getRecId(),
'departureCity' => $departureCityObj,
'type' => 'search_country_from_' . $departureCity,
'seoUrls' => $seoUrls,
'hotels' => $hotels,
]);
$response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER, 'true');
return $response;
}
/**
* @Route(
* "/search/{country}/{city}/from-{departureCity}/",
* name="app_city_search_departure_city",
* methods={"GET"}
* )
*/
public function citySearchDepartureCity(Request $request, $country, $city, $departureCity)
{
$market = $request->getSession()->get('market');
$countryObj = $this->em->getRepository(Country::class)->findOneBy(['fNameTr' => $country]);
if (is_null($countryObj)) throw new NotFoundHttpException('This page not found.');
$cityObj = $this->em->getRepository(City::class)->findOneBy(['fNameTr' => $city]);
if (is_null($cityObj)) throw new NotFoundHttpException('This page not found.');
$locale = $request->getLocale();
$departureCityObj = $this->em->getRepository(City::class)->checkDepartureCity($departureCity, $locale);
if (is_null($departureCityObj)) throw new NotFoundHttpException('This page not found.');
$cities = $this->page->getCities($countryObj->getRecId(), $cityObj->getId(), $locale);
$page = $this->generator->getLandingPage($market, $country, $city, null, null, null, null, $departureCityObj['id'], $locale, true);
$seo = $this->generator->getTourSeoAction($market, $country, $city, null, null, $departureCityObj['id'], $locale, true);
$seoUrls = $this->geoSeoUrlRepository->findByCity($cityObj->getId());
$hotels = $this->getCountriesHP($market, $page, 'hotels', 'city', $cityObj->getId(), $locale);
$response = $this->render('geo/city-search.html.twig', [
'cities' => $cities,
'page' => $page,
'seo' => $seo,
'country' => $country,
'countryId' => $countryObj->getId(),
'cityId' => $cityObj->getId(),
'city' => $city,
'departureCity' => $departureCityObj,
'type' => 'search_resort_from_' . $departureCity,
'seoUrls' => $seoUrls,
'hotels' => $hotels,
]);
$response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER, 'true');
return $response;
}
/**
* @Route(
* "/search/{country}/",
* name="app_country_search",
* methods={"GET"}
* )
*/
public function countrySearch(Request $request, $country)
{
$market = $request->getSession()->get('market');
$countryObj = $this->em->getRepository(Country::class)->findOneBy(['fNameTr' => $country]);
if (is_null($countryObj)) throw new NotFoundHttpException('This page not found.');
$locale = $request->getLocale();
$cities = $this->page->getCities($countryObj->getRecId(), null, $locale);
$page = $this->generator->getLandingPage($market, $country, null, null, null, null, null, null, $locale);
$seo = $this->generator->getTourSeoAction($market, $country, null, null, null, null, $locale);
$selections = $this->generator->getSelectionsForGeoById($market['code'], $countryObj->getRecId());
$factsBlocks = $this->page->getGeoTextById($countryObj->getRecId(), 'country', 'facts');
$aboutBlocks = $this->page->getGeoTextById($countryObj->getRecId(), 'country', 'about');
$seoUrls = $this->geoSeoUrlRepository->findByCountry($countryObj->getRecId());
$countries = $this->getCountriesHP($market, $page);
$hotels = $this->getCountriesHP($market, $page, 'hotels', 'country', $countryObj->getRecId(), $locale);
$response = $this->render('geo/country-search.html.twig', [
'cities' => $cities,
'page' => $page,
'seo' => $seo,
'country' => $country,
'countryId' => $countryObj->getRecId(),
'type' => 'search_country',
'selections' => $selections,
'factsBlocks' => $factsBlocks,
'aboutBlocks' => $aboutBlocks,
'seoUrls' => $seoUrls,
'countries' => $countries,
'hotels' => $hotels,
]);
$response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER, 'true');
return $response;
}
/**
* @Route(
* "/search/{country}/{city}/",
* name="app_city_search",
* methods={"GET"}
* )
*/
public function citySearch(Request $request, $country, $city, TranslatorInterface $translator)
{
$market = $request->getSession()->get('market');
$countryObj = $this->em->getRepository(Country::class)->findOneBy(['fNameTr' => $country]);
if (is_null($countryObj)) throw new NotFoundHttpException('This page not found.');
$cityObj = $this->em->getRepository(City::class)->findOneBy(['fNameTr' => $city]);
if (is_null($cityObj)) throw new NotFoundHttpException('This page not found.');
$locale = $request->getLocale();
$cities = $this->page->getCities($countryObj->getRecId(), $cityObj->getId(), $locale);
$page = $this->generator->getLandingPage($market, $country, $city, null, null, null, null, null, $locale);
$seo = $this->generator->getTourSeoAction($market, $country, $city, null, null, null, $locale);
$selections = $this->generator->getSelectionsForGeoById($market['code'], $cityObj->getId());
$factsBlocks = $this->page->getGeoTextById($cityObj->getId(), 'city', 'facts');
$aboutBlocks = $this->page->getGeoTextById($cityObj->getId(), 'city', 'about');
$seoUrls = $this->geoSeoUrlRepository->findByCity($cityObj->getId());
$countries = $this->getCountriesHP($market, $page);
$hotels = $this->getCountriesHP($market, $page, 'hotels', 'city', $cityObj->getId(), $locale);
$response = $this->render('geo/city-search.html.twig', [
'cities' => $cities,
'page' => $page,
'seo' => $seo,
'country' => $country,
'city' => $city,
'countryId' => $countryObj->getId(),
'cityId' => $cityObj->getId(),
'type' => 'search_resort',
'selections' => $selections,
'factsBlocks' => $factsBlocks,
'aboutBlocks' => $aboutBlocks,
'seoUrls' => $seoUrls,
'countries' => $countries,
'hotels' => $hotels,
]);
$response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER, 'true');
return $response;
}
/**
* @Route(
* "/countries/",
* name="app_countries",
* methods={"GET"}
* )
*/
public function countries(Request $request)
{
$market = $request->getSession()->get('market');
$locale = $request->getLocale();
$page = $this->generator->getPageCountries($market, $locale);
// dd($page);
$seo = $this->generator->getSeoCountries($locale);
$response = $this->render('geo/countries.html.twig', [
'page' => $page,
'seo' => $seo,
]);
$response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER, 'true');
return $response;
}
/**
* @Route(
* "/{country}/cities/{rubric}/",
* name="app_country_cities_rubric",
* methods={"GET"}
* )
*/
public function countryCitiesRubric(Request $request, $country, $rubric)
{
$market = $request->getSession()->get('market');
$countryObj = $this->em->getRepository(Country::class)->findOneBy(['fNameTr' => $country]);
if (is_null($countryObj)) throw new NotFoundHttpException('This page not found.');
$rubricObj = $this->em->getRepository(Rubric::class)->checkByCountryAndSlug($countryObj, $rubric);
if (empty($rubricObj)) $rubricObj = $this->em->getRepository(Rubric::class)->checkByCountryAndSlug($countryObj, $rubric, true);
if (empty($rubricObj)) throw new NotFoundHttpException('This page not found.');
$locale = $request->getLocale();
$page = $this->generator->getLandingPage($market, $country, null, null, null, null, null, null, $locale);
$seo = $this->generator->getRubricSeo($countryObj, $rubricObj, $locale);
$rubrics = $this->generator->getRubrics($countryObj, $rubricObj, $locale);
$response = $this->render('geo/country-cities-rubric.html.twig', [
'page' => $page,
'seo' => $seo,
'country' => $country,
'countryId' => $countryObj->getRecId(),
'type' => 'search_country',
'rubrics' => $rubrics,
'rubricObj' => $rubricObj,
]);
$response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER, 'true');
return $response;
}
/**
* @Route(
* "/{country}/cities/",
* name="app_country_cities",
* methods={"GET"}
* )
*/
public function countryCities(Request $request, $country)
{
$market = $request->getSession()->get('market');
$countryObj = $this->em->getRepository(Country::class)->findOneBy(['fNameTr' => $country]);
if (is_null($countryObj)) throw new NotFoundHttpException('This page not found.');
$locale = $request->getLocale();
$page = $this->generator->getLandingPage($market, $country, null, null, null, null, null, null, $locale, false, true);
$seo = $this->generator->getRubricSeo($countryObj, null, $locale);
$rubrics = $this->generator->getRubrics($countryObj, null, $locale);
$cities = $this->page->getCities($countryObj->getRecId(), null, $locale);
if (empty($rubrics)) $rubrics = $this->generator->getRubrics($countryObj, null, $locale, true);
$response = $this->render('geo/country-cities.html.twig', [
'page' => $page,
'seo' => $seo,
'country' => $country,
'countryId' => $countryObj->getRecId(),
'type' => 'search_country',
'rubrics' => $rubrics,
'cities' => $cities,
]);
$response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER, 'true');
return $response;
}
/**
* @Route(
* "/{country}/",
* name="app_country",
* methods={"GET"},
* requirements={"country"="^(?!acc).*"},
* priority=-10
* )
*/
public function country(Request $request, $country)
{
if (empty($country)) throw new NotFoundHttpException('This page not found.');
$countryObj = $this->em->getRepository(Country::class)->findOneBy(['fNameTr' => $country]);
if (is_null($countryObj)) throw new NotFoundHttpException('This page not found.');
return $this->redirectToRoute('app_country_search', ['country' => $country], 301);
}
/**
* @Route(
* "/{country}/{city}/",
* name="app_city",
* methods={"GET"},
* requirements={"country"="^(?!acc).*"},
* priority=-10
* )
*/
public function city(Request $request, $country, $city)
{
$countryObj = $this->em->getRepository(Country::class)->findOneBy(['fNameTr' => $country]);
if (is_null($countryObj)) throw new NotFoundHttpException('This page not found.');
$cityObj = $this->em->getRepository(City::class)->findOneBy(['fNameTr' => $city]);
if (is_null($cityObj)) throw new NotFoundHttpException('This page not found.');
return $this->redirectToRoute('app_city_search', ['country' => $country, 'city' => $city], 301);
}
public function getCountriesHP($market, $page, $data = 'countries', $geo = 'country', $geoId = 1, $locale = 'ru')
{
if (
empty($page->hotBudget) &&
empty($page->hot) &&
empty($page->hotLux) &&
empty($page->qualityPrice) &&
empty($page->friendsBudget) &&
empty($page->friends) &&
empty($page->friendsLux) &&
empty($page->romanticBudget) &&
empty($page->romantic) &&
empty($page->romanticLux) &&
empty($page->familyBudget) &&
empty($page->family) &&
empty($page->familyLux) &&
empty($page->peacefulBudget) &&
empty($page->peaceful) &&
empty($page->peacefulLux)
) {
if ($data == 'hotels') return $this->page->getTopHotelsByGeo($geo, $geoId, $locale);
return $this->page->getPopularCountriesForHP($market);
}
return [];
}
}