src/Controller/Front/MainController.php line 102

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