diff --git a/app/modules/photo/PhotoModule.php b/app/modules/photo/PhotoModule.php index 2f4ed51..4fdfff8 100644 --- a/app/modules/photo/PhotoModule.php +++ b/app/modules/photo/PhotoModule.php @@ -51,11 +51,11 @@ class PhotoModule extends Module { if (isset($model->id)) { $value = PhotoService::getByEntity($entity, $model->id); + echo Html::img($value, ['width' => '200px']); } - echo Html::img($value, ['width' => '200px']); $input = FileBuilder::build("image", [ 'class' => 'form-control', - 'value' => $value, + 'value' => $value ?? '', ]); $input->setLabel("Фото"); $input->create()->render(); diff --git a/kernel/EntityRelation.php b/kernel/EntityRelation.php index 1e44fea..682e584 100644 --- a/kernel/EntityRelation.php +++ b/kernel/EntityRelation.php @@ -121,7 +121,7 @@ class EntityRelation return false; } - public function addEntityRelation(string $entity, string $property): bool + public static function addEntityRelation(string $entity, string $property): bool { $entity_relations_info = Option::where("key", "entity_relations")->first(); if ($entity_relations_info) { diff --git a/kernel/app_modules/tag/controllers/TagController.php b/kernel/app_modules/tag/controllers/TagController.php index a906116..e3cde3e 100755 --- a/kernel/app_modules/tag/controllers/TagController.php +++ b/kernel/app_modules/tag/controllers/TagController.php @@ -8,8 +8,11 @@ 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\EntityRelation; use kernel\helpers\Debug; +use kernel\models\Option; use kernel\modules\menu\service\MenuService; +use kernel\Request; class TagController extends AdminController { @@ -100,7 +103,40 @@ class TagController extends AdminController public function actionSettings(): void { - $this->cgView->render('form.php'); + $this->cgView->render('settingsForm.php'); + } + + #[NoReturn] public function actionSaveSettings(): void + { + $request = new Request(); + $entities = $request->post('entity'); + + $entityRelationsModel = Option::where("key", "entity_relations")->first(); + $entityRelations = json_decode($entityRelationsModel->value, true); + + + + Debug::prn($entities); + Debug::prn($entityRelations); + + + if (isset($entities)) { + foreach ($entityRelations as $entity => $property) { + if (in_array($entity, $entities)) { + if (!in_array('tag', $property)) { + EntityRelation::addEntityRelation($entity, 'tag'); + } + } else { + EntityRelation::removePropertyFromEntityRelations($entity, array_search('tag', $property)); + } + } + } else { + foreach ($entityRelations as $entity => $property) { + EntityRelation::removeEntityRelation($entity); + } + } + +// $this->redirect("/admin/settings/tag"); } } \ 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 c17fa96..adb1c9e 100755 --- a/kernel/app_modules/tag/routs/tag.php +++ b/kernel/app_modules/tag/routs/tag.php @@ -28,6 +28,7 @@ App::$collector->group(["prefix" => "admin"], function (CgRouteCollector $router }); App::$collector->group(["prefix" => "settings"], function (CGRouteCollector $router) { App::$collector->get('/tag', [\app\modules\tag\controllers\TagController::class, 'actionSettings']); + App::$collector->post('/tag/update', [\app\modules\tag\controllers\TagController::class, 'actionSaveSettings']); }); }); }); \ No newline at end of file diff --git a/kernel/app_modules/tag/views/tag/settingsForm.php b/kernel/app_modules/tag/views/tag/settingsForm.php new file mode 100644 index 0000000..b7f2ffb --- /dev/null +++ b/kernel/app_modules/tag/views/tag/settingsForm.php @@ -0,0 +1,42 @@ +beginForm("/admin/settings/tag/update"); + +$form->field(\itguild\forms\inputs\Select::class, "entity[]", [ + 'class' => "form-control", + 'value' => $model->entity ?? '', + 'multiple' => "multiple", + +]) + ->setLabel("Сущности") + ->setOptions(\kernel\EntityRelation::getEntityList()) + ->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();