entity relations
This commit is contained in:
parent
19d668418c
commit
ee9d93f137
@ -2,6 +2,8 @@
|
||||
|
||||
namespace app\modules\tag;
|
||||
|
||||
use itguild\forms\builders\TextInputBuilder;
|
||||
use itguild\forms\Form;
|
||||
use kernel\Module;
|
||||
use kernel\modules\menu\service\MenuService;
|
||||
use kernel\services\MigrationService;
|
||||
@ -35,4 +37,11 @@ class TagModule extends Module
|
||||
{
|
||||
$this->menuService->removeItemBySlug("tag");
|
||||
}
|
||||
|
||||
public function formInputs(): void
|
||||
{
|
||||
$input = TextInputBuilder::build("tags", ['class' => 'form-control', 'placeholder' => "Теги"]);
|
||||
$input->setLabel("Теги");
|
||||
$input->create()->render();
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@
|
||||
"version": "0.2",
|
||||
"author": "ITGuild",
|
||||
"slug": "tag",
|
||||
"type": "additional_property",
|
||||
"description": "Tags module",
|
||||
"app_module_path": "{APP}/modules/{slug}",
|
||||
"module_class": "app\\modules\\tag\\TagModule",
|
||||
|
@ -4,23 +4,70 @@ namespace kernel;
|
||||
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\models\Option;
|
||||
use kernel\modules\option\service\OptionService;
|
||||
use kernel\services\ModuleService;
|
||||
|
||||
class EntityRelation
|
||||
{
|
||||
protected ModuleService $moduleService;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->moduleService = new ModuleService();
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
$list = [];
|
||||
$activeModules = $this->moduleService->getActiveModules();
|
||||
foreach ($activeModules as $module) {
|
||||
if (isset($module['type']) and $module['type'] === "entity") {
|
||||
$list[] = $module['slug'];
|
||||
}
|
||||
|
||||
return $entities;
|
||||
}
|
||||
|
||||
return [];
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function getAdditionalPropertyList(): array
|
||||
{
|
||||
$list = [];
|
||||
$activeModules = $this->moduleService->getActiveModules();
|
||||
foreach ($activeModules as $module) {
|
||||
if (isset($module['type']) and $module['type'] === "additional_property") {
|
||||
$list[] = $module['slug'];
|
||||
}
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function getEntitiesRelations(): array|bool
|
||||
{
|
||||
$entity_relations = OptionService::getItem("entity_relations");
|
||||
if ($entity_relations) {
|
||||
return json_decode($entity_relations, true);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function removeFromEntityRelations(string $entity, string $property)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function getEntityRelationsBySlug(string $slug)
|
||||
{
|
||||
$entityRelations = $this->getEntitiesRelations();
|
||||
if ($entityRelations) {
|
||||
if (isset($entityRelations[$slug])){
|
||||
return $entityRelations[$slug];
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function addEntityRelation(array $data): bool
|
||||
@ -40,4 +87,32 @@ class EntityRelation
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getAdditionalPropertyClassBySlug(string $slug)
|
||||
{
|
||||
$module = $this->moduleService->getModuleInfoBySlug($slug);
|
||||
if (isset($module['module_class'])) {
|
||||
return new $module['module_class']();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function renderFormInputsBySlug(string $slug): void
|
||||
{
|
||||
$moduleClass = $this->getAdditionalPropertyClassBySlug($slug);
|
||||
if ($moduleClass and method_exists($moduleClass, "formInputs")) {
|
||||
$moduleClass->formInputs();
|
||||
}
|
||||
}
|
||||
|
||||
public function renderEntityAdditionalPropertyFormBySlug(string $slug): void
|
||||
{
|
||||
$relations = $this->getEntityRelationsBySlug($slug);
|
||||
if ($relations){
|
||||
foreach ($relations as $relation){
|
||||
$this->renderFormInputsBySlug($relation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ use DirectoryIterator;
|
||||
use JetBrains\PhpStorm\NoReturn;
|
||||
use Josantonius\Session\Facades\Session;
|
||||
use kernel\AdminController;
|
||||
use kernel\EntityRelation;
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\models\Option;
|
||||
use kernel\modules\module_shop_client\services\ModuleShopClientService;
|
||||
|
@ -3,6 +3,7 @@
|
||||
"version": "0.2",
|
||||
"author": "ITGuild",
|
||||
"slug": "post",
|
||||
"type": "entity",
|
||||
"description": "Post module",
|
||||
"module_class": "kernel\\modules\\post\\PostModule",
|
||||
"module_class_file": "{KERNEL_MODULES}/post/PostModule.php",
|
||||
|
@ -33,6 +33,9 @@ $form->field(class: \itguild\forms\inputs\Select::class, name: "user_id", params
|
||||
->setOptions(\kernel\modules\user\service\UserService::createUsernameArr())
|
||||
->render();
|
||||
|
||||
$entityRelations = new \kernel\EntityRelation();
|
||||
$entityRelations->renderEntityAdditionalPropertyFormBySlug("post");
|
||||
|
||||
?>
|
||||
<div class="row">
|
||||
<div class="col-sm-2">
|
||||
|
@ -3,6 +3,7 @@
|
||||
"version": "0.1",
|
||||
"author": "ITGuild",
|
||||
"slug": "user",
|
||||
"type": "entity",
|
||||
"description": "User module",
|
||||
"module_class": "kernel\\modules\\user\\UserModule",
|
||||
"module_class_file": "{KERNEL_MODULES}/user/UserModule.php",
|
||||
|
Loading…
Reference in New Issue
Block a user