entity relations
This commit is contained in:
43
kernel/EntityRelation.php
Normal file
43
kernel/EntityRelation.php
Normal 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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user