src/Flowcode/UserBundle/Controller/UserGroupController.php
public function deleteAction(Request $request, $id) {

        $form = $this->createDeleteForm($id);
        $form->handleRequest($request);

        if ($form->isValid()) {

            $em = $this->getDoctrine()->getManager();
            $userGroup = $em->getRepository('AmulenUserBundle:UserGroup')->find($id);

            if (!$userGroup) {
                throw $this->createNotFoundException('Unable to find UserGroup entity.');
            }

            $var = $em->getRepository('AmulenUserBundle:User')->findByGroup($userGroup);
            echo $var;
            die("123");

            $users = $this->getUsersByUserGroup($userGroup);
            
            if (count($users) == 0)
            {
                $em->remove($userGroup);
                $em->flush();
            }
            else
            {
                $this->get('session')->getFlashBag()->add('warning', "El grupo de roles no pude eliminarse debido a que posee usuarios asociados.");
                return $this->redirect($request->getUri());
            }
        }

        return $this->redirect($this->generateUrl('admin_usergroup'));
    }
public function deleteAction(Request $request, $id) {

        $form = $this->createDeleteForm($id);
        $form->handleRequest($request);

        if ($form->isValid()) {

            $em = $this->getDoctrine()->getManager();
            $userGroup = $em->getRepository('AmulenUserBundle:UserGroup')->find($id);

            if (!$userGroup) {
                throw $this->createNotFoundException('Unable to find UserGroup entity.');
            }

            $var = $em->getRepository('AmulenUserBundle:User')->findByGroup($userGroup);
            echo $var;
            die("123");

            $users = $this->getUsersByUserGroup($userGroup);
            
            if (count($users) == 0)
            {
                $em->remove($userGroup);
                $em->flush();
            }
            else
            {
                $this->get('session')->getFlashBag()->add('warning', "El grupo de roles no pude eliminarse debido a que posee usuarios asociados.");
                return $this->redirect($request->getUri());
            }
        }

        return $this->redirect($this->generateUrl('admin_usergroup'));
    }
public function deleteAction ( Request $ request , $ id ) { $ form = $ this -> createDeleteForm ( $ id ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isValid ( ) ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ userGroup = $ em -> getRepository ( 'AmulenUserBundle:UserGroup' ) -> find ( $ id ) ; if ( ! $ userGroup ) { throw $ this -> createNotFoundException ( 'Unable to find UserGroup entity.' ) ; } $ var = $ em -> getRepository ( 'AmulenUserBundle:User' ) -> findByGroup ( $ userGroup ) ; echo $ var ; die ( "123" ) ; $ users = $ this -> getUsersByUserGroup ( $ userGroup ) ; if ( count ( $ users ) == 0 ) { $ em -> remove ( $ userGroup ) ; $ em -> flush ( ) ; } else { $ this -> get ( 'session' ) -> getFlashBag ( ) -> add ( 'warning' , "El grupo de roles no pude eliminarse debido a que posee usuarios asociados." ) ; return $ this -> redirect ( $ request -> getUri ( ) ) ; } } return $ this -> redirect ( $ this -> generateUrl ( 'admin_usergroup' ) ) ; }
Deletes a UserGroup entity.

@Route("/{id}", name="admin_usergroup_delete")
@Method("DELETE")
Deletes a UserGroup entity .