diff --git a/app/modules/tag/TagModule.php b/app/modules/tag/TagModule.php index 50b7982..2350a8f 100644 --- a/app/modules/tag/TagModule.php +++ b/app/modules/tag/TagModule.php @@ -71,6 +71,7 @@ class TagModule extends Module { $tag = new Tag(); $tag->label = $request->post('tag'); + $tag->entity = $entity; $tag->status = Tag::ACTIVE_STATUS; $tag->slug = Slug::createSlug($request->post('tag'), $model); $tag->save(); diff --git a/kernel/EntityRelation.php b/kernel/EntityRelation.php index cd6139b..933ff14 100644 --- a/kernel/EntityRelation.php +++ b/kernel/EntityRelation.php @@ -18,13 +18,14 @@ class EntityRelation } - public function getEntityList(): array + public static function getEntityList(): array { $list = []; - $activeModules = $this->moduleService->getActiveModules(); + $moduleService = new ModuleService(); + $activeModules = $moduleService->getActiveModules(); foreach ($activeModules as $module) { if (isset($module['type']) and $module['type'] === "entity") { - $list[] = $module['slug']; + $list[$module['slug']] = $module['name']; } } diff --git a/kernel/app_modules/tag/controllers/TagController.php b/kernel/app_modules/tag/controllers/TagController.php index 748af2a..a906116 100755 --- a/kernel/app_modules/tag/controllers/TagController.php +++ b/kernel/app_modules/tag/controllers/TagController.php @@ -100,7 +100,7 @@ class TagController extends AdminController public function actionSettings(): void { - echo "tag settings"; + $this->cgView->render('form.php'); } } \ No newline at end of file diff --git a/kernel/app_modules/tag/migrations/tag/2024_10_08_093710_create_tag_table.php b/kernel/app_modules/tag/migrations/tag/2024_10_08_093710_create_tag_table.php index b037292..37c4be5 100755 --- a/kernel/app_modules/tag/migrations/tag/2024_10_08_093710_create_tag_table.php +++ b/kernel/app_modules/tag/migrations/tag/2024_10_08_093710_create_tag_table.php @@ -14,6 +14,7 @@ return new class extends Migration \kernel\App::$db->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(); diff --git a/kernel/app_modules/tag/models/Tag.php b/kernel/app_modules/tag/models/Tag.php index 3ef42c2..e7f6eea 100755 --- a/kernel/app_modules/tag/models/Tag.php +++ b/kernel/app_modules/tag/models/Tag.php @@ -25,6 +25,7 @@ class Tag extends Model { return [ 'label' => 'Заголовок', + 'entity' => 'Сущность', 'slug' => 'Slug', 'status' => 'Статус', ]; diff --git a/kernel/app_modules/tag/models/forms/CreateTagForm.php b/kernel/app_modules/tag/models/forms/CreateTagForm.php index 4a651ac..8f68633 100755 --- a/kernel/app_modules/tag/models/forms/CreateTagForm.php +++ b/kernel/app_modules/tag/models/forms/CreateTagForm.php @@ -11,6 +11,7 @@ class CreateTagForm extends FormModel { return [ 'label' => 'required|min-str-len:5|max-str-len:30', + 'entity' => 'required', 'slug' => '', 'status' => '' ]; diff --git a/kernel/app_modules/tag/services/TagService.php b/kernel/app_modules/tag/services/TagService.php index a057059..81b518e 100755 --- a/kernel/app_modules/tag/services/TagService.php +++ b/kernel/app_modules/tag/services/TagService.php @@ -4,15 +4,17 @@ namespace kernel\app_modules\tag\services; use kernel\app_modules\tag\models\Tag; use kernel\FormModel; +use kernel\helpers\Debug; use kernel\helpers\Slug; +use kernel\services\ModuleService; class TagService { - public function create(FormModel $form_model): false|Tag { $model = new Tag(); $model->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()){ @@ -28,6 +30,7 @@ class TagService $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()){ diff --git a/kernel/app_modules/tag/views/tag/form.php b/kernel/app_modules/tag/views/tag/form.php index eb408c7..2685b40 100755 --- a/kernel/app_modules/tag/views/tag/form.php +++ b/kernel/app_modules/tag/views/tag/form.php @@ -16,6 +16,14 @@ $form->field(class: \itguild\forms\inputs\TextInput::class, name: "label", param ->setLabel("Заголовок") ->render(); +$form->field(class: \itguild\forms\inputs\Select::class, name: "entity", params: [ + 'class' => "form-control", + 'value' => $model->entity ?? '' +]) + ->setLabel("Сущность") + ->setOptions(\kernel\EntityRelation::getEntityList()) + ->render(); + $form->field(\itguild\forms\inputs\Select::class, 'status', [ 'class' => "form-control", 'value' => $model->status ?? ''