예제 #1
0
 /**
  * @param Game $game
  */
 public function updateTeamTaskLinks(Game $game)
 {
     //Убиваем сирот
     $teamPositions = $this->manager->getRepository('sdGameBundle:TeamTaskSequence')->findBy(['game' => $game]);
     foreach ($teamPositions as $teamTaskSequence) {
         if (!($game->getTasks()->contains($teamTaskSequence->getTask()) && $game->getTeams()->contains($teamTaskSequence->getTeam()))) {
             $this->manager->remove($teamTaskSequence);
             $this->manager->flush();
         }
     }
     $index = 0;
     foreach ($game->getTeams() as $team) {
         foreach ($game->getTasks() as $task) {
             $teamTaskSequence = $this->manager->getRepository('sdGameBundle:TeamTaskSequence')->findOneBy(['task' => $task, 'team' => $team]);
             if (!is_null($teamTaskSequence) || $task->getType() === Task::TYPE_FREE) {
                 continue;
             }
             $teamTaskSequence = new TeamTaskSequence();
             $teamTaskSequence->setGame($game);
             $teamTaskSequence->setTeam($team);
             $teamTaskSequence->setTask($task);
             $teamTaskSequence->setNum($index);
             $this->manager->persist($teamTaskSequence);
             $this->manager->flush();
             $index++;
         }
     }
 }
예제 #2
0
 /**
  * @param Request $request
  * @param int     $id
  *
  * @return RedirectResponse|\Symfony\Component\HttpFoundation\Response
  */
 public function priorityAction(Request $request, $id = null)
 {
     $game = $this->getDoctrine()->getRepository('sdGameBundle:Game')->find($id);
     if ($game->isPast()) {
         throw new NotFoundHttpException();
     }
     if ($request->isMethod('POST')) {
         $positions = $request->request->get('position');
         $taskPositions = $this->getDoctrine()->getRepository('sdGameBundle:TeamTaskSequence')->findBy(['game' => $game]);
         array_map(function ($taskPosition) {
             $this->getDoctrine()->getManager()->remove($taskPosition);
         }, $taskPositions);
         $this->getDoctrine()->getManager()->flush();
         $taskPositions = new ArrayCollection();
         foreach ($positions as $teamId => $tasks) {
             $team = $this->getDoctrine()->getRepository('sdUserBundle:Team')->find($teamId);
             foreach ($tasks as $positionNum => $taskId) {
                 $task = $this->getDoctrine()->getRepository('sdGameBundle:Task')->find($taskId);
                 $taskPosition = new TeamTaskSequence();
                 $taskPosition->setGame($game);
                 $taskPosition->setTask($task);
                 $taskPosition->setTeam($team);
                 $taskPosition->setNum($positionNum);
                 $this->getDoctrine()->getManager()->persist($taskPosition);
                 $taskPositions->add($taskPosition);
             }
         }
         $this->getDoctrine()->getManager()->flush();
         $this->addFlash('sonata_flash_success', 'Сохранено!');
         return new RedirectResponse($this->generateUrl('admin_sd_game_game_priority', ['id' => $game->getId()]));
     } else {
         $taskPositions = $this->getDoctrine()->getRepository('sdGameBundle:TeamTaskSequence')->findBy(['game' => $game], ['num' => 'ASC']);
     }
     return $this->render('sdAdminBundle:CRUD:games_priority.html.twig', ['action' => 'priority', 'game' => $game, 'task_positions' => $taskPositions]);
 }