81 lines
2.9 KiB
PHP
81 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Controller;
|
|
|
|
use App\Repository\ParticipantRepository;
|
|
use App\Repository\SiteRepository;
|
|
use App\Repository\SortieRepository;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\Routing\Attribute\Route;
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
class MainController extends AbstractController
|
|
{
|
|
|
|
#[Route('/', name: 'home')]
|
|
public function home(SortieRepository $sortieRepository, TokenStorageInterface $tokenStorage,): Response
|
|
{
|
|
// Récupérer les 5 dernières sorties
|
|
$latestSorties = $sortieRepository->findBy([], ['dateHeureDebut' => 'DESC'], 5);
|
|
$token = $tokenStorage->getToken();
|
|
$userConnect = $token?->getUser();
|
|
$dateLimit = new \DateTime();
|
|
$dateLimit->modify('-30 days'); // Date limite = il y a 30 jours
|
|
|
|
$pastEvents = $sortieRepository->createQueryBuilder('s')
|
|
->where('s.dateHeureDebut < :now')
|
|
->andWhere('s.dateHeureDebut >= :dateLimit')
|
|
->setParameter('now', new \DateTime())
|
|
->setParameter('dateLimit', $dateLimit)
|
|
->orderBy('s.dateHeureDebut', 'DESC')
|
|
->getQuery()
|
|
->getResult();
|
|
|
|
return $this->render('main/home.html.twig', [
|
|
'lastSorties' => $latestSorties,
|
|
'profile' => $userConnect,
|
|
'pastEvents' => $pastEvents,
|
|
]);
|
|
}
|
|
|
|
#[Route('/dashboard', name: 'dashboard')]
|
|
public function dashboard(
|
|
TokenStorageInterface $tokenStorage,
|
|
SortieRepository $sortieRepository,
|
|
Request $request
|
|
): Response {
|
|
$token = $tokenStorage->getToken();
|
|
$userConnect = $token?->getUser();
|
|
|
|
$sorties = $sortieRepository->findForDashboard();
|
|
$sortiesParticipation = $sortieRepository->findUserParticipation($userConnect);
|
|
$sortiesOrganisation = $sortieRepository->findUserOrganisation($userConnect);
|
|
|
|
return $this->render('main/dashboard.html.twig', [
|
|
'profile' => $userConnect,
|
|
'sorties' => $sorties,
|
|
'sortiesParticipation' => $sortiesParticipation,
|
|
'sortiesOrganisation' => $sortiesOrganisation,
|
|
]);
|
|
}
|
|
|
|
#[Route('/inscription', name: 'inscription')]
|
|
public function inscription(TokenStorageInterface $tokenStorage): Response
|
|
{
|
|
return $this->render('main/inscription.html.twig');
|
|
}
|
|
|
|
#[Route('/participants', name: 'participants')]
|
|
public function participants(TokenStorageInterface $tokenStorage, ParticipantRepository $participantRepository): Response
|
|
{
|
|
$token = $tokenStorage->getToken();
|
|
$userConnect = $token?->getUser();
|
|
return $this->render('main/participants.html.twig', [
|
|
'profile' => $userConnect,
|
|
'participants' => $participantRepository->findAll(),
|
|
]);
|
|
}
|
|
}
|