/** * Delete a Belong Group entity. * * @View(statusCode=200) * * @param Request $request * @param $entity * @internal param $id * * @return Response */ public function deleteUserbelonggroupsAction(Request $request, Groups $group, Userbelonggroup $entity) { $user = $this->getUser(); if ($user == $entity->getUser() and $entity->getRole() != 1 or $user == $group->getUser()) { try { $em = $this->getDoctrine()->getManager(); $em->remove($entity); $em->flush(); return array('type' => 'success', 'alert' => 'alert-success', 'message' => 'You don\'t belong this group anymore !'); } catch (\Exception $e) { // return FOSView::create($e->getMessage(), Codes::HTTP_INTERNAL_SERVER_ERROR); return array('type' => 'error'); } } else { throw $this->createNotFoundException('No able to modify : ' . $entity); } }