99 lines
2.7 KiB
PHP
99 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace kernel\app_modules\event\controllers;
|
|
|
|
use Exception;
|
|
use JetBrains\PhpStorm\NoReturn;
|
|
use kernel\AdminController;
|
|
use kernel\app_modules\event\models\forms\CreateEventContactForm;
|
|
use kernel\app_modules\event\models\EventContact;
|
|
use kernel\app_modules\event\services\EventContactService;
|
|
use kernel\helpers\Debug;
|
|
|
|
class EventContactController extends AdminController
|
|
{
|
|
private EventContactService $eventService;
|
|
protected function init(): void
|
|
{
|
|
parent::init();
|
|
$this->cgView->viewPath = KERNEL_APP_MODULES_DIR . "/event/views/eventcontact/";
|
|
$this->eventService = new EventContactService();
|
|
}
|
|
|
|
public function actionCreate(): void
|
|
{
|
|
$this->cgView->render("form.php");
|
|
}
|
|
|
|
#[NoReturn] public function actionAdd(): void
|
|
{
|
|
$eventForm = new CreateEventContactForm();
|
|
$eventForm->load($_REQUEST);
|
|
if ($eventForm->validate()){
|
|
$event = $this->eventService->create($eventForm);
|
|
if ($event){
|
|
$this->redirect("/admin/event-contacts/view/" . $event->id);
|
|
}
|
|
}
|
|
$this->redirect("/admin/event-contacts/create");
|
|
}
|
|
|
|
public function actionIndex($page_number = 1): void
|
|
{
|
|
$this->cgView->render("index.php", ['page_number' => $page_number]);
|
|
}
|
|
|
|
/**
|
|
* @throws Exception
|
|
*/
|
|
public function actionView($id): void
|
|
{
|
|
$event = EventContact::find($id);
|
|
|
|
if (!$event){
|
|
throw new Exception(message: "The event contact not found");
|
|
}
|
|
$this->cgView->render("view.php", ['event' => $event]);
|
|
}
|
|
|
|
/**
|
|
* @throws Exception
|
|
*/
|
|
public function actionUpdate($id): void
|
|
{
|
|
$model = EventContact::find($id);
|
|
if (!$model){
|
|
throw new Exception(message: "The event contact not found");
|
|
}
|
|
|
|
$this->cgView->render("form.php", ['model' => $model]);
|
|
}
|
|
|
|
/**
|
|
* @throws Exception
|
|
*/
|
|
public function actionEdit($id): void
|
|
{
|
|
$event = EventContact::find($id);
|
|
if (!$event){
|
|
throw new Exception(message: "The event not found");
|
|
}
|
|
$eventForm = new CreateEventContactForm();
|
|
$eventService = new EventContactService();
|
|
$eventForm->load($_REQUEST);
|
|
if ($eventForm->validate()) {
|
|
$event = $eventService->update($eventForm, $event);
|
|
if ($event) {
|
|
$this->redirect("/admin/event-contacts/view/" . $event->id);
|
|
}
|
|
}
|
|
$this->redirect("/admin/event-contacts/update/" . $id);
|
|
}
|
|
|
|
#[NoReturn] public function actionDelete($id): void
|
|
{
|
|
$event = EventContact::find($id)->first();
|
|
$event->delete();
|
|
$this->redirect("/admin/event-contacts/");
|
|
}
|
|
} |