tag settings
This commit is contained in:
parent
b981ff0c44
commit
567ab8544d
@ -65,6 +65,7 @@ class TagModule extends Module
|
||||
if (isset($model->id)) {
|
||||
$value = TagEntityService::getTagsByEntity($entity, $model->id);
|
||||
}
|
||||
|
||||
$input = SelectBuilder::build("tag[]", [
|
||||
'class' => 'form-control',
|
||||
'placeholder' => 'Теги',
|
||||
|
@ -25,7 +25,7 @@ class EntityRelation
|
||||
$activeModules = $moduleService->getActiveModules();
|
||||
foreach ($activeModules as $module) {
|
||||
if (isset($module['type']) and $module['type'] === "entity") {
|
||||
$list[$module['slug']] = $module['name'];
|
||||
$list[$module['slug']] = $module['slug'];
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ class EntityRelation
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function getEntitiesRelations(): array|bool
|
||||
public static function getEntitiesRelations(): array|bool
|
||||
{
|
||||
$entity_relations = OptionService::getItem("entity_relations");
|
||||
if ($entity_relations) {
|
||||
@ -61,8 +61,13 @@ class EntityRelation
|
||||
if ($entity_relations_info) {
|
||||
$entity_relations = json_decode($entity_relations_info->value, true);
|
||||
if ($entity_relations[$entity]) {
|
||||
if ($entity_relations[$entity][$property]) {
|
||||
unset($entity_relations[$entity][$property]);
|
||||
$propertyKey = array_search($property, $entity_relations[$entity]);
|
||||
if ($entity_relations[$entity][$propertyKey] === $property) {
|
||||
unset($entity_relations[$entity][$propertyKey]);
|
||||
$entity_relations[$entity] = array_values($entity_relations[$entity]);
|
||||
if (empty($entity_relations[$entity])) {
|
||||
unset($entity_relations[$entity]);
|
||||
}
|
||||
$entity_relations_info->value = json_encode($entity_relations, JSON_UNESCAPED_UNICODE);
|
||||
$entity_relations_info->save();
|
||||
return true;
|
||||
@ -129,7 +134,7 @@ class EntityRelation
|
||||
if (isset($entity_relations[$entity])) {
|
||||
$entity_relations[$entity][] = $property;
|
||||
} else {
|
||||
$entity_relations[$entity] = $property;
|
||||
$entity_relations[$entity][] = $property;
|
||||
}
|
||||
$entity_relations_info->value = json_encode($entity_relations, JSON_UNESCAPED_UNICODE);
|
||||
$entity_relations_info->save();
|
||||
@ -231,4 +236,17 @@ class EntityRelation
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function getEntityByProperty(string $data): array
|
||||
{
|
||||
$entityRelations = self::getEntitiesRelations();
|
||||
$entities = [];
|
||||
foreach ($entityRelations as $entity => $property) {
|
||||
if (in_array($data, $property)) {
|
||||
$entities[] = $entity;
|
||||
}
|
||||
}
|
||||
|
||||
return $entities;
|
||||
}
|
||||
}
|
@ -111,32 +111,32 @@ class TagController extends AdminController
|
||||
$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);
|
||||
|
||||
$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 {
|
||||
EntityRelation::removePropertyFromEntityRelations($entity, array_search('tag', $property));
|
||||
if (in_array('tag', $property)) {
|
||||
EntityRelation::removePropertyFromEntityRelations($entity, 'tag');
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach ($entityRelations as $entity => $property) {
|
||||
EntityRelation::removeEntityRelation($entity);
|
||||
EntityRelation::removePropertyFromEntityRelations($entity, 'tag');
|
||||
}
|
||||
}
|
||||
|
||||
// $this->redirect("/admin/settings/tag");
|
||||
$this->redirect("/admin/settings/tag", 302);
|
||||
}
|
||||
|
||||
}
|
@ -1,14 +1,13 @@
|
||||
<?php
|
||||
|
||||
use itguild\forms\builders\SelectBuilder;
|
||||
use kernel\EntityRelation;
|
||||
|
||||
$form = new \itguild\forms\ActiveForm();
|
||||
$form->beginForm("/admin/settings/tag/update");
|
||||
|
||||
//\kernel\helpers\Debug::dd($value);
|
||||
|
||||
$form->field(\itguild\forms\inputs\Select::class, "entity[]", [
|
||||
'class' => "form-control",
|
||||
'value' => $model->entity ?? '',
|
||||
'value' => \kernel\EntityRelation::getEntityByProperty('tag') ?? '',
|
||||
'multiple' => "multiple",
|
||||
|
||||
])
|
||||
|
Loading…
Reference in New Issue
Block a user