Ejemplo n.º 1
0
 /**
  * @return TournamentInitializator
  */
 private function createTournamentEvent() : TournamentInitializator
 {
     $frequency = '25 20 * * * *';
     $timeBegin = "+1minute";
     $tournamentName = "Create new tournament";
     $timeBase = 180000;
     return (new TournamentInitializator())->setFrequency($frequency)->setTournamentName($tournamentName)->setGameParams((new GameParams())->setTimeBase($timeBase))->setTimeBegin($timeBegin)->setTournamentParams(TournamentParamsFactory::create(TournamentType::ROUND_ROBIN()));
 }
Ejemplo n.º 2
0
 /**
  * @param array $data
  * @return mixed
  */
 protected function createEntity($data)
 {
     $tournament = new Tournament();
     $tournament->setName($data['name'])->setCurrentRound((int) @$data["current_round"]);
     if (isset($data['private'])) {
         $tournament->setPrivate($data['private']);
     }
     if (isset($data["status"])) {
         $this->container->get("core.handler.tournament")->changeTournamentStatus($tournament, new TournamentStatus($data["status"]));
     }
     $tournamentPlayersMap = [];
     if (isset($data['players'])) {
         foreach ($data['players'] as $referencePlayer) {
             /** @var User $player */
             $player = $this->getReference($referencePlayer);
             $tournamentPlayer = new TournamentPlayer();
             $countBlack = mt_rand(4, 5);
             $whiteInRow = mt_rand(0, 2);
             $tournamentPlayer->setTournament($tournament)->setPlayer($player)->setWhiteInRow($whiteInRow)->setBlackInRow($whiteInRow ? 0 : mt_rand(0, 2))->setCountBlack($countBlack)->setCountWhite(9 - $countBlack)->setPoints(mt_rand(0, 9))->setCoefficient(mt_rand(0, 2))->setMissedRound(!!mt_rand(0, 1));
             $opponents = $this->getShuffleOpponents($data["players"], $referencePlayer, min(count($data["players"]), 9));
             foreach ($opponents as $opponent) {
                 $tournamentPlayer->addOpponent($opponent);
             }
             $tournament->getPlayers()->add($tournamentPlayer);
             $tournamentPlayersMap[$player->getId()] = $tournamentPlayer;
         }
     }
     if (isset($data["game_params"])) {
         /** @var GameParams $gameParams */
         $gameParams = $this->container->get("jms_serializer")->deserialize(json_encode($data["game_params"]), 'CoreBundle\\Model\\Game\\GameParams', 'json');
         $tournament->setGameParams($gameParams);
     }
     if (isset($data["tournament_params"])) {
         $tournamentParams = TournamentParamsFactory::create($data["tournament_params"]["type"]);
         if (isset($data["tournament_params"]["time_begin"])) {
             $tournamentParams->setTimeBegin($this->container->get("core.service.date")->getDateTime($data["tournament_params"]["time_begin"]));
             if (isset($data["tournament_params"]["games_vs_opponent"])) {
                 $tournamentParams->setGamesVsOpponent($data["tournament_params"]["games_vs_opponent"]);
             }
         }
         $tournament->setTournamentParams($tournamentParams);
     }
     if (isset($data["games"])) {
         foreach ($data["games"] as $dataGame) {
             /** @var Game $game */
             $game = $this->getReference($dataGame["reference"]);
             $this->container->get("core.handler.tournament")->addGameToTournament($tournament, $game, $dataGame["round"], $tournamentPlayersMap[$game->getUserWhite()->getId()], $tournamentPlayersMap[$game->getUserBlack()->getId()]);
         }
     }
     return $tournament;
 }
Ejemplo n.º 3
0
 /**
  * @param Tournament $tournament
  */
 private function changeTournamentTypeOnSwiss(Tournament $tournament)
 {
     $tournamentParams = TournamentParamsFactory::create(TournamentType::SWITZ())->setTimeBegin($tournament->getTournamentParams()->getTimeBegin());
     $tournament->setTournamentParams($tournamentParams)->setRounds($this->container->getParameter("rounds_for_swiss"));
     $this->getManager()->persist($tournament);
     $this->getManager()->flush();
 }
Ejemplo n.º 4
0
 /**
  * @param string $frequency
  * @param string $timeBegin
  * @param string $tournamentName
  * @param int $timeBase
  * @param int $timeIncrement
  * @param bool $private
  * @param array|string $players
  * @param int $gamesVsOpponent
  */
 public function createTournamentEvent(string $frequency, string $timeBegin, string $tournamentName, int $timeBase, int $timeIncrement = 0, bool $private = false, string $players = '', int $gamesVsOpponent = 2)
 {
     $this->container->get("core.handler.event")->initEventAndSave((new TournamentInitializator())->setFrequency($frequency)->setPlayerIds(empty($players) ? [] : explode(',', $players))->setTournamentName($tournamentName)->setPrivate($private)->setGameParams((new GameParams())->setTimeBase($timeBase)->setTimeIncrement($timeIncrement))->setTimeBegin($timeBegin)->setTournamentParams(TournamentParamsFactory::create(TournamentType::ROUND_ROBIN())->setGamesVsOpponent($gamesVsOpponent)), "core.service.event.tournament.create");
 }