cgView->viewPath = KERNEL_APP_MODULES_DIR . "/card/views/card_program_conditions/"; $this->cardProgramConditionsService = new CardProgramConditionsService(); } public function actionCreate(): void { $this->cgView->render("form.php"); } #[NoReturn] public function actionAdd(): void { $cardForm = new CreateCardProgramConditionsForm(); $cardForm->load($_REQUEST); if ($cardForm->validate()){ $cardProgramConditions = $this->cardProgramConditionsService->create($cardForm); if ($cardProgramConditions){ Flash::setMessage("success", "Card program conditions created " . $cardProgramConditions->title); $this->redirect("/admin/card_program_conditions/" . $cardProgramConditions->id); } } Flash::setMessage("error", $cardForm->getErrorsStr()); $this->redirect("/admin/card_program_conditions/create"); } public function actionIndex($page_number = 1): void { $this->cgView->render("index.php", ['page_number' => $page_number]); } /** * @throws Exception */ public function actionView($id): void { $card_program = CardProgramConditions::find($id); if (!$card_program){ throw new Exception(message: "The card program conditions not found"); } $this->cgView->render("view.php", ['card_program_conditions' => $card_program]); } /** * @throws Exception */ public function actionUpdate($id): void { $model = CardProgramConditions::find($id); if (!$model){ throw new Exception(message: "The card program conditions not found"); } $this->cgView->render("form.php", ['model' => $model]); } /** * @throws Exception */ public function actionEdit($id): void { $cardProgramConditions = CardProgramConditions::find($id); if (!$cardProgramConditions){ throw new Exception(message: "The card program conditions not found"); } $cardProgramConditionsForm = new CreateCardProgramConditionsForm(); $cardProgramConditionsForm->load($_REQUEST); if ($cardProgramConditionsForm->validate()) { $card = $this->cardProgramConditionsService->update($cardProgramConditionsForm, $cardProgramConditions); if ($card) { Flash::setMessage("success", "Card program updated " . $cardProgramConditions->title); $this->redirect("/admin/card_program_conditions/" . $card->id); } } Flash::setMessage("error", $cardProgramConditionsForm->getErrorsStr()); $this->redirect("/admin/card_program_conditions/update/" . $id); } #[NoReturn] public function actionDelete($id): void { $card_program = CardProgramConditions::where("id", $id)->first(); if (!$card_program){ Flash::setMessage("error", "Card program conditions not found"); } else { Flash::setMessage("success", "Card program conditions deleted"); $card_program->delete(); } $this->redirect("/admin/card_program_conditions/"); } }