photo settings
This commit is contained in:
		| @@ -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 | ||||
|   | ||||
| @@ -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); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -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); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -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']); | ||||
|         }); | ||||
|     }); | ||||
| }); | ||||
							
								
								
									
										46
									
								
								kernel/app_modules/photo/views/settingsForm.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								kernel/app_modules/photo/views/settingsForm.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,46 @@ | ||||
| <?php | ||||
|  | ||||
| $form = new \itguild\forms\ActiveForm(); | ||||
| $form->beginForm("/admin/settings/photo/update"); | ||||
|  | ||||
| ?> | ||||
|  | ||||
| <div class="row"> | ||||
|     <h5>Выберите сущности, к которым хотите прикрепить фото</h5> | ||||
| </div> | ||||
|  | ||||
| <?php | ||||
| $form->field(\itguild\forms\inputs\Select::class, "entity[]", [ | ||||
|     'class' => "form-control", | ||||
|     'value' => \kernel\EntityRelation::getEntityByProperty('photo') ?? '', | ||||
|     'multiple' => "multiple", | ||||
|  | ||||
| ]) | ||||
|     ->setLabel("Сущности") | ||||
|     ->setOptions(\kernel\EntityRelation::getEntityList()) | ||||
|     ->render(); | ||||
| ?> | ||||
|     <div class="row"> | ||||
|         <div class="col-sm-2"> | ||||
|             <?php | ||||
|             $form->field(\itguild\forms\inputs\Button::class, name: "btn-submit", params: [ | ||||
|                 'class' => "btn btn-primary ", | ||||
|                 'value' => 'Отправить', | ||||
|                 'typeInput' => 'submit' | ||||
|             ]) | ||||
|                 ->render(); | ||||
|             ?> | ||||
|         </div> | ||||
|         <div class="col-sm-2"> | ||||
|             <?php | ||||
|             $form->field(\itguild\forms\inputs\Button::class, name: "btn-reset", params: [ | ||||
|                 'class' => "btn btn-warning", | ||||
|                 'value' => 'Сбросить', | ||||
|                 'typeInput' => 'reset' | ||||
|             ]) | ||||
|                 ->render(); | ||||
|             ?> | ||||
|         </div> | ||||
|     </div> | ||||
| <?php | ||||
| $form->endForm(); | ||||
| @@ -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); | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -4,7 +4,13 @@ $form = new \itguild\forms\ActiveForm(); | ||||
| $form->beginForm("/admin/settings/tag/update"); | ||||
|  | ||||
| //\kernel\helpers\Debug::dd($value); | ||||
| ?> | ||||
|  | ||||
| <div class="row"> | ||||
|     <h5>Выберите сущности, к которым хотите прикрепить теги</h5> | ||||
| </div> | ||||
|  | ||||
| <?php | ||||
| $form->field(\itguild\forms\inputs\Select::class, "entity[]", [ | ||||
|     'class' => "form-control", | ||||
|     'value' => \kernel\EntityRelation::getEntityByProperty('tag') ?? '', | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user