/** * @Route("/admin/generate-sql-for-test/{testId}/{courseId}") */ public function generateSqlAction($testId, $courseId) { $course = $this->getDoctrine()->getRepository('LearningMainBundle:Course')->findOneById($courseId); $oldTest = $this->getDoctrine()->getRepository('LearningMainBundle:CourseModule')->findOneById($testId); $test = new CourseModule(); $test->setTitle($oldTest->getTitle()); $test->setCreated(new \DateTime()); $test->setUpdated(new \DateTime()); $test->setStep(true); $test->setCourse($course); $test->setType($oldTest->getType()); $test->setPosition($oldTest->getPosition()); $this->getDoctrine()->getManager()->persist($test); $this->getDoctrine()->getManager()->flush($test); $this->getDoctrine()->getManager()->refresh($test); foreach ($oldTest->getQuestions() as $oldQuestion) { $question = new CourseQuestion(); $question->setTitle($oldQuestion->getTitle()); $question->setPosition($oldQuestion->getPosition()); $question->setCreated(new \DateTime()); $question->setUpdated(new \DateTime()); $question->setModule($test); $this->getDoctrine()->getManager()->persist($question); $this->getDoctrine()->getManager()->flush($question); $this->getDoctrine()->getManager()->refresh($question); foreach ($oldQuestion->getAnswers() as $oldAnswer) { $answer = new CourseAnswer(); $answer->setCreated(new \DateTime()); $answer->setUpdated(new \DateTime()); $answer->setText($oldAnswer->getText()); $answer->setCorrect($oldAnswer->isCorrect()); $answer->setQuestion($question); $this->getDoctrine()->getManager()->persist($answer); $this->getDoctrine()->getManager()->flush($answer); $this->getDoctrine()->getManager()->refresh($answer); } } return new Response('Копирование завершено'); // echo "INSERT coursemodule SET course_id=$newCourseId, title='2', type='test', position='1', isStep=1, timeToLearn=0, created='2016-01-14 00:00:00', updated='2016-01-14 00:00:00'<br />"; // foreach ($test->getQuestions() as $question){ // echo "INSERT coursequestion SET module_id={moduleId}, title='".$question->getTitle()."', position='".$question->getPosition()."', enabled=1, created='2016-01-14 00:00:00', updated='2016-01-14 00:00:00'<br />"; //// foreach ($question->getAnswers as $answer) { //// echo "INSERT courseanswer SET module_id={moduleId}, title='".$question->getTitle()."', position='".$question->getPosition()."', enabled=1, created='2016-01-14 00:00:00', updated='2016-01-14 00:00:00'<br />"; //// } // } }