/** * @Route("/newQuestion/{idQuizz}/{idQuestion}/{ajax}", name="new_question", defaults={"idQuestion" = null}) */ public function newQuestionAction($idQuizz, $idQuestion = null, $ajax = null) { $question = new Question(); $quizz = $this->getDoctrine()->getManager()->getRepository('AppBundle:Quizz')->find($idQuizz); $question->setQuizz($quizz); if ($idQuestion != null) { $question = $this->getDoctrine()->getManager()->getRepository('AppBundle:Question')->find($idQuestion); } $form = $this->createForm(new QuestionType(), $question, array('action' => $this->generateUrl('save_question', array('idQuestion' => $idQuestion)), 'attr' => array('class' => 'modifQuestionForm'))); $nbQuestion = $quizz->getQuestions()->count() + 1; if ($ajax != null) { if ($question->getId() != null) { $form = $this->setFormResponsesValues($form, $question); $nbQuestion = $quizz->getQuestions()->indexOf($question) + 1; } return $this->render(":back:shortQuestionForm.html.twig", array("form" => $form->createView(), 'nbQuestion' => $nbQuestion, 'question' => $question)); } else { return $this->render(":back:new_question.html.twig", array("form" => $form->createView(), 'nbQuestion' => $nbQuestion, 'createQuizz' => true)); } }