Beispiel #1
0
 public function findSequenceTasks(Game $game, Team $team)
 {
     $isTeam = $game->getGameType() === Game::GAME_TYPE_TEAM;
     //@TODO индивидуальные задания
     return $this->getEntityManager()->createQuery('SELECT tts FROM sdGameBundle:TeamTaskSequence tts
               JOIN tts.task t
               WHERE tts.team = :team
               AND tts.game = :game
               ORDER BY tts.num')->setParameters(['team' => $team, 'game' => $game]);
 }
Beispiel #2
0
 /**
  * @TODO бонусы и штрафы за коды
  * @param Game $game
  * @param Team $team
  * @return array
  */
 public function getTotalTime(Game $game, Team $team)
 {
     $summaryTime = 0;
     $summaryBonus = 0;
     $summaryPenalty = 0;
     $sequence = $this->manager->getRepository('sdGameBundle:TeamTaskSequence')->findBy(['team' => $team, 'completeType' => [TeamTaskSequence::COMPLETE_CODE, TeamTaskSequence::COMPLETE_MANUAL, TeamTaskSequence::COMPLETE_TIMEOUT], 'game' => $game]);
     foreach ($sequence as $teamTask) {
         switch ($teamTask->getCompleteType()) {
             /** @noinspection PhpMissingBreakStatementInspection */
             case TeamTaskSequence::COMPLETE_TIMEOUT:
                 $summaryPenalty += $teamTask->getTask()->getPenaltyTime() * 60;
             case TeamTaskSequence::COMPLETE_CODE:
             case TeamTaskSequence::COMPLETE_MANUAL:
                 $summaryTime += $teamTask->getCompleted()->getTimestamp() - $teamTask->getStarted()->getTimestamp();
                 break;
             default:
                 continue;
         }
     }
     foreach ($game->getTasks() as $task) {
         if ($task->getType() === Task::TYPE_FREE && $this->isLevelCompleted($task, $team)) {
             $summaryBonus += $task->getBonusTime() * 60;
         }
     }
     return ['time' => $summaryTime, 'bonus' => $summaryBonus, 'penalty' => $summaryPenalty];
 }
 public function importGameAction(Request $request)
 {
     $data = [];
     $uploadForm = $this->createFormBuilder($data)->add('file', 'file', ['label' => 'Файл игры для импорта'])->add('submit', 'submit', ['label' => 'Импортировать'])->getForm();
     if ($request->isMethod('POST')) {
         $uploadForm->handleRequest($request);
         $data = $uploadForm->getData();
         /** @var UploadedFile $uploadedFile */
         $uploadedFile = $data['file'];
         $importJson = file_get_contents($uploadedFile->getRealPath());
         $import = json_decode($importJson, true);
         $game = new Game();
         $game->setTitle($import['title']);
         $game->setGameType($import['game_type']);
         $game->setAnounce($import['anounce']);
         $this->getDoctrine()->getManager()->persist($game);
         foreach ($import['tasks'] as $taskData) {
             $task = new Task();
             $task->setTitle($taskData['title']);
             $task->setType($taskData['type']);
             $task->setText($taskData['text']);
             $task->setPenaltyTime($taskData['penalty_time']);
             $task->setTaskTime($taskData['task_time']);
             //                $task->setBonusTime($taskData['bonus_time']);
             foreach ($taskData['codes'] as $codeData) {
                 $code = new Code();
                 $code->setCode($codeData['code']);
                 $code->setLevel($codeData['level']);
                 $task->addCode($code);
             }
             foreach ($taskData['helps'] as $helpData) {
                 $help = new Help();
                 $help->setShowTime($helpData['show_time']);
                 $help->setText($helpData['text']);
                 $task->addHelp($help);
             }
             $game->addTask($task);
         }
         $this->getDoctrine()->getManager()->flush();
         $this->addFlash('success', 'Игра импортирована');
     }
     return $this->render('sdAdminBundle:CRUD:import_game.html.twig', ['action' => 'edit', 'form' => $uploadForm->createView()]);
 }
Beispiel #4
0
 /**
  * @param Game $object
  */
 public function preUpdate($object)
 {
     $object->setTasks($object->getTasks());
 }