/**
  * Creates a form to delete a Resposta entity.
  *
  * @param Resposta $respostum The Resposta entity
  *
  * @return \Symfony\Component\Form\Form The form
  */
 private function createDeleteForm(Resposta $respostum)
 {
     return $this->createFormBuilder()->setAction($this->generateUrl('resposta_delete', array('id' => $respostum->getId())))->setMethod('DELETE')->getForm();
 }
 /**
  * Displays a form to edit an existing Enquisa entity.
  *
  * @Route("/{id}/edit", name="enquisa_edit")
  * @Method({"GET", "POST"})
  */
 public function editAction(Request $request, Enquisa $enquisa)
 {
     /** @var $em Doctrine\ORM\EntityManager */
     $em = $this->getDoctrine()->getManager();
     $deleteForm = $this->createDeleteForm($enquisa);
     $editForm = $this->createForm('EnquisaBundle\\Form\\EnquisaType', $enquisa);
     $editForm->handleRequest($request);
     if ($editForm->isSubmitted() && $editForm->isValid()) {
         $em->persist($enquisa);
         $em->flush();
         // Eliminar respostas anteriores
         $query = $em->createQuery('DELETE FROM EnquisaBundle\\Entity\\Resposta r WHERE r.enquisa=:enquisa');
         $query->setParameters(array('enquisa' => $enquisa));
         $query->execute();
         $opciones = $request->get('opcion');
         foreach ($opciones as $opcion) {
             /** @var $resposta EnquisaBundle\Entity\Resposta */
             $resposta = new Resposta();
             $resposta->setEnquisa($enquisa);
             $resposta->setOpcion($em->getRepository('EnquisaBundle:Opcion')->findOneById($opcion));
             $em->persist($resposta);
             $em->flush();
         }
         return $this->redirectToRoute('enquisa_edit', array('id' => $enquisa->getId()));
     }
     $em = $this->getDoctrine()->getManager();
     $preguntas = $em->getRepository('EnquisaBundle:Pregunta')->getOpciones();
     return $this->render('enquisa/edit.html.twig', array('enquisa' => $enquisa, 'edit_form' => $editForm->createView(), 'delete_form' => $deleteForm->createView(), 'preguntas' => $preguntas));
 }