src/Controller/Front/MainController.php line 47

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Front;
  3. use App\Config\FileDataTypeEnum;
  4. use App\Config\FaqRouteEnum;
  5. use App\Entity\FrontPage;
  6. use App\Entity\SocialNetwork;
  7. use App\Repository\SocialNetworkRepository;
  8. use App\Repository\HubLocationRepository;
  9. use App\Service\CurrencyService;
  10. use App\Service\FrontRecentSearchService;
  11. use App\Service\FrontService;
  12. use App\Service\ParameterService;
  13. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  14. use Symfony\Component\HttpFoundation\RedirectResponse;
  15. use Symfony\Component\HttpFoundation\Response;
  16. use Symfony\Component\Routing\Annotation\Route;
  17. use Symfony\Component\HttpFoundation\Request;
  18. class MainController extends AbstractController
  19. {
  20.     public function __construct(
  21.         private readonly FrontService             $frontService,
  22.         private readonly ParameterService         $parameterService,
  23.         private readonly FrontRecentSearchService $frontRecentSearchService,
  24.     )
  25.     {
  26.     }
  27.     #[Route('/auto_redirect', name: 'app_main_auto_redirect', methods: ['GET'])]
  28.     public function autoRedirect(): RedirectResponse
  29.     {
  30.         if ($this->getUser() && $this->isGranted('ROLE_AGENT')) {
  31.             return $this->redirectToRoute('app_admin_dashboard');
  32.         }
  33. //        if ($this->getUser() && $this->getUser()->getCustomer()) {
  34. //            return $this->redirectToRoute('app_front_user_area_booking');
  35. //        }
  36.         return $this->redirectToRoute('app_main');
  37.     }
  38.     #[Route('/', name: 'app_main', methods: ['GET', 'POST'])]
  39.     public function index(Request $request): Response
  40.     {
  41.         $error = $request->query->get("error");
  42.         $flightSuggestions = $this->frontService->getSuggestions('', 'FLIGHT');
  43.         $hotelSuggestions = $this->frontService->getSuggestions('', 'HOTEL');
  44.         $isB2B = $this->parameterService->isB2BMode();
  45.         $isSearchByMap = $this->parameterService->isSearchMap();
  46.         $template = $isB2B && !$this->getUser() ? "security/btob/login.html.twig" : "front/main/home.html.twig";
  47.         $frontMenus = $this->frontService->getFrontMenu();
  48.         $twig_parameters = [
  49.             'social_networks' => $this->frontService->getSocialNetworks(),
  50.             'currencies' => $this->frontService->getCurrencies(),
  51.             'agencies' => $this->frontService->getAgencies(),
  52.             'society' => $this->parameterService->getSocietyParameters(),
  53.             'front' => $this->parameterService->getFrontParameters(),
  54.             'hotel_search_history' => $this->frontRecentSearchService->getRecentSearchHotel(),
  55.             'flightSuggestions' => $flightSuggestions,
  56.             'hotelSuggestions' => $hotelSuggestions,
  57.             'isSearchByMap'=> $isSearchByMap,
  58.         ];
  59.         $sliderType = FileDataTypeEnum::slider;
  60.         if ($isB2B) {
  61.             $twig_parameters ['error'] = $error;
  62.             $sliderType = FileDataTypeEnum::sliderB2B;
  63.         }
  64.         $user = $this->getUser();
  65.         if ($user) {
  66.             $customer = $user->getCustomer();
  67.             if ($customer && $customer->getClass() == 'CustomerMoral') {
  68.                 $sliderType = FileDataTypeEnum::sliderB2B;
  69.             }
  70.         }
  71.         $twig_parameters ['homePage'] = $this->frontService->getHomePage();
  72.         $twig_parameters ['menu_front'] = $frontMenus;
  73.         $twig_parameters ['sliderImages'] = $this->frontService->getSliderImages($sliderType);
  74.         $twig_parameters ['sections'] = $this->frontService->getSections();
  75.         $twig_parameters ['zones'] = $this->frontService->getFrontZones();
  76.         $twig_parameters ['seo'] = $this->frontService->getSeoInfo(FrontPage::HOME_PAGE);
  77.         $twig_parameters ['modules'] = $this->parameterService->getActiveModules();
  78.         $twig_parameters ['home'] = 1;
  79.         $twig_parameters ['currencySwitcher'] = true;
  80.         $twig_parameters ['tracking_tools'] = $this->frontService->getTrackingTools();
  81.         $twig_parameters ['faqs'] = $this->frontService->getFaqs(FaqRouteEnum::APP_MAIN);
  82.         $twig_parameters ['tripSelectorVariant'] = $this->parameterService->getFlightTripSelectorVariant();
  83.         return $this->render($template, $twig_parameters);
  84.     }
  85.     #[Route('/convert-currency/{amount}/{from}/{to}', name: 'convert_currency')]
  86.     public function getConvertedCurrency(CurrencyService $currencyService, $amount, $from, $to
  87.     ): Response
  88.     {
  89.         $converted_amount = $currencyService->convert($amount, $from, $to);
  90.         return new Response(sprintf('%s', $converted_amount));
  91.     }
  92.     #[Route('/front/social_network/{id}', name: 'app_main_click_social_network', methods: ['GET', 'POST'])]
  93.     public function clickOnSocialNetwork(SocialNetwork $socialNetwork, SocialNetworkRepository $socialNetworkRepository): Response
  94.     {
  95.         $counter = $socialNetwork->getClicksCount();
  96.         if (is_null($counter)) {
  97.             $counter = 0;
  98.         }
  99.         $counter++;
  100.         $socialNetwork->setClicksCount($counter);
  101.         $socialNetworkRepository->add($socialNetwork, true);
  102.         return $this->redirect($socialNetwork->getUrl());
  103.     }
  104.     #[Route('/info-message', name: 'front_info_message', methods: ['GET'])]
  105.     public function flashMessagePage(): Response
  106.     {
  107.         $twig_parameters = [
  108.             'society' => $this->parameterService->getSocietyParameters(),
  109.             'social_networks' => $this->frontService->getSocialNetworks(),
  110.             'currencies' => $this->frontService->getCurrencies(),
  111.             'agencies' => $this->frontService->getAgencies(),
  112.             'tracking_tools' => $this->frontService->getTrackingTools()
  113.         ];
  114.         $twig_parameters = array_merge($twig_parameters, $this->frontService->getTrackingTools());
  115.         return $this->render("front/flash.html.twig", $twig_parameters);
  116.     }
  117. }