diff --git a/app/modules/photo/PhotoModule.php b/app/modules/photo/PhotoModule.php index 4fdfff8..1ead103 100644 --- a/app/modules/photo/PhotoModule.php +++ b/app/modules/photo/PhotoModule.php @@ -40,11 +40,19 @@ class PhotoModule extends Module "url" => "/admin/photo", "slug" => "photo", ]); + + $this->menuService->createItem([ + "label" => "Фото", + "url" => "/admin/settings/photo", + "slug" => "photo_settings", + "parent_slug" => "settings" + ]); } public function deactivate(): void { $this->menuService->removeItemBySlug("photo"); + $this->menuService->removeItemBySlug("photo_settings"); } public function formInputs(string $entity, Model $model = null): void diff --git a/kernel/EntityRelation.php b/kernel/EntityRelation.php index 6b2fc42..1d118c2 100644 --- a/kernel/EntityRelation.php +++ b/kernel/EntityRelation.php @@ -249,4 +249,31 @@ class EntityRelation return $entities; } + + public static function configurationEntitiesByProperty(array|null $entities, string $property): void + { + $entityRelations = self::getEntitiesRelations(); + if (isset($entities)) { + foreach ($entities as $entity) { + if (!isset($entityRelations[$entity])) { + EntityRelation::addEntityRelation($entity, $property); + } + } + foreach ($entityRelations as $entity => $additionalProperty) { + if (in_array($entity, $entities)) { + if (!in_array($property, $additionalProperty)) { + EntityRelation::addEntityRelation($entity, $property); + } + } else { + if (in_array($property, $additionalProperty)) { + EntityRelation::removePropertyFromEntityRelations($entity, $property); + } + } + } + } else { + foreach ($entityRelations as $entity => $additionalProperty) { + EntityRelation::removePropertyFromEntityRelations($entity, $property); + } + } + } } \ No newline at end of file diff --git a/kernel/app_modules/photo/controllers/PhotoController.php b/kernel/app_modules/photo/controllers/PhotoController.php index e241869..17be731 100755 --- a/kernel/app_modules/photo/controllers/PhotoController.php +++ b/kernel/app_modules/photo/controllers/PhotoController.php @@ -8,7 +8,11 @@ use kernel\AdminController; use kernel\app_modules\photo\models\form\CreatePhotoForm; use kernel\app_modules\photo\models\Photo; use kernel\app_modules\photo\services\PhotoService; +use kernel\EntityRelation; +use kernel\Flash; use kernel\helpers\Debug; +use kernel\Request; + class PhotoController extends AdminController { private PhotoService $photoService; @@ -55,50 +59,19 @@ class PhotoController extends AdminController $this->cgView->render("view.php", ['photo' => $photo]); } -// /** -// * @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/view/" . $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/"); -// } -// -// public function actionSettings(): void -// { -// $this->cgView->render('form.php'); -// } + public function actionSettings(): void + { + $this->cgView->render('settingsForm.php'); + } + + #[NoReturn] public function actionSaveSettings(): void + { + $request = new Request(); + $entities = $request->post('entity'); + EntityRelation::configurationEntitiesByProperty($entities, 'photo'); + + Flash::setMessage("success", "Настройка прошла успешно"); + $this->redirect("/admin/settings/photo", 302); + } } \ No newline at end of file diff --git a/kernel/app_modules/photo/routs/photo.php b/kernel/app_modules/photo/routs/photo.php index 4c74627..06d732e 100755 --- a/kernel/app_modules/photo/routs/photo.php +++ b/kernel/app_modules/photo/routs/photo.php @@ -16,5 +16,9 @@ App::$collector->group(["prefix" => "admin"], function (CgRouteCollector $router App::$collector->any("/edit/{id}", [\kernel\app_modules\photo\controllers\PhotoController::class, 'actionEdit']); App::$collector->get('/delete/{id}', [\kernel\app_modules\photo\controllers\PhotoController::class]); }); + App::$collector->group(["prefix" => "settings"], function (CGRouteCollector $router) { + App::$collector->get('/photo', [\kernel\app_modules\photo\controllers\PhotoController::class, 'actionSettings']); + App::$collector->post('/photo/update', [\kernel\app_modules\photo\controllers\PhotoController::class, 'actionSaveSettings']); + }); }); }); \ No newline at end of file diff --git a/kernel/app_modules/photo/views/settingsForm.php b/kernel/app_modules/photo/views/settingsForm.php new file mode 100644 index 0000000..49d60bd --- /dev/null +++ b/kernel/app_modules/photo/views/settingsForm.php @@ -0,0 +1,46 @@ +beginForm("/admin/settings/photo/update"); + +?> + +
+
Выберите сущности, к которым хотите прикрепить фото
+
+ +field(\itguild\forms\inputs\Select::class, "entity[]", [ + 'class' => "form-control", + 'value' => \kernel\EntityRelation::getEntityByProperty('photo') ?? '', + '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(); diff --git a/kernel/app_modules/tag/controllers/TagController.php b/kernel/app_modules/tag/controllers/TagController.php index dfe95ad..88cd0c7 100755 --- a/kernel/app_modules/tag/controllers/TagController.php +++ b/kernel/app_modules/tag/controllers/TagController.php @@ -9,6 +9,7 @@ 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\Flash; use kernel\helpers\Debug; use kernel\models\Option; use kernel\modules\menu\service\MenuService; @@ -110,32 +111,9 @@ class TagController extends AdminController { $request = new Request(); $entities = $request->post('entity'); + EntityRelation::configurationEntitiesByProperty($entities, 'tag'); - $entityRelations = EntityRelation::getEntitiesRelations(); - - if (isset($entities)) { - foreach ($entities as $entity) { - if (!isset($entityRelations[$entity])) { - EntityRelation::addEntityRelation($entity, 'tag'); - } - } - foreach ($entityRelations as $entity => $property) { - if (in_array($entity, $entities)) { - if (!in_array('tag', $property)) { - EntityRelation::addEntityRelation($entity, 'tag'); - } - } else { - if (in_array('tag', $property)) { - EntityRelation::removePropertyFromEntityRelations($entity, 'tag'); - } - } - } - } else { - foreach ($entityRelations as $entity => $property) { - EntityRelation::removePropertyFromEntityRelations($entity, 'tag'); - } - } - + Flash::setMessage("success", "Настройка прошла успешно"); $this->redirect("/admin/settings/tag", 302); } diff --git a/kernel/app_modules/tag/views/tag/settingsForm.php b/kernel/app_modules/tag/views/tag/settingsForm.php index 6c3d209..54f1280 100644 --- a/kernel/app_modules/tag/views/tag/settingsForm.php +++ b/kernel/app_modules/tag/views/tag/settingsForm.php @@ -4,7 +4,13 @@ $form = new \itguild\forms\ActiveForm(); $form->beginForm("/admin/settings/tag/update"); //\kernel\helpers\Debug::dd($value); +?> +
+
Выберите сущности, к которым хотите прикрепить теги
+
+ +field(\itguild\forms\inputs\Select::class, "entity[]", [ 'class' => "form-control", 'value' => \kernel\EntityRelation::getEntityByProperty('tag') ?? '', diff --git a/kernel/services/ModuleService.php b/kernel/services/ModuleService.php index 682e73c..ac11546 100644 --- a/kernel/services/ModuleService.php +++ b/kernel/services/ModuleService.php @@ -4,11 +4,13 @@ namespace kernel\services; use DirectoryIterator; use kernel\EntityRelation; +use kernel\Flash; use kernel\helpers\Debug; use kernel\helpers\Files; use kernel\helpers\Manifest; use kernel\helpers\RESTClient; use kernel\models\Option; +use MongoDB\Driver\Session; use ZipArchive; class ModuleService @@ -359,8 +361,6 @@ class ModuleService mkdir(RESOURCES_DIR . '/tmp/modules', 0777, true); } $fileHelper->pack($tmpModuleDirFull, RESOURCES_DIR . '/tmp/modules/' . $moduleName . '.igm'); - - //$fileHelper->recursiveRemoveDir($tmpModuleDirFull); } /** @@ -442,14 +442,18 @@ class ModuleService public function isLastVersion(string $slug): bool { - $modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug'); + try { + $modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug'); - $modules_info = json_decode($modules_info->getBody()->getContents(), true); - $mod_info = $this->getModuleInfoBySlug($slug); - foreach ($modules_info as $mod) { - if ($mod['slug'] === $mod_info['slug'] && $mod['version'] === $mod_info['version']) { - return true; + $modules_info = json_decode($modules_info->getBody()->getContents(), true); + $mod_info = $this->getModuleInfoBySlug($slug); + foreach ($modules_info as $mod) { + if ($mod['slug'] === $mod_info['slug'] && $mod['version'] === $mod_info['version']) { + return true; + } } + } catch (\Exception $e) { + throw new \Exception("Не удалось получить доступ к магазину модулей"); } return false; diff --git a/kernel/views/module/index.php b/kernel/views/module/index.php index 7ccb464..6287a2f 100644 --- a/kernel/views/module/index.php +++ b/kernel/views/module/index.php @@ -7,6 +7,7 @@ * @var \kernel\services\ModuleService $moduleService */ +use kernel\Flash; use kernel\widgets\IconBtn\IconBtnActivateWidget; use kernel\widgets\IconBtn\IconBtnDeactivateWidget; use kernel\widgets\IconBtn\IconBtnDeleteWidget;