From 19d668418c35656e729f389e7fdb364d39f4618e Mon Sep 17 00:00:00 2001 From: stasbilay02 Date: Wed, 20 Nov 2024 15:30:29 +0300 Subject: [PATCH] entity relations --- kernel/EntityRelation.php | 43 +++++++++++++++++++++++++++++++ kernel/services/ModuleService.php | 7 +++-- 2 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 kernel/EntityRelation.php diff --git a/kernel/EntityRelation.php b/kernel/EntityRelation.php new file mode 100644 index 0000000..58506a0 --- /dev/null +++ b/kernel/EntityRelation.php @@ -0,0 +1,43 @@ +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; + } +} \ No newline at end of file diff --git a/kernel/services/ModuleService.php b/kernel/services/ModuleService.php index 3840192..f064e17 100644 --- a/kernel/services/ModuleService.php +++ b/kernel/services/ModuleService.php @@ -3,7 +3,6 @@ namespace kernel\services; use DirectoryIterator; -use GuzzleHttp\Client; use kernel\helpers\Debug; use kernel\helpers\Files; use kernel\helpers\Manifest; @@ -67,9 +66,9 @@ class ModuleService { $active_modules = Option::where("key", "active_modules")->first(); if ($active_modules) { - $path = json_decode($active_modules->value); - foreach ($path->modules as $p) { - if ($p === $slug) { + $modules = json_decode($active_modules->value); + foreach ($modules->modules as $mod) { + if ($mod === $slug) { return true; } }