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

View File

@ -3,7 +3,6 @@
namespace kernel\services; namespace kernel\services;
use DirectoryIterator; use DirectoryIterator;
use GuzzleHttp\Client;
use kernel\helpers\Debug; use kernel\helpers\Debug;
use kernel\helpers\Files; use kernel\helpers\Files;
use kernel\helpers\Manifest; use kernel\helpers\Manifest;
@ -67,9 +66,9 @@ class ModuleService
{ {
$active_modules = Option::where("key", "active_modules")->first(); $active_modules = Option::where("key", "active_modules")->first();
if ($active_modules) { if ($active_modules) {
$path = json_decode($active_modules->value); $modules = json_decode($active_modules->value);
foreach ($path->modules as $p) { foreach ($modules->modules as $mod) {
if ($p === $slug) { if ($mod === $slug) {
return true; return true;
} }
} }