settings for tag

This commit is contained in:
Билай Станислав 2024-11-29 16:54:35 +03:00
parent 0ed97877fd
commit b981ff0c44
5 changed files with 83 additions and 4 deletions

View File

@ -51,11 +51,11 @@ class PhotoModule extends Module
{ {
if (isset($model->id)) { if (isset($model->id)) {
$value = PhotoService::getByEntity($entity, $model->id); $value = PhotoService::getByEntity($entity, $model->id);
}
echo Html::img($value, ['width' => '200px']); echo Html::img($value, ['width' => '200px']);
}
$input = FileBuilder::build("image", [ $input = FileBuilder::build("image", [
'class' => 'form-control', 'class' => 'form-control',
'value' => $value, 'value' => $value ?? '',
]); ]);
$input->setLabel("Фото"); $input->setLabel("Фото");
$input->create()->render(); $input->create()->render();

View File

@ -121,7 +121,7 @@ class EntityRelation
return false; 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(); $entity_relations_info = Option::where("key", "entity_relations")->first();
if ($entity_relations_info) { if ($entity_relations_info) {

View File

@ -8,8 +8,11 @@ use kernel\AdminController;
use kernel\app_modules\tag\models\forms\CreateTagForm; 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\helpers\Debug; use kernel\helpers\Debug;
use kernel\models\Option;
use kernel\modules\menu\service\MenuService; use kernel\modules\menu\service\MenuService;
use kernel\Request;
class TagController extends AdminController class TagController extends AdminController
{ {
@ -100,7 +103,40 @@ class TagController extends AdminController
public function actionSettings(): void 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");
} }
} }

View File

@ -28,6 +28,7 @@ App::$collector->group(["prefix" => "admin"], function (CgRouteCollector $router
}); });
App::$collector->group(["prefix" => "settings"], function (CGRouteCollector $router) { App::$collector->group(["prefix" => "settings"], function (CGRouteCollector $router) {
App::$collector->get('/tag', [\app\modules\tag\controllers\TagController::class, 'actionSettings']); App::$collector->get('/tag', [\app\modules\tag\controllers\TagController::class, 'actionSettings']);
App::$collector->post('/tag/update', [\app\modules\tag\controllers\TagController::class, 'actionSaveSettings']);
}); });
}); });
}); });

View File

@ -0,0 +1,42 @@
<?php
use itguild\forms\builders\SelectBuilder;
use kernel\EntityRelation;
$form = new \itguild\forms\ActiveForm();
$form->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();
?>
<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();