From 9abfdd2fd9b4d7b2e068f99828c863dedd7ff973 Mon Sep 17 00:00:00 2001 From: stasbilay02 Date: Wed, 9 Oct 2024 16:42:20 +0300 Subject: [PATCH 1/4] install, uninstall. pack to ModuleService --- app/modules/tag/manifest.json | 1 - .../console/controllers/ModuleController.php | 66 +++--------- kernel/controllers/ModuleController.php | 2 +- kernel/services/ModuleService.php | 80 +++++++++++++- .../app/TagModule.php | 38 +++++++ .../app/controllers/TagController.php | 8 ++ .../app/manifest.json | 12 +++ .../app/routs/tag.php | 2 + .../kernel/controllers/TagController.php | 101 ++++++++++++++++++ .../2024_10_08_093710_create_tag_table.php | 31 ++++++ .../kernel/models/Tag.php | 46 ++++++++ .../kernel/models/forms/CreateTagForm.php | 20 ++++ .../kernel/routs/tag.php | 18 ++++ .../kernel/services/TagService.php | 42 ++++++++ .../kernel/views/form.php | 58 ++++++++++ .../kernel/views/index.php | 39 +++++++ .../kernel/views/view.php | 30 ++++++ .../app/TagModule.php | 38 +++++++ .../app/controllers/TagController.php | 8 ++ .../app/manifest.json | 12 +++ .../app/routs/tag.php | 2 + .../kernel/controllers/TagController.php | 101 ++++++++++++++++++ .../2024_10_08_093710_create_tag_table.php | 31 ++++++ .../kernel/models/Tag.php | 46 ++++++++ .../kernel/models/forms/CreateTagForm.php | 20 ++++ .../kernel/routs/tag.php | 18 ++++ .../kernel/services/TagService.php | 42 ++++++++ .../kernel/views/form.php | 58 ++++++++++ .../kernel/views/index.php | 39 +++++++ .../kernel/views/view.php | 30 ++++++ .../app/TagModule.php | 38 +++++++ .../app/controllers/TagController.php | 8 ++ .../app/manifest.json | 12 +++ .../app/routs/tag.php | 2 + .../kernel/controllers/TagController.php | 101 ++++++++++++++++++ .../2024_10_08_093710_create_tag_table.php | 31 ++++++ .../kernel/models/Tag.php | 46 ++++++++ .../kernel/models/forms/CreateTagForm.php | 20 ++++ .../kernel/routs/tag.php | 18 ++++ .../kernel/services/TagService.php | 42 ++++++++ .../kernel/views/form.php | 58 ++++++++++ .../kernel/views/index.php | 39 +++++++ .../kernel/views/view.php | 30 ++++++ .../app/TagModule.php | 38 +++++++ .../app/controllers/TagController.php | 8 ++ .../app/manifest.json | 12 +++ .../app/routs/tag.php | 2 + .../kernel/controllers/TagController.php | 101 ++++++++++++++++++ .../2024_10_08_093710_create_tag_table.php | 31 ++++++ .../kernel/models/Tag.php | 46 ++++++++ .../kernel/models/forms/CreateTagForm.php | 20 ++++ .../kernel/routs/tag.php | 18 ++++ .../kernel/services/TagService.php | 42 ++++++++ .../kernel/views/form.php | 58 ++++++++++ .../kernel/views/index.php | 39 +++++++ .../kernel/views/view.php | 30 ++++++ .../app/TagModule.php | 38 +++++++ .../app/controllers/TagController.php | 8 ++ .../app/manifest.json | 12 +++ .../app/routs/tag.php | 2 + .../kernel/controllers/TagController.php | 101 ++++++++++++++++++ .../2024_10_08_093710_create_tag_table.php | 31 ++++++ .../kernel/models/Tag.php | 46 ++++++++ .../kernel/models/forms/CreateTagForm.php | 20 ++++ .../kernel/routs/tag.php | 18 ++++ .../kernel/services/TagService.php | 42 ++++++++ .../kernel/views/form.php | 58 ++++++++++ .../kernel/views/index.php | 39 +++++++ .../kernel/views/view.php | 30 ++++++ resources/tmp/modules/tag.itguild | Bin 6338 -> 6311 bytes 70 files changed, 2317 insertions(+), 57 deletions(-) create mode 100644 resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/app/TagModule.php create mode 100644 resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/app/controllers/TagController.php create mode 100644 resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/app/manifest.json create mode 100644 resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/app/routs/tag.php create mode 100644 resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/controllers/TagController.php create mode 100644 resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/migrations/2024_10_08_093710_create_tag_table.php create mode 100644 resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/models/Tag.php create mode 100644 resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/models/forms/CreateTagForm.php create mode 100644 resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/routs/tag.php create mode 100644 resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/services/TagService.php create mode 100644 resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/views/form.php create mode 100644 resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/views/index.php create mode 100644 resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/views/view.php create mode 100644 resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/app/TagModule.php create mode 100644 resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/app/controllers/TagController.php create mode 100644 resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/app/manifest.json create mode 100644 resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/app/routs/tag.php create mode 100644 resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/controllers/TagController.php create mode 100644 resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/migrations/2024_10_08_093710_create_tag_table.php create mode 100644 resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/models/Tag.php create mode 100644 resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/models/forms/CreateTagForm.php create mode 100644 resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/routs/tag.php create mode 100644 resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/services/TagService.php create mode 100644 resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/views/form.php create mode 100644 resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/views/index.php create mode 100644 resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/views/view.php create mode 100644 resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/app/TagModule.php create mode 100644 resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/app/controllers/TagController.php create mode 100644 resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/app/manifest.json create mode 100644 resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/app/routs/tag.php create mode 100644 resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/controllers/TagController.php create mode 100644 resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/migrations/2024_10_08_093710_create_tag_table.php create mode 100644 resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/models/Tag.php create mode 100644 resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/models/forms/CreateTagForm.php create mode 100644 resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/routs/tag.php create mode 100644 resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/services/TagService.php create mode 100644 resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/views/form.php create mode 100644 resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/views/index.php create mode 100644 resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/views/view.php create mode 100644 resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/app/TagModule.php create mode 100644 resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/app/controllers/TagController.php create mode 100644 resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/app/manifest.json create mode 100644 resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/app/routs/tag.php create mode 100644 resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/controllers/TagController.php create mode 100644 resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/migrations/2024_10_08_093710_create_tag_table.php create mode 100644 resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/models/Tag.php create mode 100644 resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/models/forms/CreateTagForm.php create mode 100644 resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/routs/tag.php create mode 100644 resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/services/TagService.php create mode 100644 resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/views/form.php create mode 100644 resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/views/index.php create mode 100644 resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/views/view.php create mode 100644 resources/tmp/ad/fb7687573df162d45c5044239738988c/app/TagModule.php create mode 100644 resources/tmp/ad/fb7687573df162d45c5044239738988c/app/controllers/TagController.php create mode 100644 resources/tmp/ad/fb7687573df162d45c5044239738988c/app/manifest.json create mode 100644 resources/tmp/ad/fb7687573df162d45c5044239738988c/app/routs/tag.php create mode 100644 resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/controllers/TagController.php create mode 100644 resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/migrations/2024_10_08_093710_create_tag_table.php create mode 100644 resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/models/Tag.php create mode 100644 resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/models/forms/CreateTagForm.php create mode 100644 resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/routs/tag.php create mode 100644 resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/services/TagService.php create mode 100644 resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/views/form.php create mode 100644 resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/views/index.php create mode 100644 resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/views/view.php diff --git a/app/modules/tag/manifest.json b/app/modules/tag/manifest.json index 974f984..456f81c 100644 --- a/app/modules/tag/manifest.json +++ b/app/modules/tag/manifest.json @@ -5,7 +5,6 @@ "slug": "tag", "description": "Tags module", "app_module_path": "{APP}/modules/{slug}", - "kernel_module_path": "{KERNEL_APP_MODULES}/{slug}", "module_class": "app\\modules\\tag\\TagModule", "module_class_file": "{APP}/modules/tag/TagModule.php", "routs": "routs/tag.php" diff --git a/kernel/console/controllers/ModuleController.php b/kernel/console/controllers/ModuleController.php index 67417d7..c586f76 100644 --- a/kernel/console/controllers/ModuleController.php +++ b/kernel/console/controllers/ModuleController.php @@ -22,31 +22,11 @@ class ModuleController extends ConsoleController throw new \Exception('Missing module path "--path" specified'); } - $zip = new ZipArchive; - $tmpModuleDir = md5(time()); - $res = $zip->open(ROOT_DIR . $this->argv['path']); - if ($res === TRUE) { - $tmpModuleDirFull = RESOURCES_DIR . '/tmp/ad/' . $tmpModuleDir . "/"; - $zip->extractTo($tmpModuleDirFull); - $zip->close(); - $this->out->r('Архив распакован', 'green'); + if (file_exists(ROOT_DIR . $this->argv['path'])) { + $moduleService = new ModuleService(); + $moduleService->installModule($this->argv['path']); } else { - $this->out->r('Message: Ошибка чтения архива', 'red'); - } - - if (file_exists($tmpModuleDirFull . "/app/manifest.json")){ - $manifestJson = getConst(file_get_contents($tmpModuleDirFull . "/app/manifest.json")); - $manifest = Manifest::getWithVars($manifestJson); - $this->out->r('manifest.json инициализирован', 'green'); - - $fileHelper = new Files(); - $fileHelper->copy_folder($tmpModuleDirFull . '/app', $manifest['app_module_path']); - $fileHelper->copy_folder($tmpModuleDirFull . '/kernel', $manifest['kernel_module_path']); - - $this->out->r("Удаляем временные файлы", 'green'); - $fileHelper->recursiveRemoveDir($tmpModuleDirFull); - - $this->out->r("Модуль " . $manifest['name'] . " установлен", 'green'); + $this->out->r("Модуль не найден", 'red'); } } @@ -61,25 +41,15 @@ class ModuleController extends ConsoleController if (file_exists(ROOT_DIR . $this->argv['path'])) { $moduleService = new ModuleService(); - $moduleInfo = $moduleService->getModuleInfo(APP_DIR . '/modules/' . basename($this->argv['path'])); - - if ($moduleService->isActive($moduleInfo['slug'])) { - $moduleService->setActiveModule($moduleInfo['slug']); - } - - $fileHelper = new Files(); - if (file_exists(APP_DIR . '/modules/' . $moduleInfo['slug'])) { - $fileHelper->recursiveRemoveDir(APP_DIR . '/modules/'. $moduleInfo['slug']); - } - if (file_exists(KERNEL_APP_MODULES_DIR . '/' . $moduleInfo['slug'])) { - $fileHelper->recursiveRemoveDir(KERNEL_APP_MODULES_DIR . '/' . $moduleInfo['slug']); - } - $this->out->r("Модуль удален", 'green'); + $moduleService->uninstallModule($this->argv['path']); } else { $this->out->r("Модуль не найден", 'red'); } } + /** + * @throws \Exception + */ public function actionPackModule(): void { if (!isset($this->argv['path'])) { @@ -87,22 +57,10 @@ class ModuleController extends ConsoleController } if (file_exists(ROOT_DIR . $this->argv['path'])) { - $moduleName = basename($this->argv['path']); - - $tmpModuleDirFull = RESOURCES_DIR . '/tmp/ad/' . $moduleName . "/"; - - $fileHelper = new Files(); - $fileHelper->copy_folder(APP_DIR . '/modules/' . $moduleName, $tmpModuleDirFull . 'app/'); - $fileHelper->copy_folder(KERNEL_APP_MODULES_DIR . '/' . $moduleName, $tmpModuleDirFull . 'kernel/'); - - $this->out->r("Модуль собран во временную папку", 'green'); - - $fileHelper->pack($tmpModuleDirFull, RESOURCES_DIR . '/tmp/modules/' . $moduleName . '.itguild'); - - $this->out->r("Архив создан", 'green'); - $fileHelper->recursiveRemoveDir($tmpModuleDirFull); - $this->out->r("Временная папка удалена", 'green'); - + $moduleService = new ModuleService(); + $moduleService->packModule($this->argv['path']); + } else { + $this->out->r("Модуль не найден", 'red'); } } diff --git a/kernel/controllers/ModuleController.php b/kernel/controllers/ModuleController.php index e8524e8..cbae844 100644 --- a/kernel/controllers/ModuleController.php +++ b/kernel/controllers/ModuleController.php @@ -51,7 +51,7 @@ class ModuleController extends AdminController public function actionActivate(): void { $request = new Request(); - $this->moduleService->setActiveModule($request->get("slug")); + $this->moduleService->toggleModule($request->get("slug")); $mod_info = $this->moduleService->getModuleInfoBySlug($request->get('slug')); $this->cgView->render("view.php", ['data' => $mod_info]); diff --git a/kernel/services/ModuleService.php b/kernel/services/ModuleService.php index f787be5..f639cff 100644 --- a/kernel/services/ModuleService.php +++ b/kernel/services/ModuleService.php @@ -3,9 +3,12 @@ namespace kernel\services; use DirectoryIterator; +use kernel\console\Out; use kernel\helpers\Debug; +use kernel\helpers\Files; use kernel\helpers\Manifest; use kernel\models\Option; +use ZipArchive; class ModuleService { @@ -44,7 +47,7 @@ class ModuleService return false; } - public function setActiveModule(string $module): void + public function toggleModule(string $module): void { $active_modules = Option::where("key", "active_modules")->first(); $path = json_decode($active_modules->value); @@ -154,4 +157,79 @@ class ModuleService return $migrationsPaths; } + /** + * @throws \Exception + */ + public function installModule(string $path): void + { + $zip = new ZipArchive; + $tmpModuleDir = md5(time()); + $res = $zip->open(ROOT_DIR . $path); + if ($res === TRUE) { + $tmpModuleDirFull = RESOURCES_DIR . '/tmp/ad/' . $tmpModuleDir . "/"; + $zip->extractTo($tmpModuleDirFull); + $zip->close(); +// $out->out->r('Архив распакован', 'green'); +// } else { +// $this->out->r('Message: Ошибка чтения архива', 'red'); + } + + if (!file_exists($tmpModuleDirFull . "/app/manifest.json")) { + throw new \Exception('manifest.json not found'); + } + + $manifestJson = getConst(file_get_contents($tmpModuleDirFull . "/app/manifest.json")); + $manifest = Manifest::getWithVars($manifestJson); +// $this->out->r('manifest.json инициализирован', 'green'); + + $fileHelper = new Files(); + $fileHelper->copy_folder($tmpModuleDirFull . '/app', $manifest['app_module_path']); + if (isset($manifest['kernel_module_path'])) { + $fileHelper->copy_folder($tmpModuleDirFull . '/kernel', $manifest['kernel_module_path']); + } else { + $fileHelper->copy_folder($tmpModuleDirFull . '/kernel', KERNEL_APP_MODULES_DIR . '/' . $manifest['slug']); + } + +// $this->out->r("Удаляем временные файлы", 'green'); + $fileHelper->recursiveRemoveDir($tmpModuleDirFull); + +// $this->out->r("Модуль " . $manifest['name'] . " установлен", 'green'); + } + + public function uninstallModule(string $path): void + { + $moduleInfo = $this->getModuleInfo(APP_DIR . '/modules/' . basename($path)); + + if ($this->isActive($moduleInfo['slug'])) { + $this->toggleModule($moduleInfo['slug']); + } + + $fileHelper = new Files(); + if (file_exists(APP_DIR . '/modules/' . $moduleInfo['slug'])) { + $fileHelper->recursiveRemoveDir(APP_DIR . '/modules/'. $moduleInfo['slug']); + } + if (file_exists(KERNEL_APP_MODULES_DIR . '/' . $moduleInfo['slug'])) { + $fileHelper->recursiveRemoveDir(KERNEL_APP_MODULES_DIR . '/' . $moduleInfo['slug']); + } + } + + public function packModule(string $path): void + { + $moduleName = basename($path); + + $tmpModuleDirFull = RESOURCES_DIR . '/tmp/ad/' . $moduleName . "/"; + + $fileHelper = new Files(); + $fileHelper->copy_folder(APP_DIR . '/modules/' . $moduleName, $tmpModuleDirFull . 'app/'); + $fileHelper->copy_folder(KERNEL_APP_MODULES_DIR . '/' . $moduleName, $tmpModuleDirFull . 'kernel/'); + +// $this->out->r("Модуль собран во временную папку", 'green'); + + $fileHelper->pack($tmpModuleDirFull, RESOURCES_DIR . '/tmp/modules/' . $moduleName . '.itguild'); + +// $this->out->r("Архив создан", 'green'); + $fileHelper->recursiveRemoveDir($tmpModuleDirFull); +// $this->out->r("Временная папка удалена", 'green'); + } + } \ No newline at end of file diff --git a/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/app/TagModule.php b/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/app/TagModule.php new file mode 100644 index 0000000..b2f0ffd --- /dev/null +++ b/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/app/TagModule.php @@ -0,0 +1,38 @@ +menuService = new MenuService(); + $this->migrationService = new MigrationService(); + } + + /** + * @throws \Exception + */ + public function init(): void + { + $this->migrationService->runAtPath("{KERNEL_APP_MODULES}/tag/migrations"); + + $this->menuService->createItem([ + "label" => "Тэги", + "url" => "/admin/tag", + "slug" => "tag", + ]); + } + + public function deactivate(): void + { + $this->menuService->removeItemBySlug("tag"); + } +} \ No newline at end of file diff --git a/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/app/controllers/TagController.php b/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/app/controllers/TagController.php new file mode 100644 index 0000000..4598872 --- /dev/null +++ b/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/app/controllers/TagController.php @@ -0,0 +1,8 @@ +cgView->viewPath = KERNEL_APP_MODULES_DIR . "/tag/views/"; + $this->tagService = new TagService(); + } + + public function actionCreate(): void + { + $this->cgView->render("form.php"); + } + + #[NoReturn] public function actionAdd(): void + { + $tagForm = new CreateTagForm(); + $tagForm->load($_REQUEST); + if ($tagForm->validate()){ + $tag = $this->tagService->create($tagForm); + if ($tag){ + $this->redirect("/admin/tag/" . $tag->id); + } + } + $this->redirect("/admin/tag/create"); + } + + public function actionIndex($page_number = 1): void + { + $this->cgView->render("index.php", ['page_number' => $page_number]); + } + + /** + * @throws Exception + */ + public function actionView($id): void + { + $tag = Tag::find($id); + + if (!$tag){ + throw new Exception(message: "The tag not found"); + } + $this->cgView->render("view.php", ['tag' => $tag]); + } + + /** + * @throws Exception + */ + public function actionUpdate($id): void + { + $model = Tag::find($id); + if (!$model){ + throw new Exception(message: "The tag not found"); + } + + $this->cgView->render("form.php", ['model' => $model]); + } + + /** + * @throws Exception + */ + public function actionEdit($id): void + { + $tag = Tag::find($id); + if (!$tag){ + throw new Exception(message: "The tag not found"); + } + $tagForm = new CreateTagForm(); + $tagService = new TagService(); + $tagForm->load($_REQUEST); + if ($tagForm->validate()) { + $tag = $tagService->update($tagForm, $tag); + if ($tag) { + $this->redirect("/admin/tag/" . $tag->id); + } + } + $this->redirect("/admin/tag/update/" . $id); + } + + #[NoReturn] public function actionDelete($id): void + { + $post = Tag::find($id)->first(); + $post->delete(); + $this->redirect("/admin/tag/"); + } + +} \ No newline at end of file diff --git a/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/migrations/2024_10_08_093710_create_tag_table.php b/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/migrations/2024_10_08_093710_create_tag_table.php new file mode 100644 index 0000000..37c4be5 --- /dev/null +++ b/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/migrations/2024_10_08_093710_create_tag_table.php @@ -0,0 +1,31 @@ +schema->create('tag', function (Blueprint $table) { + $table->increments('id'); + $table->string('label', 255)->nullable(false); + $table->string('entity', 255)->nullable(false); + $table->string('slug', 255)->unique(); + $table->integer('status')->default(1); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + \kernel\App::$db->schema->dropIfExists('tag'); + } +}; diff --git a/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/models/Tag.php b/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/models/Tag.php new file mode 100644 index 0000000..49e1bb4 --- /dev/null +++ b/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/models/Tag.php @@ -0,0 +1,46 @@ + 'Заголовок', + 'entity' => 'Сущность', + 'slug' => 'Slug', + 'status' => 'Статус', + ]; + } + + /** + * @return string[] + */ + public static function getStatus(): array + { + return [ + self::DISABLE_STATUS => "Не активный", + self::ACTIVE_STATUS => "Активный", + ]; + } + +} \ No newline at end of file diff --git a/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/models/forms/CreateTagForm.php b/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/models/forms/CreateTagForm.php new file mode 100644 index 0000000..82fd893 --- /dev/null +++ b/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/models/forms/CreateTagForm.php @@ -0,0 +1,20 @@ + 'required|min-str-len:5|max-str-len:30', + 'entity' => 'required|min-str-len:1|max-str-len:50', + 'slug' => '', + 'status' => '' + ]; + } + +} \ No newline at end of file diff --git a/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/routs/tag.php b/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/routs/tag.php new file mode 100644 index 0000000..6ec41fe --- /dev/null +++ b/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/routs/tag.php @@ -0,0 +1,18 @@ +group(["prefix" => "admin"], function (CgRouteCollector $router) { + App::$collector->group(["prefix" => "tag"], function (CGRouteCollector $router){ + App::$collector->get('/', [\app\modules\tag\controllers\TagController::class, 'actionIndex']); + App::$collector->get('/page/{page_number}', [\app\modules\tag\controllers\TagController::class, 'actionIndex']); + App::$collector->get('/create', [\app\modules\tag\controllers\TagController::class, 'actionCreate']); + App::$collector->post("/", [\app\modules\tag\controllers\TagController::class, 'actionAdd']); + App::$collector->get('/{id}', [\app\modules\tag\controllers\TagController::class, 'actionView']); + App::$collector->any('/update/{id}', [\app\modules\tag\controllers\TagController::class, 'actionUpdate']); + App::$collector->any("/edit/{id}", [\app\modules\tag\controllers\TagController::class, 'actionEdit']); + App::$collector->get('/delete/{id}', [\app\modules\tag\controllers\TagController::class, 'actionDelete']); + }); +}); \ No newline at end of file diff --git a/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/services/TagService.php b/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/services/TagService.php new file mode 100644 index 0000000..9407f0a --- /dev/null +++ b/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/services/TagService.php @@ -0,0 +1,42 @@ +label = $form_model->getItem('label'); + $model->entity = $form_model->getItem('entity'); + $model->status = $form_model->getItem('status'); + $model->slug = Slug::createSlug($form_model->getItem('label'), Tag::class); + if ($model->save()){ + return $model; + } + + return false; + } + + public function update(FormModel $form_model, Tag $tag): false|Tag + { + if ($tag->label !== $form_model->getItem('label')) { + $tag->slug = Slug::createSlug($form_model->getItem('label'), Tag::class); + } + $tag->label = $form_model->getItem('label'); + $tag->entity = $form_model->getItem('entity'); + $tag->status = $form_model->getItem('status'); + + if ($tag->save()){ + return $tag; + } + + return false; + } + +} \ No newline at end of file diff --git a/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/views/form.php b/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/views/form.php new file mode 100644 index 0000000..3a37b96 --- /dev/null +++ b/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/views/form.php @@ -0,0 +1,58 @@ +beginForm(isset($model) ? "/admin/tag/edit/" . $model->id : "/admin/tag"); + +$form->field(class: \itguild\forms\inputs\TextInput::class, name: "label", params: [ + 'class' => "form-control", + 'placeholder' => 'Заголовок', + 'value' => $model->label ?? '' +]) + ->setLabel("Заголовок") + ->render(); + +$form->field(class: \itguild\forms\inputs\TextInput::class, name: "entity", params: [ + 'class' => "form-control", + 'placeholder' => 'Сущность', + 'value' => $model->entity ?? '' +]) + ->setLabel("Сущность") + ->render(); + +$form->field(\itguild\forms\inputs\Select::class, 'status', [ + 'class' => "form-control", + 'value' => $model->status ?? '' +]) + ->setLabel("Статус") + ->setOptions(Tag::getStatus()) + ->render(); +?> +
+
+ field(\itguild\forms\inputs\Button::class, name: "btn-submit", params: [ + 'class' => "btn btn-primary ", + 'value' => 'Отправить', + 'typeInput' => 'submit' + ]) + ->render(); + ?> +
+
+ field(\itguild\forms\inputs\Button::class, name: "btn-reset", params: [ + 'class' => "btn btn-warning", + 'value' => 'Сбросить', + 'typeInput' => 'reset' + ]) + ->render(); + ?> +
+
+endForm(); diff --git a/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/views/index.php b/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/views/index.php new file mode 100644 index 0000000..0d5503f --- /dev/null +++ b/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/views/index.php @@ -0,0 +1,39 @@ + $page_number, + 'perPage' => 8, + 'params' => ["class" => "table table-bordered", "border" => "2"], + 'baseUrl' => "/admin/tag", +])); + +$table->beforePrint(function () { + return PrimaryBtn::create("Создать", "/admin/tag/create")->fetch(); + //return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch(); +}); + +$table->columns([ + "status" => [ + "value" => function ($cell) { + return Tag::getStatus()[$cell]; + }] +]); + +$table->addAction(\kernel\IGTabel\action_column\ViewActionColumn::class); +$table->addAction(\kernel\IGTabel\action_column\DeleteActionColumn::class); +$table->addAction(\kernel\IGTabel\action_column\EditActionColumn::class); +$table->create(); +$table->render(); \ No newline at end of file diff --git a/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/views/view.php b/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/views/view.php new file mode 100644 index 0000000..b09034f --- /dev/null +++ b/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/views/view.php @@ -0,0 +1,30 @@ + ["class" => "table table-bordered", "border" => "2"], + 'baseUrl' => "/admin/tag", +])); +$table->beforePrint(function () use ($tag) { + $btn = PrimaryBtn::create("Список", "/admin/tag")->fetch(); + $btn .= SuccessBtn::create("Редактировать", "/admin/tag/update/" . $tag->id)->fetch(); + $btn .= DangerBtn::create("Удалить", "/admin/tag/delete/" . $tag->id)->fetch(); + return $btn; +}); +$table->rows([ + 'status' => (function ($data) { + return \kernel\app_modules\tag\models\Tag::getStatus()[$data]; + }) +]); +$table->create(); +$table->render(); \ No newline at end of file diff --git a/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/app/TagModule.php b/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/app/TagModule.php new file mode 100644 index 0000000..b2f0ffd --- /dev/null +++ b/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/app/TagModule.php @@ -0,0 +1,38 @@ +menuService = new MenuService(); + $this->migrationService = new MigrationService(); + } + + /** + * @throws \Exception + */ + public function init(): void + { + $this->migrationService->runAtPath("{KERNEL_APP_MODULES}/tag/migrations"); + + $this->menuService->createItem([ + "label" => "Тэги", + "url" => "/admin/tag", + "slug" => "tag", + ]); + } + + public function deactivate(): void + { + $this->menuService->removeItemBySlug("tag"); + } +} \ No newline at end of file diff --git a/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/app/controllers/TagController.php b/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/app/controllers/TagController.php new file mode 100644 index 0000000..4598872 --- /dev/null +++ b/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/app/controllers/TagController.php @@ -0,0 +1,8 @@ +cgView->viewPath = KERNEL_APP_MODULES_DIR . "/tag/views/"; + $this->tagService = new TagService(); + } + + public function actionCreate(): void + { + $this->cgView->render("form.php"); + } + + #[NoReturn] public function actionAdd(): void + { + $tagForm = new CreateTagForm(); + $tagForm->load($_REQUEST); + if ($tagForm->validate()){ + $tag = $this->tagService->create($tagForm); + if ($tag){ + $this->redirect("/admin/tag/" . $tag->id); + } + } + $this->redirect("/admin/tag/create"); + } + + public function actionIndex($page_number = 1): void + { + $this->cgView->render("index.php", ['page_number' => $page_number]); + } + + /** + * @throws Exception + */ + public function actionView($id): void + { + $tag = Tag::find($id); + + if (!$tag){ + throw new Exception(message: "The tag not found"); + } + $this->cgView->render("view.php", ['tag' => $tag]); + } + + /** + * @throws Exception + */ + public function actionUpdate($id): void + { + $model = Tag::find($id); + if (!$model){ + throw new Exception(message: "The tag not found"); + } + + $this->cgView->render("form.php", ['model' => $model]); + } + + /** + * @throws Exception + */ + public function actionEdit($id): void + { + $tag = Tag::find($id); + if (!$tag){ + throw new Exception(message: "The tag not found"); + } + $tagForm = new CreateTagForm(); + $tagService = new TagService(); + $tagForm->load($_REQUEST); + if ($tagForm->validate()) { + $tag = $tagService->update($tagForm, $tag); + if ($tag) { + $this->redirect("/admin/tag/" . $tag->id); + } + } + $this->redirect("/admin/tag/update/" . $id); + } + + #[NoReturn] public function actionDelete($id): void + { + $post = Tag::find($id)->first(); + $post->delete(); + $this->redirect("/admin/tag/"); + } + +} \ No newline at end of file diff --git a/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/migrations/2024_10_08_093710_create_tag_table.php b/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/migrations/2024_10_08_093710_create_tag_table.php new file mode 100644 index 0000000..37c4be5 --- /dev/null +++ b/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/migrations/2024_10_08_093710_create_tag_table.php @@ -0,0 +1,31 @@ +schema->create('tag', function (Blueprint $table) { + $table->increments('id'); + $table->string('label', 255)->nullable(false); + $table->string('entity', 255)->nullable(false); + $table->string('slug', 255)->unique(); + $table->integer('status')->default(1); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + \kernel\App::$db->schema->dropIfExists('tag'); + } +}; diff --git a/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/models/Tag.php b/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/models/Tag.php new file mode 100644 index 0000000..49e1bb4 --- /dev/null +++ b/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/models/Tag.php @@ -0,0 +1,46 @@ + 'Заголовок', + 'entity' => 'Сущность', + 'slug' => 'Slug', + 'status' => 'Статус', + ]; + } + + /** + * @return string[] + */ + public static function getStatus(): array + { + return [ + self::DISABLE_STATUS => "Не активный", + self::ACTIVE_STATUS => "Активный", + ]; + } + +} \ No newline at end of file diff --git a/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/models/forms/CreateTagForm.php b/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/models/forms/CreateTagForm.php new file mode 100644 index 0000000..82fd893 --- /dev/null +++ b/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/models/forms/CreateTagForm.php @@ -0,0 +1,20 @@ + 'required|min-str-len:5|max-str-len:30', + 'entity' => 'required|min-str-len:1|max-str-len:50', + 'slug' => '', + 'status' => '' + ]; + } + +} \ No newline at end of file diff --git a/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/routs/tag.php b/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/routs/tag.php new file mode 100644 index 0000000..6ec41fe --- /dev/null +++ b/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/routs/tag.php @@ -0,0 +1,18 @@ +group(["prefix" => "admin"], function (CgRouteCollector $router) { + App::$collector->group(["prefix" => "tag"], function (CGRouteCollector $router){ + App::$collector->get('/', [\app\modules\tag\controllers\TagController::class, 'actionIndex']); + App::$collector->get('/page/{page_number}', [\app\modules\tag\controllers\TagController::class, 'actionIndex']); + App::$collector->get('/create', [\app\modules\tag\controllers\TagController::class, 'actionCreate']); + App::$collector->post("/", [\app\modules\tag\controllers\TagController::class, 'actionAdd']); + App::$collector->get('/{id}', [\app\modules\tag\controllers\TagController::class, 'actionView']); + App::$collector->any('/update/{id}', [\app\modules\tag\controllers\TagController::class, 'actionUpdate']); + App::$collector->any("/edit/{id}", [\app\modules\tag\controllers\TagController::class, 'actionEdit']); + App::$collector->get('/delete/{id}', [\app\modules\tag\controllers\TagController::class, 'actionDelete']); + }); +}); \ No newline at end of file diff --git a/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/services/TagService.php b/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/services/TagService.php new file mode 100644 index 0000000..9407f0a --- /dev/null +++ b/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/services/TagService.php @@ -0,0 +1,42 @@ +label = $form_model->getItem('label'); + $model->entity = $form_model->getItem('entity'); + $model->status = $form_model->getItem('status'); + $model->slug = Slug::createSlug($form_model->getItem('label'), Tag::class); + if ($model->save()){ + return $model; + } + + return false; + } + + public function update(FormModel $form_model, Tag $tag): false|Tag + { + if ($tag->label !== $form_model->getItem('label')) { + $tag->slug = Slug::createSlug($form_model->getItem('label'), Tag::class); + } + $tag->label = $form_model->getItem('label'); + $tag->entity = $form_model->getItem('entity'); + $tag->status = $form_model->getItem('status'); + + if ($tag->save()){ + return $tag; + } + + return false; + } + +} \ No newline at end of file diff --git a/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/views/form.php b/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/views/form.php new file mode 100644 index 0000000..3a37b96 --- /dev/null +++ b/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/views/form.php @@ -0,0 +1,58 @@ +beginForm(isset($model) ? "/admin/tag/edit/" . $model->id : "/admin/tag"); + +$form->field(class: \itguild\forms\inputs\TextInput::class, name: "label", params: [ + 'class' => "form-control", + 'placeholder' => 'Заголовок', + 'value' => $model->label ?? '' +]) + ->setLabel("Заголовок") + ->render(); + +$form->field(class: \itguild\forms\inputs\TextInput::class, name: "entity", params: [ + 'class' => "form-control", + 'placeholder' => 'Сущность', + 'value' => $model->entity ?? '' +]) + ->setLabel("Сущность") + ->render(); + +$form->field(\itguild\forms\inputs\Select::class, 'status', [ + 'class' => "form-control", + 'value' => $model->status ?? '' +]) + ->setLabel("Статус") + ->setOptions(Tag::getStatus()) + ->render(); +?> +
+
+ field(\itguild\forms\inputs\Button::class, name: "btn-submit", params: [ + 'class' => "btn btn-primary ", + 'value' => 'Отправить', + 'typeInput' => 'submit' + ]) + ->render(); + ?> +
+
+ field(\itguild\forms\inputs\Button::class, name: "btn-reset", params: [ + 'class' => "btn btn-warning", + 'value' => 'Сбросить', + 'typeInput' => 'reset' + ]) + ->render(); + ?> +
+
+endForm(); diff --git a/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/views/index.php b/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/views/index.php new file mode 100644 index 0000000..0d5503f --- /dev/null +++ b/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/views/index.php @@ -0,0 +1,39 @@ + $page_number, + 'perPage' => 8, + 'params' => ["class" => "table table-bordered", "border" => "2"], + 'baseUrl' => "/admin/tag", +])); + +$table->beforePrint(function () { + return PrimaryBtn::create("Создать", "/admin/tag/create")->fetch(); + //return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch(); +}); + +$table->columns([ + "status" => [ + "value" => function ($cell) { + return Tag::getStatus()[$cell]; + }] +]); + +$table->addAction(\kernel\IGTabel\action_column\ViewActionColumn::class); +$table->addAction(\kernel\IGTabel\action_column\DeleteActionColumn::class); +$table->addAction(\kernel\IGTabel\action_column\EditActionColumn::class); +$table->create(); +$table->render(); \ No newline at end of file diff --git a/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/views/view.php b/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/views/view.php new file mode 100644 index 0000000..b09034f --- /dev/null +++ b/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/views/view.php @@ -0,0 +1,30 @@ + ["class" => "table table-bordered", "border" => "2"], + 'baseUrl' => "/admin/tag", +])); +$table->beforePrint(function () use ($tag) { + $btn = PrimaryBtn::create("Список", "/admin/tag")->fetch(); + $btn .= SuccessBtn::create("Редактировать", "/admin/tag/update/" . $tag->id)->fetch(); + $btn .= DangerBtn::create("Удалить", "/admin/tag/delete/" . $tag->id)->fetch(); + return $btn; +}); +$table->rows([ + 'status' => (function ($data) { + return \kernel\app_modules\tag\models\Tag::getStatus()[$data]; + }) +]); +$table->create(); +$table->render(); \ No newline at end of file diff --git a/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/app/TagModule.php b/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/app/TagModule.php new file mode 100644 index 0000000..b2f0ffd --- /dev/null +++ b/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/app/TagModule.php @@ -0,0 +1,38 @@ +menuService = new MenuService(); + $this->migrationService = new MigrationService(); + } + + /** + * @throws \Exception + */ + public function init(): void + { + $this->migrationService->runAtPath("{KERNEL_APP_MODULES}/tag/migrations"); + + $this->menuService->createItem([ + "label" => "Тэги", + "url" => "/admin/tag", + "slug" => "tag", + ]); + } + + public function deactivate(): void + { + $this->menuService->removeItemBySlug("tag"); + } +} \ No newline at end of file diff --git a/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/app/controllers/TagController.php b/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/app/controllers/TagController.php new file mode 100644 index 0000000..4598872 --- /dev/null +++ b/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/app/controllers/TagController.php @@ -0,0 +1,8 @@ +cgView->viewPath = KERNEL_APP_MODULES_DIR . "/tag/views/"; + $this->tagService = new TagService(); + } + + public function actionCreate(): void + { + $this->cgView->render("form.php"); + } + + #[NoReturn] public function actionAdd(): void + { + $tagForm = new CreateTagForm(); + $tagForm->load($_REQUEST); + if ($tagForm->validate()){ + $tag = $this->tagService->create($tagForm); + if ($tag){ + $this->redirect("/admin/tag/" . $tag->id); + } + } + $this->redirect("/admin/tag/create"); + } + + public function actionIndex($page_number = 1): void + { + $this->cgView->render("index.php", ['page_number' => $page_number]); + } + + /** + * @throws Exception + */ + public function actionView($id): void + { + $tag = Tag::find($id); + + if (!$tag){ + throw new Exception(message: "The tag not found"); + } + $this->cgView->render("view.php", ['tag' => $tag]); + } + + /** + * @throws Exception + */ + public function actionUpdate($id): void + { + $model = Tag::find($id); + if (!$model){ + throw new Exception(message: "The tag not found"); + } + + $this->cgView->render("form.php", ['model' => $model]); + } + + /** + * @throws Exception + */ + public function actionEdit($id): void + { + $tag = Tag::find($id); + if (!$tag){ + throw new Exception(message: "The tag not found"); + } + $tagForm = new CreateTagForm(); + $tagService = new TagService(); + $tagForm->load($_REQUEST); + if ($tagForm->validate()) { + $tag = $tagService->update($tagForm, $tag); + if ($tag) { + $this->redirect("/admin/tag/" . $tag->id); + } + } + $this->redirect("/admin/tag/update/" . $id); + } + + #[NoReturn] public function actionDelete($id): void + { + $post = Tag::find($id)->first(); + $post->delete(); + $this->redirect("/admin/tag/"); + } + +} \ No newline at end of file diff --git a/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/migrations/2024_10_08_093710_create_tag_table.php b/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/migrations/2024_10_08_093710_create_tag_table.php new file mode 100644 index 0000000..37c4be5 --- /dev/null +++ b/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/migrations/2024_10_08_093710_create_tag_table.php @@ -0,0 +1,31 @@ +schema->create('tag', function (Blueprint $table) { + $table->increments('id'); + $table->string('label', 255)->nullable(false); + $table->string('entity', 255)->nullable(false); + $table->string('slug', 255)->unique(); + $table->integer('status')->default(1); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + \kernel\App::$db->schema->dropIfExists('tag'); + } +}; diff --git a/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/models/Tag.php b/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/models/Tag.php new file mode 100644 index 0000000..49e1bb4 --- /dev/null +++ b/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/models/Tag.php @@ -0,0 +1,46 @@ + 'Заголовок', + 'entity' => 'Сущность', + 'slug' => 'Slug', + 'status' => 'Статус', + ]; + } + + /** + * @return string[] + */ + public static function getStatus(): array + { + return [ + self::DISABLE_STATUS => "Не активный", + self::ACTIVE_STATUS => "Активный", + ]; + } + +} \ No newline at end of file diff --git a/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/models/forms/CreateTagForm.php b/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/models/forms/CreateTagForm.php new file mode 100644 index 0000000..82fd893 --- /dev/null +++ b/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/models/forms/CreateTagForm.php @@ -0,0 +1,20 @@ + 'required|min-str-len:5|max-str-len:30', + 'entity' => 'required|min-str-len:1|max-str-len:50', + 'slug' => '', + 'status' => '' + ]; + } + +} \ No newline at end of file diff --git a/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/routs/tag.php b/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/routs/tag.php new file mode 100644 index 0000000..6ec41fe --- /dev/null +++ b/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/routs/tag.php @@ -0,0 +1,18 @@ +group(["prefix" => "admin"], function (CgRouteCollector $router) { + App::$collector->group(["prefix" => "tag"], function (CGRouteCollector $router){ + App::$collector->get('/', [\app\modules\tag\controllers\TagController::class, 'actionIndex']); + App::$collector->get('/page/{page_number}', [\app\modules\tag\controllers\TagController::class, 'actionIndex']); + App::$collector->get('/create', [\app\modules\tag\controllers\TagController::class, 'actionCreate']); + App::$collector->post("/", [\app\modules\tag\controllers\TagController::class, 'actionAdd']); + App::$collector->get('/{id}', [\app\modules\tag\controllers\TagController::class, 'actionView']); + App::$collector->any('/update/{id}', [\app\modules\tag\controllers\TagController::class, 'actionUpdate']); + App::$collector->any("/edit/{id}", [\app\modules\tag\controllers\TagController::class, 'actionEdit']); + App::$collector->get('/delete/{id}', [\app\modules\tag\controllers\TagController::class, 'actionDelete']); + }); +}); \ No newline at end of file diff --git a/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/services/TagService.php b/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/services/TagService.php new file mode 100644 index 0000000..9407f0a --- /dev/null +++ b/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/services/TagService.php @@ -0,0 +1,42 @@ +label = $form_model->getItem('label'); + $model->entity = $form_model->getItem('entity'); + $model->status = $form_model->getItem('status'); + $model->slug = Slug::createSlug($form_model->getItem('label'), Tag::class); + if ($model->save()){ + return $model; + } + + return false; + } + + public function update(FormModel $form_model, Tag $tag): false|Tag + { + if ($tag->label !== $form_model->getItem('label')) { + $tag->slug = Slug::createSlug($form_model->getItem('label'), Tag::class); + } + $tag->label = $form_model->getItem('label'); + $tag->entity = $form_model->getItem('entity'); + $tag->status = $form_model->getItem('status'); + + if ($tag->save()){ + return $tag; + } + + return false; + } + +} \ No newline at end of file diff --git a/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/views/form.php b/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/views/form.php new file mode 100644 index 0000000..3a37b96 --- /dev/null +++ b/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/views/form.php @@ -0,0 +1,58 @@ +beginForm(isset($model) ? "/admin/tag/edit/" . $model->id : "/admin/tag"); + +$form->field(class: \itguild\forms\inputs\TextInput::class, name: "label", params: [ + 'class' => "form-control", + 'placeholder' => 'Заголовок', + 'value' => $model->label ?? '' +]) + ->setLabel("Заголовок") + ->render(); + +$form->field(class: \itguild\forms\inputs\TextInput::class, name: "entity", params: [ + 'class' => "form-control", + 'placeholder' => 'Сущность', + 'value' => $model->entity ?? '' +]) + ->setLabel("Сущность") + ->render(); + +$form->field(\itguild\forms\inputs\Select::class, 'status', [ + 'class' => "form-control", + 'value' => $model->status ?? '' +]) + ->setLabel("Статус") + ->setOptions(Tag::getStatus()) + ->render(); +?> +
+
+ field(\itguild\forms\inputs\Button::class, name: "btn-submit", params: [ + 'class' => "btn btn-primary ", + 'value' => 'Отправить', + 'typeInput' => 'submit' + ]) + ->render(); + ?> +
+
+ field(\itguild\forms\inputs\Button::class, name: "btn-reset", params: [ + 'class' => "btn btn-warning", + 'value' => 'Сбросить', + 'typeInput' => 'reset' + ]) + ->render(); + ?> +
+
+endForm(); diff --git a/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/views/index.php b/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/views/index.php new file mode 100644 index 0000000..0d5503f --- /dev/null +++ b/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/views/index.php @@ -0,0 +1,39 @@ + $page_number, + 'perPage' => 8, + 'params' => ["class" => "table table-bordered", "border" => "2"], + 'baseUrl' => "/admin/tag", +])); + +$table->beforePrint(function () { + return PrimaryBtn::create("Создать", "/admin/tag/create")->fetch(); + //return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch(); +}); + +$table->columns([ + "status" => [ + "value" => function ($cell) { + return Tag::getStatus()[$cell]; + }] +]); + +$table->addAction(\kernel\IGTabel\action_column\ViewActionColumn::class); +$table->addAction(\kernel\IGTabel\action_column\DeleteActionColumn::class); +$table->addAction(\kernel\IGTabel\action_column\EditActionColumn::class); +$table->create(); +$table->render(); \ No newline at end of file diff --git a/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/views/view.php b/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/views/view.php new file mode 100644 index 0000000..b09034f --- /dev/null +++ b/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/views/view.php @@ -0,0 +1,30 @@ + ["class" => "table table-bordered", "border" => "2"], + 'baseUrl' => "/admin/tag", +])); +$table->beforePrint(function () use ($tag) { + $btn = PrimaryBtn::create("Список", "/admin/tag")->fetch(); + $btn .= SuccessBtn::create("Редактировать", "/admin/tag/update/" . $tag->id)->fetch(); + $btn .= DangerBtn::create("Удалить", "/admin/tag/delete/" . $tag->id)->fetch(); + return $btn; +}); +$table->rows([ + 'status' => (function ($data) { + return \kernel\app_modules\tag\models\Tag::getStatus()[$data]; + }) +]); +$table->create(); +$table->render(); \ No newline at end of file diff --git a/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/app/TagModule.php b/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/app/TagModule.php new file mode 100644 index 0000000..b2f0ffd --- /dev/null +++ b/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/app/TagModule.php @@ -0,0 +1,38 @@ +menuService = new MenuService(); + $this->migrationService = new MigrationService(); + } + + /** + * @throws \Exception + */ + public function init(): void + { + $this->migrationService->runAtPath("{KERNEL_APP_MODULES}/tag/migrations"); + + $this->menuService->createItem([ + "label" => "Тэги", + "url" => "/admin/tag", + "slug" => "tag", + ]); + } + + public function deactivate(): void + { + $this->menuService->removeItemBySlug("tag"); + } +} \ No newline at end of file diff --git a/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/app/controllers/TagController.php b/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/app/controllers/TagController.php new file mode 100644 index 0000000..4598872 --- /dev/null +++ b/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/app/controllers/TagController.php @@ -0,0 +1,8 @@ +cgView->viewPath = KERNEL_APP_MODULES_DIR . "/tag/views/"; + $this->tagService = new TagService(); + } + + public function actionCreate(): void + { + $this->cgView->render("form.php"); + } + + #[NoReturn] public function actionAdd(): void + { + $tagForm = new CreateTagForm(); + $tagForm->load($_REQUEST); + if ($tagForm->validate()){ + $tag = $this->tagService->create($tagForm); + if ($tag){ + $this->redirect("/admin/tag/" . $tag->id); + } + } + $this->redirect("/admin/tag/create"); + } + + public function actionIndex($page_number = 1): void + { + $this->cgView->render("index.php", ['page_number' => $page_number]); + } + + /** + * @throws Exception + */ + public function actionView($id): void + { + $tag = Tag::find($id); + + if (!$tag){ + throw new Exception(message: "The tag not found"); + } + $this->cgView->render("view.php", ['tag' => $tag]); + } + + /** + * @throws Exception + */ + public function actionUpdate($id): void + { + $model = Tag::find($id); + if (!$model){ + throw new Exception(message: "The tag not found"); + } + + $this->cgView->render("form.php", ['model' => $model]); + } + + /** + * @throws Exception + */ + public function actionEdit($id): void + { + $tag = Tag::find($id); + if (!$tag){ + throw new Exception(message: "The tag not found"); + } + $tagForm = new CreateTagForm(); + $tagService = new TagService(); + $tagForm->load($_REQUEST); + if ($tagForm->validate()) { + $tag = $tagService->update($tagForm, $tag); + if ($tag) { + $this->redirect("/admin/tag/" . $tag->id); + } + } + $this->redirect("/admin/tag/update/" . $id); + } + + #[NoReturn] public function actionDelete($id): void + { + $post = Tag::find($id)->first(); + $post->delete(); + $this->redirect("/admin/tag/"); + } + +} \ No newline at end of file diff --git a/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/migrations/2024_10_08_093710_create_tag_table.php b/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/migrations/2024_10_08_093710_create_tag_table.php new file mode 100644 index 0000000..37c4be5 --- /dev/null +++ b/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/migrations/2024_10_08_093710_create_tag_table.php @@ -0,0 +1,31 @@ +schema->create('tag', function (Blueprint $table) { + $table->increments('id'); + $table->string('label', 255)->nullable(false); + $table->string('entity', 255)->nullable(false); + $table->string('slug', 255)->unique(); + $table->integer('status')->default(1); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + \kernel\App::$db->schema->dropIfExists('tag'); + } +}; diff --git a/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/models/Tag.php b/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/models/Tag.php new file mode 100644 index 0000000..49e1bb4 --- /dev/null +++ b/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/models/Tag.php @@ -0,0 +1,46 @@ + 'Заголовок', + 'entity' => 'Сущность', + 'slug' => 'Slug', + 'status' => 'Статус', + ]; + } + + /** + * @return string[] + */ + public static function getStatus(): array + { + return [ + self::DISABLE_STATUS => "Не активный", + self::ACTIVE_STATUS => "Активный", + ]; + } + +} \ No newline at end of file diff --git a/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/models/forms/CreateTagForm.php b/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/models/forms/CreateTagForm.php new file mode 100644 index 0000000..82fd893 --- /dev/null +++ b/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/models/forms/CreateTagForm.php @@ -0,0 +1,20 @@ + 'required|min-str-len:5|max-str-len:30', + 'entity' => 'required|min-str-len:1|max-str-len:50', + 'slug' => '', + 'status' => '' + ]; + } + +} \ No newline at end of file diff --git a/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/routs/tag.php b/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/routs/tag.php new file mode 100644 index 0000000..6ec41fe --- /dev/null +++ b/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/routs/tag.php @@ -0,0 +1,18 @@ +group(["prefix" => "admin"], function (CgRouteCollector $router) { + App::$collector->group(["prefix" => "tag"], function (CGRouteCollector $router){ + App::$collector->get('/', [\app\modules\tag\controllers\TagController::class, 'actionIndex']); + App::$collector->get('/page/{page_number}', [\app\modules\tag\controllers\TagController::class, 'actionIndex']); + App::$collector->get('/create', [\app\modules\tag\controllers\TagController::class, 'actionCreate']); + App::$collector->post("/", [\app\modules\tag\controllers\TagController::class, 'actionAdd']); + App::$collector->get('/{id}', [\app\modules\tag\controllers\TagController::class, 'actionView']); + App::$collector->any('/update/{id}', [\app\modules\tag\controllers\TagController::class, 'actionUpdate']); + App::$collector->any("/edit/{id}", [\app\modules\tag\controllers\TagController::class, 'actionEdit']); + App::$collector->get('/delete/{id}', [\app\modules\tag\controllers\TagController::class, 'actionDelete']); + }); +}); \ No newline at end of file diff --git a/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/services/TagService.php b/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/services/TagService.php new file mode 100644 index 0000000..9407f0a --- /dev/null +++ b/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/services/TagService.php @@ -0,0 +1,42 @@ +label = $form_model->getItem('label'); + $model->entity = $form_model->getItem('entity'); + $model->status = $form_model->getItem('status'); + $model->slug = Slug::createSlug($form_model->getItem('label'), Tag::class); + if ($model->save()){ + return $model; + } + + return false; + } + + public function update(FormModel $form_model, Tag $tag): false|Tag + { + if ($tag->label !== $form_model->getItem('label')) { + $tag->slug = Slug::createSlug($form_model->getItem('label'), Tag::class); + } + $tag->label = $form_model->getItem('label'); + $tag->entity = $form_model->getItem('entity'); + $tag->status = $form_model->getItem('status'); + + if ($tag->save()){ + return $tag; + } + + return false; + } + +} \ No newline at end of file diff --git a/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/views/form.php b/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/views/form.php new file mode 100644 index 0000000..3a37b96 --- /dev/null +++ b/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/views/form.php @@ -0,0 +1,58 @@ +beginForm(isset($model) ? "/admin/tag/edit/" . $model->id : "/admin/tag"); + +$form->field(class: \itguild\forms\inputs\TextInput::class, name: "label", params: [ + 'class' => "form-control", + 'placeholder' => 'Заголовок', + 'value' => $model->label ?? '' +]) + ->setLabel("Заголовок") + ->render(); + +$form->field(class: \itguild\forms\inputs\TextInput::class, name: "entity", params: [ + 'class' => "form-control", + 'placeholder' => 'Сущность', + 'value' => $model->entity ?? '' +]) + ->setLabel("Сущность") + ->render(); + +$form->field(\itguild\forms\inputs\Select::class, 'status', [ + 'class' => "form-control", + 'value' => $model->status ?? '' +]) + ->setLabel("Статус") + ->setOptions(Tag::getStatus()) + ->render(); +?> +
+
+ field(\itguild\forms\inputs\Button::class, name: "btn-submit", params: [ + 'class' => "btn btn-primary ", + 'value' => 'Отправить', + 'typeInput' => 'submit' + ]) + ->render(); + ?> +
+
+ field(\itguild\forms\inputs\Button::class, name: "btn-reset", params: [ + 'class' => "btn btn-warning", + 'value' => 'Сбросить', + 'typeInput' => 'reset' + ]) + ->render(); + ?> +
+
+endForm(); diff --git a/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/views/index.php b/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/views/index.php new file mode 100644 index 0000000..0d5503f --- /dev/null +++ b/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/views/index.php @@ -0,0 +1,39 @@ + $page_number, + 'perPage' => 8, + 'params' => ["class" => "table table-bordered", "border" => "2"], + 'baseUrl' => "/admin/tag", +])); + +$table->beforePrint(function () { + return PrimaryBtn::create("Создать", "/admin/tag/create")->fetch(); + //return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch(); +}); + +$table->columns([ + "status" => [ + "value" => function ($cell) { + return Tag::getStatus()[$cell]; + }] +]); + +$table->addAction(\kernel\IGTabel\action_column\ViewActionColumn::class); +$table->addAction(\kernel\IGTabel\action_column\DeleteActionColumn::class); +$table->addAction(\kernel\IGTabel\action_column\EditActionColumn::class); +$table->create(); +$table->render(); \ No newline at end of file diff --git a/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/views/view.php b/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/views/view.php new file mode 100644 index 0000000..b09034f --- /dev/null +++ b/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/views/view.php @@ -0,0 +1,30 @@ + ["class" => "table table-bordered", "border" => "2"], + 'baseUrl' => "/admin/tag", +])); +$table->beforePrint(function () use ($tag) { + $btn = PrimaryBtn::create("Список", "/admin/tag")->fetch(); + $btn .= SuccessBtn::create("Редактировать", "/admin/tag/update/" . $tag->id)->fetch(); + $btn .= DangerBtn::create("Удалить", "/admin/tag/delete/" . $tag->id)->fetch(); + return $btn; +}); +$table->rows([ + 'status' => (function ($data) { + return \kernel\app_modules\tag\models\Tag::getStatus()[$data]; + }) +]); +$table->create(); +$table->render(); \ No newline at end of file diff --git a/resources/tmp/ad/fb7687573df162d45c5044239738988c/app/TagModule.php b/resources/tmp/ad/fb7687573df162d45c5044239738988c/app/TagModule.php new file mode 100644 index 0000000..b2f0ffd --- /dev/null +++ b/resources/tmp/ad/fb7687573df162d45c5044239738988c/app/TagModule.php @@ -0,0 +1,38 @@ +menuService = new MenuService(); + $this->migrationService = new MigrationService(); + } + + /** + * @throws \Exception + */ + public function init(): void + { + $this->migrationService->runAtPath("{KERNEL_APP_MODULES}/tag/migrations"); + + $this->menuService->createItem([ + "label" => "Тэги", + "url" => "/admin/tag", + "slug" => "tag", + ]); + } + + public function deactivate(): void + { + $this->menuService->removeItemBySlug("tag"); + } +} \ No newline at end of file diff --git a/resources/tmp/ad/fb7687573df162d45c5044239738988c/app/controllers/TagController.php b/resources/tmp/ad/fb7687573df162d45c5044239738988c/app/controllers/TagController.php new file mode 100644 index 0000000..4598872 --- /dev/null +++ b/resources/tmp/ad/fb7687573df162d45c5044239738988c/app/controllers/TagController.php @@ -0,0 +1,8 @@ +cgView->viewPath = KERNEL_APP_MODULES_DIR . "/tag/views/"; + $this->tagService = new TagService(); + } + + public function actionCreate(): void + { + $this->cgView->render("form.php"); + } + + #[NoReturn] public function actionAdd(): void + { + $tagForm = new CreateTagForm(); + $tagForm->load($_REQUEST); + if ($tagForm->validate()){ + $tag = $this->tagService->create($tagForm); + if ($tag){ + $this->redirect("/admin/tag/" . $tag->id); + } + } + $this->redirect("/admin/tag/create"); + } + + public function actionIndex($page_number = 1): void + { + $this->cgView->render("index.php", ['page_number' => $page_number]); + } + + /** + * @throws Exception + */ + public function actionView($id): void + { + $tag = Tag::find($id); + + if (!$tag){ + throw new Exception(message: "The tag not found"); + } + $this->cgView->render("view.php", ['tag' => $tag]); + } + + /** + * @throws Exception + */ + public function actionUpdate($id): void + { + $model = Tag::find($id); + if (!$model){ + throw new Exception(message: "The tag not found"); + } + + $this->cgView->render("form.php", ['model' => $model]); + } + + /** + * @throws Exception + */ + public function actionEdit($id): void + { + $tag = Tag::find($id); + if (!$tag){ + throw new Exception(message: "The tag not found"); + } + $tagForm = new CreateTagForm(); + $tagService = new TagService(); + $tagForm->load($_REQUEST); + if ($tagForm->validate()) { + $tag = $tagService->update($tagForm, $tag); + if ($tag) { + $this->redirect("/admin/tag/" . $tag->id); + } + } + $this->redirect("/admin/tag/update/" . $id); + } + + #[NoReturn] public function actionDelete($id): void + { + $post = Tag::find($id)->first(); + $post->delete(); + $this->redirect("/admin/tag/"); + } + +} \ No newline at end of file diff --git a/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/migrations/2024_10_08_093710_create_tag_table.php b/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/migrations/2024_10_08_093710_create_tag_table.php new file mode 100644 index 0000000..37c4be5 --- /dev/null +++ b/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/migrations/2024_10_08_093710_create_tag_table.php @@ -0,0 +1,31 @@ +schema->create('tag', function (Blueprint $table) { + $table->increments('id'); + $table->string('label', 255)->nullable(false); + $table->string('entity', 255)->nullable(false); + $table->string('slug', 255)->unique(); + $table->integer('status')->default(1); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + \kernel\App::$db->schema->dropIfExists('tag'); + } +}; diff --git a/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/models/Tag.php b/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/models/Tag.php new file mode 100644 index 0000000..49e1bb4 --- /dev/null +++ b/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/models/Tag.php @@ -0,0 +1,46 @@ + 'Заголовок', + 'entity' => 'Сущность', + 'slug' => 'Slug', + 'status' => 'Статус', + ]; + } + + /** + * @return string[] + */ + public static function getStatus(): array + { + return [ + self::DISABLE_STATUS => "Не активный", + self::ACTIVE_STATUS => "Активный", + ]; + } + +} \ No newline at end of file diff --git a/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/models/forms/CreateTagForm.php b/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/models/forms/CreateTagForm.php new file mode 100644 index 0000000..82fd893 --- /dev/null +++ b/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/models/forms/CreateTagForm.php @@ -0,0 +1,20 @@ + 'required|min-str-len:5|max-str-len:30', + 'entity' => 'required|min-str-len:1|max-str-len:50', + 'slug' => '', + 'status' => '' + ]; + } + +} \ No newline at end of file diff --git a/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/routs/tag.php b/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/routs/tag.php new file mode 100644 index 0000000..6ec41fe --- /dev/null +++ b/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/routs/tag.php @@ -0,0 +1,18 @@ +group(["prefix" => "admin"], function (CgRouteCollector $router) { + App::$collector->group(["prefix" => "tag"], function (CGRouteCollector $router){ + App::$collector->get('/', [\app\modules\tag\controllers\TagController::class, 'actionIndex']); + App::$collector->get('/page/{page_number}', [\app\modules\tag\controllers\TagController::class, 'actionIndex']); + App::$collector->get('/create', [\app\modules\tag\controllers\TagController::class, 'actionCreate']); + App::$collector->post("/", [\app\modules\tag\controllers\TagController::class, 'actionAdd']); + App::$collector->get('/{id}', [\app\modules\tag\controllers\TagController::class, 'actionView']); + App::$collector->any('/update/{id}', [\app\modules\tag\controllers\TagController::class, 'actionUpdate']); + App::$collector->any("/edit/{id}", [\app\modules\tag\controllers\TagController::class, 'actionEdit']); + App::$collector->get('/delete/{id}', [\app\modules\tag\controllers\TagController::class, 'actionDelete']); + }); +}); \ No newline at end of file diff --git a/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/services/TagService.php b/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/services/TagService.php new file mode 100644 index 0000000..9407f0a --- /dev/null +++ b/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/services/TagService.php @@ -0,0 +1,42 @@ +label = $form_model->getItem('label'); + $model->entity = $form_model->getItem('entity'); + $model->status = $form_model->getItem('status'); + $model->slug = Slug::createSlug($form_model->getItem('label'), Tag::class); + if ($model->save()){ + return $model; + } + + return false; + } + + public function update(FormModel $form_model, Tag $tag): false|Tag + { + if ($tag->label !== $form_model->getItem('label')) { + $tag->slug = Slug::createSlug($form_model->getItem('label'), Tag::class); + } + $tag->label = $form_model->getItem('label'); + $tag->entity = $form_model->getItem('entity'); + $tag->status = $form_model->getItem('status'); + + if ($tag->save()){ + return $tag; + } + + return false; + } + +} \ No newline at end of file diff --git a/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/views/form.php b/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/views/form.php new file mode 100644 index 0000000..3a37b96 --- /dev/null +++ b/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/views/form.php @@ -0,0 +1,58 @@ +beginForm(isset($model) ? "/admin/tag/edit/" . $model->id : "/admin/tag"); + +$form->field(class: \itguild\forms\inputs\TextInput::class, name: "label", params: [ + 'class' => "form-control", + 'placeholder' => 'Заголовок', + 'value' => $model->label ?? '' +]) + ->setLabel("Заголовок") + ->render(); + +$form->field(class: \itguild\forms\inputs\TextInput::class, name: "entity", params: [ + 'class' => "form-control", + 'placeholder' => 'Сущность', + 'value' => $model->entity ?? '' +]) + ->setLabel("Сущность") + ->render(); + +$form->field(\itguild\forms\inputs\Select::class, 'status', [ + 'class' => "form-control", + 'value' => $model->status ?? '' +]) + ->setLabel("Статус") + ->setOptions(Tag::getStatus()) + ->render(); +?> +
+
+ field(\itguild\forms\inputs\Button::class, name: "btn-submit", params: [ + 'class' => "btn btn-primary ", + 'value' => 'Отправить', + 'typeInput' => 'submit' + ]) + ->render(); + ?> +
+
+ field(\itguild\forms\inputs\Button::class, name: "btn-reset", params: [ + 'class' => "btn btn-warning", + 'value' => 'Сбросить', + 'typeInput' => 'reset' + ]) + ->render(); + ?> +
+
+endForm(); diff --git a/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/views/index.php b/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/views/index.php new file mode 100644 index 0000000..0d5503f --- /dev/null +++ b/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/views/index.php @@ -0,0 +1,39 @@ + $page_number, + 'perPage' => 8, + 'params' => ["class" => "table table-bordered", "border" => "2"], + 'baseUrl' => "/admin/tag", +])); + +$table->beforePrint(function () { + return PrimaryBtn::create("Создать", "/admin/tag/create")->fetch(); + //return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch(); +}); + +$table->columns([ + "status" => [ + "value" => function ($cell) { + return Tag::getStatus()[$cell]; + }] +]); + +$table->addAction(\kernel\IGTabel\action_column\ViewActionColumn::class); +$table->addAction(\kernel\IGTabel\action_column\DeleteActionColumn::class); +$table->addAction(\kernel\IGTabel\action_column\EditActionColumn::class); +$table->create(); +$table->render(); \ No newline at end of file diff --git a/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/views/view.php b/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/views/view.php new file mode 100644 index 0000000..b09034f --- /dev/null +++ b/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/views/view.php @@ -0,0 +1,30 @@ + ["class" => "table table-bordered", "border" => "2"], + 'baseUrl' => "/admin/tag", +])); +$table->beforePrint(function () use ($tag) { + $btn = PrimaryBtn::create("Список", "/admin/tag")->fetch(); + $btn .= SuccessBtn::create("Редактировать", "/admin/tag/update/" . $tag->id)->fetch(); + $btn .= DangerBtn::create("Удалить", "/admin/tag/delete/" . $tag->id)->fetch(); + return $btn; +}); +$table->rows([ + 'status' => (function ($data) { + return \kernel\app_modules\tag\models\Tag::getStatus()[$data]; + }) +]); +$table->create(); +$table->render(); \ No newline at end of file diff --git a/resources/tmp/modules/tag.itguild b/resources/tmp/modules/tag.itguild index aca28888bcc1397bd414ccf762abc3a5c8055539..0d175c2eb71db89e0f89be34f5de022a98729591 100644 GIT binary patch delta 458 zcmX?PxZIE@z?+#xgn@~HgMqzyBhOMsCidpdn;9LLK=fB;NiZ$I76zs>IDUfZWNr>H zoy#i@R^P_w2d1y_H!#+-H+x2^Utd3I2?GOz8Y2UP5RleSEGW>=P0Y(oOD!(Z%PP*# zOYPmrbyz{f^?OaL#q=eyyGylXxg?FalsbJ`gpV$dbo#em8xhUs;jEX0yA{Jdh_RKNp?}qMAgqLDYMZG!PXo>H?zXiaLX+ zM-WO~EC|G_76S_&5DNkE#KfIIRFt?6FG@&F-Yjkml6WC5!>BNsRYDQO(U6egI3NrO fzsZdp@{@DLctGNn5;Ba@lc!0ju^kfu1}_5u!%3g; delta 492 zcmZ2(c*u|^z?+#xgn@~HgCV7IBhOMsrj*Lfn;9LLK=fB;NiZ$I76zs>IDUfZWNr>H zoy#i@R^P_w2d1y_H!#+xRC-4Ka{80LpMilPmXU!$2uSNE78K~`Cgx?Pr52ayWfkY= zrS|!AHyOyZy|3f?C=+!(&rxXNv?+Jll3xU6?%HS{d*uDSy1bT$xz*q7-rqCiIGmwi z+xsmsWRjb!w1T`==yCRj+ZE3x40k;hy0Ft`X5Upl?KG)|Stfi}Lh3^|3E%o1AoXpJ zS Date: Thu, 10 Oct 2024 11:12:01 +0300 Subject: [PATCH 2/4] install, uninstall. pack to ModuleService --- .../app/TagModule.php | 38 ------- .../app/controllers/TagController.php | 8 -- .../app/manifest.json | 12 --- .../app/routs/tag.php | 2 - .../kernel/controllers/TagController.php | 101 ------------------ .../2024_10_08_093710_create_tag_table.php | 31 ------ .../kernel/models/Tag.php | 46 -------- .../kernel/models/forms/CreateTagForm.php | 20 ---- .../kernel/routs/tag.php | 18 ---- .../kernel/services/TagService.php | 42 -------- .../kernel/views/form.php | 58 ---------- .../kernel/views/index.php | 39 ------- .../kernel/views/view.php | 30 ------ .../app/TagModule.php | 38 ------- .../app/controllers/TagController.php | 8 -- .../app/manifest.json | 12 --- .../app/routs/tag.php | 2 - .../kernel/controllers/TagController.php | 101 ------------------ .../2024_10_08_093710_create_tag_table.php | 31 ------ .../kernel/models/Tag.php | 46 -------- .../kernel/models/forms/CreateTagForm.php | 20 ---- .../kernel/routs/tag.php | 18 ---- .../kernel/services/TagService.php | 42 -------- .../kernel/views/form.php | 58 ---------- .../kernel/views/index.php | 39 ------- .../kernel/views/view.php | 30 ------ .../app/TagModule.php | 38 ------- .../app/controllers/TagController.php | 8 -- .../app/manifest.json | 12 --- .../app/routs/tag.php | 2 - .../kernel/controllers/TagController.php | 101 ------------------ .../2024_10_08_093710_create_tag_table.php | 31 ------ .../kernel/models/Tag.php | 46 -------- .../kernel/models/forms/CreateTagForm.php | 20 ---- .../kernel/routs/tag.php | 18 ---- .../kernel/services/TagService.php | 42 -------- .../kernel/views/form.php | 58 ---------- .../kernel/views/index.php | 39 ------- .../kernel/views/view.php | 30 ------ .../app/TagModule.php | 38 ------- .../app/controllers/TagController.php | 8 -- .../app/manifest.json | 12 --- .../app/routs/tag.php | 2 - .../kernel/controllers/TagController.php | 101 ------------------ .../2024_10_08_093710_create_tag_table.php | 31 ------ .../kernel/models/Tag.php | 46 -------- .../kernel/models/forms/CreateTagForm.php | 20 ---- .../kernel/routs/tag.php | 18 ---- .../kernel/services/TagService.php | 42 -------- .../kernel/views/form.php | 58 ---------- .../kernel/views/index.php | 39 ------- .../kernel/views/view.php | 30 ------ .../app/TagModule.php | 38 ------- .../app/controllers/TagController.php | 8 -- .../app/manifest.json | 12 --- .../app/routs/tag.php | 2 - .../kernel/controllers/TagController.php | 101 ------------------ .../2024_10_08_093710_create_tag_table.php | 31 ------ .../kernel/models/Tag.php | 46 -------- .../kernel/models/forms/CreateTagForm.php | 20 ---- .../kernel/routs/tag.php | 18 ---- .../kernel/services/TagService.php | 42 -------- .../kernel/views/form.php | 58 ---------- .../kernel/views/index.php | 39 ------- .../kernel/views/view.php | 30 ------ 65 files changed, 2225 deletions(-) delete mode 100644 resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/app/TagModule.php delete mode 100644 resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/app/controllers/TagController.php delete mode 100644 resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/app/manifest.json delete mode 100644 resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/app/routs/tag.php delete mode 100644 resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/controllers/TagController.php delete mode 100644 resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/migrations/2024_10_08_093710_create_tag_table.php delete mode 100644 resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/models/Tag.php delete mode 100644 resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/models/forms/CreateTagForm.php delete mode 100644 resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/routs/tag.php delete mode 100644 resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/services/TagService.php delete mode 100644 resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/views/form.php delete mode 100644 resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/views/index.php delete mode 100644 resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/views/view.php delete mode 100644 resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/app/TagModule.php delete mode 100644 resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/app/controllers/TagController.php delete mode 100644 resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/app/manifest.json delete mode 100644 resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/app/routs/tag.php delete mode 100644 resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/controllers/TagController.php delete mode 100644 resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/migrations/2024_10_08_093710_create_tag_table.php delete mode 100644 resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/models/Tag.php delete mode 100644 resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/models/forms/CreateTagForm.php delete mode 100644 resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/routs/tag.php delete mode 100644 resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/services/TagService.php delete mode 100644 resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/views/form.php delete mode 100644 resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/views/index.php delete mode 100644 resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/views/view.php delete mode 100644 resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/app/TagModule.php delete mode 100644 resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/app/controllers/TagController.php delete mode 100644 resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/app/manifest.json delete mode 100644 resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/app/routs/tag.php delete mode 100644 resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/controllers/TagController.php delete mode 100644 resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/migrations/2024_10_08_093710_create_tag_table.php delete mode 100644 resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/models/Tag.php delete mode 100644 resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/models/forms/CreateTagForm.php delete mode 100644 resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/routs/tag.php delete mode 100644 resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/services/TagService.php delete mode 100644 resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/views/form.php delete mode 100644 resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/views/index.php delete mode 100644 resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/views/view.php delete mode 100644 resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/app/TagModule.php delete mode 100644 resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/app/controllers/TagController.php delete mode 100644 resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/app/manifest.json delete mode 100644 resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/app/routs/tag.php delete mode 100644 resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/controllers/TagController.php delete mode 100644 resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/migrations/2024_10_08_093710_create_tag_table.php delete mode 100644 resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/models/Tag.php delete mode 100644 resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/models/forms/CreateTagForm.php delete mode 100644 resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/routs/tag.php delete mode 100644 resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/services/TagService.php delete mode 100644 resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/views/form.php delete mode 100644 resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/views/index.php delete mode 100644 resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/views/view.php delete mode 100644 resources/tmp/ad/fb7687573df162d45c5044239738988c/app/TagModule.php delete mode 100644 resources/tmp/ad/fb7687573df162d45c5044239738988c/app/controllers/TagController.php delete mode 100644 resources/tmp/ad/fb7687573df162d45c5044239738988c/app/manifest.json delete mode 100644 resources/tmp/ad/fb7687573df162d45c5044239738988c/app/routs/tag.php delete mode 100644 resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/controllers/TagController.php delete mode 100644 resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/migrations/2024_10_08_093710_create_tag_table.php delete mode 100644 resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/models/Tag.php delete mode 100644 resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/models/forms/CreateTagForm.php delete mode 100644 resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/routs/tag.php delete mode 100644 resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/services/TagService.php delete mode 100644 resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/views/form.php delete mode 100644 resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/views/index.php delete mode 100644 resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/views/view.php diff --git a/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/app/TagModule.php b/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/app/TagModule.php deleted file mode 100644 index b2f0ffd..0000000 --- a/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/app/TagModule.php +++ /dev/null @@ -1,38 +0,0 @@ -menuService = new MenuService(); - $this->migrationService = new MigrationService(); - } - - /** - * @throws \Exception - */ - public function init(): void - { - $this->migrationService->runAtPath("{KERNEL_APP_MODULES}/tag/migrations"); - - $this->menuService->createItem([ - "label" => "Тэги", - "url" => "/admin/tag", - "slug" => "tag", - ]); - } - - public function deactivate(): void - { - $this->menuService->removeItemBySlug("tag"); - } -} \ No newline at end of file diff --git a/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/app/controllers/TagController.php b/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/app/controllers/TagController.php deleted file mode 100644 index 4598872..0000000 --- a/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/app/controllers/TagController.php +++ /dev/null @@ -1,8 +0,0 @@ -cgView->viewPath = KERNEL_APP_MODULES_DIR . "/tag/views/"; - $this->tagService = new TagService(); - } - - public function actionCreate(): void - { - $this->cgView->render("form.php"); - } - - #[NoReturn] public function actionAdd(): void - { - $tagForm = new CreateTagForm(); - $tagForm->load($_REQUEST); - if ($tagForm->validate()){ - $tag = $this->tagService->create($tagForm); - if ($tag){ - $this->redirect("/admin/tag/" . $tag->id); - } - } - $this->redirect("/admin/tag/create"); - } - - public function actionIndex($page_number = 1): void - { - $this->cgView->render("index.php", ['page_number' => $page_number]); - } - - /** - * @throws Exception - */ - public function actionView($id): void - { - $tag = Tag::find($id); - - if (!$tag){ - throw new Exception(message: "The tag not found"); - } - $this->cgView->render("view.php", ['tag' => $tag]); - } - - /** - * @throws Exception - */ - public function actionUpdate($id): void - { - $model = Tag::find($id); - if (!$model){ - throw new Exception(message: "The tag not found"); - } - - $this->cgView->render("form.php", ['model' => $model]); - } - - /** - * @throws Exception - */ - public function actionEdit($id): void - { - $tag = Tag::find($id); - if (!$tag){ - throw new Exception(message: "The tag not found"); - } - $tagForm = new CreateTagForm(); - $tagService = new TagService(); - $tagForm->load($_REQUEST); - if ($tagForm->validate()) { - $tag = $tagService->update($tagForm, $tag); - if ($tag) { - $this->redirect("/admin/tag/" . $tag->id); - } - } - $this->redirect("/admin/tag/update/" . $id); - } - - #[NoReturn] public function actionDelete($id): void - { - $post = Tag::find($id)->first(); - $post->delete(); - $this->redirect("/admin/tag/"); - } - -} \ No newline at end of file diff --git a/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/migrations/2024_10_08_093710_create_tag_table.php b/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/migrations/2024_10_08_093710_create_tag_table.php deleted file mode 100644 index 37c4be5..0000000 --- a/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/migrations/2024_10_08_093710_create_tag_table.php +++ /dev/null @@ -1,31 +0,0 @@ -schema->create('tag', function (Blueprint $table) { - $table->increments('id'); - $table->string('label', 255)->nullable(false); - $table->string('entity', 255)->nullable(false); - $table->string('slug', 255)->unique(); - $table->integer('status')->default(1); - $table->timestamps(); - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - \kernel\App::$db->schema->dropIfExists('tag'); - } -}; diff --git a/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/models/Tag.php b/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/models/Tag.php deleted file mode 100644 index 49e1bb4..0000000 --- a/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/models/Tag.php +++ /dev/null @@ -1,46 +0,0 @@ - 'Заголовок', - 'entity' => 'Сущность', - 'slug' => 'Slug', - 'status' => 'Статус', - ]; - } - - /** - * @return string[] - */ - public static function getStatus(): array - { - return [ - self::DISABLE_STATUS => "Не активный", - self::ACTIVE_STATUS => "Активный", - ]; - } - -} \ No newline at end of file diff --git a/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/models/forms/CreateTagForm.php b/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/models/forms/CreateTagForm.php deleted file mode 100644 index 82fd893..0000000 --- a/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/models/forms/CreateTagForm.php +++ /dev/null @@ -1,20 +0,0 @@ - 'required|min-str-len:5|max-str-len:30', - 'entity' => 'required|min-str-len:1|max-str-len:50', - 'slug' => '', - 'status' => '' - ]; - } - -} \ No newline at end of file diff --git a/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/routs/tag.php b/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/routs/tag.php deleted file mode 100644 index 6ec41fe..0000000 --- a/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/routs/tag.php +++ /dev/null @@ -1,18 +0,0 @@ -group(["prefix" => "admin"], function (CgRouteCollector $router) { - App::$collector->group(["prefix" => "tag"], function (CGRouteCollector $router){ - App::$collector->get('/', [\app\modules\tag\controllers\TagController::class, 'actionIndex']); - App::$collector->get('/page/{page_number}', [\app\modules\tag\controllers\TagController::class, 'actionIndex']); - App::$collector->get('/create', [\app\modules\tag\controllers\TagController::class, 'actionCreate']); - App::$collector->post("/", [\app\modules\tag\controllers\TagController::class, 'actionAdd']); - App::$collector->get('/{id}', [\app\modules\tag\controllers\TagController::class, 'actionView']); - App::$collector->any('/update/{id}', [\app\modules\tag\controllers\TagController::class, 'actionUpdate']); - App::$collector->any("/edit/{id}", [\app\modules\tag\controllers\TagController::class, 'actionEdit']); - App::$collector->get('/delete/{id}', [\app\modules\tag\controllers\TagController::class, 'actionDelete']); - }); -}); \ No newline at end of file diff --git a/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/services/TagService.php b/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/services/TagService.php deleted file mode 100644 index 9407f0a..0000000 --- a/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/services/TagService.php +++ /dev/null @@ -1,42 +0,0 @@ -label = $form_model->getItem('label'); - $model->entity = $form_model->getItem('entity'); - $model->status = $form_model->getItem('status'); - $model->slug = Slug::createSlug($form_model->getItem('label'), Tag::class); - if ($model->save()){ - return $model; - } - - return false; - } - - public function update(FormModel $form_model, Tag $tag): false|Tag - { - if ($tag->label !== $form_model->getItem('label')) { - $tag->slug = Slug::createSlug($form_model->getItem('label'), Tag::class); - } - $tag->label = $form_model->getItem('label'); - $tag->entity = $form_model->getItem('entity'); - $tag->status = $form_model->getItem('status'); - - if ($tag->save()){ - return $tag; - } - - return false; - } - -} \ No newline at end of file diff --git a/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/views/form.php b/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/views/form.php deleted file mode 100644 index 3a37b96..0000000 --- a/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/views/form.php +++ /dev/null @@ -1,58 +0,0 @@ -beginForm(isset($model) ? "/admin/tag/edit/" . $model->id : "/admin/tag"); - -$form->field(class: \itguild\forms\inputs\TextInput::class, name: "label", params: [ - 'class' => "form-control", - 'placeholder' => 'Заголовок', - 'value' => $model->label ?? '' -]) - ->setLabel("Заголовок") - ->render(); - -$form->field(class: \itguild\forms\inputs\TextInput::class, name: "entity", params: [ - 'class' => "form-control", - 'placeholder' => 'Сущность', - 'value' => $model->entity ?? '' -]) - ->setLabel("Сущность") - ->render(); - -$form->field(\itguild\forms\inputs\Select::class, 'status', [ - 'class' => "form-control", - 'value' => $model->status ?? '' -]) - ->setLabel("Статус") - ->setOptions(Tag::getStatus()) - ->render(); -?> -
-
- field(\itguild\forms\inputs\Button::class, name: "btn-submit", params: [ - 'class' => "btn btn-primary ", - 'value' => 'Отправить', - 'typeInput' => 'submit' - ]) - ->render(); - ?> -
-
- field(\itguild\forms\inputs\Button::class, name: "btn-reset", params: [ - 'class' => "btn btn-warning", - 'value' => 'Сбросить', - 'typeInput' => 'reset' - ]) - ->render(); - ?> -
-
-endForm(); diff --git a/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/views/index.php b/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/views/index.php deleted file mode 100644 index 0d5503f..0000000 --- a/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/views/index.php +++ /dev/null @@ -1,39 +0,0 @@ - $page_number, - 'perPage' => 8, - 'params' => ["class" => "table table-bordered", "border" => "2"], - 'baseUrl' => "/admin/tag", -])); - -$table->beforePrint(function () { - return PrimaryBtn::create("Создать", "/admin/tag/create")->fetch(); - //return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch(); -}); - -$table->columns([ - "status" => [ - "value" => function ($cell) { - return Tag::getStatus()[$cell]; - }] -]); - -$table->addAction(\kernel\IGTabel\action_column\ViewActionColumn::class); -$table->addAction(\kernel\IGTabel\action_column\DeleteActionColumn::class); -$table->addAction(\kernel\IGTabel\action_column\EditActionColumn::class); -$table->create(); -$table->render(); \ No newline at end of file diff --git a/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/views/view.php b/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/views/view.php deleted file mode 100644 index b09034f..0000000 --- a/resources/tmp/ad/288812b9d3be03880a18cfc8baa6b9cc/kernel/views/view.php +++ /dev/null @@ -1,30 +0,0 @@ - ["class" => "table table-bordered", "border" => "2"], - 'baseUrl' => "/admin/tag", -])); -$table->beforePrint(function () use ($tag) { - $btn = PrimaryBtn::create("Список", "/admin/tag")->fetch(); - $btn .= SuccessBtn::create("Редактировать", "/admin/tag/update/" . $tag->id)->fetch(); - $btn .= DangerBtn::create("Удалить", "/admin/tag/delete/" . $tag->id)->fetch(); - return $btn; -}); -$table->rows([ - 'status' => (function ($data) { - return \kernel\app_modules\tag\models\Tag::getStatus()[$data]; - }) -]); -$table->create(); -$table->render(); \ No newline at end of file diff --git a/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/app/TagModule.php b/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/app/TagModule.php deleted file mode 100644 index b2f0ffd..0000000 --- a/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/app/TagModule.php +++ /dev/null @@ -1,38 +0,0 @@ -menuService = new MenuService(); - $this->migrationService = new MigrationService(); - } - - /** - * @throws \Exception - */ - public function init(): void - { - $this->migrationService->runAtPath("{KERNEL_APP_MODULES}/tag/migrations"); - - $this->menuService->createItem([ - "label" => "Тэги", - "url" => "/admin/tag", - "slug" => "tag", - ]); - } - - public function deactivate(): void - { - $this->menuService->removeItemBySlug("tag"); - } -} \ No newline at end of file diff --git a/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/app/controllers/TagController.php b/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/app/controllers/TagController.php deleted file mode 100644 index 4598872..0000000 --- a/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/app/controllers/TagController.php +++ /dev/null @@ -1,8 +0,0 @@ -cgView->viewPath = KERNEL_APP_MODULES_DIR . "/tag/views/"; - $this->tagService = new TagService(); - } - - public function actionCreate(): void - { - $this->cgView->render("form.php"); - } - - #[NoReturn] public function actionAdd(): void - { - $tagForm = new CreateTagForm(); - $tagForm->load($_REQUEST); - if ($tagForm->validate()){ - $tag = $this->tagService->create($tagForm); - if ($tag){ - $this->redirect("/admin/tag/" . $tag->id); - } - } - $this->redirect("/admin/tag/create"); - } - - public function actionIndex($page_number = 1): void - { - $this->cgView->render("index.php", ['page_number' => $page_number]); - } - - /** - * @throws Exception - */ - public function actionView($id): void - { - $tag = Tag::find($id); - - if (!$tag){ - throw new Exception(message: "The tag not found"); - } - $this->cgView->render("view.php", ['tag' => $tag]); - } - - /** - * @throws Exception - */ - public function actionUpdate($id): void - { - $model = Tag::find($id); - if (!$model){ - throw new Exception(message: "The tag not found"); - } - - $this->cgView->render("form.php", ['model' => $model]); - } - - /** - * @throws Exception - */ - public function actionEdit($id): void - { - $tag = Tag::find($id); - if (!$tag){ - throw new Exception(message: "The tag not found"); - } - $tagForm = new CreateTagForm(); - $tagService = new TagService(); - $tagForm->load($_REQUEST); - if ($tagForm->validate()) { - $tag = $tagService->update($tagForm, $tag); - if ($tag) { - $this->redirect("/admin/tag/" . $tag->id); - } - } - $this->redirect("/admin/tag/update/" . $id); - } - - #[NoReturn] public function actionDelete($id): void - { - $post = Tag::find($id)->first(); - $post->delete(); - $this->redirect("/admin/tag/"); - } - -} \ No newline at end of file diff --git a/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/migrations/2024_10_08_093710_create_tag_table.php b/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/migrations/2024_10_08_093710_create_tag_table.php deleted file mode 100644 index 37c4be5..0000000 --- a/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/migrations/2024_10_08_093710_create_tag_table.php +++ /dev/null @@ -1,31 +0,0 @@ -schema->create('tag', function (Blueprint $table) { - $table->increments('id'); - $table->string('label', 255)->nullable(false); - $table->string('entity', 255)->nullable(false); - $table->string('slug', 255)->unique(); - $table->integer('status')->default(1); - $table->timestamps(); - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - \kernel\App::$db->schema->dropIfExists('tag'); - } -}; diff --git a/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/models/Tag.php b/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/models/Tag.php deleted file mode 100644 index 49e1bb4..0000000 --- a/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/models/Tag.php +++ /dev/null @@ -1,46 +0,0 @@ - 'Заголовок', - 'entity' => 'Сущность', - 'slug' => 'Slug', - 'status' => 'Статус', - ]; - } - - /** - * @return string[] - */ - public static function getStatus(): array - { - return [ - self::DISABLE_STATUS => "Не активный", - self::ACTIVE_STATUS => "Активный", - ]; - } - -} \ No newline at end of file diff --git a/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/models/forms/CreateTagForm.php b/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/models/forms/CreateTagForm.php deleted file mode 100644 index 82fd893..0000000 --- a/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/models/forms/CreateTagForm.php +++ /dev/null @@ -1,20 +0,0 @@ - 'required|min-str-len:5|max-str-len:30', - 'entity' => 'required|min-str-len:1|max-str-len:50', - 'slug' => '', - 'status' => '' - ]; - } - -} \ No newline at end of file diff --git a/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/routs/tag.php b/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/routs/tag.php deleted file mode 100644 index 6ec41fe..0000000 --- a/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/routs/tag.php +++ /dev/null @@ -1,18 +0,0 @@ -group(["prefix" => "admin"], function (CgRouteCollector $router) { - App::$collector->group(["prefix" => "tag"], function (CGRouteCollector $router){ - App::$collector->get('/', [\app\modules\tag\controllers\TagController::class, 'actionIndex']); - App::$collector->get('/page/{page_number}', [\app\modules\tag\controllers\TagController::class, 'actionIndex']); - App::$collector->get('/create', [\app\modules\tag\controllers\TagController::class, 'actionCreate']); - App::$collector->post("/", [\app\modules\tag\controllers\TagController::class, 'actionAdd']); - App::$collector->get('/{id}', [\app\modules\tag\controllers\TagController::class, 'actionView']); - App::$collector->any('/update/{id}', [\app\modules\tag\controllers\TagController::class, 'actionUpdate']); - App::$collector->any("/edit/{id}", [\app\modules\tag\controllers\TagController::class, 'actionEdit']); - App::$collector->get('/delete/{id}', [\app\modules\tag\controllers\TagController::class, 'actionDelete']); - }); -}); \ No newline at end of file diff --git a/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/services/TagService.php b/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/services/TagService.php deleted file mode 100644 index 9407f0a..0000000 --- a/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/services/TagService.php +++ /dev/null @@ -1,42 +0,0 @@ -label = $form_model->getItem('label'); - $model->entity = $form_model->getItem('entity'); - $model->status = $form_model->getItem('status'); - $model->slug = Slug::createSlug($form_model->getItem('label'), Tag::class); - if ($model->save()){ - return $model; - } - - return false; - } - - public function update(FormModel $form_model, Tag $tag): false|Tag - { - if ($tag->label !== $form_model->getItem('label')) { - $tag->slug = Slug::createSlug($form_model->getItem('label'), Tag::class); - } - $tag->label = $form_model->getItem('label'); - $tag->entity = $form_model->getItem('entity'); - $tag->status = $form_model->getItem('status'); - - if ($tag->save()){ - return $tag; - } - - return false; - } - -} \ No newline at end of file diff --git a/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/views/form.php b/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/views/form.php deleted file mode 100644 index 3a37b96..0000000 --- a/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/views/form.php +++ /dev/null @@ -1,58 +0,0 @@ -beginForm(isset($model) ? "/admin/tag/edit/" . $model->id : "/admin/tag"); - -$form->field(class: \itguild\forms\inputs\TextInput::class, name: "label", params: [ - 'class' => "form-control", - 'placeholder' => 'Заголовок', - 'value' => $model->label ?? '' -]) - ->setLabel("Заголовок") - ->render(); - -$form->field(class: \itguild\forms\inputs\TextInput::class, name: "entity", params: [ - 'class' => "form-control", - 'placeholder' => 'Сущность', - 'value' => $model->entity ?? '' -]) - ->setLabel("Сущность") - ->render(); - -$form->field(\itguild\forms\inputs\Select::class, 'status', [ - 'class' => "form-control", - 'value' => $model->status ?? '' -]) - ->setLabel("Статус") - ->setOptions(Tag::getStatus()) - ->render(); -?> -
-
- field(\itguild\forms\inputs\Button::class, name: "btn-submit", params: [ - 'class' => "btn btn-primary ", - 'value' => 'Отправить', - 'typeInput' => 'submit' - ]) - ->render(); - ?> -
-
- field(\itguild\forms\inputs\Button::class, name: "btn-reset", params: [ - 'class' => "btn btn-warning", - 'value' => 'Сбросить', - 'typeInput' => 'reset' - ]) - ->render(); - ?> -
-
-endForm(); diff --git a/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/views/index.php b/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/views/index.php deleted file mode 100644 index 0d5503f..0000000 --- a/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/views/index.php +++ /dev/null @@ -1,39 +0,0 @@ - $page_number, - 'perPage' => 8, - 'params' => ["class" => "table table-bordered", "border" => "2"], - 'baseUrl' => "/admin/tag", -])); - -$table->beforePrint(function () { - return PrimaryBtn::create("Создать", "/admin/tag/create")->fetch(); - //return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch(); -}); - -$table->columns([ - "status" => [ - "value" => function ($cell) { - return Tag::getStatus()[$cell]; - }] -]); - -$table->addAction(\kernel\IGTabel\action_column\ViewActionColumn::class); -$table->addAction(\kernel\IGTabel\action_column\DeleteActionColumn::class); -$table->addAction(\kernel\IGTabel\action_column\EditActionColumn::class); -$table->create(); -$table->render(); \ No newline at end of file diff --git a/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/views/view.php b/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/views/view.php deleted file mode 100644 index b09034f..0000000 --- a/resources/tmp/ad/6061f1739a4083115f9124a9eefbc9e4/kernel/views/view.php +++ /dev/null @@ -1,30 +0,0 @@ - ["class" => "table table-bordered", "border" => "2"], - 'baseUrl' => "/admin/tag", -])); -$table->beforePrint(function () use ($tag) { - $btn = PrimaryBtn::create("Список", "/admin/tag")->fetch(); - $btn .= SuccessBtn::create("Редактировать", "/admin/tag/update/" . $tag->id)->fetch(); - $btn .= DangerBtn::create("Удалить", "/admin/tag/delete/" . $tag->id)->fetch(); - return $btn; -}); -$table->rows([ - 'status' => (function ($data) { - return \kernel\app_modules\tag\models\Tag::getStatus()[$data]; - }) -]); -$table->create(); -$table->render(); \ No newline at end of file diff --git a/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/app/TagModule.php b/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/app/TagModule.php deleted file mode 100644 index b2f0ffd..0000000 --- a/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/app/TagModule.php +++ /dev/null @@ -1,38 +0,0 @@ -menuService = new MenuService(); - $this->migrationService = new MigrationService(); - } - - /** - * @throws \Exception - */ - public function init(): void - { - $this->migrationService->runAtPath("{KERNEL_APP_MODULES}/tag/migrations"); - - $this->menuService->createItem([ - "label" => "Тэги", - "url" => "/admin/tag", - "slug" => "tag", - ]); - } - - public function deactivate(): void - { - $this->menuService->removeItemBySlug("tag"); - } -} \ No newline at end of file diff --git a/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/app/controllers/TagController.php b/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/app/controllers/TagController.php deleted file mode 100644 index 4598872..0000000 --- a/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/app/controllers/TagController.php +++ /dev/null @@ -1,8 +0,0 @@ -cgView->viewPath = KERNEL_APP_MODULES_DIR . "/tag/views/"; - $this->tagService = new TagService(); - } - - public function actionCreate(): void - { - $this->cgView->render("form.php"); - } - - #[NoReturn] public function actionAdd(): void - { - $tagForm = new CreateTagForm(); - $tagForm->load($_REQUEST); - if ($tagForm->validate()){ - $tag = $this->tagService->create($tagForm); - if ($tag){ - $this->redirect("/admin/tag/" . $tag->id); - } - } - $this->redirect("/admin/tag/create"); - } - - public function actionIndex($page_number = 1): void - { - $this->cgView->render("index.php", ['page_number' => $page_number]); - } - - /** - * @throws Exception - */ - public function actionView($id): void - { - $tag = Tag::find($id); - - if (!$tag){ - throw new Exception(message: "The tag not found"); - } - $this->cgView->render("view.php", ['tag' => $tag]); - } - - /** - * @throws Exception - */ - public function actionUpdate($id): void - { - $model = Tag::find($id); - if (!$model){ - throw new Exception(message: "The tag not found"); - } - - $this->cgView->render("form.php", ['model' => $model]); - } - - /** - * @throws Exception - */ - public function actionEdit($id): void - { - $tag = Tag::find($id); - if (!$tag){ - throw new Exception(message: "The tag not found"); - } - $tagForm = new CreateTagForm(); - $tagService = new TagService(); - $tagForm->load($_REQUEST); - if ($tagForm->validate()) { - $tag = $tagService->update($tagForm, $tag); - if ($tag) { - $this->redirect("/admin/tag/" . $tag->id); - } - } - $this->redirect("/admin/tag/update/" . $id); - } - - #[NoReturn] public function actionDelete($id): void - { - $post = Tag::find($id)->first(); - $post->delete(); - $this->redirect("/admin/tag/"); - } - -} \ No newline at end of file diff --git a/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/migrations/2024_10_08_093710_create_tag_table.php b/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/migrations/2024_10_08_093710_create_tag_table.php deleted file mode 100644 index 37c4be5..0000000 --- a/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/migrations/2024_10_08_093710_create_tag_table.php +++ /dev/null @@ -1,31 +0,0 @@ -schema->create('tag', function (Blueprint $table) { - $table->increments('id'); - $table->string('label', 255)->nullable(false); - $table->string('entity', 255)->nullable(false); - $table->string('slug', 255)->unique(); - $table->integer('status')->default(1); - $table->timestamps(); - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - \kernel\App::$db->schema->dropIfExists('tag'); - } -}; diff --git a/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/models/Tag.php b/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/models/Tag.php deleted file mode 100644 index 49e1bb4..0000000 --- a/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/models/Tag.php +++ /dev/null @@ -1,46 +0,0 @@ - 'Заголовок', - 'entity' => 'Сущность', - 'slug' => 'Slug', - 'status' => 'Статус', - ]; - } - - /** - * @return string[] - */ - public static function getStatus(): array - { - return [ - self::DISABLE_STATUS => "Не активный", - self::ACTIVE_STATUS => "Активный", - ]; - } - -} \ No newline at end of file diff --git a/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/models/forms/CreateTagForm.php b/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/models/forms/CreateTagForm.php deleted file mode 100644 index 82fd893..0000000 --- a/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/models/forms/CreateTagForm.php +++ /dev/null @@ -1,20 +0,0 @@ - 'required|min-str-len:5|max-str-len:30', - 'entity' => 'required|min-str-len:1|max-str-len:50', - 'slug' => '', - 'status' => '' - ]; - } - -} \ No newline at end of file diff --git a/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/routs/tag.php b/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/routs/tag.php deleted file mode 100644 index 6ec41fe..0000000 --- a/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/routs/tag.php +++ /dev/null @@ -1,18 +0,0 @@ -group(["prefix" => "admin"], function (CgRouteCollector $router) { - App::$collector->group(["prefix" => "tag"], function (CGRouteCollector $router){ - App::$collector->get('/', [\app\modules\tag\controllers\TagController::class, 'actionIndex']); - App::$collector->get('/page/{page_number}', [\app\modules\tag\controllers\TagController::class, 'actionIndex']); - App::$collector->get('/create', [\app\modules\tag\controllers\TagController::class, 'actionCreate']); - App::$collector->post("/", [\app\modules\tag\controllers\TagController::class, 'actionAdd']); - App::$collector->get('/{id}', [\app\modules\tag\controllers\TagController::class, 'actionView']); - App::$collector->any('/update/{id}', [\app\modules\tag\controllers\TagController::class, 'actionUpdate']); - App::$collector->any("/edit/{id}", [\app\modules\tag\controllers\TagController::class, 'actionEdit']); - App::$collector->get('/delete/{id}', [\app\modules\tag\controllers\TagController::class, 'actionDelete']); - }); -}); \ No newline at end of file diff --git a/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/services/TagService.php b/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/services/TagService.php deleted file mode 100644 index 9407f0a..0000000 --- a/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/services/TagService.php +++ /dev/null @@ -1,42 +0,0 @@ -label = $form_model->getItem('label'); - $model->entity = $form_model->getItem('entity'); - $model->status = $form_model->getItem('status'); - $model->slug = Slug::createSlug($form_model->getItem('label'), Tag::class); - if ($model->save()){ - return $model; - } - - return false; - } - - public function update(FormModel $form_model, Tag $tag): false|Tag - { - if ($tag->label !== $form_model->getItem('label')) { - $tag->slug = Slug::createSlug($form_model->getItem('label'), Tag::class); - } - $tag->label = $form_model->getItem('label'); - $tag->entity = $form_model->getItem('entity'); - $tag->status = $form_model->getItem('status'); - - if ($tag->save()){ - return $tag; - } - - return false; - } - -} \ No newline at end of file diff --git a/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/views/form.php b/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/views/form.php deleted file mode 100644 index 3a37b96..0000000 --- a/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/views/form.php +++ /dev/null @@ -1,58 +0,0 @@ -beginForm(isset($model) ? "/admin/tag/edit/" . $model->id : "/admin/tag"); - -$form->field(class: \itguild\forms\inputs\TextInput::class, name: "label", params: [ - 'class' => "form-control", - 'placeholder' => 'Заголовок', - 'value' => $model->label ?? '' -]) - ->setLabel("Заголовок") - ->render(); - -$form->field(class: \itguild\forms\inputs\TextInput::class, name: "entity", params: [ - 'class' => "form-control", - 'placeholder' => 'Сущность', - 'value' => $model->entity ?? '' -]) - ->setLabel("Сущность") - ->render(); - -$form->field(\itguild\forms\inputs\Select::class, 'status', [ - 'class' => "form-control", - 'value' => $model->status ?? '' -]) - ->setLabel("Статус") - ->setOptions(Tag::getStatus()) - ->render(); -?> -
-
- field(\itguild\forms\inputs\Button::class, name: "btn-submit", params: [ - 'class' => "btn btn-primary ", - 'value' => 'Отправить', - 'typeInput' => 'submit' - ]) - ->render(); - ?> -
-
- field(\itguild\forms\inputs\Button::class, name: "btn-reset", params: [ - 'class' => "btn btn-warning", - 'value' => 'Сбросить', - 'typeInput' => 'reset' - ]) - ->render(); - ?> -
-
-endForm(); diff --git a/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/views/index.php b/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/views/index.php deleted file mode 100644 index 0d5503f..0000000 --- a/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/views/index.php +++ /dev/null @@ -1,39 +0,0 @@ - $page_number, - 'perPage' => 8, - 'params' => ["class" => "table table-bordered", "border" => "2"], - 'baseUrl' => "/admin/tag", -])); - -$table->beforePrint(function () { - return PrimaryBtn::create("Создать", "/admin/tag/create")->fetch(); - //return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch(); -}); - -$table->columns([ - "status" => [ - "value" => function ($cell) { - return Tag::getStatus()[$cell]; - }] -]); - -$table->addAction(\kernel\IGTabel\action_column\ViewActionColumn::class); -$table->addAction(\kernel\IGTabel\action_column\DeleteActionColumn::class); -$table->addAction(\kernel\IGTabel\action_column\EditActionColumn::class); -$table->create(); -$table->render(); \ No newline at end of file diff --git a/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/views/view.php b/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/views/view.php deleted file mode 100644 index b09034f..0000000 --- a/resources/tmp/ad/7289057c248ba8f15a95ff2a8ffdb261/kernel/views/view.php +++ /dev/null @@ -1,30 +0,0 @@ - ["class" => "table table-bordered", "border" => "2"], - 'baseUrl' => "/admin/tag", -])); -$table->beforePrint(function () use ($tag) { - $btn = PrimaryBtn::create("Список", "/admin/tag")->fetch(); - $btn .= SuccessBtn::create("Редактировать", "/admin/tag/update/" . $tag->id)->fetch(); - $btn .= DangerBtn::create("Удалить", "/admin/tag/delete/" . $tag->id)->fetch(); - return $btn; -}); -$table->rows([ - 'status' => (function ($data) { - return \kernel\app_modules\tag\models\Tag::getStatus()[$data]; - }) -]); -$table->create(); -$table->render(); \ No newline at end of file diff --git a/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/app/TagModule.php b/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/app/TagModule.php deleted file mode 100644 index b2f0ffd..0000000 --- a/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/app/TagModule.php +++ /dev/null @@ -1,38 +0,0 @@ -menuService = new MenuService(); - $this->migrationService = new MigrationService(); - } - - /** - * @throws \Exception - */ - public function init(): void - { - $this->migrationService->runAtPath("{KERNEL_APP_MODULES}/tag/migrations"); - - $this->menuService->createItem([ - "label" => "Тэги", - "url" => "/admin/tag", - "slug" => "tag", - ]); - } - - public function deactivate(): void - { - $this->menuService->removeItemBySlug("tag"); - } -} \ No newline at end of file diff --git a/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/app/controllers/TagController.php b/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/app/controllers/TagController.php deleted file mode 100644 index 4598872..0000000 --- a/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/app/controllers/TagController.php +++ /dev/null @@ -1,8 +0,0 @@ -cgView->viewPath = KERNEL_APP_MODULES_DIR . "/tag/views/"; - $this->tagService = new TagService(); - } - - public function actionCreate(): void - { - $this->cgView->render("form.php"); - } - - #[NoReturn] public function actionAdd(): void - { - $tagForm = new CreateTagForm(); - $tagForm->load($_REQUEST); - if ($tagForm->validate()){ - $tag = $this->tagService->create($tagForm); - if ($tag){ - $this->redirect("/admin/tag/" . $tag->id); - } - } - $this->redirect("/admin/tag/create"); - } - - public function actionIndex($page_number = 1): void - { - $this->cgView->render("index.php", ['page_number' => $page_number]); - } - - /** - * @throws Exception - */ - public function actionView($id): void - { - $tag = Tag::find($id); - - if (!$tag){ - throw new Exception(message: "The tag not found"); - } - $this->cgView->render("view.php", ['tag' => $tag]); - } - - /** - * @throws Exception - */ - public function actionUpdate($id): void - { - $model = Tag::find($id); - if (!$model){ - throw new Exception(message: "The tag not found"); - } - - $this->cgView->render("form.php", ['model' => $model]); - } - - /** - * @throws Exception - */ - public function actionEdit($id): void - { - $tag = Tag::find($id); - if (!$tag){ - throw new Exception(message: "The tag not found"); - } - $tagForm = new CreateTagForm(); - $tagService = new TagService(); - $tagForm->load($_REQUEST); - if ($tagForm->validate()) { - $tag = $tagService->update($tagForm, $tag); - if ($tag) { - $this->redirect("/admin/tag/" . $tag->id); - } - } - $this->redirect("/admin/tag/update/" . $id); - } - - #[NoReturn] public function actionDelete($id): void - { - $post = Tag::find($id)->first(); - $post->delete(); - $this->redirect("/admin/tag/"); - } - -} \ No newline at end of file diff --git a/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/migrations/2024_10_08_093710_create_tag_table.php b/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/migrations/2024_10_08_093710_create_tag_table.php deleted file mode 100644 index 37c4be5..0000000 --- a/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/migrations/2024_10_08_093710_create_tag_table.php +++ /dev/null @@ -1,31 +0,0 @@ -schema->create('tag', function (Blueprint $table) { - $table->increments('id'); - $table->string('label', 255)->nullable(false); - $table->string('entity', 255)->nullable(false); - $table->string('slug', 255)->unique(); - $table->integer('status')->default(1); - $table->timestamps(); - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - \kernel\App::$db->schema->dropIfExists('tag'); - } -}; diff --git a/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/models/Tag.php b/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/models/Tag.php deleted file mode 100644 index 49e1bb4..0000000 --- a/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/models/Tag.php +++ /dev/null @@ -1,46 +0,0 @@ - 'Заголовок', - 'entity' => 'Сущность', - 'slug' => 'Slug', - 'status' => 'Статус', - ]; - } - - /** - * @return string[] - */ - public static function getStatus(): array - { - return [ - self::DISABLE_STATUS => "Не активный", - self::ACTIVE_STATUS => "Активный", - ]; - } - -} \ No newline at end of file diff --git a/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/models/forms/CreateTagForm.php b/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/models/forms/CreateTagForm.php deleted file mode 100644 index 82fd893..0000000 --- a/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/models/forms/CreateTagForm.php +++ /dev/null @@ -1,20 +0,0 @@ - 'required|min-str-len:5|max-str-len:30', - 'entity' => 'required|min-str-len:1|max-str-len:50', - 'slug' => '', - 'status' => '' - ]; - } - -} \ No newline at end of file diff --git a/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/routs/tag.php b/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/routs/tag.php deleted file mode 100644 index 6ec41fe..0000000 --- a/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/routs/tag.php +++ /dev/null @@ -1,18 +0,0 @@ -group(["prefix" => "admin"], function (CgRouteCollector $router) { - App::$collector->group(["prefix" => "tag"], function (CGRouteCollector $router){ - App::$collector->get('/', [\app\modules\tag\controllers\TagController::class, 'actionIndex']); - App::$collector->get('/page/{page_number}', [\app\modules\tag\controllers\TagController::class, 'actionIndex']); - App::$collector->get('/create', [\app\modules\tag\controllers\TagController::class, 'actionCreate']); - App::$collector->post("/", [\app\modules\tag\controllers\TagController::class, 'actionAdd']); - App::$collector->get('/{id}', [\app\modules\tag\controllers\TagController::class, 'actionView']); - App::$collector->any('/update/{id}', [\app\modules\tag\controllers\TagController::class, 'actionUpdate']); - App::$collector->any("/edit/{id}", [\app\modules\tag\controllers\TagController::class, 'actionEdit']); - App::$collector->get('/delete/{id}', [\app\modules\tag\controllers\TagController::class, 'actionDelete']); - }); -}); \ No newline at end of file diff --git a/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/services/TagService.php b/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/services/TagService.php deleted file mode 100644 index 9407f0a..0000000 --- a/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/services/TagService.php +++ /dev/null @@ -1,42 +0,0 @@ -label = $form_model->getItem('label'); - $model->entity = $form_model->getItem('entity'); - $model->status = $form_model->getItem('status'); - $model->slug = Slug::createSlug($form_model->getItem('label'), Tag::class); - if ($model->save()){ - return $model; - } - - return false; - } - - public function update(FormModel $form_model, Tag $tag): false|Tag - { - if ($tag->label !== $form_model->getItem('label')) { - $tag->slug = Slug::createSlug($form_model->getItem('label'), Tag::class); - } - $tag->label = $form_model->getItem('label'); - $tag->entity = $form_model->getItem('entity'); - $tag->status = $form_model->getItem('status'); - - if ($tag->save()){ - return $tag; - } - - return false; - } - -} \ No newline at end of file diff --git a/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/views/form.php b/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/views/form.php deleted file mode 100644 index 3a37b96..0000000 --- a/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/views/form.php +++ /dev/null @@ -1,58 +0,0 @@ -beginForm(isset($model) ? "/admin/tag/edit/" . $model->id : "/admin/tag"); - -$form->field(class: \itguild\forms\inputs\TextInput::class, name: "label", params: [ - 'class' => "form-control", - 'placeholder' => 'Заголовок', - 'value' => $model->label ?? '' -]) - ->setLabel("Заголовок") - ->render(); - -$form->field(class: \itguild\forms\inputs\TextInput::class, name: "entity", params: [ - 'class' => "form-control", - 'placeholder' => 'Сущность', - 'value' => $model->entity ?? '' -]) - ->setLabel("Сущность") - ->render(); - -$form->field(\itguild\forms\inputs\Select::class, 'status', [ - 'class' => "form-control", - 'value' => $model->status ?? '' -]) - ->setLabel("Статус") - ->setOptions(Tag::getStatus()) - ->render(); -?> -
-
- field(\itguild\forms\inputs\Button::class, name: "btn-submit", params: [ - 'class' => "btn btn-primary ", - 'value' => 'Отправить', - 'typeInput' => 'submit' - ]) - ->render(); - ?> -
-
- field(\itguild\forms\inputs\Button::class, name: "btn-reset", params: [ - 'class' => "btn btn-warning", - 'value' => 'Сбросить', - 'typeInput' => 'reset' - ]) - ->render(); - ?> -
-
-endForm(); diff --git a/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/views/index.php b/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/views/index.php deleted file mode 100644 index 0d5503f..0000000 --- a/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/views/index.php +++ /dev/null @@ -1,39 +0,0 @@ - $page_number, - 'perPage' => 8, - 'params' => ["class" => "table table-bordered", "border" => "2"], - 'baseUrl' => "/admin/tag", -])); - -$table->beforePrint(function () { - return PrimaryBtn::create("Создать", "/admin/tag/create")->fetch(); - //return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch(); -}); - -$table->columns([ - "status" => [ - "value" => function ($cell) { - return Tag::getStatus()[$cell]; - }] -]); - -$table->addAction(\kernel\IGTabel\action_column\ViewActionColumn::class); -$table->addAction(\kernel\IGTabel\action_column\DeleteActionColumn::class); -$table->addAction(\kernel\IGTabel\action_column\EditActionColumn::class); -$table->create(); -$table->render(); \ No newline at end of file diff --git a/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/views/view.php b/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/views/view.php deleted file mode 100644 index b09034f..0000000 --- a/resources/tmp/ad/cb177f1a6276ef6231a7e09311a283d0/kernel/views/view.php +++ /dev/null @@ -1,30 +0,0 @@ - ["class" => "table table-bordered", "border" => "2"], - 'baseUrl' => "/admin/tag", -])); -$table->beforePrint(function () use ($tag) { - $btn = PrimaryBtn::create("Список", "/admin/tag")->fetch(); - $btn .= SuccessBtn::create("Редактировать", "/admin/tag/update/" . $tag->id)->fetch(); - $btn .= DangerBtn::create("Удалить", "/admin/tag/delete/" . $tag->id)->fetch(); - return $btn; -}); -$table->rows([ - 'status' => (function ($data) { - return \kernel\app_modules\tag\models\Tag::getStatus()[$data]; - }) -]); -$table->create(); -$table->render(); \ No newline at end of file diff --git a/resources/tmp/ad/fb7687573df162d45c5044239738988c/app/TagModule.php b/resources/tmp/ad/fb7687573df162d45c5044239738988c/app/TagModule.php deleted file mode 100644 index b2f0ffd..0000000 --- a/resources/tmp/ad/fb7687573df162d45c5044239738988c/app/TagModule.php +++ /dev/null @@ -1,38 +0,0 @@ -menuService = new MenuService(); - $this->migrationService = new MigrationService(); - } - - /** - * @throws \Exception - */ - public function init(): void - { - $this->migrationService->runAtPath("{KERNEL_APP_MODULES}/tag/migrations"); - - $this->menuService->createItem([ - "label" => "Тэги", - "url" => "/admin/tag", - "slug" => "tag", - ]); - } - - public function deactivate(): void - { - $this->menuService->removeItemBySlug("tag"); - } -} \ No newline at end of file diff --git a/resources/tmp/ad/fb7687573df162d45c5044239738988c/app/controllers/TagController.php b/resources/tmp/ad/fb7687573df162d45c5044239738988c/app/controllers/TagController.php deleted file mode 100644 index 4598872..0000000 --- a/resources/tmp/ad/fb7687573df162d45c5044239738988c/app/controllers/TagController.php +++ /dev/null @@ -1,8 +0,0 @@ -cgView->viewPath = KERNEL_APP_MODULES_DIR . "/tag/views/"; - $this->tagService = new TagService(); - } - - public function actionCreate(): void - { - $this->cgView->render("form.php"); - } - - #[NoReturn] public function actionAdd(): void - { - $tagForm = new CreateTagForm(); - $tagForm->load($_REQUEST); - if ($tagForm->validate()){ - $tag = $this->tagService->create($tagForm); - if ($tag){ - $this->redirect("/admin/tag/" . $tag->id); - } - } - $this->redirect("/admin/tag/create"); - } - - public function actionIndex($page_number = 1): void - { - $this->cgView->render("index.php", ['page_number' => $page_number]); - } - - /** - * @throws Exception - */ - public function actionView($id): void - { - $tag = Tag::find($id); - - if (!$tag){ - throw new Exception(message: "The tag not found"); - } - $this->cgView->render("view.php", ['tag' => $tag]); - } - - /** - * @throws Exception - */ - public function actionUpdate($id): void - { - $model = Tag::find($id); - if (!$model){ - throw new Exception(message: "The tag not found"); - } - - $this->cgView->render("form.php", ['model' => $model]); - } - - /** - * @throws Exception - */ - public function actionEdit($id): void - { - $tag = Tag::find($id); - if (!$tag){ - throw new Exception(message: "The tag not found"); - } - $tagForm = new CreateTagForm(); - $tagService = new TagService(); - $tagForm->load($_REQUEST); - if ($tagForm->validate()) { - $tag = $tagService->update($tagForm, $tag); - if ($tag) { - $this->redirect("/admin/tag/" . $tag->id); - } - } - $this->redirect("/admin/tag/update/" . $id); - } - - #[NoReturn] public function actionDelete($id): void - { - $post = Tag::find($id)->first(); - $post->delete(); - $this->redirect("/admin/tag/"); - } - -} \ No newline at end of file diff --git a/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/migrations/2024_10_08_093710_create_tag_table.php b/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/migrations/2024_10_08_093710_create_tag_table.php deleted file mode 100644 index 37c4be5..0000000 --- a/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/migrations/2024_10_08_093710_create_tag_table.php +++ /dev/null @@ -1,31 +0,0 @@ -schema->create('tag', function (Blueprint $table) { - $table->increments('id'); - $table->string('label', 255)->nullable(false); - $table->string('entity', 255)->nullable(false); - $table->string('slug', 255)->unique(); - $table->integer('status')->default(1); - $table->timestamps(); - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - \kernel\App::$db->schema->dropIfExists('tag'); - } -}; diff --git a/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/models/Tag.php b/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/models/Tag.php deleted file mode 100644 index 49e1bb4..0000000 --- a/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/models/Tag.php +++ /dev/null @@ -1,46 +0,0 @@ - 'Заголовок', - 'entity' => 'Сущность', - 'slug' => 'Slug', - 'status' => 'Статус', - ]; - } - - /** - * @return string[] - */ - public static function getStatus(): array - { - return [ - self::DISABLE_STATUS => "Не активный", - self::ACTIVE_STATUS => "Активный", - ]; - } - -} \ No newline at end of file diff --git a/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/models/forms/CreateTagForm.php b/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/models/forms/CreateTagForm.php deleted file mode 100644 index 82fd893..0000000 --- a/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/models/forms/CreateTagForm.php +++ /dev/null @@ -1,20 +0,0 @@ - 'required|min-str-len:5|max-str-len:30', - 'entity' => 'required|min-str-len:1|max-str-len:50', - 'slug' => '', - 'status' => '' - ]; - } - -} \ No newline at end of file diff --git a/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/routs/tag.php b/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/routs/tag.php deleted file mode 100644 index 6ec41fe..0000000 --- a/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/routs/tag.php +++ /dev/null @@ -1,18 +0,0 @@ -group(["prefix" => "admin"], function (CgRouteCollector $router) { - App::$collector->group(["prefix" => "tag"], function (CGRouteCollector $router){ - App::$collector->get('/', [\app\modules\tag\controllers\TagController::class, 'actionIndex']); - App::$collector->get('/page/{page_number}', [\app\modules\tag\controllers\TagController::class, 'actionIndex']); - App::$collector->get('/create', [\app\modules\tag\controllers\TagController::class, 'actionCreate']); - App::$collector->post("/", [\app\modules\tag\controllers\TagController::class, 'actionAdd']); - App::$collector->get('/{id}', [\app\modules\tag\controllers\TagController::class, 'actionView']); - App::$collector->any('/update/{id}', [\app\modules\tag\controllers\TagController::class, 'actionUpdate']); - App::$collector->any("/edit/{id}", [\app\modules\tag\controllers\TagController::class, 'actionEdit']); - App::$collector->get('/delete/{id}', [\app\modules\tag\controllers\TagController::class, 'actionDelete']); - }); -}); \ No newline at end of file diff --git a/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/services/TagService.php b/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/services/TagService.php deleted file mode 100644 index 9407f0a..0000000 --- a/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/services/TagService.php +++ /dev/null @@ -1,42 +0,0 @@ -label = $form_model->getItem('label'); - $model->entity = $form_model->getItem('entity'); - $model->status = $form_model->getItem('status'); - $model->slug = Slug::createSlug($form_model->getItem('label'), Tag::class); - if ($model->save()){ - return $model; - } - - return false; - } - - public function update(FormModel $form_model, Tag $tag): false|Tag - { - if ($tag->label !== $form_model->getItem('label')) { - $tag->slug = Slug::createSlug($form_model->getItem('label'), Tag::class); - } - $tag->label = $form_model->getItem('label'); - $tag->entity = $form_model->getItem('entity'); - $tag->status = $form_model->getItem('status'); - - if ($tag->save()){ - return $tag; - } - - return false; - } - -} \ No newline at end of file diff --git a/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/views/form.php b/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/views/form.php deleted file mode 100644 index 3a37b96..0000000 --- a/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/views/form.php +++ /dev/null @@ -1,58 +0,0 @@ -beginForm(isset($model) ? "/admin/tag/edit/" . $model->id : "/admin/tag"); - -$form->field(class: \itguild\forms\inputs\TextInput::class, name: "label", params: [ - 'class' => "form-control", - 'placeholder' => 'Заголовок', - 'value' => $model->label ?? '' -]) - ->setLabel("Заголовок") - ->render(); - -$form->field(class: \itguild\forms\inputs\TextInput::class, name: "entity", params: [ - 'class' => "form-control", - 'placeholder' => 'Сущность', - 'value' => $model->entity ?? '' -]) - ->setLabel("Сущность") - ->render(); - -$form->field(\itguild\forms\inputs\Select::class, 'status', [ - 'class' => "form-control", - 'value' => $model->status ?? '' -]) - ->setLabel("Статус") - ->setOptions(Tag::getStatus()) - ->render(); -?> -
-
- field(\itguild\forms\inputs\Button::class, name: "btn-submit", params: [ - 'class' => "btn btn-primary ", - 'value' => 'Отправить', - 'typeInput' => 'submit' - ]) - ->render(); - ?> -
-
- field(\itguild\forms\inputs\Button::class, name: "btn-reset", params: [ - 'class' => "btn btn-warning", - 'value' => 'Сбросить', - 'typeInput' => 'reset' - ]) - ->render(); - ?> -
-
-endForm(); diff --git a/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/views/index.php b/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/views/index.php deleted file mode 100644 index 0d5503f..0000000 --- a/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/views/index.php +++ /dev/null @@ -1,39 +0,0 @@ - $page_number, - 'perPage' => 8, - 'params' => ["class" => "table table-bordered", "border" => "2"], - 'baseUrl' => "/admin/tag", -])); - -$table->beforePrint(function () { - return PrimaryBtn::create("Создать", "/admin/tag/create")->fetch(); - //return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch(); -}); - -$table->columns([ - "status" => [ - "value" => function ($cell) { - return Tag::getStatus()[$cell]; - }] -]); - -$table->addAction(\kernel\IGTabel\action_column\ViewActionColumn::class); -$table->addAction(\kernel\IGTabel\action_column\DeleteActionColumn::class); -$table->addAction(\kernel\IGTabel\action_column\EditActionColumn::class); -$table->create(); -$table->render(); \ No newline at end of file diff --git a/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/views/view.php b/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/views/view.php deleted file mode 100644 index b09034f..0000000 --- a/resources/tmp/ad/fb7687573df162d45c5044239738988c/kernel/views/view.php +++ /dev/null @@ -1,30 +0,0 @@ - ["class" => "table table-bordered", "border" => "2"], - 'baseUrl' => "/admin/tag", -])); -$table->beforePrint(function () use ($tag) { - $btn = PrimaryBtn::create("Список", "/admin/tag")->fetch(); - $btn .= SuccessBtn::create("Редактировать", "/admin/tag/update/" . $tag->id)->fetch(); - $btn .= DangerBtn::create("Удалить", "/admin/tag/delete/" . $tag->id)->fetch(); - return $btn; -}); -$table->rows([ - 'status' => (function ($data) { - return \kernel\app_modules\tag\models\Tag::getStatus()[$data]; - }) -]); -$table->create(); -$table->render(); \ No newline at end of file From e29108f21dd97e0909e3935acf9dea34e4965f1b Mon Sep 17 00:00:00 2001 From: stasbilay02 Date: Thu, 10 Oct 2024 11:19:51 +0300 Subject: [PATCH 3/4] action update module add --- .../console/controllers/ModuleController.php | 14 ++++++ kernel/console/routs/cli.php | 1 + kernel/services/ModuleService.php | 47 ++++++++++++++++++ resources/tmp/modules/tag.itguild | Bin 6311 -> 6372 bytes 4 files changed, 62 insertions(+) diff --git a/kernel/console/controllers/ModuleController.php b/kernel/console/controllers/ModuleController.php index c586f76..539b687 100644 --- a/kernel/console/controllers/ModuleController.php +++ b/kernel/console/controllers/ModuleController.php @@ -64,4 +64,18 @@ class ModuleController extends ConsoleController } } + /** + * @throws \Exception + */ + public function actionUpdateModule(): void + { + if (!isset($this->argv['path'])) { + throw new \Exception('Missing module path "--path" specified'); + } + if (file_exists(ROOT_DIR . $this->argv['path'])) { + $moduleService = new ModuleService(); + $moduleService->updateModule($this->argv['path']); + } + } + } \ No newline at end of file diff --git a/kernel/console/routs/cli.php b/kernel/console/routs/cli.php index ba24d43..537a724 100644 --- a/kernel/console/routs/cli.php +++ b/kernel/console/routs/cli.php @@ -25,5 +25,6 @@ App::$collector->group(["prefix" => "module"], callback: function (RouteCollecto App::$collector->console('install', [\kernel\console\controllers\ModuleController::class, 'actionInstallModule']); App::$collector->console('uninstall', [\kernel\console\controllers\ModuleController::class, 'actionUninstallModule']); App::$collector->console('pack', [\kernel\console\controllers\ModuleController::class, 'actionPackModule']); + App::$collector->console('update', [\kernel\console\controllers\ModuleController::class, 'actionUpdateModule']); }); diff --git a/kernel/services/ModuleService.php b/kernel/services/ModuleService.php index f639cff..8d9d228 100644 --- a/kernel/services/ModuleService.php +++ b/kernel/services/ModuleService.php @@ -172,6 +172,9 @@ class ModuleService // $out->out->r('Архив распакован', 'green'); // } else { // $this->out->r('Message: Ошибка чтения архива', 'red'); + } else { + $zip->close(); + throw new \Exception("unable to open zip archive"); } if (!file_exists($tmpModuleDirFull . "/app/manifest.json")) { @@ -192,6 +195,7 @@ class ModuleService // $this->out->r("Удаляем временные файлы", 'green'); $fileHelper->recursiveRemoveDir($tmpModuleDirFull); + var_dump($tmpModuleDirFull); // $this->out->r("Модуль " . $manifest['name'] . " установлен", 'green'); } @@ -229,7 +233,50 @@ class ModuleService // $this->out->r("Архив создан", 'green'); $fileHelper->recursiveRemoveDir($tmpModuleDirFull); + // $this->out->r("Временная папка удалена", 'green'); } + /** + * @throws \Exception + */ + public function updateModule(string $path): void + { + $zip = new ZipArchive; + $tmpModuleDir = md5(time()); + $res = $zip->open(ROOT_DIR . $path); + if ($res === TRUE) { + $tmpModuleDirFull = RESOURCES_DIR . '/tmp/ad/' . $tmpModuleDir . "/"; + $zip->extractTo($tmpModuleDirFull); + $zip->close(); +// $out->out->r('Архив распакован', 'green'); +// } else { +// $this->out->r('Message: Ошибка чтения архива', 'red'); + } else { + $zip->close(); + throw new \Exception("unable to open zip archive"); + } + + if (!file_exists($tmpModuleDirFull . "/app/manifest.json")) { + throw new \Exception('manifest.json not found'); + } + + $manifestJson = getConst(file_get_contents($tmpModuleDirFull . "/app/manifest.json")); + $manifest = Manifest::getWithVars($manifestJson); +// $this->out->r('manifest.json инициализирован', 'green'); + + $fileHelper = new Files(); + if (isset($manifest['kernel_module_path'])) { + $fileHelper->copy_folder($tmpModuleDirFull . '/kernel', $manifest['kernel_module_path']); + } else { + $fileHelper->copy_folder($tmpModuleDirFull . '/kernel', KERNEL_APP_MODULES_DIR . '/' . $manifest['slug']); + } + +// $this->out->r("Удаляем временные файлы", 'green'); + $fileHelper->recursiveRemoveDir($tmpModuleDirFull); + +// $this->out->r("Модуль " . $manifest['name'] . " установлен", 'green'); + + } + } \ No newline at end of file diff --git a/resources/tmp/modules/tag.itguild b/resources/tmp/modules/tag.itguild index 0d175c2eb71db89e0f89be34f5de022a98729591..9d0dc578cb2f39c4fb9b0eff0aad20c1502f6cda 100644 GIT binary patch delta 1115 zcmZ2(_{5Mmz?+#xgn@~HgJDIa*GAqYjLblK^A<*XCNSe0vjl`8$QH^Z1eA)jJLKZ= zg^7W|gNuPdjbXBum`454u-N>|1|qfR*BdMpy17N~(bm+~jbfP_dN1Ye(FvYvnuV(bin>hh8&H8ifCUK_sH)}t+1t zc|(4Y4Xcl<{$cpTak_L?f!y?&YC6swk2rgaJ0@%PKK!{(fMw?AAkG+1jui^VLK5=4 zP5V1G3yOJs%JFa&GrBw@ph>-PQeC}F#mXNotUgiFrbb+np%Q18UC?WHxRxaqH2>cE z6O6)F+sZ%AJD9rF@KE;csmz<4?`^SiU)y{yZ}(m6n%g#(8Ku={|MJ~bTh_bshGx)> zXEMR_)QVUNB3CSwxW3KvllIS&hvZrq=o;@bkR2X|}bAR|z^62Vj)q`c4u~MGV zM%sH*E^m7ED{kwQ%PI#y!c&^>tgiyq=pY|4Tafz3}k5HC|8R z9P~TdpI6kCow!_`Yv!$aB`<&CWp&nN>M6?|yRM`^?Rj(7_v~KJxD$;0`mXohZest| zb>*_o8m_LbSM(#etd@kmPVVB0H1|@g*pe_iMCnx0$h=wo}$sdDviRt9)1W<7N9FjujVroH}jx6*g4kEU!5T+tqq{&wBOQ;Qd6H(vRW zsG1e{=IZya=j=C~`&FAacl*KnUz|5BQ51_xoKvYAy>IC}z3h%B`%7KsE=!v;Y3<*z ztR{YK{tyu^%k&vpi_h=Ss25stAgeiR-_QKkqef3&_SG{(G7md6_iRq#W`|^!JYF$K zK5FOlg)px3*Mk|8BLy#lGnTH^Dwwtvbq3STqE2A?gs2lQ zO8%QHF6IuFNfeW2oHDsqOickKZ?fXA_GJbJhAKt|1`Qw$16vyB@lLMg)tdZPj0ddk z4^Z3o$r9qKV4j1xG!whP3$i4?jIj7EA9_e!&ysrmV2vfy={bR_f!(Q=eEuR=hOn z30jysOGP2{d|?r*N=1*tWgAi3;$Na)(mi(uJXAR6W;J#52QAt9rgKk)HmKO88ta|A zmb0~b_UuPeLZW^Xd|K0mRCdOX>V5lNFP5RqIyYSw z*DHT+UNZ~XxKPYHNx^nI$5F$y>ud8rd@Gx}Yj@jOKgsMnC)=_kU33dd|G(L~t$zNJ zDV1wK8vG~}?pdcTV5bJ?8@iAo0oi8Zf}^|as#oSZ{+T`2!HzLdiEJ> z>&tI~J8Q!etK9u+f|l-Et^G@&V;pYG)J&OGQpBl!EV1#y?>?p^Md*njh`RLZpV*?|WNUhOln{;y&6`~1%5 z&wkxM=X}Y)LqL16L3~>7&mR+a-Zl|9SwFiYY*}i|=Pe=4aX^@XK|iseU~(ge{N#Qy9 Date: Thu, 10 Oct 2024 16:45:53 +0300 Subject: [PATCH 4/4] dependences --- bootstrap.php | 1 + kernel/controllers/ModuleController.php | 6 ++--- kernel/modules/post/manifest.json | 3 ++- kernel/services/ModuleService.php | 29 +++++++++++++++++-------- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/bootstrap.php b/bootstrap.php index afca5a1..da9207e 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -33,6 +33,7 @@ function getConst($text): array|false|string ]; $str = $text; + foreach($constStr as $key => $value) { $str = str_replace($key, $value, $str); diff --git a/kernel/controllers/ModuleController.php b/kernel/controllers/ModuleController.php index cbae844..458671e 100644 --- a/kernel/controllers/ModuleController.php +++ b/kernel/controllers/ModuleController.php @@ -24,10 +24,10 @@ class ModuleController extends AdminController public function actionIndex(): void { - $admin_theme_paths = Option::where("key", "module_paths")->first(); + $module_paths = Option::where("key", "module_paths")->first(); $dirs = []; - if ($admin_theme_paths){ - $path = json_decode($admin_theme_paths->value); + if ($module_paths){ + $path = json_decode($module_paths->value); foreach ($path->paths as $p){ $dirs[] = getConst($p); } diff --git a/kernel/modules/post/manifest.json b/kernel/modules/post/manifest.json index fb2c610..51e2b4a 100644 --- a/kernel/modules/post/manifest.json +++ b/kernel/modules/post/manifest.json @@ -7,5 +7,6 @@ "module_class": "kernel\\modules\\post\\PostModule", "module_class_file": "{KERNEL_MODULES}/post/PostModule.php", "routs": "routs/post.php", - "migration_path": "migrations" + "migration_path": "migrations", + "dependence": "user" } \ No newline at end of file diff --git a/kernel/services/ModuleService.php b/kernel/services/ModuleService.php index 8d9d228..24b602c 100644 --- a/kernel/services/ModuleService.php +++ b/kernel/services/ModuleService.php @@ -3,7 +3,6 @@ namespace kernel\services; use DirectoryIterator; -use kernel\console\Out; use kernel\helpers\Debug; use kernel\helpers\Files; use kernel\helpers\Manifest; @@ -47,20 +46,32 @@ class ModuleService return false; } + /** + * @throws \Exception + */ public function toggleModule(string $module): void { - $active_modules = Option::where("key", "active_modules")->first(); - $path = json_decode($active_modules->value); - if (in_array($module, $path->modules)) { - unset($path->modules[array_search($module, $path->modules)]); - $path->modules = array_values($path->modules); + $active_modules_info = Option::where("key", "active_modules")->first(); + $active_modules = json_decode($active_modules_info->value); + if (in_array($module, $active_modules->modules)) { + unset($active_modules->modules[array_search($module, $active_modules->modules)]); + $active_modules->modules = array_values($active_modules->modules); $this->runDeactivateScript($this->getModuleInfoBySlug($module)); } else { - $path->modules[] = $module; + $module_info = $this->getModuleInfoBySlug($module); + if (isset($module_info['dependence'])) { + $dependence_array = explode(';', $module_info['dependence']); + foreach ($dependence_array as $depend) { + if (!in_array($depend, $active_modules->modules)) { + throw new \Exception("first activate the $depend module"); + } + } + } + $active_modules->modules[] = $module; $this->runInitScript($this->getModuleInfoBySlug($module)); } - $active_modules->value = json_encode($path, JSON_UNESCAPED_UNICODE); - $active_modules->save(); + $active_modules_info->value = json_encode($active_modules, JSON_UNESCAPED_UNICODE); + $active_modules_info->save(); } public function getModuleDir(string $slug)