diff --git a/src/Service/GameGridGenerator.php b/src/Service/GameGridGenerator.php index 4353557..c7c39b0 100644 --- a/src/Service/GameGridGenerator.php +++ b/src/Service/GameGridGenerator.php @@ -9,6 +9,7 @@ use App\Entity\Game; use App\Entity\GameRow; use App\Entity\User; use App\Repository\ActorRepository; +use App\Repository\MovieRepository; use App\Repository\MovieRoleRepository; use Doctrine\ORM\EntityManagerInterface; @@ -17,6 +18,7 @@ class GameGridGenerator public function __construct( private readonly ActorRepository $actorRepository, private readonly MovieRoleRepository $movieRoleRepository, + private readonly MovieRepository $movieRepository, private readonly WikidataAwardGateway $wikidataAwardGateway, private readonly EntityManagerInterface $em, ) {} @@ -74,7 +76,7 @@ class GameGridGenerator /** * Compute display data (grid, width, middle) from a Game entity for the React component. * - * @return array{grid: list, width: int, middle: int} + * @return array{grid: list, width: int, middle: int} */ public function computeGridData(Game $game): array { @@ -113,10 +115,14 @@ class GameGridGenerator $rightSize = $rightSizeActor; } + $hintText = $this->resolveHintText($row); + $grid[] = [ 'actorName' => $actor->getName(), 'actorId' => $actor->getId(), 'pos' => $pos, + 'hintType' => $row->getHintType(), + 'hintText' => $hintText, ]; } @@ -208,4 +214,21 @@ class GameGridGenerator return null; } + + private function resolveHintText(GameRow $row): ?string + { + $type = $row->getHintType(); + $data = $row->getHintData(); + + if ($type === null || $data === null) { + return null; + } + + return match ($type) { + 'film' => $this->movieRepository->find((int) $data)?->getTitle(), + 'character' => $this->movieRoleRepository->find((int) $data)?->getCharacter(), + 'award' => $data, + default => null, + }; + } }