示例#1
0
 /**
  * @param TournamentPostRecordRequest $request
  * @return Tournament
  */
 public function processPostRecord(TournamentPostRecordRequest $request) : Tournament
 {
     $user = $this->container->get("core.handler.user")->getSecureUser($request);
     try {
         $tournament = $this->repository->find($request->getTournamentId());
     } catch (TournamentNotFoundException $e) {
         $this->getRequestError()->addError("tournament_id", "Tournament is not found")->throwException(ResponseStatusCode::NOT_FOUND);
     }
     /** @var Tournament $tournament */
     if ($tournament->isPrivate()) {
         $this->getRequestError()->addError("login", "This is private tournament")->throwException(ResponseStatusCode::FORBIDDEN);
     }
     if ($tournament->getStatus() != TournamentStatus::NEW()) {
         $this->getRequestError()->addError("login", "Tournament has already been started")->throwException(ResponseStatusCode::FORBIDDEN);
     }
     if ($user->getLag() > $this->container->getParameter("max_lag_for_record")) {
         //            $this->getRequestError()->addError("login", "Your lag is too big")
         //                ->throwException(ResponseStatusCode::FORBIDDEN);
     }
     if ($user->isBanned()) {
         $this->getRequestError()->addError("login", "You are banned")->throwException(ResponseStatusCode::FORBIDDEN);
     }
     if ($this->isUserInTournament($tournament, $user)) {
         $this->getRequestError()->addError("login", "You are already in tournament")->throwException(ResponseStatusCode::FORBIDDEN);
     }
     /** @var Tournament $tournament */
     $tournament->addPlayer($user);
     $this->manager->persist($tournament);
     $this->manager->flush();
     $this->setMineToTournament($tournament, $user);
     return $tournament;
 }