diff --git a/kernel/IGTabel/action_column/DeleteActionColumn.php b/kernel/IGTabel/action_column/DeleteActionColumn.php
new file mode 100644
index 0000000..740d36a
--- /dev/null
+++ b/kernel/IGTabel/action_column/DeleteActionColumn.php
@@ -0,0 +1,15 @@
+baseUrl . $this->prefix . $this->id;
+ return " Удалить ";
+ }
+}
\ No newline at end of file
diff --git a/kernel/IGTabel/action_column/EditActionColumn.php b/kernel/IGTabel/action_column/EditActionColumn.php
new file mode 100644
index 0000000..6747a53
--- /dev/null
+++ b/kernel/IGTabel/action_column/EditActionColumn.php
@@ -0,0 +1,16 @@
+baseUrl . $this->prefix . $this->id;
+ return " Редактировать ";
+ }
+}
\ No newline at end of file
diff --git a/kernel/app_modules/tag/controllers/TagController.php b/kernel/app_modules/tag/controllers/TagController.php
index 6a72046..2a72451 100644
--- a/kernel/app_modules/tag/controllers/TagController.php
+++ b/kernel/app_modules/tag/controllers/TagController.php
@@ -2,15 +2,41 @@
namespace kernel\app_modules\tag\controllers;
+use Exception;
+use JetBrains\PhpStorm\NoReturn;
use kernel\AdminController;
+use kernel\app_modules\tag\models\forms\CreateTagForm;
+use kernel\app_modules\tag\models\Tag;
+use kernel\app_modules\tag\services\TagService;
+use kernel\helpers\Debug;
use kernel\modules\menu\service\MenuService;
class TagController extends AdminController
{
+ private TagService $tagService;
protected function init(): void
{
parent::init();
- $this->cgView->viewPath = KERNEL_APP_MODULES_DIR . "/tag/views/";;
+ $this->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
@@ -18,4 +44,58 @@ class TagController extends AdminController
$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/kernel/app_modules/tag/models/Tag.php b/kernel/app_modules/tag/models/Tag.php
index fb408c9..49e1bb4 100644
--- a/kernel/app_modules/tag/models/Tag.php
+++ b/kernel/app_modules/tag/models/Tag.php
@@ -4,6 +4,15 @@ namespace kernel\app_modules\tag\models;
use Illuminate\Database\Eloquent\Model;
+/**
+ * @property int $id
+ * @property string $label
+ * @property string $entity
+ * @property string $slug
+ * @property int $status
+ * @method static where(int[] $array)
+ * @method static find($id)
+ */
class Tag extends Model
{
const DISABLE_STATUS = 0;
diff --git a/kernel/app_modules/tag/models/forms/CreateTagForm.php b/kernel/app_modules/tag/models/forms/CreateTagForm.php
new file mode 100644
index 0000000..82fd893
--- /dev/null
+++ b/kernel/app_modules/tag/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/kernel/app_modules/tag/routs/tag.php b/kernel/app_modules/tag/routs/tag.php
index edabefa..6ec41fe 100644
--- a/kernel/app_modules/tag/routs/tag.php
+++ b/kernel/app_modules/tag/routs/tag.php
@@ -7,12 +7,12 @@ use Phroute\Phroute\RouteCollector;
App::$collector->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}', [\kernel\modules\menu\controllers\MenuController::class, 'actionIndex']);
-// App::$collector->get('/create', [\kernel\modules\menu\controllers\MenuController::class, 'actionCreate']);
-// App::$collector->post("/", [\kernel\modules\menu\controllers\MenuController::class, 'actionAdd']);
-// App::$collector->get('/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionView']);
-// App::$collector->any('/update/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionUpdate']);
-// App::$collector->any("/edit/{id}", [\kernel\modules\menu\controllers\MenuController::class, 'actionEdit']);
-// App::$collector->get('/delete/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionDelete']);
+ 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/kernel/app_modules/tag/services/TagService.php b/kernel/app_modules/tag/services/TagService.php
new file mode 100644
index 0000000..9407f0a
--- /dev/null
+++ b/kernel/app_modules/tag/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/kernel/app_modules/tag/views/form.php b/kernel/app_modules/tag/views/form.php
new file mode 100644
index 0000000..3a37b96
--- /dev/null
+++ b/kernel/app_modules/tag/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/kernel/app_modules/tag/views/index.php b/kernel/app_modules/tag/views/index.php
index c423207..0d5503f 100644
--- a/kernel/app_modules/tag/views/index.php
+++ b/kernel/app_modules/tag/views/index.php
@@ -24,8 +24,16 @@ $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(MenuEditActionColumn::class);
-//$table->addAction(MenuDeleteActionColumn::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/kernel/app_modules/tag/views/view.php b/kernel/app_modules/tag/views/view.php
new file mode 100644
index 0000000..b09034f
--- /dev/null
+++ b/kernel/app_modules/tag/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/kernel/console/controllers/AdminThemeController.php b/kernel/console/controllers/AdminThemeController.php
index 585bc30..2fc1739 100644
--- a/kernel/console/controllers/AdminThemeController.php
+++ b/kernel/console/controllers/AdminThemeController.php
@@ -55,8 +55,6 @@ class AdminThemeController extends ConsoleController
if (file_exists(ROOT_DIR . $this->argv['path'])) {
$themeName = basename($this->argv['path']);
$active_admin_theme = Option::where("key", "active_admin_theme")->first();
- var_dump($active_admin_theme->value);
- var_dump(ROOT_DIR . $this->argv['path']);
if ($active_admin_theme->value === ROOT_DIR . $this->argv['path']) {
$this->out->r("Меняем тему на базовую", 'green');
$adminThemeService = new AdminThemeService();
diff --git a/kernel/console/controllers/ModuleController.php b/kernel/console/controllers/ModuleController.php
index 4201f5f..d9e3aac 100644
--- a/kernel/console/controllers/ModuleController.php
+++ b/kernel/console/controllers/ModuleController.php
@@ -3,6 +3,7 @@
namespace kernel\console\controllers;
use kernel\console\ConsoleController;
+use kernel\helpers\Debug;
use kernel\helpers\Files;
use kernel\helpers\Manifest;
use kernel\models\Option;
@@ -75,4 +76,34 @@ class ModuleController extends ConsoleController
}
}
+ public function actionPackModule(): void
+ {
+ if (!isset($this->argv['path'])) {
+ throw new \Exception('Missing module path "--path" specified');
+ }
+
+ 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($zip, RESOURCES_DIR . '/tmp/modules/' . $moduleName . '.zip');
+ $fileHelper->pack($tmpModuleDirFull, RESOURCES_DIR . '/tmp/modules/' . $moduleName . '.zip');
+
+// $zip->addEmptyDir($moduleName);
+// $zip->close();
+// $this->out->r("zip закрыт", 'green');
+
+ $this->out->r("Архив создан", 'green');
+
+ }
+ }
+
}
\ No newline at end of file
diff --git a/kernel/console/routs/cli.php b/kernel/console/routs/cli.php
index 5976755..ba24d43 100644
--- a/kernel/console/routs/cli.php
+++ b/kernel/console/routs/cli.php
@@ -24,5 +24,6 @@ App::$collector->group(["prefix" => "admin"], callback: function (RouteCollector
App::$collector->group(["prefix" => "module"], callback: function (RouteCollector $router){
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']);
});
diff --git a/kernel/helpers/Files.php b/kernel/helpers/Files.php
index 7294d71..f70ef16 100644
--- a/kernel/helpers/Files.php
+++ b/kernel/helpers/Files.php
@@ -3,6 +3,7 @@
namespace kernel\helpers;
use FilesystemIterator;
+use ZipArchive;
class Files
{
@@ -41,4 +42,44 @@ class Files
}
rmdir($dir);
}
+
+ public function pack(string $source, string $destination, bool $include_source = true): void
+ {
+ $zip = new ZipArchive();
+ $zip->open($destination, ZipArchive::CREATE | ZipArchive::OVERWRITE);
+ if ($include_source) {
+ $zip->addEmptyDir(basename($source));
+ }
+
+ if (is_file($source)) {
+ $zip->addFile(basename($source));
+ }
+
+ if (is_dir($source)) {
+ $this->recursiveAddFile($zip, $source);
+ }
+
+ $zip->close();
+ }
+
+ private function recursiveAddFile(ZipArchive $zip, string $dir): void
+ {
+ $includes = new FilesystemIterator($dir);
+// Debug::prn($includes);
+ foreach ($includes as $include) {
+// var_dump($include->getFilename());
+ if(is_dir($include)/* && !is_link($include)*/) {
+ var_dump('ЭТО ПАПКА');
+// $d = dir($include);
+// $entry = $d->read();
+// if ($entry == '.' || $entry == '..') continue;
+ $zip->addEmptyDir(basename($include));
+ $this->recursiveAddFile($zip, $include);
+ }
+ else {
+ var_dump("ЭТО ФАЙЛ");
+ $zip->addFile($include);
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/kernel/modules/option/views/view.php b/kernel/modules/option/views/view.php
index d8068c2..b0e77b0 100644
--- a/kernel/modules/option/views/view.php
+++ b/kernel/modules/option/views/view.php
@@ -19,5 +19,11 @@ $table->beforePrint(function () use ($option) {
$btn .= DangerBtn::create("Удалить", "/admin/option/delete/" . $option->id)->fetch();
return $btn;
});
+
+$table->rows([
+ 'status' => (function ($data) {
+ return \kernel\modules\option\models\Option::getStatus()[$data];
+ })
+]);
$table->create();
$table->render();
\ No newline at end of file
diff --git a/kernel/modules/post/service/PostService.php b/kernel/modules/post/service/PostService.php
index 7b3abad..2294ce2 100644
--- a/kernel/modules/post/service/PostService.php
+++ b/kernel/modules/post/service/PostService.php
@@ -15,7 +15,6 @@ class PostService
$model->content = $form_model->getItem('content');
$model->user_id = $form_model->getItem('user_id');
$model->title = $form_model->getItem('title');
-// $model->slug = Slug::recursiveCreateSlug(Post::class, $this->createSlug($form_model));
$model->slug = Slug::createSlug($form_model->getItem('title'), Post::class);
if ($model->save()){
return $model;
diff --git a/kernel/routs/admin.php b/kernel/routs/admin.php
index d638d15..7e238d7 100644
--- a/kernel/routs/admin.php
+++ b/kernel/routs/admin.php
@@ -9,6 +9,7 @@ App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
App::$collector->group(["prefix" => "module"], function (RouteCollector $router){
App::$collector->get('/', [\kernel\controllers\ModuleController::class, 'actionIndex']);
App::$collector->get('/activate', [\kernel\controllers\ModuleController::class, 'actionActivate']);
+ App::$collector->get('/view', [\kernel\controllers\ModuleController::class, 'actionView']);
});
});
});
\ No newline at end of file
diff --git a/resources/tmp/modules/tag/TagModule.php b/resources/tmp/ad/tag/app/TagModule.php
similarity index 72%
rename from resources/tmp/modules/tag/TagModule.php
rename to resources/tmp/ad/tag/app/TagModule.php
index ee01d77..b2f0ffd 100644
--- a/resources/tmp/modules/tag/TagModule.php
+++ b/resources/tmp/ad/tag/app/TagModule.php
@@ -4,14 +4,17 @@ namespace app\modules\tag;
use kernel\Module;
use kernel\modules\menu\service\MenuService;
+use kernel\services\MigrationService;
class TagModule extends Module
{
public MenuService $menuService;
+ public MigrationService $migrationService;
public function __construct()
{
$this->menuService = new MenuService();
+ $this->migrationService = new MigrationService();
}
/**
@@ -19,6 +22,8 @@ class TagModule extends Module
*/
public function init(): void
{
+ $this->migrationService->runAtPath("{KERNEL_APP_MODULES}/tag/migrations");
+
$this->menuService->createItem([
"label" => "Тэги",
"url" => "/admin/tag",
diff --git a/resources/tmp/ad/tag/app/controllers/TagController.php b/resources/tmp/ad/tag/app/controllers/TagController.php
new file mode 100644
index 0000000..4598872
--- /dev/null
+++ b/resources/tmp/ad/tag/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/tag/kernel/migrations/2024_10_08_093710_create_tag_table.php b/resources/tmp/ad/tag/kernel/migrations/2024_10_08_093710_create_tag_table.php
new file mode 100644
index 0000000..37c4be5
--- /dev/null
+++ b/resources/tmp/ad/tag/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/tag/kernel/models/Tag.php b/resources/tmp/ad/tag/kernel/models/Tag.php
new file mode 100644
index 0000000..49e1bb4
--- /dev/null
+++ b/resources/tmp/ad/tag/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/tag/kernel/models/forms/CreateTagForm.php b/resources/tmp/ad/tag/kernel/models/forms/CreateTagForm.php
new file mode 100644
index 0000000..82fd893
--- /dev/null
+++ b/resources/tmp/ad/tag/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/tag/kernel/routs/tag.php b/resources/tmp/ad/tag/kernel/routs/tag.php
new file mode 100644
index 0000000..6ec41fe
--- /dev/null
+++ b/resources/tmp/ad/tag/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/tag/kernel/services/TagService.php b/resources/tmp/ad/tag/kernel/services/TagService.php
new file mode 100644
index 0000000..9407f0a
--- /dev/null
+++ b/resources/tmp/ad/tag/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/tag/kernel/views/form.php b/resources/tmp/ad/tag/kernel/views/form.php
new file mode 100644
index 0000000..3a37b96
--- /dev/null
+++ b/resources/tmp/ad/tag/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/tag/kernel/views/index.php b/resources/tmp/ad/tag/kernel/views/index.php
new file mode 100644
index 0000000..0d5503f
--- /dev/null
+++ b/resources/tmp/ad/tag/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/tag/kernel/views/view.php b/resources/tmp/ad/tag/kernel/views/view.php
new file mode 100644
index 0000000..b09034f
--- /dev/null
+++ b/resources/tmp/ad/tag/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 (2)/home/stas/PhpProjects/MicroFrameWork/resources/tmp/ad/tag/app/TagModule.php b/resources/tmp/modules/tag (2)/home/stas/PhpProjects/MicroFrameWork/resources/tmp/ad/tag/app/TagModule.php
new file mode 100644
index 0000000..b2f0ffd
--- /dev/null
+++ b/resources/tmp/modules/tag (2)/home/stas/PhpProjects/MicroFrameWork/resources/tmp/ad/tag/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/modules/tag (2)/home/stas/PhpProjects/MicroFrameWork/resources/tmp/ad/tag/app/controllers/TagController.php b/resources/tmp/modules/tag (2)/home/stas/PhpProjects/MicroFrameWork/resources/tmp/ad/tag/app/controllers/TagController.php
new file mode 100644
index 0000000..4598872
--- /dev/null
+++ b/resources/tmp/modules/tag (2)/home/stas/PhpProjects/MicroFrameWork/resources/tmp/ad/tag/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/modules/tag (2)/home/stas/PhpProjects/MicroFrameWork/resources/tmp/ad/tag/kernel/migrations/2024_10_08_093710_create_tag_table.php b/resources/tmp/modules/tag (2)/home/stas/PhpProjects/MicroFrameWork/resources/tmp/ad/tag/kernel/migrations/2024_10_08_093710_create_tag_table.php
new file mode 100644
index 0000000..37c4be5
--- /dev/null
+++ b/resources/tmp/modules/tag (2)/home/stas/PhpProjects/MicroFrameWork/resources/tmp/ad/tag/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/modules/tag (2)/home/stas/PhpProjects/MicroFrameWork/resources/tmp/ad/tag/kernel/models/Tag.php b/resources/tmp/modules/tag (2)/home/stas/PhpProjects/MicroFrameWork/resources/tmp/ad/tag/kernel/models/Tag.php
new file mode 100644
index 0000000..49e1bb4
--- /dev/null
+++ b/resources/tmp/modules/tag (2)/home/stas/PhpProjects/MicroFrameWork/resources/tmp/ad/tag/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/modules/tag (2)/home/stas/PhpProjects/MicroFrameWork/resources/tmp/ad/tag/kernel/models/forms/CreateTagForm.php b/resources/tmp/modules/tag (2)/home/stas/PhpProjects/MicroFrameWork/resources/tmp/ad/tag/kernel/models/forms/CreateTagForm.php
new file mode 100644
index 0000000..82fd893
--- /dev/null
+++ b/resources/tmp/modules/tag (2)/home/stas/PhpProjects/MicroFrameWork/resources/tmp/ad/tag/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/modules/tag (2)/home/stas/PhpProjects/MicroFrameWork/resources/tmp/ad/tag/kernel/routs/tag.php b/resources/tmp/modules/tag (2)/home/stas/PhpProjects/MicroFrameWork/resources/tmp/ad/tag/kernel/routs/tag.php
new file mode 100644
index 0000000..6ec41fe
--- /dev/null
+++ b/resources/tmp/modules/tag (2)/home/stas/PhpProjects/MicroFrameWork/resources/tmp/ad/tag/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/modules/tag (2)/home/stas/PhpProjects/MicroFrameWork/resources/tmp/ad/tag/kernel/services/TagService.php b/resources/tmp/modules/tag (2)/home/stas/PhpProjects/MicroFrameWork/resources/tmp/ad/tag/kernel/services/TagService.php
new file mode 100644
index 0000000..9407f0a
--- /dev/null
+++ b/resources/tmp/modules/tag (2)/home/stas/PhpProjects/MicroFrameWork/resources/tmp/ad/tag/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/modules/tag (2)/home/stas/PhpProjects/MicroFrameWork/resources/tmp/ad/tag/kernel/views/form.php b/resources/tmp/modules/tag (2)/home/stas/PhpProjects/MicroFrameWork/resources/tmp/ad/tag/kernel/views/form.php
new file mode 100644
index 0000000..3a37b96
--- /dev/null
+++ b/resources/tmp/modules/tag (2)/home/stas/PhpProjects/MicroFrameWork/resources/tmp/ad/tag/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/modules/tag (2)/home/stas/PhpProjects/MicroFrameWork/resources/tmp/ad/tag/kernel/views/index.php b/resources/tmp/modules/tag (2)/home/stas/PhpProjects/MicroFrameWork/resources/tmp/ad/tag/kernel/views/index.php
new file mode 100644
index 0000000..0d5503f
--- /dev/null
+++ b/resources/tmp/modules/tag (2)/home/stas/PhpProjects/MicroFrameWork/resources/tmp/ad/tag/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/modules/tag (2)/home/stas/PhpProjects/MicroFrameWork/resources/tmp/ad/tag/kernel/views/view.php b/resources/tmp/modules/tag (2)/home/stas/PhpProjects/MicroFrameWork/resources/tmp/ad/tag/kernel/views/view.php
new file mode 100644
index 0000000..b09034f
--- /dev/null
+++ b/resources/tmp/modules/tag (2)/home/stas/PhpProjects/MicroFrameWork/resources/tmp/ad/tag/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.zip b/resources/tmp/modules/tag.zip
index 940a046..0bfc347 100644
Binary files a/resources/tmp/modules/tag.zip and b/resources/tmp/modules/tag.zip differ
diff --git a/resources/tmp/modules/tag/app/TagModule.php b/resources/tmp/modules/tag/app/TagModule.php
new file mode 100644
index 0000000..b2f0ffd
--- /dev/null
+++ b/resources/tmp/modules/tag/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/modules/tag/app/controllers/TagController.php b/resources/tmp/modules/tag/app/controllers/TagController.php
new file mode 100644
index 0000000..4598872
--- /dev/null
+++ b/resources/tmp/modules/tag/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/modules/tag/kernel/models/Tag.php b/resources/tmp/modules/tag/kernel/models/Tag.php
index 55042a3..49e1bb4 100644
--- a/resources/tmp/modules/tag/kernel/models/Tag.php
+++ b/resources/tmp/modules/tag/kernel/models/Tag.php
@@ -1,9 +1,18 @@
'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/modules/tag/kernel/routs/tag.php b/resources/tmp/modules/tag/kernel/routs/tag.php
new file mode 100644
index 0000000..6ec41fe
--- /dev/null
+++ b/resources/tmp/modules/tag/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/modules/tag/kernel/services/TagService.php b/resources/tmp/modules/tag/kernel/services/TagService.php
new file mode 100644
index 0000000..9407f0a
--- /dev/null
+++ b/resources/tmp/modules/tag/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/modules/tag/kernel/views/form.php b/resources/tmp/modules/tag/kernel/views/form.php
new file mode 100644
index 0000000..3a37b96
--- /dev/null
+++ b/resources/tmp/modules/tag/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/modules/tag/kernel/views/index.php b/resources/tmp/modules/tag/kernel/views/index.php
new file mode 100644
index 0000000..0d5503f
--- /dev/null
+++ b/resources/tmp/modules/tag/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/modules/tag/kernel/views/view.php b/resources/tmp/modules/tag/kernel/views/view.php
new file mode 100644
index 0000000..b09034f
--- /dev/null
+++ b/resources/tmp/modules/tag/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