Ejemplo n.º 1
0
 /**
  * Displays a form to create a new Quiz entity.
  *
  * @Route("/approach/new/{id}", name="quiz_approach")
  * @Template()
  */
 public function quizAction(Request $request, $id)
 {
     $em = $this->getDoctrine()->getManager();
     $quiz = $em->getRepository('AppBundle:Quiz')->find($id);
     if (!$quiz) {
         throw $this->createNotFoundException("Quiz nie istnieje");
     }
     $entity = new QuizApproach();
     $entity->setQuiz($quiz);
     foreach ($quiz->getQuestions() as $question) {
         $questionApproach = new QuestionApproach();
         $questionApproach->setQuestion($question);
         $entity->addQuestionsApproach($questionApproach);
     }
     $form = $this->createForm(new QuizApproachType(), $entity, []);
     $form->handleRequest($request);
     if ($form->isValid()) {
         if ($form->get('end')->isClicked()) {
             $em = $this->getDoctrine()->getManager();
             $em->persist($entity);
             $em->flush();
             return $this->redirect($this->generateUrl('approach_show', array('id' => $entity->getId())));
         }
     }
     return array('entity' => $entity, 'form' => $form->createView());
 }
Ejemplo n.º 2
0
 /**
  * Add questionsApproach
  *
  * @param \AppBundle\Entity\QuestionApproach $questionsApproach
  * @return QuizApproach
  */
 public function addQuestionsApproach(\AppBundle\Entity\QuestionApproach $questionsApproach)
 {
     $questionsApproach->setQuizApproach($this);
     $this->questionsApproach[] = $questionsApproach;
     return $this;
 }