Ejemplo n.º 1
0
 /**
  * @param TeamGame $teamGame
  * @return Game
  */
 public function addTeamGame(TeamGame $teamGame)
 {
     $teamGame->setGame($this);
     $this->teamGames->add($teamGame);
     return $this;
 }
 /**
  * @param TeamGame $teamGame
  * @return GameTask|null
  */
 public function findCurrentTask(TeamGame $teamGame)
 {
     return $this->createQueryBuilder('gt')->where('gt.game = :game')->andWhere('gt.level >= :level')->setParameter('game', $teamGame->getGame())->setParameter('level', $teamGame->getTaskLevel())->addOrderBy('gt.level', 'ASC')->setMaxResults(1)->getQuery()->getOneOrNullResult();
 }
 /**
  * @Route("/{game}/team/new", name="admin_game_team_new")
  * @param Game $game
  * @param Request $request
  * @return Response
  */
 public function gameTeamNewAction(Game $game, Request $request)
 {
     $teamGame = new TeamGame();
     $teamGame->setGame($game);
     $form = $this->createForm(TeamGameType::class, $teamGame);
     $form->handleRequest($request);
     if ($form->isValid()) {
         //проверяем есть ли уже укоманды игра в это время (startAt, endAt)
         $activeTeamGame = $this->getDoctrine()->getRepository(TeamGame::class)->findTeamGameInTimePeriod($teamGame->getTeam(), $game->getStartAt(), $game->getEndAt());
         if ($activeTeamGame) {
             $this->addFlash('danger', sprintf('Этой команде уже назначена игра в этот временной промежуток. (id: %s, name: %s)', $activeTeamGame->getGame()->getId(), $activeTeamGame->getGame()->getName()));
         } else {
             $this->addFlash('success', 'Команда добавлена');
             $manager = $this->getDoctrine()->getManager();
             $manager->persist($teamGame);
             $manager->flush();
             return $this->redirectToRoute('admin_game_team_list', ['game' => $game->getId()]);
         }
     }
     return $this->render('AdminBundle:TeamGame:new.html.twig', ['game' => $game, 'form' => $form->createView()]);
 }