src/Controller/Front/MainController.php line 46

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