diff --git a/src/Controller/TournamentController.php b/src/Controller/TournamentController.php index a291b8c..f2a666f 100644 --- a/src/Controller/TournamentController.php +++ b/src/Controller/TournamentController.php @@ -6,6 +6,7 @@ use App\Repository\TournamentRepository; use App\Service\PlayOffGameService; use App\Service\QualifyingGameService; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Attribute\Route; @@ -18,6 +19,21 @@ class TournamentController extends AbstractController private readonly PlayOffGameService $playOffGameService, ) {} + #[Route(path: '/', name: 'tournament_list_get', methods: ['GET'])] + public function getTournamentList(Request $request) + { + $page = $request->get('page') ?? 0; + return $this->render( + 'index.html.twig', + [ + 'tournamentList' => $this->tournamentRepository->getTournamentList($page), + 'tournamentCount' => $this->tournamentRepository->getTotalTournament(), + 'page' => $page, + 'tournamentPerPage' => TournamentRepository::TOURNAMENT_PER_PAGE + ] + ); + } + #[Route(path: '/tournament/{tournamentId}', name: 'tournament_get', methods: ['GET'])] public function getTournament($tournamentId): Response { @@ -38,4 +54,10 @@ class TournamentController extends AbstractController ['tournament' => $tournament] ); } + + #[Route(path: '/tournament', name: 'tournament_create', methods: ['POST'])] + public function createTournament() + { + return $this->redirectToRoute('tournament_list'); + } } \ No newline at end of file diff --git a/src/Controller/TournamentGeneratorController.php b/src/Controller/TournamentGeneratorController.php index 2e6c0ae..ac36511 100644 --- a/src/Controller/TournamentGeneratorController.php +++ b/src/Controller/TournamentGeneratorController.php @@ -34,7 +34,7 @@ class TournamentGeneratorController extends AbstractController private PlayOffGameService $playOffGameService ) {} - #[Route(path: '/', name: 'tournament_generate', methods: ['get'])] + #[Route(path: '/generate', name: 'tournament_generate', methods: ['get'])] public function index(Request $request): Response { $faker = Factory::create(); diff --git a/src/Entity/Division.php b/src/Entity/Division.php index 6c3060c..648ba98 100644 --- a/src/Entity/Division.php +++ b/src/Entity/Division.php @@ -25,7 +25,7 @@ class Division private ?string $id = null; public function __construct( - #[ORM\Column(type: Types::STRING, length: 255 ,nullable: false)] + #[ORM\Column(type: Types::STRING, length: 255, nullable: false)] private readonly string $title, #[ORM\ManyToOne(targetEntity: Tournament::class, cascade: ['persist'], inversedBy: 'divisionList')] @@ -33,13 +33,13 @@ class Division private readonly Tournament $tournament, #[ORM\OneToMany(targetEntity: Player::class, mappedBy: 'division')] - private Collection $playerList = new ArrayCollection(), + private Collection $playerList = new ArrayCollection(), /** * @var Collection */ #[ORM\OneToMany(targetEntity: QualifyingGame::class, mappedBy: 'division')] - private Collection $gameList = new ArrayCollection(), + private Collection $gameList = new ArrayCollection(), #[ORM\Column(type: Types::DATETIME_IMMUTABLE, nullable: false)] private readonly DateTimeImmutable $createdAt = new DateTimeImmutable(), @@ -128,7 +128,7 @@ class Division { $playerIdList = []; foreach ($players as $player) $playerIdList[] = $player->getId(); - $gameList = $this->gameList->filter( + $gameList = $this->gameList->filter( function (QualifyingGame $qualifyingGame) use ($playerIdList) { $scorePlayerIdList = []; foreach ($qualifyingGame->getScoreList() as $scoreList) { @@ -164,7 +164,7 @@ class Division $totalScore = 0; foreach ($this->gameList as $game) { foreach ($game->getScoreList() as $score) { - if(is_null($score->getScore())) continue 2; + if (is_null($score->getScore())) continue 2; } $criteria = new Criteria(); $criteria->orderBy(['score' => Order::Descending]) diff --git a/src/Entity/Game/GameInterface.php b/src/Entity/Game/GameInterface.php index 5547f0e..f10b862 100644 --- a/src/Entity/Game/GameInterface.php +++ b/src/Entity/Game/GameInterface.php @@ -2,12 +2,16 @@ namespace App\Entity\Game; -use App\Enum\GameStatus; +use App\Entity\Player; use Doctrine\Common\Collections\Collection; use DateTimeImmutable; interface GameInterface { + /** + * @return string|null + */ + public function getId(): ?string; /** * @return DateTimeImmutable */ @@ -17,4 +21,10 @@ interface GameInterface * @return Collection */ public function getScoreList(): Collection; + + /** + * @param Player $player + * @return GameScore|null + */ + public function getPlayerScore(Player $player): ?GameScore; } \ No newline at end of file diff --git a/src/Entity/Game/GameScore.php b/src/Entity/Game/GameScore.php index 074afc1..220267a 100644 --- a/src/Entity/Game/GameScore.php +++ b/src/Entity/Game/GameScore.php @@ -26,9 +26,7 @@ class GameScore #[ORM\Column(nullable: true)] private ?int $score = null, - ) { - - } + ) {} /** * @return string|null diff --git a/src/Entity/Game/PlayOffGame.php b/src/Entity/Game/PlayOffGame.php index f868a64..1197bf0 100644 --- a/src/Entity/Game/PlayOffGame.php +++ b/src/Entity/Game/PlayOffGame.php @@ -4,7 +4,6 @@ namespace App\Entity\Game; use App\Entity\Player; use App\Entity\Tournament; -use App\Enum\GameStatus; use App\Repository\Game\QualifyingGameRepository; use DateTimeImmutable; use Doctrine\Common\Collections\Collection; diff --git a/src/Entity/Game/QualifyingGame.php b/src/Entity/Game/QualifyingGame.php index bd553ae..077433b 100644 --- a/src/Entity/Game/QualifyingGame.php +++ b/src/Entity/Game/QualifyingGame.php @@ -22,10 +22,10 @@ class QualifyingGame implements GameInterface public function __construct( #[ORM\ManyToOne(cascade: ['remove'])] - private Division $division, + private readonly Division $division, #[ORM\OneToOne(cascade: ['remove', 'persist'])] - private Game $game, + private readonly Game $game, ) { $this->division->addGame($this); } diff --git a/src/Entity/Tournament.php b/src/Entity/Tournament.php index a0d142a..b155366 100644 --- a/src/Entity/Tournament.php +++ b/src/Entity/Tournament.php @@ -2,9 +2,7 @@ namespace App\Entity; -use App\Entity\Game\Game; use App\Entity\Game\PlayOffGame; -use App\Enum\TournamentStatus; use App\Repository\TournamentRepository; use DateTimeImmutable; use Doctrine\Common\Collections\ArrayCollection; diff --git a/src/Enum/GameStatus.php b/src/Enum/GameStatus.php index 8a71ca3..841a1ce 100644 --- a/src/Enum/GameStatus.php +++ b/src/Enum/GameStatus.php @@ -4,8 +4,8 @@ namespace App\Enum; enum GameStatus: string { - case NEW = 'new'; - case ACTIVE = 'active'; - case ENDED = 'ended'; + case new = 'new'; + case active = 'active'; + case ended = 'ended'; } diff --git a/src/Enum/GameType.php b/src/Enum/GameType.php deleted file mode 100644 index f13729d..0000000 --- a/src/Enum/GameType.php +++ /dev/null @@ -1,9 +0,0 @@ -getEntityManager()->flush(); return $tournamentEntity; } + + /** + * @param int $page + * @return Collection + */ + public function getTournamentList(int $page = 0): Collection + { + $query = $this->createQueryBuilder('t') + ->setFirstResult(self::TOURNAMENT_PER_PAGE * $page) + ->setMaxResults(self::TOURNAMENT_PER_PAGE); + return new ArrayCollection($query->getQuery()->getResult()); + } + + /** + * @return int + */ + public function getTotalTournament(): int + { + return count($this->findAll()); + } } diff --git a/templates/base.html.twig b/templates/base.html.twig index 2982ee2..cdf188e 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -11,7 +11,7 @@ {% block body %}{% endblock %} diff --git a/templates/index.html.twig b/templates/index.html.twig index 7ca4f45..2b94600 100644 --- a/templates/index.html.twig +++ b/templates/index.html.twig @@ -2,19 +2,39 @@ {% block body %}
-
+
Create tournament
- +
- +
+
- tournament list + {% if tournamentCount > 0 %} +
There are {{ tournamentCount }} created tournaments.
+ + {% for tournament in tournamentList %} + + {% endfor %} + + {% if page > 0 %} + Previous + {% endif %} + {% if page + 1 < tournamentCount/tournamentPerPage and tournamentList.count() >= tournamentPerPage %} + Next + {% endif %} + {% else %} +
No tournaments have been created yet.
+ {% endif %}
{% endblock %} diff --git a/templates/tournament.html.twig b/templates/tournament.html.twig index 46a7479..1d469af 100644 --- a/templates/tournament.html.twig +++ b/templates/tournament.html.twig @@ -1,7 +1,6 @@ {% extends "base.html.twig" %} {% block body %}
-

Tournament {{ tournament.getTitle() }}

@@ -44,7 +43,13 @@

Play off

{% for stage, stageGameList in tournament.getPlayOffStageList() %} -

1 / {{ stage }}

+

+ {% if stage > 1 %} + 1 / {{ stage }} + {% else %} + Final + {% endif %} +

{% for index, playOffStageGame in stageGameList %} @@ -64,10 +69,10 @@ {% endfor %} -
-

Winner

+
+

Tournament Winner

{% set winner = tournament.getStageWinnerList(1) %} -

{{ winner.first().getPlayer().getTitle() }}

+

{{ winner.first().getPlayer().getTitle() }}

{% endblock %}