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.         $template $isB2B && !$this->getUser() ? "security/btob/login.html.twig" "front/main/home.html.twig";
  46.         $frontMenus $this->frontService->getFrontMenu();
  47.         $twig_parameters = [
  48.             'social_networks' => $this->frontService->getSocialNetworks(),
  49.             'currencies' => $this->frontService->getCurrencies(),
  50.             'agencies' => $this->frontService->getAgencies(),
  51.             'society' => $this->parameterService->getSocietyParameters(),
  52.             'front' => $this->parameterService->getFrontParameters(),
  53.             'hotel_search_history' => $this->frontRecentSearchService->getRecentSearchHotel(),
  54.             'flightSuggestions' => $flightSuggestions,
  55.             'hotelSuggestions' => $hotelSuggestions,
  56.         ];
  57.         $sliderType FileDataTypeEnum::slider;
  58.         if ($isB2B) {
  59.             $twig_parameters ['error'] = $error;
  60.             $sliderType FileDataTypeEnum::sliderB2B;
  61.         }
  62.         $user $this->getUser();
  63.         if ($user) {
  64.             $customer $user->getCustomer();
  65.             if ($customer && $customer->getClass() == 'CustomerMoral') {
  66.                 $sliderType FileDataTypeEnum::sliderB2B;
  67.             }
  68.         }
  69.         $twig_parameters ['homePage'] = $this->frontService->getHomePage();
  70.         $twig_parameters ['menu_front'] = $frontMenus;
  71.         $twig_parameters ['sliderImages'] = $this->frontService->getSliderImages($sliderType);
  72.         $twig_parameters ['sections'] = $this->frontService->getSections();
  73.         $twig_parameters ['zones'] = $this->frontService->getFrontZones();
  74.         $twig_parameters ['seo'] = $this->frontService->getSeoInfo(FrontPage::HOME_PAGE);
  75.         $twig_parameters ['modules'] = $this->parameterService->getActiveModules();
  76.         $twig_parameters ['home'] = 1;
  77.         $twig_parameters ['currencySwitcher'] = true;
  78.         $twig_parameters ['tracking_tools'] = $this->frontService->getTrackingTools();
  79.         $twig_parameters ['faqs'] = $this->frontService->getFaqs(FaqRouteEnum::APP_MAIN);
  80.         return $this->render($template$twig_parameters);
  81.     }
  82.     #[Route('/convert-currency/{amount}/{from}/{to}'name'convert_currency')]
  83.     public function getConvertedCurrency(CurrencyService $currencyService$amount$from$to
  84.     ): Response
  85.     {
  86.         $converted_amount $currencyService->convert($amount$from$to);
  87.         return new Response(sprintf('%s'$converted_amount));
  88.     }
  89.     #[Route('/front/social_network/{id}'name'app_main_click_social_network'methods: ['GET''POST'])]
  90.     public function clickOnSocialNetwork(SocialNetwork $socialNetworkSocialNetworkRepository $socialNetworkRepository): Response
  91.     {
  92.         $counter $socialNetwork->getClicksCount();
  93.         if (is_null($counter)) {
  94.             $counter 0;
  95.         }
  96.         $counter++;
  97.         $socialNetwork->setClicksCount($counter);
  98.         $socialNetworkRepository->add($socialNetworktrue);
  99.         return $this->redirect($socialNetwork->getUrl());
  100.     }
  101.     #[Route('/info-message'name'front_info_message'methods: ['GET'])]
  102.     public function flashMessagePage(): Response
  103.     {
  104.         $twig_parameters = [
  105.             'society' => $this->parameterService->getSocietyParameters(),
  106.             'social_networks' => $this->frontService->getSocialNetworks(),
  107.             'currencies' => $this->frontService->getCurrencies(),
  108.             'agencies' => $this->frontService->getAgencies(),
  109.             'tracking_tools' => $this->frontService->getTrackingTools()
  110.         ];
  111.         $twig_parameters array_merge($twig_parameters$this->frontService->getTrackingTools());
  112.         return $this->render("front/flash.html.twig"$twig_parameters);
  113.     }
  114. }