diff --git a/src/Game/Controller/GameAdminGameController.php b/src/Game/Controller/GameAdminGameController.php index 55a5df3..c185aac 100644 --- a/src/Game/Controller/GameAdminGameController.php +++ b/src/Game/Controller/GameAdminGameController.php @@ -6,6 +6,7 @@ namespace App\Game\Controller; use App\Game\Entity\GameSetting; use App\Game\Enum\GameSettingType; +use App\Game\Enum\GameStatus; use App\Game\Form\AdminGameType; use App\Game\Entity\Game; use App\Game\Repository\GameRepository; @@ -29,6 +30,41 @@ final class GameAdminGameController extends AbstractController ]); } + #[Route('/new', name: 'game_admin_game_new', methods: ['GET', 'POST'])] + public function new( + Request $request, + EntityManagerInterface $em, + ): Response { + $game = new Game(); + $game->setStatus(GameStatus::IN_DEVELOPMENT); + + $form = $this->createForm(AdminGameType::class, $game); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $totalTime = $form->get('totalTime')->getData(); + + $em->persist($game); + + if ($totalTime !== null) { + $totalTimeSetting = new GameSetting(); + $totalTimeSetting->setGame($game); + $totalTimeSetting->setName(GameSettingType::TOTAL_TIME); + $totalTimeSetting->setValue((string) $totalTime); + $em->persist($totalTimeSetting); + } + + $em->flush(); + $this->addFlash('success', sprintf('Game "%s" created.', $game->getName())); + + return $this->redirectToRoute('game_admin_games'); + } + + return $this->render('game/admin/games/new.html.twig', [ + 'form' => $form, + ]); + } + #[Route('/{id}/edit', name: 'game_admin_game_edit', methods: ['GET', 'POST'])] public function edit( Game $game, diff --git a/templates/game/admin/games/index.html.twig b/templates/game/admin/games/index.html.twig index 5262a4f..eac2c84 100644 --- a/templates/game/admin/games/index.html.twig +++ b/templates/game/admin/games/index.html.twig @@ -5,7 +5,18 @@ {% block admin_body %}