cgView->viewPath = KERNEL_APP_MODULES_DIR . "/tgbot/views/notification/"; $this->notificationService = new TgbotNotificationService(); } public function actionCreate(): void { $this->cgView->render("form.php"); } public function actionIndex($page_number = 1): void { $this->cgView->render("index.php", ['page_number' => $page_number]); } #[NoReturn] public function actionAdd(): void { $tgForm = new CreateTgbotNotificationForm(); $tgForm->load($_REQUEST); if ($tgForm->validate()) { $tg = $this->notificationService->create($tgForm); if ($tg) { $this->redirect("/admin/tg-bot-notification/view/" . $tg->id); } } Flash::setMessage("error", $tgForm->getErrorsStr()); $this->redirect("/admin/tg-bot-notification/create"); } /** * @throws Exception */ public function actionUpdate($id): void { $model = TgbotNotification::find($id); if (!$model) { throw new Exception(message: "The notification not found"); } $this->cgView->render("form.php", ['model' => $model]); } /** * @throws Exception */ public function actionEdit($id): void { $tg = TgbotNotification::find($id); if (!$tg) { throw new Exception(message: "The tag not found"); } $tgForm = new CreateTgbotNotificationForm(); $tgService = new TgbotNotificationService(); $tgForm->load($_REQUEST); if ($tgForm->validate()) { $tg = $tgService->update($tgForm, $tg); if ($tg) { $this->redirect("/admin/tg-bot-notification/view/" . $tg->id); } } Flash::setMessage("error", $tgForm->getErrorsStr()); $this->redirect("/admin/tg-bot-notification/update/" . $id); } /** * @throws Exception */ public function actionView($id): void { $tg = TgbotNotification::find($id); if (!$tg) { throw new Exception(message: "The notification not found"); } $this->cgView->render("view.php", ['tg' => $tg]); } /** * @throws Exception */ #[NoReturn] public function actionDelete(int $id): void { $post = TgbotNotification::find($id)->first(); if (!$post){ throw new Exception(message: "The tg notification not found"); } Flash::setMessage("success", "Notification deleted"); $post->delete(); $this->redirect("/admin/tg-bot-notification/"); } }