private function createXML(Questionnaire $questionnaire, User $user)
 {
     $rootNode = new \SimpleXMLElement("<?xml version='1.0' encoding='UTF-8' standalone='yes'?><Antworten></Antworten>");
     $itemNode = $rootNode->addChild('item');
     $itemNode->addChild('itemCode', 'mk');
     // Let's load based on questionnaire:
     $repository = $this->getDoctrine()->getRepository('AppBundle:Question');
     $question = $repository->findOneBy(array('questionnaireId' => $questionnaire->getId()));
     /**
      * @var Question $question
      */
     while ($question != null) {
         $this->buildBlock($question, $user, $rootNode);
         $question = $this->getNextQuestion($question, $user);
     }
     echo $rootNode->asXML();
 }
 /**
  * Creates a form to delete a Questionnaire entity by id.
  *
  * This is necessary because browsers don't support HTTP methods different
  * from GET and POST. Since the controller that removes the blog posts expects
  * a DELETE method, the trick is to create a simple form that *fakes* the
  * HTTP DELETE method.
  * See http://symfony.com/doc/current/cookbook/routing/method_parameters.html.
  *
  * @param  Questionnaire $questionnaire The questionnaire object
  * @return \Symfony\Component\Form\Form The form
  */
 private function createDeleteForm(Questionnaire $questionnaire)
 {
     return $this->createFormBuilder()->setAction($this->generateUrl('questionnaire_post_delete', array('id' => $questionnaire->getId())))->setMethod('DELETE')->getForm();
 }
Esempio n. 3
0
 /**
  * Gives new answers to existing Questionnaire Entity
  *
  * @Route("/new/{id}", requirements={"id" = "\d+"}, name="answer_post_new")
  * @Method({"GET", "POST", "DELETE"})
  *
  * NOTE: the Method annotation is optional, but it's a recommended practice
  * to constraint the HTTP methods each controller responds to (by default
  * it responds to all methods).
  */
 public function newAction(Questionnaire $questionnaire, Statement $statement, Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     // $repository = $this->getDoctrine()->getRepository('AppBundle:Statement');
     // $statements = $repository->findAll();
     //
     // $statementCollection = new Answer;
     //
     // foreach ($statements as $statement) {
     //
     //   $statementCollection->getStatement()->add($statement);
     // }
     //
     // $collection = $this->createForm(new AnswerType, $statementCollection);
     //
     // return $this->render('Questionnaire/Answer/new.html.twig', array(
     //   'collection' => $collection->createView()
     // ));
     // $repo_statement = $this->getDoctrine()->getRepository('AppBundle:Statement');
     // $repo_questionnaire = $this->getDoctrine()->getRepository('AppBundle:Questionnaire');
     // $questionnaire = $repo_questionnaire->findOneById($id);
     //
     // if (is_null($questionnaire)) {
     //     throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
     // }
     //
     // // $statement = $repo_statement->findOneBy(
     // //     array('questionnaire'=>$questionnaire,'statement'=>$this->getStatement())
     // // );
     foreach ($questionnaire->getstatements() as $key => $statement) {
         $repo_statement = $this->getDoctrine()->getRepository('AppBundle:Statement');
         $statement = $repo_statement->findOneBy(array('questionnaire' => $questionnaire, 'statement' => $this->getStatement()));
         $answer[$key] = new Answer($key);
         $form[$key] = $this->createForm(new AnswerType(), $answer[$key])->createView();
     }
     $request = $this->getRequest();
     if ($request->getMethod() == 'POST') {
         $form->bindRequest($request);
         // the isSubmitted() method is completely optional because the other
         // isValid() method already checks whether the form is submitted.
         // However, we explicitly add it to improve code readability.
         // See http://symfony.com/doc/current/best_practices/forms.html#handling-form-submits
         if ($form->isSubmitted() && $form->isValid()) {
             $questionnaireAns = $form["questionnaireAns"]->getData();
             foreach ($questionnaireAns as $questionnaire) {
                 $id = $questionnaire->getId();
                 $dbQuestionnaire = $em->getRepository('AppBundle:Questionnaire')->find($id);
                 if (!$dbQuestionnaire) {
                     throw $this - createNotFoundException('No $dbQuestionnaire found for id ' . $id);
                 }
                 $dbQuestionnaire->addAnswer($answer);
             }
             $statements = $form["statements"]->getData();
             foreach ($statements as $statement) {
                 $id = $statement->getId();
                 $dbStatement = $em->getRepository('AppBundle:Statement')->find($id);
                 if (!$dbStatement) {
                     throw $this - createNotFoundException('No dbStatement found for id ' . $id);
                 }
                 $dbStatement->addAnswer($answer);
             }
             $em->persist($answer);
             $em->flush();
             return $this->redirectToRoute('answer');
         }
     }
     return $this->render('Questionnaire/Answer/new.html.twig', array('questionnaire' => $questionnaire, 'statement' => $statement, 'answer' => $answer, 'form' => $form->createView()));
 }