104 lines
2.8 KiB
PHP
104 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace kernel\app_modules\ЕÑtest\controllers;
|
|
|
|
use Exception;
|
|
use JetBrains\PhpStorm\NoReturn;
|
|
use kernel\AdminController;
|
|
use kernel\app_modules\ЕÑtest\models\forms\CreateЕÑtestForm;
|
|
use kernel\app_modules\ЕÑtest\models\ЕÑtest;
|
|
use kernel\app_modules\ЕÑtest\services\ЕÑtestService;
|
|
use kernel\EntityRelation;
|
|
use kernel\Flash;
|
|
use kernel\helpers\Debug;
|
|
use kernel\models\Option;
|
|
use kernel\modules\menu\service\MenuService;
|
|
use kernel\Request;
|
|
|
|
class ЕÑtestController extends AdminController
|
|
{
|
|
private ЕÑtestService $ЕÑtestService;
|
|
protected function init(): void
|
|
{
|
|
parent::init();
|
|
$this->cgView->viewPath = KERNEL_APP_MODULES_DIR . "/ЕÑtest/views/";
|
|
$this->ЕÑtestService = new ЕÑtestService();
|
|
}
|
|
|
|
public function actionCreate(): void
|
|
{
|
|
$this->cgView->render("form.php");
|
|
}
|
|
|
|
#[NoReturn] public function actionAdd(): void
|
|
{
|
|
$ЕÑtestForm = new CreateЕÑtestForm();
|
|
$ЕÑtestForm->load($_REQUEST);
|
|
if ($ЕÑtestForm->validate()){
|
|
$ЕÑtest = $this->ЕÑtestService->create($ЕÑtestForm);
|
|
if ($ЕÑtest){
|
|
$this->redirect("/admin/ЕÑtest/view/" . $ЕÑtest->id);
|
|
}
|
|
}
|
|
$this->redirect("/admin/ЕÑtest/create");
|
|
}
|
|
|
|
public function actionIndex($page_number = 1): void
|
|
{
|
|
$this->cgView->render("index.php", ['page_number' => $page_number]);
|
|
}
|
|
|
|
/**
|
|
* @throws Exception
|
|
*/
|
|
public function actionView($id): void
|
|
{
|
|
$ЕÑtest = ЕÑtest::find($id);
|
|
|
|
if (!$ЕÑtest){
|
|
throw new Exception(message: "The ЕÑtest not found");
|
|
}
|
|
$this->cgView->render("view.php", ['ЕÑtest' => $ЕÑtest]);
|
|
}
|
|
|
|
/**
|
|
* @throws Exception
|
|
*/
|
|
public function actionUpdate($id): void
|
|
{
|
|
$model = ЕÑtest::find($id);
|
|
if (!$model){
|
|
throw new Exception(message: "The ЕÑtest not found");
|
|
}
|
|
|
|
$this->cgView->render("form.php", ['model' => $model]);
|
|
}
|
|
|
|
/**
|
|
* @throws Exception
|
|
*/
|
|
public function actionEdit($id): void
|
|
{
|
|
$ЕÑtest = ЕÑtest::find($id);
|
|
if (!$ЕÑtest){
|
|
throw new Exception(message: "The ЕÑtest not found");
|
|
}
|
|
$ЕÑtestForm = new CreateЕÑtestForm();
|
|
$ЕÑtestService = new ЕÑtestService();
|
|
$ЕÑtestForm->load($_REQUEST);
|
|
if ($ЕÑtestForm->validate()) {
|
|
$ЕÑtest = $ЕÑtestService->update($ЕÑtestForm, $ЕÑtest);
|
|
if ($ЕÑtest) {
|
|
$this->redirect("/admin/ЕÑtest/view/" . $ЕÑtest->id);
|
|
}
|
|
}
|
|
$this->redirect("/admin/ЕÑtest/update/" . $id);
|
|
}
|
|
|
|
#[NoReturn] public function actionDelete($id): void
|
|
{
|
|
$ЕÑtest = ЕÑtest::find($id)->first();
|
|
$ЕÑtest->delete();
|
|
$this->redirect("/admin/ЕÑtest/");
|
|
}
|
|
} |