コード例 #1
0
ファイル: SwissService.php プロジェクト: StasPiv/playzone
 /**
  * @param Tournament $tournament
  * @return void
  */
 public function makeDrawForNextRound(Tournament $tournament)
 {
     $nextRound = $tournament->getCurrentRound() + 1;
     $this->makeDraw($tournament, $nextRound);
     $tournament->setCurrentRound($nextRound);
     $this->manager->flush($tournament);
 }
コード例 #2
0
 /**
  * @param Tournament $tournament
  */
 public function notifyAboutNewTournament(Tournament $tournament)
 {
     $title = $this->container->get("templating")->render('Post/newtournament.topic.html.twig', ['tournament' => $tournament]);
     $postModel = new Post($this->container->getParameter("app_immortalchess.forum_playzone"), $tournament->getGameParams()->getTimeBase() === 180000 ? self::THREAD_FOR_3_MINUTES : self::THREAD_FOR_5_MINUTES, $this->container->getParameter("app_immortalchess.post_username_for_calls"), $this->container->getParameter("app_immortalchess.post_userid_for_calls"), $title, $this->container->get("templating")->render('Post/newtournament.html.twig', ['tournament' => $tournament]));
     $postModel->setThreadTitle($title);
     return $this->container->get("immortalchessnet.service.publish")->publishNewPost($postModel);
 }
コード例 #3
0
 /**
  * @param Tournament $tournament
  * @return TournamentDrawInterface
  * @throws TournamentIncorrectTypeException
  */
 public function create(Tournament $tournament) : TournamentDrawInterface
 {
     switch ($tournament->getTournamentParams()->getType()) {
         case TournamentType::ROUND_ROBIN():
             return $this->container->get("core.service.round_robin");
         case TournamentType::SWITZ():
             return $this->container->get("core.service.swiss");
         default:
             throw new TournamentIncorrectTypeException();
     }
 }
コード例 #4
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;
 }
コード例 #5
0
ファイル: TournamentType.php プロジェクト: blevoir/teamlol
 /**
  * {@inheritDoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('name', 'text', array('label' => 'lg.tournament.fields.name'));
     $builder->add('description', 'textarea', array('label' => 'lg.tournament.fields.description', 'attr' => array('class' => 'tinymce')));
     $builder->add('type', 'choice', array('label' => 'lg.tournament.fields.type', 'empty_value' => 'lg.tournament.fields.type_empty', 'choices' => \CoreBundle\Entity\Tournament::getTournamentTypes()));
     $builder->add('automatic', 'choice', array('label' => 'lg.tournament.fields.automatic', 'expanded' => true, 'choices' => array(1 => 'lg.core.yes', 0 => 'lg.core.no')));
     $builder->add('startedAt', 'datetime', array('widget' => 'single_text', 'label' => 'lg.tournament.fields.startedAt', 'format' => 'dd-MM-yyyy HH:mm', 'attr' => array('class' => 'datetimepicker')));
     $builder->add('registerStartDate', 'datetime', array('widget' => 'single_text', 'label' => 'lg.tournament.fields.registerStartDate', 'format' => 'dd-MM-yyyy HH:mm', 'attr' => array('class' => 'datetimepicker')));
     $builder->add('registerEndDate', 'datetime', array('widget' => 'single_text', 'label' => 'lg.tournament.fields.registerEndDate', 'format' => 'dd-MM-yyyy HH:mm', 'attr' => array('class' => 'datetimepicker')));
 }
コード例 #6
0
 /**
  * @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);
 }
コード例 #7
0
 /**
  * @param Tournament $tournament
  * @throws EventAlreadyFoundException
  */
 private function assertEventNotExists(Tournament $tournament)
 {
     $events = $this->container->get("core.handler.event")->getRepository()->findBy(["eventCommandService" => self::EVENT_COMMAND_TYPE]);
     foreach ($events as $event) {
         /** @var TournamentContainerInterface $tournamentContainer */
         $tournamentContainer = $event->getEventModel();
         if ($tournamentContainer->getTournamentId() == $tournament->getId()) {
             throw new EventAlreadyFoundException();
         }
     }
 }
コード例 #8
0
 /**
  * Vérifie que l'utilisateur a le droit de gérer le tournoi
  *
  * @param \CoreBundle\Controller\Tournament $tournament
  * @author Benjamin Levoir <*****@*****.**>
  */
 private function assertRights(\CoreBundle\Entity\Tournament $tournament)
 {
     if (!$this->getUser()->isAdmin() && $tournament->getReferees()->contains($this->getUser())) {
         throw $this->createAccessDeniedException();
     }
 }
コード例 #9
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;
 }