entity relations

This commit is contained in:
2024-11-20 15:30:29 +03:00
parent a3f97456bc
commit 19d668418c
2 changed files with 46 additions and 4 deletions

43
kernel/EntityRelation.php Normal file
View File

@ -0,0 +1,43 @@
<?php
namespace kernel;
use kernel\helpers\Debug;
use kernel\models\Option;
class EntityRelation
{
public function getEntityList(): array
{
$entity_relations = Option::where("key", "entity_relations")->first();
if ($entity_relations) {
$entity_relations = json_decode($entity_relations->value, true);
$entities = [];
foreach ($entity_relations as $entity => $relation) {
$entities[] = $entity;
}
return $entities;
}
return [];
}
public function addEntityRelation(array $data): bool
{
$entity_relations_info = Option::where("key", "entity_relations")->first();
if ($entity_relations_info) {
$entity_relations = json_decode($entity_relations_info->value, true);
foreach ($data as $entity => $relation) {
$entity_relations[$entity] = $relation;
}
$entity_relations_info->value = json_encode($entity_relations, JSON_UNESCAPED_UNICODE);
$entity_relations_info->save();
return true;
}
return false;
}
}