src/Controller/Front/MainController.php line 50

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