<?php
namespace App\Controller\Front;
use App\Config\FileDataTypeEnum;
use App\Entity\FrontPage;
use App\Entity\SocialNetwork;
use App\Repository\SocialNetworkRepository;
use App\Repository\HubLocationRepository;
use App\Service\CurrencyService;
use App\Service\FrontRecentSearchService;
use App\Service\FrontService;
use App\Service\ParameterService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class MainController extends AbstractController
{
public function __construct(
private readonly FrontService $frontService,
private readonly ParameterService $parameterService,
private readonly FrontRecentSearchService $frontRecentSearchService,
)
{
}
#[Route('/auto_redirect', name: 'app_main_auto_redirect', methods: ['GET'])]
public function autoRedirect(): RedirectResponse
{
if ($this->getUser() && $this->isGranted('ROLE_AGENT')) {
return $this->redirectToRoute('app_admin_dashboard');
}
// if ($this->getUser() && $this->getUser()->getCustomer()) {
// return $this->redirectToRoute('app_front_user_area_booking');
// }
return $this->redirectToRoute('app_main');
}
#[Route('/', name: 'app_main', methods: ['GET', 'POST'])]
public function index(): Response
{
$flightSuggestions = $this->frontService->getSuggestions('', 'FLIGHT');
$hotelSuggestions = $this->frontService->getSuggestions('', 'HOTEL');
$isB2B = $this->parameterService->isB2BMode();
$template = $isB2B && !$this->getUser() ? "security/btob/login.html.twig" : "front/main/home.html.twig";
$twig_parameters = [
'social_networks' => $this->frontService->getSocialNetworks(),
'currencies' => $this->frontService->getCurrencies(),
'agencies' => $this->frontService->getAgencies(),
'society' => $this->parameterService->getSocietyParameters(),
'front' => $this->parameterService->getFrontParameters(),
'hotel_search_history' => $this->frontRecentSearchService->getRecentSearchHotel(),
'flightSuggestions' => $flightSuggestions,
'hotelSuggestions' => $hotelSuggestions,
];
if ($isB2B) {
$twig_parameters ['error'] = false;
}
$sliderType = FileDataTypeEnum::slider;
$user = $this->getUser();
if ($user) {
$customer = $user->getCustomer();
if ($customer && $customer->getClass() == 'CustomerMoral') {
$sliderType = FileDataTypeEnum::sliderB2B;
}
}
$twig_parameters ['homePage'] = $this->frontService->getHomePage();
$twig_parameters ['menu_front'] = $this->frontService->getFrontMenu();
$twig_parameters ['sliderImages'] = $this->frontService->getSliderImages($sliderType);
$twig_parameters ['sections'] = $this->frontService->getSections();
$twig_parameters ['zones'] = $this->frontService->getFrontZones();
$twig_parameters ['seo'] = $this->frontService->getSeoInfo(FrontPage::HOME_PAGE);
$twig_parameters ['modules'] = $this->parameterService->getActiveModules();
$twig_parameters ['home'] = 1;
$twig_parameters ['currencySwitcher'] = true;
$twig_parameters ['tracking_tools'] = $this->frontService->getTrackingTools();
return $this->render($template, $twig_parameters);
}
#[Route('/convert-currency/{amount}/{from}/{to}', name: 'convert_currency')]
public function getConvertedCurrency(CurrencyService $currencyService, $amount, $from, $to
): Response
{
$converted_amount = $currencyService->convert($amount, $from, $to);
return new Response(sprintf('%s', $converted_amount));
}
#[Route('/front/social_network/{id}', name: 'app_main_click_social_network', methods: ['GET', 'POST'])]
public function clickOnSocialNetwork(SocialNetwork $socialNetwork, SocialNetworkRepository $socialNetworkRepository): Response
{
$counter = $socialNetwork->getClicksCount();
if (is_null($counter)) {
$counter = 0;
}
$counter++;
$socialNetwork->setClicksCount($counter);
$socialNetworkRepository->add($socialNetwork, true);
return $this->redirect($socialNetwork->getUrl());
}
#[Route('/info-message', name: 'front_info_message', methods: ['GET'])]
public function flashMessagePage(): Response
{
$twig_parameters = [
'society' => $this->parameterService->getSocietyParameters(),
'social_networks' => $this->frontService->getSocialNetworks(),
'currencies' => $this->frontService->getCurrencies(),
'agencies' => $this->frontService->getAgencies(),
'tracking_tools' => $this->frontService->getTrackingTools()
];
$twig_parameters= array_merge($twig_parameters, $this->frontService->getTrackingTools());
return $this->render("front/flash.html.twig", $twig_parameters);
}
}