<?php
namespace App\Controller;
use App\Entity\Reporting;
use App\Repository\ReportingRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class LoginController extends AbstractController
{
public function menu(int $active, string $subActive = '')
{
return $this->render('default/menu.html.twig', [
'active' => $active,
'subActive' => $subActive
]);
}
#[Route('/logout', name: 'app_logout')]
public function logout(): void
{
throw new \Exception('Don\'t forget to activate logout in security.yaml');
}
#[Route('/login', name: 'login')]
public function index(Request $request, AuthenticationUtils $authenticationUtils): Response
{
$error = $authenticationUtils->getLastAuthenticationError();
$lastEmail = $authenticationUtils->getLastUsername();
/**
* @var ReportingRepository
*/
$reportingRepository = $this->getDoctrine()->getManager()->getRepository(Reporting::class);
$reporting = $request->get('reporting') ? $reportingRepository->find( $request->get('reporting')) : $reportingRepository->findOneBy(['state' => 0], ['id' => 'DESC']);
return $this->render('login/index.html.twig', [
'last_email' => $lastEmail,
'error' => $error,
'reportings' => $reportingRepository->findAll(),
'reporting' => $reporting,
'stats' => $reporting ? $reportingRepository->findStatsByTown($reporting->getId()) : []
]);
}
}