<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use App\Services\SessionService;
use Symfony\Contracts\Translation\TranslatorInterface;
class HomeController extends AbstractController
{
private SessionService $sessionService;
public function __construct(SessionService $sessionService)
{
$this->sessionService = $sessionService;
}
public function indexNoLocale(Request $request): Response
{
$language = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
if ($request->get('lang')) {
$language = $request->get('lang');
}
if ($language != 'fr' && $language != 'en') {
$language = 'en';
}
return $this->redirectToRoute('root', ['_locale' => $language]);
}
public function oldUrlInterceptor(Request $request)
{
$language = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
if ($request->get('lang')) {
$language = $request->get('lang');
}
if ($language != 'fr' && $language != 'en') {
$language = 'en';
}
$redirectUrl = $this->generateUrl('root', ['_locale' => $language]);
return $this->redirect($redirectUrl);
}
#[Route('/', name: 'root', methods: ["GET"])]
public function index(Request $request): Response
{
return $this->redirectToRoute('app_login');
}
#[Route('/overview', name: 'overview', methods: ["GET"])]
public function overview(Request $request,TranslatorInterface $translator): Response
{
$data = $this->sessionService->_getBaseParameters();
$session = $request->getSession();
if ($session->get('code')) {
return $this->redirectToRoute('home');
}
$data['title'] = $translator->trans('pages.overview.title');
return $this->render('BasePages/overview.twig', $data);
}
#[Route('/questions', name: 'questions', methods: ["GET"])]
public function questions(Request $request,TranslatorInterface $translator): Response
{
$data = $this->sessionService->_getBaseParameters();
$data['title'] = $translator->trans('pages.questions.title');
return $this->render('BasePages/questions.twig', $data);
}
}