cgView->viewPath = KERNEL_APP_MODULES_DIR . "/event/views/"; $this->eventService = new EventService(); } public function actionCreate(): void { $this->cgView->render("form.php"); } #[NoReturn] public function actionAdd(): void { $eventForm = new CreateEventForm(); $eventForm->load($_REQUEST); if ($eventForm->validate()){ $event = $this->eventService->create($eventForm); $entityRelation = new EntityRelation(); $entityRelation->saveEntityRelation(entity: "event", model: $event, request: new Request()); if ($event){ $this->redirect("/admin/event/view/" . $event->id); } } $this->redirect("/admin/event/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 = Event::find($id); if (!$event){ throw new Exception(message: "The event not found"); } $this->cgView->render("view.php", ['event' => $event]); } /** * @throws Exception */ public function actionUpdate($id): void { $model = Event::find($id); if (!$model){ throw new Exception(message: "The event not found"); } $this->cgView->render("form.php", ['model' => $model]); } /** * @throws Exception */ public function actionEdit($id): void { $event = Event::find($id); if (!$event){ throw new Exception(message: "The event not found"); } $eventForm = new CreateEventForm(); $eventService = new EventService(); $eventForm->load($_REQUEST); if ($eventForm->validate()) { $event = $eventService->update($eventForm, $event); $entityRelation = new EntityRelation(); $entityRelation->saveEntityRelation(entity: "event", model: $event, request: new Request()); if ($event) { $this->redirect("/admin/event/view/" . $event->id); } } $this->redirect("/admin/event/update/" . $id); } #[NoReturn] public function actionDelete($id): void { $event = Event::find($id)->first(); $event->delete(); $this->redirect("/admin/event/"); } }