/** * Deletes the given user. */ public function deleteAction() { $userMapper = new UserMapper(); $userId = $this->getRequest()->getParam('id'); if ($userId && $this->getRequest()->isSecure()) { $deleteUser = $userMapper->getUserById($userId); /* * Admingroup has always id "1" because group is not deletable. */ if ($deleteUser->getId() == Registry::get('user')->getId()) { $this->addMessage('delOwnUserProhibited', 'warning'); } elseif ($deleteUser->hasGroup(1) && $userMapper->getAdministratorCount() === 1) { $this->addMessage('delLastAdminProhibited', 'warning'); /* * Delete adminuser only if he is not the last admin. */ } else { if ($deleteUser->getAvatar() != 'static/img/noavatar.jpg') { unlink($deleteUser->getAvatar()); } if (is_dir(APPLICATION_PATH . '/modules/user/static/upload/gallery/' . $userId)) { $path = APPLICATION_PATH . '/modules/user/static/upload/gallery/' . $userId; $files = array_diff(scandir($path), array('.', '..')); foreach ($files as $file) { unlink(realpath($path) . '/' . $file); } rmdir($path); } if ($userMapper->delete($userId)) { $this->addMessage('delUserMsg'); } } } $this->redirect(array('action' => 'index')); }
/** * Deletes the given user. */ public function deleteAction() { $userMapper = new UserMapper(); $userId = $this->getRequest()->getParam('id'); if ($userId && $this->getRequest()->isSecure()) { $deleteUser = $userMapper->getUserById($userId); /* * Admingroup has always id "1" because group is not deletable. */ if ($deleteUser->getId() == Registry::get('user')->getId()) { $this->addMessage('delOwnUserProhibited', 'warning'); } elseif ($deleteUser->hasGroup(1) && $userMapper->getAdministratorCount() === 1) { $this->addMessage('delLastAdminProhibited', 'warning'); /* * Delete adminuser only if he is not the last admin. */ } else { if ($deleteUser->getAvatar() != 'static/img/noavatar.jpg') { unlink($deleteUser->getAvatar()); } if ($userMapper->delete($userId)) { $this->addMessage('delUserMsg'); } } } $this->redirect(array('action' => 'index')); }