MicroFrameWork/kernel/modules/post/views/view.php

52 lines
1.6 KiB
PHP
Raw Normal View History

2024-07-25 16:15:18 +03:00
<?php
/**
2024-07-26 11:57:05 +03:00
* @var \Illuminate\Database\Eloquent\Collection $content
2024-07-25 16:15:18 +03:00
*/
2024-08-07 15:30:45 +03:00
2024-09-06 16:53:20 +03:00
use kernel\modules\user\models\User;
2024-08-07 15:30:45 +03:00
use Itguild\EloquentTable\ViewEloquentTable;
use Itguild\EloquentTable\ViewJsonTableEloquentModel;
2024-11-20 12:45:02 +03:00
use kernel\widgets\IconBtn\IconBtnDeleteWidget;
use kernel\widgets\IconBtn\IconBtnEditWidget;
use kernel\widgets\IconBtn\IconBtnListWidget;
2024-07-25 16:15:18 +03:00
2024-08-07 15:30:45 +03:00
$table = new ViewEloquentTable(new ViewJsonTableEloquentModel($content, [
2024-07-25 16:15:18 +03:00
'params' => ["class" => "table table-bordered", "border" => "2"],
2024-08-07 15:30:45 +03:00
'baseUrl' => "/admin/post",
]));
$table->beforePrint(function () use ($content) {
2024-11-20 12:45:02 +03:00
$btn = IconBtnListWidget::create(['url' => '/admin/post'])->run();
$btn .= IconBtnEditWidget::create(['url' => '/admin/post/update/' . $content->id])->run();
$btn .= IconBtnDeleteWidget::create(['url' => '/admin/post/delete/' . $content->id])->run();
2024-07-25 16:15:18 +03:00
return $btn;
});
2024-11-20 12:45:02 +03:00
2024-11-27 17:11:06 +03:00
$entityRelation = new \kernel\EntityRelation();
2024-11-28 12:15:30 +03:00
$additionals = $entityRelation->getEntityAdditionalProperty("post", $content);
foreach ($additionals as $key => $additional) {
$table->addRow($key, function () use ($additional) {
return $additional;
}, ['after' => 'user_id']);
}
2024-11-27 17:11:06 +03:00
2024-08-07 15:30:45 +03:00
$table->rows([
'created_at' => function ($data) {
2024-11-28 12:15:30 +03:00
if (!$data) {
2024-08-07 15:30:45 +03:00
return null;
}
return (new DateTimeImmutable($data))->format("d-m-Y");
},
'updated_at' => function ($data) {
2024-11-28 12:15:30 +03:00
if (!$data) {
2024-08-07 15:30:45 +03:00
return null;
}
return (new DateTimeImmutable($data))->format("d-m-Y");
},
'user_id' => (function ($data) {
return User::find($data)->username;
})
]);
2024-07-25 16:15:18 +03:00
$table->create();
$table->render();