120 lines
		
	
	
		
			3.9 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			120 lines
		
	
	
		
			3.9 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
namespace kernel\app_modules\card\controllers;
 | 
						|
 | 
						|
use Exception;
 | 
						|
use JetBrains\PhpStorm\NoReturn;
 | 
						|
use kernel\AdminController;
 | 
						|
use kernel\app_modules\card\models\CardProgram;
 | 
						|
use kernel\app_modules\card\models\CardProgramConditions;
 | 
						|
use kernel\app_modules\card\models\forms\CreateCardProgramConditionsForm;
 | 
						|
use kernel\app_modules\card\models\forms\CreateCardProgramForm;
 | 
						|
use kernel\app_modules\card\services\CardProgramConditionsService;
 | 
						|
use kernel\app_modules\card\services\CardProgramService;
 | 
						|
use kernel\app_modules\card\services\CardService;
 | 
						|
use kernel\Flash;
 | 
						|
 | 
						|
class CardProgramConditionsController extends AdminController
 | 
						|
{
 | 
						|
 | 
						|
    private CardProgramConditionsService $cardProgramConditionsService;
 | 
						|
 | 
						|
    protected function init(): void
 | 
						|
    {
 | 
						|
        parent::init();
 | 
						|
        $this->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/");
 | 
						|
    }
 | 
						|
 | 
						|
} |