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()]); }
public function addCode(Code $code) { $code->setTask($this); $this->codes->add($code); }
/** * @param Code $object */ public function preUpdate($object) { $object->setTask($object->getTask()); }