kernel update
This commit is contained in:
@ -5,9 +5,11 @@ namespace kernel\modules\user\controllers;
|
||||
use Exception;
|
||||
use JetBrains\PhpStorm\NoReturn;
|
||||
use kernel\AdminController;
|
||||
use kernel\EntityRelation;
|
||||
use kernel\modules\user\models\forms\CreateUserForm;
|
||||
use kernel\modules\user\models\User;
|
||||
use kernel\modules\user\service\UserService;
|
||||
use kernel\Request;
|
||||
use Twig\Error\LoaderError;
|
||||
use Twig\Error\RuntimeError;
|
||||
use Twig\Error\SyntaxError;
|
||||
@ -35,6 +37,11 @@ class UserController extends AdminController
|
||||
$userForm->load($_REQUEST);
|
||||
if ($userForm->validate()){
|
||||
$user = $this->userService->create($userForm);
|
||||
|
||||
|
||||
$entityRelation = new EntityRelation();
|
||||
$entityRelation->saveEntityRelation(entity: "user", model: $user, request: new Request());
|
||||
|
||||
if ($user){
|
||||
$this->redirect("/admin/user/view/" . $user->id);
|
||||
}
|
||||
@ -91,8 +98,12 @@ class UserController extends AdminController
|
||||
$userForm = new CreateUserForm();
|
||||
$userService = new UserService();
|
||||
$userForm->load($_REQUEST);
|
||||
if ($userForm->validate()){
|
||||
if ($userForm->validateForUpdate()){
|
||||
$user = $userService->update($userForm, $user);
|
||||
|
||||
$entityRelation = new EntityRelation();
|
||||
$entityRelation->saveEntityRelation(entity: "user", model: $user, request: new Request());
|
||||
|
||||
if ($user){
|
||||
$this->redirect("/admin/user/view/" . $user->id);
|
||||
}
|
||||
@ -100,9 +111,20 @@ class UserController extends AdminController
|
||||
$this->redirect("/admin/user/update/" . $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
#[NoReturn] public function actionDelete($id): void
|
||||
{
|
||||
User::find($id)->delete();
|
||||
$user = User::find($id)->first();
|
||||
if (!$user){
|
||||
throw new Exception(message: "The user not found");
|
||||
}
|
||||
|
||||
$entityRelation = new EntityRelation();
|
||||
$entityRelation->deleteEntityRelation(entity: "user", model: $user);
|
||||
|
||||
$user->delete();
|
||||
$this->redirect("/admin/user/");
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user