示例#1
0
 private function getEnteredCodes(Team $team, Task $task)
 {
     if ($this->enteredCodes === false || !array_key_exists($task->getId(), $this->enteredCodes)) {
         $this->enteredCodes[$task->getId()] = $this->manager->getRepository('sdGameBundle:CodeEnter')->findBy(['isCorrect' => true, 'user' => $team->getMembers()->toArray(), 'task' => $task]);
     }
     return $this->enteredCodes[$task->getId()];
 }
示例#2
0
 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()]);
 }
示例#3
0
 /**
  * @param Task $task
  *
  * @return $this
  */
 public function addTask(Task $task)
 {
     $task->setGame($this);
     $this->tasks->add($task);
     return $this;
 }
示例#4
0
 /**
  * @param Task $object
  */
 public function preUpdate($object)
 {
     $object->setCodes($object->getCodes());
 }