src/Controller/GeoController.php line 295

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Otpusk\City;
  4. use App\Entity\Otpusk\Country;
  5. use App\Entity\Otpusk\Rubric;
  6. use App\Entity\Otpusk\Selection;
  7. use App\Repository\Otpusk\GeoSeoUrlRepository;
  8. use App\Services\PageGenerator;
  9. use App\Services\PageService;
  10. use Doctrine\ORM\EntityManager;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  13. use Symfony\Component\HttpKernel\EventListener\AbstractSessionListener;
  14. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  15. use Symfony\Component\Routing\Annotation\Route;
  16. use Symfony\Contracts\Translation\TranslatorInterface;
  17. class GeoController extends AbstractController
  18. {
  19.     private $months = [
  20.         => 'january',
  21.         => 'february',
  22.         => 'march',
  23.         => 'april',
  24.         => 'may',
  25.         => 'june',
  26.         => 'july',
  27.         => 'august',
  28.         => 'september',
  29.         10 => 'october',
  30.         11 => 'november',
  31.         12 => 'december'
  32.     ];
  33.     private $em;
  34.     private $generator;
  35.     /**
  36.      * @var \App\Repository\Otpusk\GeoSeoUrlRepository
  37.      */
  38.     private $geoSeoUrlRepository;
  39.     private $page;
  40.     public function __construct(EntityManager $entityManagerPageGenerator $generatorGeoSeoUrlRepository $geoSeoUrlRepositoryPageService $page)
  41.     {
  42.         $this->em $entityManager;
  43.         $this->generator $generator;
  44.         $this->geoSeoUrlRepository $geoSeoUrlRepository;
  45.         $this->page $page;
  46.     }
  47.     /**
  48.      * @Route(
  49.      *     "/search/{country}/{city}/{season}/",
  50.      *     name="app_city_search_season",
  51.      *     methods={"GET"},
  52.      *     requirements={
  53.      *         "season"="september|october|november|december|january|february|march|april|may|june|july|august|summer|autumn|winter|spring"
  54.      *     })
  55.      */
  56.     public function citySearchSeason(Request $request$country$city$season)
  57.     {
  58.         $market $request->getSession()->get('market');
  59.         $countryObj $this->em->getRepository(Country::class)->findOneBy(['fNameTr' => $country]);
  60.         if (is_null($countryObj)) throw new NotFoundHttpException('This page not found.');
  61.         $cityObj $this->em->getRepository(City::class)->findOneBy(['fNameTr' => $city]);
  62.         if (is_null($cityObj)) throw new NotFoundHttpException('This page not found.');
  63.         $locale $request->getLocale();
  64.         $cities $this->page->getCities($countryObj->getRecId(), $cityObj->getId(), $locale);
  65.         if ($key array_search($season$this->months)) {
  66.             $page $this->generator->getLandingPage($market$country$city$keynullnullnullnull$locale);
  67.         } else {
  68.             $page $this->generator->getLandingPage($market$country$citynull$seasonnullnullnull$locale);
  69.         }
  70.         $seo $this->generator->getTourSeasonSeoAction($market$country$season$citynull$locale);
  71.         $dates $this->generator->seasonDates[$season];
  72.         $seoUrls $this->geoSeoUrlRepository->findByCity($cityObj->getId());
  73.         $countries $this->getCountriesHP($market$page);
  74.         $hotels $this->getCountriesHP($market$page'hotels''city'$cityObj->getId(), $locale);
  75.         $response $this->render('geo/city-search-season.html.twig', [
  76.             'cities' => $cities,
  77.             'page' => $page,
  78.             'seo' => $seo,
  79.             'country' => $country,
  80.             'season' => $season,
  81.             'countryId' => $countryObj->getId(),
  82.             'cityId' => $cityObj->getId(),
  83.             'city' => $city,
  84.             'dates' => $dates,
  85.             'type' => (in_array($season$this->months)) ? 'search_resort_month' 'search_resort_season',
  86.             'seoUrls' => $seoUrls,
  87.             'countries' => $countries,
  88.             'hotels' => $hotels,
  89.         ]);
  90.         $response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER'true');
  91.         return $response;
  92.     }
  93.     /**
  94.      * @Route(
  95.      *     "/search/{country}/{season}/",
  96.      *     name="app_country_search_season",
  97.      *     methods={"GET"},
  98.      *     requirements={
  99.      *         "season"="september|october|november|december|january|february|march|april|may|june|july|august|summer|autumn|winter|spring"
  100.      *     })
  101.      */
  102.     public function countrySearchSeason(Request $request$country$season)
  103.     {
  104.         $market $request->getSession()->get('market');
  105.         $countryObj $this->em->getRepository(Country::class)->findOneBy(['fNameTr' => $country]);
  106.         if (is_null($countryObj)) throw new NotFoundHttpException('This page not found.');
  107.         $locale $request->getLocale();
  108.         $cities $this->page->getCities($countryObj->getRecId(), null$locale);
  109.         if ($key array_search($season$this->months)) {
  110.             $page $this->generator->getLandingPage($market$countrynull$keynullnullnullnull$locale);
  111.         } else {
  112.             $page $this->generator->getLandingPage($market$countrynullnull$seasonnullnullnull$locale);
  113.         }
  114.         $seo $this->generator->getTourSeasonSeoAction($market$country$seasonnullnull$locale);
  115.         $dates $this->generator->seasonDates[$season];
  116.         $seoUrls $this->geoSeoUrlRepository->findByCountry($countryObj->getRecId());
  117.         $countries $this->getCountriesHP($market$page);
  118.         $hotels $this->getCountriesHP($market$page'hotels''country'$countryObj->getRecId(), $locale);
  119.         $response $this->render('geo/country-search-season.html.twig', [
  120.             'cities' => $cities,
  121.             'page' => $page,
  122.             'seo' => $seo,
  123.             'country' => $country,
  124.             'season' => $season,
  125.             'countryId' => $countryObj->getRecId(),
  126.             'dates' => $dates,
  127.             'seoUrls' => $seoUrls,
  128.             'type' => (in_array($season$this->months)) ? 'search_country_month' 'search_country_season',
  129.             'countries' => $countries,
  130.             'hotels' => $hotels,
  131.         ]);
  132.         $response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER'true');
  133.         return $response;
  134.     }
  135.     /**
  136.      * @Route(
  137.      *     "/search/{country}/from-{departureCity}/",
  138.      *     name="app_country_search_departure_city",
  139.      *     methods={"GET"}
  140.      *     )
  141.      */
  142.     public function countrySearchDepartureCity(Request $request$country$departureCity)
  143.     {
  144.         $market $request->getSession()->get('market');
  145.         $countryObj $this->em->getRepository(Country::class)->findOneBy(['fNameTr' => $country]);
  146.         if (is_null($countryObj)) throw new NotFoundHttpException('This page not found.');
  147.         $locale $request->getLocale();
  148.         $departureCityObj $this->em->getRepository(City::class)->checkDepartureCity($departureCity$locale);
  149.         if (is_null($departureCityObj)) throw new NotFoundHttpException('This page not found.');
  150.         $cities $this->page->getCities($countryObj->getRecId(), null$locale);
  151.         $page $this->generator->getLandingPage($market$countrynullnullnullnullnull$departureCityObj['id'], $localetrue);
  152.         $seo $this->generator->getTourSeoAction($market$countrynullnullnull$departureCityObj['id'], $localetrue);
  153.         $seoUrls $this->geoSeoUrlRepository->findByCountry($countryObj->getRecId());
  154.         $hotels $this->getCountriesHP($market$page'hotels''country'$countryObj->getRecId(), $locale);
  155.         $response $this->render('geo/country-search.html.twig', [
  156.             'cities' => $cities,
  157.             'page' => $page,
  158.             'seo' => $seo,
  159.             'country' => $country,
  160.             'countryId' => $countryObj->getRecId(),
  161.             'departureCity' => $departureCityObj,
  162.             'type' => 'search_country_from_' $departureCity,
  163.             'seoUrls' => $seoUrls,
  164.             'hotels' => $hotels,
  165.         ]);
  166.         $response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER'true');
  167.         return $response;
  168.     }
  169.     /**
  170.      * @Route(
  171.      *     "/search/{country}/{city}/from-{departureCity}/",
  172.      *     name="app_city_search_departure_city",
  173.      *     methods={"GET"}
  174.      *     )
  175.      */
  176.     public function citySearchDepartureCity(Request $request$country$city$departureCity)
  177.     {
  178.         $market $request->getSession()->get('market');
  179.         $countryObj $this->em->getRepository(Country::class)->findOneBy(['fNameTr' => $country]);
  180.         if (is_null($countryObj)) throw new NotFoundHttpException('This page not found.');
  181.         $cityObj $this->em->getRepository(City::class)->findOneBy(['fNameTr' => $city]);
  182.         if (is_null($cityObj)) throw new NotFoundHttpException('This page not found.');
  183.         $locale $request->getLocale();
  184.         $departureCityObj $this->em->getRepository(City::class)->checkDepartureCity($departureCity$locale);
  185.         if (is_null($departureCityObj)) throw new NotFoundHttpException('This page not found.');
  186.         $cities $this->page->getCities($countryObj->getRecId(), $cityObj->getId(), $locale);
  187.         $page $this->generator->getLandingPage($market$country$citynullnullnullnull$departureCityObj['id'], $localetrue);
  188.         $seo $this->generator->getTourSeoAction($market$country$citynullnull$departureCityObj['id'], $localetrue);
  189.         $seoUrls $this->geoSeoUrlRepository->findByCity($cityObj->getId());
  190.         $hotels $this->getCountriesHP($market$page'hotels''city'$cityObj->getId(), $locale);
  191.         $response $this->render('geo/city-search.html.twig', [
  192.             'cities' => $cities,
  193.             'page' => $page,
  194.             'seo' => $seo,
  195.             'country' => $country,
  196.             'countryId' => $countryObj->getId(),
  197.             'cityId' => $cityObj->getId(),
  198.             'city' => $city,
  199.             'departureCity' => $departureCityObj,
  200.             'type' => 'search_resort_from_' $departureCity,
  201.             'seoUrls' => $seoUrls,
  202.             'hotels' => $hotels,
  203.         ]);
  204.         $response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER'true');
  205.         return $response;
  206.     }
  207.     /**
  208.      * @Route(
  209.      *     "/search/{country}/",
  210.      *     name="app_country_search",
  211.      *     methods={"GET"}
  212.      *     )
  213.      */
  214.     public function countrySearch(Request $request$country)
  215.     {
  216.         $market $request->getSession()->get('market');
  217.         $countryObj $this->em->getRepository(Country::class)->findOneBy(['fNameTr' => $country]);
  218.         if (is_null($countryObj)) throw new NotFoundHttpException('This page not found.');
  219.         $locale $request->getLocale();
  220.         $cities $this->page->getCities($countryObj->getRecId(), null$locale);
  221.         $page $this->generator->getLandingPage($market$countrynullnullnullnullnullnull$locale);
  222.         $seo $this->generator->getTourSeoAction($market$countrynullnullnullnull$locale);
  223.         $selections $this->generator->getSelectionsForGeoById($market['code'], $countryObj->getRecId());
  224.         $factsBlocks $this->page->getGeoTextById($countryObj->getRecId(), 'country''facts');
  225.         $aboutBlocks $this->page->getGeoTextById($countryObj->getRecId(), 'country''about');
  226.         $seoUrls $this->geoSeoUrlRepository->findByCountry($countryObj->getRecId());
  227.         $countries $this->getCountriesHP($market$page);
  228.         $hotels $this->getCountriesHP($market$page'hotels''country'$countryObj->getRecId(), $locale);
  229.         $response $this->render('geo/country-search.html.twig', [
  230.             'cities' => $cities,
  231.             'page' => $page,
  232.             'seo' => $seo,
  233.             'country' => $country,
  234.             'countryId' => $countryObj->getRecId(),
  235.             'type' => 'search_country',
  236.             'selections' => $selections,
  237.             'factsBlocks' => $factsBlocks,
  238.             'aboutBlocks' => $aboutBlocks,
  239.             'seoUrls' => $seoUrls,
  240.             'countries' => $countries,
  241.             'hotels' => $hotels,
  242.         ]);
  243.         $response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER'true');
  244.         return $response;
  245.     }
  246.     /**
  247.      * @Route(
  248.      *     "/search/{country}/{city}/",
  249.      *     name="app_city_search",
  250.      *     methods={"GET"}
  251.      *     )
  252.      */
  253.     public function citySearch(Request $request$country$cityTranslatorInterface $translator)
  254.     {
  255.         $market $request->getSession()->get('market');
  256.         $countryObj $this->em->getRepository(Country::class)->findOneBy(['fNameTr' => $country]);
  257.         if (is_null($countryObj)) throw new NotFoundHttpException('This page not found.');
  258.         $cityObj $this->em->getRepository(City::class)->findOneBy(['fNameTr' => $city]);
  259.         if (is_null($cityObj)) throw new NotFoundHttpException('This page not found.');
  260.         $locale $request->getLocale();
  261.         $cities $this->page->getCities($countryObj->getRecId(), $cityObj->getId(), $locale);
  262.         $page $this->generator->getLandingPage($market$country$citynullnullnullnullnull$locale);
  263.         $seo $this->generator->getTourSeoAction($market$country$citynullnullnull$locale);
  264.         $selections $this->generator->getSelectionsForGeoById($market['code'], $cityObj->getId());
  265.         $factsBlocks $this->page->getGeoTextById($cityObj->getId(), 'city''facts');
  266.         $aboutBlocks $this->page->getGeoTextById($cityObj->getId(), 'city''about');
  267.         $seoUrls $this->geoSeoUrlRepository->findByCity($cityObj->getId());
  268.         $countries $this->getCountriesHP($market$page);
  269.         $hotels $this->getCountriesHP($market$page'hotels''city'$cityObj->getId(), $locale);
  270.         $response $this->render('geo/city-search.html.twig', [
  271.             'cities' => $cities,
  272.             'page' => $page,
  273.             'seo' => $seo,
  274.             'country' => $country,
  275.             'city' => $city,
  276.             'countryId' => $countryObj->getId(),
  277.             'cityId' => $cityObj->getId(),
  278.             'type' => 'search_resort',
  279.             'selections' => $selections,
  280.             'factsBlocks' => $factsBlocks,
  281.             'aboutBlocks' => $aboutBlocks,
  282.             'seoUrls' => $seoUrls,
  283.             'countries' => $countries,
  284.             'hotels' => $hotels,
  285.         ]);
  286.         $response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER'true');
  287.         return $response;
  288.     }
  289.     /**
  290.      * @Route(
  291.      *     "/countries/",
  292.      *     name="app_countries",
  293.      *     methods={"GET"}
  294.      *     )
  295.      */
  296.     public function countries(Request $request)
  297.     {
  298.         $market $request->getSession()->get('market');
  299.         $locale $request->getLocale();
  300.         $page $this->generator->getPageCountries($market$locale);
  301. //        dd($page);
  302.         $seo $this->generator->getSeoCountries($locale);
  303.         $response $this->render('geo/countries.html.twig', [
  304.             'page' => $page,
  305.             'seo' => $seo,
  306.         ]);
  307.         $response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER'true');
  308.         return $response;
  309.     }
  310.     /**
  311.      * @Route(
  312.      *     "/{country}/cities/{rubric}/",
  313.      *     name="app_country_cities_rubric",
  314.      *     methods={"GET"}
  315.      *     )
  316.      */
  317.     public function countryCitiesRubric(Request $request$country$rubric)
  318.     {
  319.         $market $request->getSession()->get('market');
  320.         $countryObj $this->em->getRepository(Country::class)->findOneBy(['fNameTr' => $country]);
  321.         if (is_null($countryObj)) throw new NotFoundHttpException('This page not found.');
  322.         $rubricObj $this->em->getRepository(Rubric::class)->checkByCountryAndSlug($countryObj$rubric);
  323.         if (empty($rubricObj)) $rubricObj $this->em->getRepository(Rubric::class)->checkByCountryAndSlug($countryObj$rubrictrue);
  324.         if (empty($rubricObj)) throw new NotFoundHttpException('This page not found.');
  325.         $locale $request->getLocale();
  326.         $page $this->generator->getLandingPage($market$countrynullnullnullnullnullnull$locale);
  327.         $seo $this->generator->getRubricSeo($countryObj$rubricObj$locale);
  328.         $rubrics $this->generator->getRubrics($countryObj$rubricObj$locale);
  329.         $response $this->render('geo/country-cities-rubric.html.twig', [
  330.             'page' => $page,
  331.             'seo' => $seo,
  332.             'country' => $country,
  333.             'countryId' => $countryObj->getRecId(),
  334.             'type' => 'search_country',
  335.             'rubrics' => $rubrics,
  336.             'rubricObj' => $rubricObj,
  337.         ]);
  338.         $response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER'true');
  339.         return $response;
  340.     }
  341.     /**
  342.      * @Route(
  343.      *     "/{country}/cities/",
  344.      *     name="app_country_cities",
  345.      *     methods={"GET"}
  346.      *     )
  347.      */
  348.     public function countryCities(Request $request$country)
  349.     {
  350.         $market $request->getSession()->get('market');
  351.         $countryObj $this->em->getRepository(Country::class)->findOneBy(['fNameTr' => $country]);
  352.         if (is_null($countryObj)) throw new NotFoundHttpException('This page not found.');
  353.         $locale $request->getLocale();
  354.         $page $this->generator->getLandingPage($market$countrynullnullnullnullnullnull$localefalsetrue);
  355.         $seo $this->generator->getRubricSeo($countryObjnull$locale);
  356.         $rubrics $this->generator->getRubrics($countryObjnull$locale);
  357.         $cities $this->page->getCities($countryObj->getRecId(), null$locale);
  358.         if (empty($rubrics)) $rubrics $this->generator->getRubrics($countryObjnull$localetrue);
  359.         $response $this->render('geo/country-cities.html.twig', [
  360.             'page' => $page,
  361.             'seo' => $seo,
  362.             'country' => $country,
  363.             'countryId' => $countryObj->getRecId(),
  364.             'type' => 'search_country',
  365.             'rubrics' => $rubrics,
  366.             'cities' => $cities,
  367.         ]);
  368.         $response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER'true');
  369.         return $response;
  370.     }
  371.     /**
  372.      * @Route(
  373.      *     "/{country}/",
  374.      *     name="app_country",
  375.      *     methods={"GET"},
  376.      *     requirements={"country"="^(?!acc).*"},
  377.      *     priority=-10
  378.      *     )
  379.      */
  380.     public function country(Request $request$country)
  381.     {
  382.         if (empty($country)) throw new NotFoundHttpException('This page not found.');
  383.         $countryObj $this->em->getRepository(Country::class)->findOneBy(['fNameTr' => $country]);
  384.         if (is_null($countryObj)) throw new NotFoundHttpException('This page not found.');
  385.         return $this->redirectToRoute('app_country_search', ['country' => $country], 301);
  386.     }
  387.     /**
  388.      * @Route(
  389.      *     "/{country}/{city}/",
  390.      *     name="app_city",
  391.      *     methods={"GET"},
  392.      *     requirements={"country"="^(?!acc).*"},
  393.      *     priority=-10
  394.      *     )
  395.      */
  396.     public function city(Request $request$country$city)
  397.     {
  398.         $countryObj $this->em->getRepository(Country::class)->findOneBy(['fNameTr' => $country]);
  399.         if (is_null($countryObj)) throw new NotFoundHttpException('This page not found.');
  400.         $cityObj $this->em->getRepository(City::class)->findOneBy(['fNameTr' => $city]);
  401.         if (is_null($cityObj)) throw new NotFoundHttpException('This page not found.');
  402.         return $this->redirectToRoute('app_city_search', ['country' => $country'city' => $city], 301);
  403.     }
  404.     public function getCountriesHP($market$page$data 'countries'$geo 'country'$geoId 1$locale 'ru')
  405.     {
  406.         if (
  407.             empty($page->hotBudget) &&
  408.             empty($page->hot) &&
  409.             empty($page->hotLux) &&
  410.             empty($page->qualityPrice) &&
  411.             empty($page->friendsBudget) &&
  412.             empty($page->friends) &&
  413.             empty($page->friendsLux) &&
  414.             empty($page->romanticBudget) &&
  415.             empty($page->romantic) &&
  416.             empty($page->romanticLux) &&
  417.             empty($page->familyBudget) &&
  418.             empty($page->family) &&
  419.             empty($page->familyLux) &&
  420.             empty($page->peacefulBudget) &&
  421.             empty($page->peaceful) &&
  422.             empty($page->peacefulLux)
  423.         ) {
  424.             if ($data == 'hotels') return $this->page->getTopHotelsByGeo($geo$geoId$locale);
  425.             return $this->page->getPopularCountriesForHP($market);
  426.         }
  427.         return [];
  428.     }
  429. }