Files
gestalt/kernel/app_modules/gestalt_profile/controllers/Gestalt_profileController.php
2025-06-18 14:50:18 +03:00

100 lines
3.2 KiB
PHP

<?php
namespace kernel\app_modules\gestalt_profile\controllers;
use Exception;
use JetBrains\PhpStorm\NoReturn;
use kernel\AdminController;
use kernel\app_modules\gestalt_profile\models\forms\CreateGestalt_profileForm;
use kernel\app_modules\gestalt_profile\models\Gestalt_profile;
use kernel\app_modules\gestalt_profile\services\Gestalt_profileService;
use kernel\helpers\Debug;
class Gestalt_profileController extends AdminController
{
private Gestalt_profileService $gestalt_profileService;
protected function init(): void
{
parent::init();
$this->cgView->viewPath = KERNEL_APP_MODULES_DIR . "/gestalt_profile/views/";
$this->gestalt_profileService = new Gestalt_profileService();
}
public function actionCreate(): void
{
$this->cgView->render("form.php");
}
#[NoReturn] public function actionAdd(): void
{
$gestalt_profileForm = new CreateGestalt_profileForm();
$gestalt_profileForm->load($_REQUEST);
if ($gestalt_profileForm->validate()){
$gestalt_profile = $this->gestalt_profileService->create($gestalt_profileForm);
if ($gestalt_profile){
$this->redirect("/admin/gestalt_profile/view/" . $gestalt_profile->id);
}
}
$this->redirect("/admin/gestalt_profile/create");
}
public function actionIndex($page_number = 1): void
{
$this->cgView->render("index.php", ['page_number' => $page_number]);
}
/**
* @throws Exception
*/
public function actionView($id): void
{
$gestalt_profile = Gestalt_profile::find($id);
if (!$gestalt_profile){
throw new Exception(message: "The gestalt_profile not found");
}
$this->cgView->render("view.php", ['gestalt_profile' => $gestalt_profile]);
}
/**
* @throws Exception
*/
public function actionUpdate($id): void
{
$model = Gestalt_profile::find($id);
if (!$model){
throw new Exception(message: "The gestalt_profile not found");
}
$this->cgView->render("form.php", ['model' => $model]);
}
/**
* @throws Exception
*/
public function actionEdit($id): void
{
$gestalt_profile = Gestalt_profile::find($id);
if (!$gestalt_profile){
throw new Exception(message: "The gestalt_profile not found");
}
$gestalt_profileForm = new CreateGestalt_profileForm();
$gestalt_profileService = new Gestalt_profileService();
$gestalt_profileForm->load($gestalt_profile->toArray());
$gestalt_profileForm->load($_REQUEST);
if ($gestalt_profileForm->validate()) {
$gestalt_profile = $gestalt_profileService->update($gestalt_profileForm, $gestalt_profile);
if ($gestalt_profile) {
$this->redirect("/admin/gestalt_profile/view/" . $gestalt_profile->id);
}
}
$this->redirect("/admin/gestalt_profile/update/" . $id);
}
#[NoReturn] public function actionDelete($id): void
{
$gestalt_profile = Gestalt_profile::find($id)->first();
$gestalt_profile->delete();
$this->redirect("/admin/gestalt_profile/");
}
}