feat: extract game config from POST and pass eligible AwardTypes to template
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -42,7 +42,40 @@ class GameController extends AbstractController
|
||||
return $this->redirectToRoute('app_homepage');
|
||||
}
|
||||
|
||||
$game = $generator->generate($user);
|
||||
// Build config from form parameters
|
||||
$config = [];
|
||||
|
||||
if ($user && $request->request->getBoolean('watched_only')) {
|
||||
$config['watchedOnly'] = true;
|
||||
}
|
||||
|
||||
$hintTypes = [];
|
||||
if ($request->request->getBoolean('hint_film', true)) {
|
||||
$hintTypes[] = 'film';
|
||||
}
|
||||
if ($request->request->getBoolean('hint_character', true)) {
|
||||
$hintTypes[] = 'character';
|
||||
}
|
||||
if ($request->request->getBoolean('hint_award', true)) {
|
||||
$hintTypes[] = 'award';
|
||||
}
|
||||
if (empty($hintTypes)) {
|
||||
$hintTypes = ['film', 'character', 'award'];
|
||||
}
|
||||
$config['hintTypes'] = $hintTypes;
|
||||
|
||||
/** @var list<string> $awardTypeIds */
|
||||
$awardTypeIds = $request->request->all('award_types');
|
||||
if (!empty($awardTypeIds) && in_array('award', $hintTypes)) {
|
||||
$config['awardTypeIds'] = array_map('intval', $awardTypeIds);
|
||||
}
|
||||
|
||||
$game = $generator->generate($user, $config);
|
||||
|
||||
if ($game === null) {
|
||||
$this->addFlash('error', 'Impossible de générer une grille avec ces paramètres. Essayez avec des critères moins restrictifs.');
|
||||
return $this->redirectToRoute('app_homepage');
|
||||
}
|
||||
|
||||
if (!$user) {
|
||||
$request->getSession()->set('current_game_id', $game->getId());
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace App\Controller;
|
||||
|
||||
use App\Entity\Game;
|
||||
use App\Entity\User;
|
||||
use App\Repository\AwardTypeRepository;
|
||||
use App\Repository\GameRepository;
|
||||
use App\Provider\GameGridProvider;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
@@ -20,6 +21,7 @@ class HomepageController extends AbstractController
|
||||
Request $request,
|
||||
GameRepository $gameRepository,
|
||||
GameGridProvider $gridGenerator,
|
||||
AwardTypeRepository $awardTypeRepository,
|
||||
): Response {
|
||||
/** @var User|null $user */
|
||||
$user = $this->getUser();
|
||||
@@ -42,6 +44,7 @@ class HomepageController extends AbstractController
|
||||
if (!$game) {
|
||||
return $this->render('homepage/index.html.twig', [
|
||||
'game' => null,
|
||||
'awardTypes' => $awardTypeRepository->findWithMinActors(5),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user