feat: resolve hint display text in computeGridData

This commit is contained in:
thibaud-leclere
2026-03-30 22:33:51 +02:00
parent 32ae77da53
commit 42a3567e1c

View File

@@ -9,6 +9,7 @@ use App\Entity\Game;
use App\Entity\GameRow; use App\Entity\GameRow;
use App\Entity\User; use App\Entity\User;
use App\Repository\ActorRepository; use App\Repository\ActorRepository;
use App\Repository\MovieRepository;
use App\Repository\MovieRoleRepository; use App\Repository\MovieRoleRepository;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
@@ -17,6 +18,7 @@ class GameGridGenerator
public function __construct( public function __construct(
private readonly ActorRepository $actorRepository, private readonly ActorRepository $actorRepository,
private readonly MovieRoleRepository $movieRoleRepository, private readonly MovieRoleRepository $movieRoleRepository,
private readonly MovieRepository $movieRepository,
private readonly WikidataAwardGateway $wikidataAwardGateway, private readonly WikidataAwardGateway $wikidataAwardGateway,
private readonly EntityManagerInterface $em, private readonly EntityManagerInterface $em,
) {} ) {}
@@ -74,7 +76,7 @@ class GameGridGenerator
/** /**
* Compute display data (grid, width, middle) from a Game entity for the React component. * Compute display data (grid, width, middle) from a Game entity for the React component.
* *
* @return array{grid: list<array{actorName: string, actorId: int, pos: int}>, width: int, middle: int} * @return array{grid: list<array{actorName: string, actorId: int, pos: int, hintType: ?string, hintText: ?string}>, width: int, middle: int}
*/ */
public function computeGridData(Game $game): array public function computeGridData(Game $game): array
{ {
@@ -113,10 +115,14 @@ class GameGridGenerator
$rightSize = $rightSizeActor; $rightSize = $rightSizeActor;
} }
$hintText = $this->resolveHintText($row);
$grid[] = [ $grid[] = [
'actorName' => $actor->getName(), 'actorName' => $actor->getName(),
'actorId' => $actor->getId(), 'actorId' => $actor->getId(),
'pos' => $pos, 'pos' => $pos,
'hintType' => $row->getHintType(),
'hintText' => $hintText,
]; ];
} }
@@ -208,4 +214,21 @@ class GameGridGenerator
return null; 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,
};
}
} }