MicroFrameWork/kernel/EntityRelation.php
2024-11-20 15:30:29 +03:00

43 lines
1.1 KiB
PHP

<?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;
}
}