src/Cpm/JovenesBundle/Controller/BloqueController.php
/**
     * Edits an existing Bloque entity.
     *
     * @Route("/{id}/update", name="bloque_update")
     * @Method("post")
     * @Template("CpmJovenesBundle:Bloque:edit.html.twig")
     */
Edits an existing Bloque entity.
Edits an existing Bloque entity .
public function updateAction($id)
    {
        $entity = $this->getEntityForUpdate('CpmJovenesBundle:Bloque', $id);
        $editForm   = $this->createForm(new BloqueType(), $entity);
        $deleteForm = $this->createDeleteForm($id);
        $request = $this->getRequest();
	    $editForm->bindRequest($request);
        if ($editForm->isValid()) {
	        $em = $this->getDoctrine()->getEntityManager();
	    	if (!$entity->getTienePresentaciones()){ 
	        	$presentaciones = $entity->getPresentaciones()->toArray(); 
				foreach ( $presentaciones as $presentacion ) {
						$entity->removePresentacion($presentacion);
						$em->persist($presentacion);
				}	
	        }
	        $em->persist($entity);
	        $em->flush();
			$this->setSuccessMessage("Bloque modificado satisfactoriamente");
            return $this->redirect($this->generateUrl('bloque_edit', array('id' => $id)));
        }
        return array(
            'entity'      => $entity,
            'edit_form'   => $editForm->createView(),
            'delete_form' => $deleteForm->createView(),
        );
    }
public function updateAction ( $ id ) { $ entity = $ this -> getEntityForUpdate ( 'CpmJovenesBundle:Bloque' , $ id ) ; $ editForm = $ this -> createForm ( new BloqueType ( ) , $ entity ) ; $ deleteForm = $ this -> createDeleteForm ( $ id ) ; $ request = $ this -> getRequest ( ) ; $ editForm -> bindRequest ( $ request ) ; if ( $ editForm -> isValid ( ) ) { $ em = $ this -> getDoctrine ( ) -> getEntityManager ( ) ; if ( ! $ entity -> getTienePresentaciones ( ) ) { $ presentaciones = $ entity -> getPresentaciones ( ) -> toArray ( ) ; foreach ( $ presentaciones as $ presentacion ) { $ entity -> removePresentacion ( $ presentacion ) ; $ em -> persist ( $ presentacion ) ; } } $ em -> persist ( $ entity ) ; $ em -> flush ( ) ; $ this -> setSuccessMessage ( " Bloque modificado satisfactoriamente " ) ; return $ this -> redirect ( $ this -> generateUrl ( 'bloque_edit' , array ( 'id' => $ id ) ) ) ; } return array ( 'entity' => $ entity , 'edit_form' => $ editForm -> createView ( ) , 'delete_form' => $ deleteForm -> createView ( ) , ) ; }
Edits an existing Bloque entity.
Edits an existing Bloque entity .
//al no ser un bloque de presentaciones, me aseguro que no tenga ninguna presentacion asignada