photo settings

This commit is contained in:
Билай Станислав 2024-12-02 16:25:28 +03:00
parent 567ab8544d
commit a1bed2d9f2
9 changed files with 125 additions and 78 deletions

View File

@ -40,11 +40,19 @@ class PhotoModule extends Module
"url" => "/admin/photo", "url" => "/admin/photo",
"slug" => "photo", "slug" => "photo",
]); ]);
$this->menuService->createItem([
"label" => "Фото",
"url" => "/admin/settings/photo",
"slug" => "photo_settings",
"parent_slug" => "settings"
]);
} }
public function deactivate(): void public function deactivate(): void
{ {
$this->menuService->removeItemBySlug("photo"); $this->menuService->removeItemBySlug("photo");
$this->menuService->removeItemBySlug("photo_settings");
} }
public function formInputs(string $entity, Model $model = null): void public function formInputs(string $entity, Model $model = null): void

View File

@ -249,4 +249,31 @@ class EntityRelation
return $entities; 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);
}
}
}
} }

View File

@ -8,7 +8,11 @@ use kernel\AdminController;
use kernel\app_modules\photo\models\form\CreatePhotoForm; use kernel\app_modules\photo\models\form\CreatePhotoForm;
use kernel\app_modules\photo\models\Photo; use kernel\app_modules\photo\models\Photo;
use kernel\app_modules\photo\services\PhotoService; use kernel\app_modules\photo\services\PhotoService;
use kernel\EntityRelation;
use kernel\Flash;
use kernel\helpers\Debug; use kernel\helpers\Debug;
use kernel\Request;
class PhotoController extends AdminController class PhotoController extends AdminController
{ {
private PhotoService $photoService; private PhotoService $photoService;
@ -55,50 +59,19 @@ class PhotoController extends AdminController
$this->cgView->render("view.php", ['photo' => $photo]); $this->cgView->render("view.php", ['photo' => $photo]);
} }
// /** public function actionSettings(): void
// * @throws Exception {
// */ $this->cgView->render('settingsForm.php');
// public function actionUpdate($id): void }
// {
// $model = Tag::find($id); #[NoReturn] public function actionSaveSettings(): void
// if (!$model){ {
// throw new Exception(message: "The tag not found"); $request = new Request();
// } $entities = $request->post('entity');
// EntityRelation::configurationEntitiesByProperty($entities, 'photo');
// $this->cgView->render("form.php", ['model' => $model]);
// } Flash::setMessage("success", "Настройка прошла успешно");
// $this->redirect("/admin/settings/photo", 302);
// /** }
// * @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');
// }
} }

View File

@ -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->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->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']);
});
}); });
}); });

View 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();

View File

@ -9,6 +9,7 @@ use kernel\app_modules\tag\models\forms\CreateTagForm;
use kernel\app_modules\tag\models\Tag; use kernel\app_modules\tag\models\Tag;
use kernel\app_modules\tag\services\TagService; use kernel\app_modules\tag\services\TagService;
use kernel\EntityRelation; use kernel\EntityRelation;
use kernel\Flash;
use kernel\helpers\Debug; use kernel\helpers\Debug;
use kernel\models\Option; use kernel\models\Option;
use kernel\modules\menu\service\MenuService; use kernel\modules\menu\service\MenuService;
@ -110,32 +111,9 @@ class TagController extends AdminController
{ {
$request = new Request(); $request = new Request();
$entities = $request->post('entity'); $entities = $request->post('entity');
EntityRelation::configurationEntitiesByProperty($entities, 'tag');
$entityRelations = EntityRelation::getEntitiesRelations(); Flash::setMessage("success", "Настройка прошла успешно");
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');
}
}
$this->redirect("/admin/settings/tag", 302); $this->redirect("/admin/settings/tag", 302);
} }

View File

@ -4,7 +4,13 @@ $form = new \itguild\forms\ActiveForm();
$form->beginForm("/admin/settings/tag/update"); $form->beginForm("/admin/settings/tag/update");
//\kernel\helpers\Debug::dd($value); //\kernel\helpers\Debug::dd($value);
?>
<div class="row">
<h5>Выберите сущности, к которым хотите прикрепить теги</h5>
</div>
<?php
$form->field(\itguild\forms\inputs\Select::class, "entity[]", [ $form->field(\itguild\forms\inputs\Select::class, "entity[]", [
'class' => "form-control", 'class' => "form-control",
'value' => \kernel\EntityRelation::getEntityByProperty('tag') ?? '', 'value' => \kernel\EntityRelation::getEntityByProperty('tag') ?? '',

View File

@ -4,11 +4,13 @@ namespace kernel\services;
use DirectoryIterator; use DirectoryIterator;
use kernel\EntityRelation; use kernel\EntityRelation;
use kernel\Flash;
use kernel\helpers\Debug; use kernel\helpers\Debug;
use kernel\helpers\Files; use kernel\helpers\Files;
use kernel\helpers\Manifest; use kernel\helpers\Manifest;
use kernel\helpers\RESTClient; use kernel\helpers\RESTClient;
use kernel\models\Option; use kernel\models\Option;
use MongoDB\Driver\Session;
use ZipArchive; use ZipArchive;
class ModuleService class ModuleService
@ -359,8 +361,6 @@ class ModuleService
mkdir(RESOURCES_DIR . '/tmp/modules', 0777, true); mkdir(RESOURCES_DIR . '/tmp/modules', 0777, true);
} }
$fileHelper->pack($tmpModuleDirFull, RESOURCES_DIR . '/tmp/modules/' . $moduleName . '.igm'); $fileHelper->pack($tmpModuleDirFull, RESOURCES_DIR . '/tmp/modules/' . $moduleName . '.igm');
//$fileHelper->recursiveRemoveDir($tmpModuleDirFull);
} }
/** /**
@ -442,14 +442,18 @@ class ModuleService
public function isLastVersion(string $slug): bool 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); $modules_info = json_decode($modules_info->getBody()->getContents(), true);
$mod_info = $this->getModuleInfoBySlug($slug); $mod_info = $this->getModuleInfoBySlug($slug);
foreach ($modules_info as $mod) { foreach ($modules_info as $mod) {
if ($mod['slug'] === $mod_info['slug'] && $mod['version'] === $mod_info['version']) { if ($mod['slug'] === $mod_info['slug'] && $mod['version'] === $mod_info['version']) {
return true; return true;
}
} }
} catch (\Exception $e) {
throw new \Exception("Не удалось получить доступ к магазину модулей");
} }
return false; return false;

View File

@ -7,6 +7,7 @@
* @var \kernel\services\ModuleService $moduleService * @var \kernel\services\ModuleService $moduleService
*/ */
use kernel\Flash;
use kernel\widgets\IconBtn\IconBtnActivateWidget; use kernel\widgets\IconBtn\IconBtnActivateWidget;
use kernel\widgets\IconBtn\IconBtnDeactivateWidget; use kernel\widgets\IconBtn\IconBtnDeactivateWidget;
use kernel\widgets\IconBtn\IconBtnDeleteWidget; use kernel\widgets\IconBtn\IconBtnDeleteWidget;