2024-11-29 13:23:48 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace kernel\app_modules\photo\controllers;
|
|
|
|
|
|
|
|
use Exception;
|
|
|
|
use JetBrains\PhpStorm\NoReturn;
|
|
|
|
use kernel\AdminController;
|
|
|
|
use kernel\app_modules\photo\models\form\CreatePhotoForm;
|
|
|
|
use kernel\app_modules\photo\models\Photo;
|
2024-12-12 11:58:55 +03:00
|
|
|
use kernel\app_modules\photo\service\PhotoService;
|
2024-12-02 16:25:28 +03:00
|
|
|
use kernel\EntityRelation;
|
|
|
|
use kernel\Flash;
|
2024-11-29 13:23:48 +03:00
|
|
|
use kernel\helpers\Debug;
|
2024-12-02 16:25:28 +03:00
|
|
|
use kernel\Request;
|
|
|
|
|
2024-11-29 13:23:48 +03:00
|
|
|
class PhotoController extends AdminController
|
|
|
|
{
|
|
|
|
private PhotoService $photoService;
|
|
|
|
protected function init(): void
|
|
|
|
{
|
|
|
|
parent::init();
|
|
|
|
$this->cgView->viewPath = KERNEL_APP_MODULES_DIR . "/photo/views/";
|
|
|
|
$this->photoService = new PhotoService();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function actionCreate(): void
|
|
|
|
{
|
|
|
|
$this->cgView->render("form.php");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[NoReturn] public function actionAdd(): void
|
|
|
|
{
|
|
|
|
$photoForm = new CreatePhotoForm();
|
|
|
|
$photoForm->load($_REQUEST);
|
|
|
|
if ($photoForm->validate()){
|
|
|
|
$photo = $this->photoService->create($photoForm);
|
|
|
|
if ($photo){
|
|
|
|
$this->redirect("/admin/photo/view/" . $photo->id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->redirect("/admin/photo/create");
|
|
|
|
}
|
|
|
|
|
|
|
|
public function actionIndex($page_number = 1): void
|
|
|
|
{
|
|
|
|
$this->cgView->render("index.php", ['page_number' => $page_number]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
public function actionView($id): void
|
|
|
|
{
|
|
|
|
$photo = Photo::find($id);
|
|
|
|
|
|
|
|
if (!$photo){
|
|
|
|
throw new Exception(message: "The photo not found");
|
|
|
|
}
|
|
|
|
$this->cgView->render("view.php", ['photo' => $photo]);
|
|
|
|
}
|
|
|
|
|
2024-12-02 16:25:28 +03:00
|
|
|
public function actionSettings(): void
|
|
|
|
{
|
|
|
|
$this->cgView->render('settingsForm.php');
|
|
|
|
}
|
|
|
|
|
|
|
|
#[NoReturn] public function actionSaveSettings(): void
|
|
|
|
{
|
|
|
|
$request = new Request();
|
|
|
|
$entities = $request->post('entity');
|
|
|
|
EntityRelation::configurationEntitiesByProperty($entities, 'photo');
|
|
|
|
|
|
|
|
Flash::setMessage("success", "Настройка прошла успешно");
|
|
|
|
$this->redirect("/admin/settings/photo", 302);
|
|
|
|
}
|
2024-11-29 13:23:48 +03:00
|
|
|
|
|
|
|
}
|