/**
  * @param Tournament $tournament
  */
 private function mixGamesForRoundRobin(Tournament $tournament)
 {
     $gamesMap = [];
     foreach ($tournament->getPlayers() as $firstPlayer) {
         foreach ($tournament->getPlayers() as $secondPlayer) {
             if ($firstPlayer == $secondPlayer) {
                 continue;
             }
             $gamesMap[$firstPlayer->getId()][$secondPlayer->getId()] = '';
             $gamesMap[$secondPlayer->getId()][$firstPlayer->getId()] = '';
         }
     }
     foreach ($tournament->getGames() as $tournamentGame) {
         if ($tournamentGame->getGame()->getStatus() != GameStatus::END) {
             continue;
         }
         $playerWhite = $tournamentGame->getPlayerWhite();
         $playerBlack = $tournamentGame->getPlayerBlack();
         $gamesMap[$playerWhite->getId()][$playerBlack->getId()][] = new TournamentGameRoundRobin($tournamentGame->getGame()->getId(), $tournamentGame->getGame()->getResultWhite());
         $gamesMap[$playerBlack->getId()][$playerWhite->getId()][] = new TournamentGameRoundRobin($tournamentGame->getGame()->getId(), $tournamentGame->getGame()->getResultBlack());
     }
     $tournament->setResultsForRoundRobin($gamesMap);
 }
Esempio n. 2
0
 /**
  * @param Tournament $tournament
  * @param User $user
  * @return bool
  */
 private function isUserInTournament(Tournament $tournament, User $user) : bool
 {
     foreach ($tournament->getPlayers() as $tournamentPlayer) {
         if ($tournamentPlayer->getPlayer() == $user) {
             return true;
         }
     }
     return false;
 }