Delete action

Method to delete an user from his ID

@return Zend\View\Model\ViewModel
966391
public function deleteUserAction()
    {
        if(!$this->identity()) {
          return $this->redirect()->toRoute($this->getOptions()->getLoginRedirectRoute());
        }
      
        $id = (int) $this->params()->fromRoute('id', 0);

        if ($id == 0) {
            $this->flashMessenger()->addErrorMessage($this->getTranslatorHelper()->translate('User ID invalid'));
            return $this->redirect()->toRoute('user-admin');
        }
           
        try {
            $entityManager = $this->getEntityManager();
            $user = $entityManager->getRepository('CsnUser\Entity\User')->find($id);
            $entityManager->remove($user);
            $entityManager->flush();
            $this->flashMessenger()->addSuccessMessage($this->getTranslatorHelper()->translate('User Deleted Successfully'));
        }
        catch (\Exception $e) {
            return $this->getServiceLocator()->get('csnuser_error_view')->createErrorView(
                $this->getTranslatorHelper()->translate('Something went wrong during user delete process! Please, try again later.'),
                $e,
                $this->getOptions()->getDisplayExceptions(),
                false
            );
        }

        return $this->redirect()->toRoute('user-admin');
    }
502814
public function actionDeleteIn()
    {
        $selected = Yii::$app->request->post('selected' , []);

        $ret = \yongtiger\admin\models\Log::deleteAll(['id' => explode(',', $selected)]);
        $str = $ret > 0 ? ' (IDs [' . $selected . '])' : '';
        Yii::$app->session->setFlash('info', Module::t('message', 'Deleted {0} logs.', $ret) . $str);

        return $this->redirect(['index']);
    }
1259047
public function actionDelete($id)
    {
        $model = $this->findModel($id);
        Yii::$app->getAuthManager()->remove($model->item);
        Helper::invalidate();

        return $this->redirect(['index']);
    }
51678
public function deleteAction(Request $request, $id)
    {
        $this->denyAccessUnlessGranted('ROLE_SUPER_ADMIN');

        /* @var $em EntityManager */
        $em = $this->getDoctrine()->getManager();
        /* @var UserInterface $user */
        $user = $em->getRepository($this->container->getParameter('fos_user.model.user.class'))->find($id);
        if (!is_null($user)) {
            $userEvent = new UserEvent($user, $request);
            $this->container->get('event_dispatcher')->dispatch(UserEvents::USER_DELETE_INITIALIZE, $userEvent);

            $em->remove($user);
            $em->flush();

            $this->addFlash(
                FlashTypes::SUCCESS,
                $this->container->get('translator')->trans('kuma_user.users.delete.flash.success.%username%', [
                    '%username%' => $user->getUsername(),
                ])
            );
        }

        return new RedirectResponse($this->generateUrl('KunstmaanUserManagementBundle_settings_users'));
    }
100445
public function deleteAction($id)
    {
        $manager = $this->getTaskManager();
        $manager->remove($id);

        $this->getEntityManager()->flush();

        return $this->handleView($this->view());
    }
909803
public function deleteAction()
	{
		$cntl = $this->createAdmin();

		if( ( $html = $cntl->delete() ) == '' ) {
			return $this->setPsrResponse( $cntl->getView()->response() );
		}

		$this->view->assign( 'content', $html );
	}
974741
public function indexAction()
    {
        if(!$this->identity()) {
          return $this->redirect()->toRoute($this->getOptions()->getLoginRedirectRoute());
        }
      
        $users = $this->getEntityManager()->getRepository('CsnUser\Entity\User')->findall();
        return new ViewModel(array('users' => $users));
    }
589462
public function deleteUserAction()
    {

        $response = array();
        $this->getEventManager()->trigger('meliscore_tooluser_delete_start', $this, $response);
        $translator = $this->getServiceLocator()->get('translator');
        $id = null;
        $success = 0;
        $textTitle = 'tr_meliscore_tool_user_delete';
        $textMessage = 'tr_meliscore_tool_user_delete_unable';
        $userTable = $this->getServiceLocator()->get('MelisCoreTableUser');

        if($this->getRequest()->isPost())
        {
            $id = $this->getRequest()->getPost('id');

            if(is_numeric($id))
            {
                $userTable->deleteById($id);
                $success = 1;
                $textMessage = 'tr_meliscore_tool_user_delete_success';
            }
        }

        $response = array(
            'textTitle' => $textTitle,
            'textMessage' => $textMessage,
            'success' => $success
        );
        $this->getEventManager()->trigger('meliscore_tooluser_delete_end', $this, array_merge($response, array('typeCode' => 'CORE_USER_DELETE', 'itemId' => $id)));

        return new JsonModel($response);
    }
875119
public function delete(string $id = null)
    {
        $this->request->allowMethod(['post', 'delete']);
        $role = $this->Roles->get($id);
        if ($this->Roles->delete($role)) {
            $this->Flash->success((string)__('The role has been deleted.'));
        } else {
            $this->Flash->error((string)__('The role could not be deleted. Please, try again.'));
        }

        return $this->redirect(['action' => 'index']);
    }
1175433
public function delete($id = null) {
        $role = $this->Roles->get($id);
        if ($this->request->is(['patch', 'post', 'put'])) {
            if ($this->Roles->delete($role)) {
                $this->Flash->success(__('The role has been deleted.'));
            } else {
                $this->Flash->error(__('The role could not be deleted. Please, try again.'));
            }
            return $this->redirect(['action' => 'index']);
        }
        $this->set(compact('role'));
    }
342143
public function index()
    {
        $deletedUsers = $this->repository
            ->query()
            ->withTrashed()
            ->whereStatus('DELETE_IN_PROGRESS');
        
        $dataGrid = new UserDeleteRequestDataGrid($deletedUsers);

        return view('avored-framework::user.user-delete-request.index')
            ->withDataGrid($dataGrid->dataGrid);
    }
558488
public function renderToolUserContentActionDeleteAction()
    {
        $melisKey = $this->params()->fromRoute('melisKey', '');

        $view = new ViewModel();
        $view->melisKey = $melisKey;

        return $view;
    }
1071163
public function deleteAction(Request $request, $id)
    {
        $this->checkIfUserHasPermission(Permission::CREATE_DELETE);

        $this->getParentEntityDefinition($request);

        $entity = $this->getEntity($id);

        $this->getEventDispatcher()->dispatch(
            Events::PRE_CRUD_CONTROLLER_ACTION,
            new CrudControllerActionEvent($this->meta, __FUNCTION__)
        );

        $form = $this->getAdminFormFactory()->createDeleteForm($entity, $this->entityClass)->handleRequest($request);

        if ($this->getFormHandler()->handleDeleteForm($form, $entity)) {
            $this->getEventDispatcher()->dispatch(CrudEvents::DELETED, new DeletedEvent($this->getUser(), $entity));

            return $this->redirect($this->getAdminRouter()->generate($entity, $this->entityClass, AdminRouter::TYPE_INDEX));
        }

        $url = $request->headers->get(
            'referer',
            $this->getAdminRouter()->generate($entity, $this->entityClass, AdminRouter::TYPE_INDEX)
        );

        return $this->redirect($url);
    }
1089369
public function actionDelete($id)
    {
        $request = \Yii::$app->request;
        if ($request->getIsOptions()) {
            return $this->ResponseOptions($this->verbs()['delete']);
        }
        try{
            $model = $this->findModel($id);
            Configs::authManager()->remove($model->item);
            Helper::invalidate();

        }catch (Exception $e){
            throw new Exception($e);
        }


        return ['success'=>true];
    }
311750
public function actionDelete($id)
    {
        $model = $this->findModel($id);
        Yii::$app->getUserAuthManager()->remove($model->item);
        UserRBACHelper::invalidate();
        return $this->redirect(['index']);
    }
1341414
public function actionMassDelete()
    {
        if (($ids = Yii::$app->request->post('ids')) !== null) {
            $models = $this->findUser($ids);
            foreach ($models as $model) {
                $model->delete($model);
            }
            return $this->redirect(['index']);
        } else {
            throw new HttpException(400);
        }
    }
660319
public function delete($id = null)
    {
        $this->request->allowMethod(['post', 'delete']);

        $user = $this->Users->get($id);

        //You cannot delete the admin founder
        if ($user->id === 1) {
            $this->Flash->error(__d('me_cms', 'You cannot delete the admin founder'));
        //Only the admin founder can delete others admin users
        } elseif ($user->group_id === 1 && !$this->Auth->isFounder()) {
            $this->Flash->alert(I18N_ONLY_ADMIN_FOUNDER);
        } elseif ($user->post_count) {
            $this->Flash->alert(I18N_BEFORE_DELETE);
        } else {
            $this->Users->deleteOrFail($user);

            $this->Flash->success(I18N_OPERATION_OK);
        }

        return $this->redirect(['action' => 'index']);
    }