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

116 lines
4.3 KiB
PHP

<?php
namespace kernel\app_modules\gestalt_profile_relationship\controllers;
use Exception;
use JetBrains\PhpStorm\NoReturn;
use kernel\AdminController;
use kernel\app_modules\gestalt_profile_relationship\models\forms\CreateGestaltProfileRelationshipForm;
use kernel\app_modules\gestalt_profile_relationship\models\GestaltProfileRelationship;
use kernel\app_modules\gestalt_profile_relationship\services\GestaltProfileRelationshipService;
use kernel\EntityRelation;
use kernel\Flash;
use kernel\Request;
class GestaltProfileRelationshipController extends AdminController
{
private GestaltProfileRelationshipService $gestalt_profile_relationshipService;
protected function init(): void
{
parent::init();
$this->cgView->viewPath = KERNEL_APP_MODULES_DIR . "/gestalt_profile_relationship/views/";
$this->gestalt_profile_relationshipService = new GestaltProfileRelationshipService();
}
public function actionCreate(): void
{
$this->cgView->render("form.php");
}
#[NoReturn] public function actionAdd(): void
{
$gestalt_profile_relationshipForm = new CreateGestaltProfileRelationshipForm();
$gestalt_profile_relationshipForm->load($_REQUEST);
if ($gestalt_profile_relationshipForm->validate()){
$gestalt_profile_relationship = $this->gestalt_profile_relationshipService->create($gestalt_profile_relationshipForm);
if ($gestalt_profile_relationship){
$this->redirect("/admin/gestalt_profile_relationship/view/" . $gestalt_profile_relationship->id);
}
}
$this->redirect("/admin/gestalt_profile_relationship/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_relationship = GestaltProfileRelationship::find($id);
if (!$gestalt_profile_relationship){
throw new Exception(message: "The gestalt_profile_relationship not found");
}
$this->cgView->render("view.php", ['gestalt_profile_relationship' => $gestalt_profile_relationship]);
}
/**
* @throws Exception
*/
public function actionUpdate($id): void
{
$model = GestaltProfileRelationship::find($id);
if (!$model){
throw new Exception(message: "The gestalt_profile_relationship not found");
}
$this->cgView->render("form.php", ['model' => $model]);
}
/**
* @throws Exception
*/
public function actionEdit($id): void
{
$gestalt_profile_relationship = GestaltProfileRelationship::find($id);
if (!$gestalt_profile_relationship){
throw new Exception(message: "The gestalt_profile_relationship not found");
}
$gestalt_profile_relationshipForm = new CreateGestaltProfileRelationshipForm();
$gestalt_profile_relationshipService = new GestaltProfileRelationshipService();
$gestalt_profile_relationshipForm->load($_REQUEST);
if ($gestalt_profile_relationshipForm->validate()) {
$gestalt_profile_relationship = $gestalt_profile_relationshipService->update($gestalt_profile_relationshipForm, $gestalt_profile_relationship);
if ($gestalt_profile_relationship) {
$this->redirect("/admin/gestalt_profile_relationship/view/" . $gestalt_profile_relationship->id);
}
}
$this->redirect("/admin/gestalt_profile_relationship/update/" . $id);
}
#[NoReturn] public function actionDelete($id): void
{
$gestalt_profile_relationship = GestaltProfileRelationship::find($id)->first();
$gestalt_profile_relationship->delete();
$this->redirect("/admin/gestalt_profile_relationship/");
}
public function actionSettings(): void
{
$this->cgView->render('settingsForm.php');
}
#[NoReturn] public function actionSaveSettings(): void
{
$request = new Request();
$entities = $request->post('entity');
EntityRelation::configurationEntitiesByProperty($entities, 'gestalt_profile_relationship');
Flash::setMessage("success", "Настройка прошла успешно");
$this->redirect("/admin/settings/gestalt_profile_relationship", 302);
}
}