/** * Update de receta seleccionada. * */ public function updateRec2Action(Request $request) { //****UPDATE DATOS RECETA***** $idReceta = $request->request->get('idReceta'); $em = $this->getDoctrine()->getManager(); $eReceta = $em->getRepository('uniRecetasBundle:receta')->findOneById($idReceta); $titulo = $request->request->get('titulo'); $eReceta->setTitulo($titulo); $textElab = $request->request->get('textElab'); $eReceta->setElaboracion($textElab); $foto = $request->request->get('foto'); $eReceta->setFoto($foto); $fotop = $request->request->get('fotop'); $eReceta->setFotoPeq($fotop); $fechapub = $request->request->get('fechapub'); $eReceta->setFechaPub(new \DateTime($fechapub)); $numpers = $request->request->get('numpers'); $eReceta->setNumpers($numpers); $autor = $request->request->get('idAutorRec'); $eAutor = $em->getRepository('uniRecetasBundle:autor')->findOneById($autor); if (!$eAutor) { throw $this->createNotFoundException('Unable to find autor relacionado.'); } $eReceta->setAut($eAutor); $id = $request->request->get('idCatRec'); $eCat = $em->getRepository('uniRecetasBundle:categoria')->findOneById($id); if (!$eCat) { throw $this->createNotFoundException('Unable to find categoria relacionado.'); } $eReceta->setCateg($eCat); $em->persist($eReceta); $em->flush(); //*****INGREDIENTES****** //BORRAR INGREDIENTES ANTERIORES foreach ($eReceta->getRecingr() as $r) { $em->remove($r); } $em->flush(); //VOLVER A AÑADIR LOS INGREDIENTES for ($i = 1; $i <= 10; $i++) { $cantIngred = $request->request->get('tb' . $i); $unidIngred = $request->request->get('tb' . $i . $i); $ingred = $request->request->get('tb' . $i . $i . $i); // echo('tb'.$i.'/'.$cantIngred); // echo('tb'.$i.$i.'/'.$unidIngred); // echo('tb'.$i.$i.$i.'/'.$ingred); if (($cantIngred != null or $cantIngred != '') and $ingred != "-1") { $eIngreRec = new ingredrec(); $eIngreRec->setCantidad($cantIngred); $eIngreRec->setUnidad($unidIngred); $eIngrediente = $em->getRepository('uniRecetasBundle:ingrediente')->findOneById($ingred); if (!$eIngrediente) { throw $this->createNotFoundException('Unable to find ingrediente relacionado.'); } $eIngreRec->setIIngrediente($eIngrediente); $eIngreRec->setIReceta($eReceta); $eReceta->addRecingr($eIngreRec); } } $em->persist($eReceta); $em->flush(); //Retorno al show de la receta $entity = $em->getRepository('uniRecetasBundle:receta')->findOneById($idReceta); return $this->render('uniRecetasBundle:receta:show.html.twig', array('entity' => $entity)); }
/** * {@inheritDoc} */ public function getIingrediente() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getIingrediente', array()); return parent::getIingrediente(); }