additionsl property at list
This commit is contained in:
parent
921569b950
commit
e7a20d9b97
@ -8,6 +8,7 @@ use itguild\forms\builders\TextInputBuilder;
|
||||
use itguild\forms\inputs\Select;
|
||||
use kernel\app_modules\tag\models\Tag;
|
||||
use kernel\app_modules\tag\models\TagEntity;
|
||||
use kernel\app_modules\tag\services\TagEntityService;
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\helpers\Slug;
|
||||
use kernel\Module;
|
||||
@ -61,14 +62,8 @@ class TagModule extends Module
|
||||
|
||||
public function formInputs(string $entity, Model $model = null): void
|
||||
{
|
||||
if (isset($model)) {
|
||||
$tags= TagEntity::where("entity_id", $model->id)->get()->toArray();
|
||||
$value = [];
|
||||
foreach ($tags as $tag) {
|
||||
$val = Tag::where('id', $tag['tag_id'])->first()->toArray();
|
||||
$value[] = $val['label'];
|
||||
}
|
||||
|
||||
if (isset($model->id)) {
|
||||
$value = TagEntityService::getTagsByEntity($entity, $model->id);
|
||||
}
|
||||
$input = SelectBuilder::build("tag[]", [
|
||||
'class' => 'form-control',
|
||||
@ -107,6 +102,17 @@ class TagModule extends Module
|
||||
return substr($tagsStr, 0, -2);
|
||||
}
|
||||
|
||||
public function getItem(string $entity, string $entity_id): string
|
||||
{
|
||||
$tags = TagEntity::where("entity", $entity)->where("entity_id", $entity_id)->get();
|
||||
$tagsStr = "";
|
||||
foreach ($tags as $tag) {
|
||||
$tagsStr .= $tag->tag->label . ", ";
|
||||
}
|
||||
|
||||
return substr($tagsStr, 0, -2);
|
||||
}
|
||||
|
||||
public function deleteItems(string $entity, Model $model): void
|
||||
{
|
||||
TagEntity::where("entity", $entity)->where("entity_id", $model->id)->delete();
|
||||
|
@ -204,6 +204,16 @@ class EntityRelation
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getAdditionalPropertyByEntityId(string $entity, string $entity_id, string $additionalPropertySlug): string
|
||||
{
|
||||
$moduleClass = $this->getAdditionalPropertyClassBySlug($additionalPropertySlug);
|
||||
if ($moduleClass and method_exists($moduleClass, "getItem")) {
|
||||
return $moduleClass->getItem($entity, $entity_id);
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
public function deleteEntityRelationBySlug(string $slug, string $entity, Model $model): void
|
||||
{
|
||||
$moduleClass = $this->getAdditionalPropertyClassBySlug($slug);
|
||||
|
@ -5,6 +5,7 @@ namespace kernel\app_modules\tag\services;
|
||||
use kernel\app_modules\tag\models\Tag;
|
||||
use kernel\app_modules\tag\models\TagEntity;
|
||||
use kernel\FormModel;
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\helpers\Slug;
|
||||
|
||||
class TagEntityService
|
||||
@ -36,4 +37,15 @@ class TagEntityService
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getTagsByEntity(string $entity, int $entity_id): array
|
||||
{
|
||||
$tags= TagEntity::where("entity_id", $entity_id)->where("entity", $entity)->get();
|
||||
$value = [];
|
||||
foreach ($tags as $tag) {
|
||||
$value[$tag->id] = $tag->tag->label;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
}
|
@ -24,6 +24,16 @@ $table = new ListEloquentTable(new EloquentDataProvider(Post::class, [
|
||||
'params' => ["class" => "table table-bordered", "border" => "2"],
|
||||
'baseUrl' => "/admin/post"
|
||||
]));
|
||||
|
||||
$entityRelation = new \kernel\EntityRelation();
|
||||
$additionals = $entityRelation->getEntityRelationsBySlug("post");
|
||||
|
||||
foreach ($additionals as $additional) {
|
||||
$table->addColumn($additional, $additional, function ($id) use ($entityRelation, $additional) {
|
||||
return $entityRelation->getAdditionalPropertyByEntityId("post", $id, $additional);
|
||||
});
|
||||
}
|
||||
|
||||
$table->columns([
|
||||
'created_at' => function ($data) {
|
||||
if (!$data){
|
||||
|
Loading…
Reference in New Issue
Block a user