module shop crud
This commit is contained in:
@ -2,24 +2,105 @@
|
||||
|
||||
namespace app\modules\module_shop\controllers;
|
||||
|
||||
use app\modules\module_shop\models\forms\CreateModuleShopForm;
|
||||
use app\modules\module_shop\models\ModuleShop;
|
||||
use app\modules\module_shop\services\ModuleShopService;
|
||||
use JetBrains\PhpStorm\NoReturn;
|
||||
use kernel\AdminController;
|
||||
use kernel\app_modules\tag\services\TagService;
|
||||
use kernel\services\ModuleService;
|
||||
use mysql_xdevapi\Exception;
|
||||
|
||||
class ModuleShopController extends AdminController
|
||||
{
|
||||
protected ModuleService $moduleService;
|
||||
protected ModuleShopService $moduleShopService;
|
||||
|
||||
protected function init(): void
|
||||
{
|
||||
parent::init();
|
||||
$this->cgView->viewPath = KERNEL_APP_MODULES_DIR . "/module_shop/views/";
|
||||
$this->moduleService = new ModuleService();
|
||||
$this->cgView->viewPath = APP_DIR . "/modules/module_shop/views/";
|
||||
$this->moduleShopService = new ModuleShopService();
|
||||
}
|
||||
|
||||
public function actionIndex($page_number): void
|
||||
public function actionCreate(): void
|
||||
{
|
||||
$this->cgView->render("form.php");
|
||||
}
|
||||
|
||||
#[NoReturn] public function actionAdd(): void
|
||||
{
|
||||
$moduleShopForm = new CreateModuleShopForm();
|
||||
$moduleShopForm->load($_REQUEST);
|
||||
if ($moduleShopForm->validate()) {
|
||||
$module = $this->moduleShopService->create($moduleShopForm);
|
||||
if ($module) {
|
||||
$this->redirect("/admin/module_shop/" . $module->id);
|
||||
}
|
||||
}
|
||||
$this->redirect("/admin/module_shop/create");
|
||||
}
|
||||
|
||||
public function actionIndex(int $page_number = 1): void
|
||||
{
|
||||
$this->cgView->render("index.php", ['page_number' => $page_number]);
|
||||
}
|
||||
|
||||
public function actionView(int $id): void
|
||||
{
|
||||
$module = ModuleShop::find($id);
|
||||
|
||||
if (!$module) {
|
||||
throw new Exception("The module not found");
|
||||
}
|
||||
$this->cgView->render("view.php", ['module' => $module]);
|
||||
}
|
||||
|
||||
public function actionUpdate(int $id): void
|
||||
{
|
||||
$model = ModuleShop::find($id);
|
||||
|
||||
if (!$model) {
|
||||
throw new Exception("The module not found");
|
||||
}
|
||||
|
||||
$this->cgView->render("form.php", ['model' => $model]);
|
||||
}
|
||||
|
||||
public function actionEdit(int $id): void
|
||||
{
|
||||
$module = ModuleShop::find($id);
|
||||
|
||||
if (!$module) {
|
||||
throw new Exception("The module not found");
|
||||
}
|
||||
$moduleForm = new CreateModuleShopForm();
|
||||
$moduleForm->load($_REQUEST);
|
||||
if ($moduleForm->validate()) {
|
||||
$module = $this->moduleShopService->update($moduleForm, $module);
|
||||
if ($module) {
|
||||
$this->redirect("/admin/module_shop/" . $module->id);
|
||||
}
|
||||
}
|
||||
$this->redirect("/admin/module_shop/update/" . $id);
|
||||
}
|
||||
|
||||
public function actionDelete(int $id): void
|
||||
{
|
||||
$module = ModuleShop::find($id);
|
||||
if (!$module) {
|
||||
throw new Exception("The module not found");
|
||||
}
|
||||
|
||||
$module->delete();
|
||||
$this->redirect("/admin/module_shop");
|
||||
}
|
||||
|
||||
public function actionPack(int $id): void
|
||||
{
|
||||
$module = ModuleShop::find($id);
|
||||
if (!$module) {
|
||||
throw new Exception("The module not found");
|
||||
}
|
||||
$this->moduleShopService->packModule($module);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user