The chat used to disappear the moment a session left CREATED status.
Sessions now record a finishedAt timestamp when they're won or lost,
and the lobby (with chat) stays reachable via /game/{session} for an
hour afterward instead of immediately redirecting to the win/lose
feedback page. The lobby template shows a distinct "game finished"
header with a link to that feedback page during this window.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
46 lines
1.6 KiB
PHP
46 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Game\Controller;
|
|
|
|
use App\Game\Entity\Session;
|
|
use App\Game\Enum\SessionStatus;
|
|
use App\Game\Repository\SessionRepository;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
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\Attribute\IsGranted;
|
|
|
|
#[Route('/admin/sessions')]
|
|
#[IsGranted('ROLE_ADMIN')]
|
|
final class GameAdminSessionController extends AbstractController
|
|
{
|
|
#[Route('', name: 'game_admin_sessions', methods: ['GET'])]
|
|
public function index(SessionRepository $sessionRepository): Response
|
|
{
|
|
return $this->render('game/admin/sessions/index.html.twig', [
|
|
'sessions' => $sessionRepository->findBy([], ['created' => 'DESC']),
|
|
]);
|
|
}
|
|
|
|
#[Route('/{id}/close', name: 'game_admin_session_close', methods: ['POST'])]
|
|
public function close(Session $session, Request $request, EntityManagerInterface $em): Response
|
|
{
|
|
if (!$this->isCsrfTokenValid('close_session_' . $session->getId(), $request->request->get('_token'))) {
|
|
$this->addFlash('danger', 'Invalid CSRF token.');
|
|
return $this->redirectToRoute('game_admin_sessions');
|
|
}
|
|
|
|
$session->setStatus(SessionStatus::LOST);
|
|
$session->setFinishedAt(new \DateTime());
|
|
$em->flush();
|
|
|
|
$this->addFlash('success', sprintf('Session #%d closed.', $session->getId()));
|
|
|
|
return $this->redirectToRoute('game_admin_sessions');
|
|
}
|
|
}
|