kernel update
This commit is contained in:
@ -6,9 +6,12 @@ namespace kernel\modules\post\controllers;
|
||||
use Exception;
|
||||
use JetBrains\PhpStorm\NoReturn;
|
||||
use kernel\AdminController;
|
||||
use kernel\EntityRelation;
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\modules\post\models\forms\CreatePostForm;
|
||||
use kernel\modules\post\models\Post;
|
||||
use kernel\modules\post\service\PostService;
|
||||
use kernel\Request;
|
||||
|
||||
class PostController extends AdminController
|
||||
{
|
||||
@ -31,6 +34,10 @@ class PostController extends AdminController
|
||||
$postForm->load($_REQUEST);
|
||||
if ($postForm->validate()) {
|
||||
$post = $this->postService->create($postForm);
|
||||
|
||||
$entityRelation = new EntityRelation();
|
||||
$entityRelation->saveEntityRelation(entity: "post", model: $post, request: new Request());
|
||||
|
||||
if ($post) {
|
||||
$this->redirect("/admin/post/view/" . $post->id);
|
||||
}
|
||||
@ -86,6 +93,10 @@ class PostController extends AdminController
|
||||
$postForm->load($_REQUEST);
|
||||
if ($postForm->validate()) {
|
||||
$post = $this->postService->update($postForm, $post);
|
||||
|
||||
$entityRelation = new EntityRelation();
|
||||
$entityRelation->saveEntityRelation(entity: "post", model: $post, request: new Request());
|
||||
|
||||
if ($post) {
|
||||
$this->redirect("/admin/post/view/" . $post->id);
|
||||
}
|
||||
@ -102,6 +113,10 @@ class PostController extends AdminController
|
||||
if (!$post){
|
||||
throw new Exception(message: "The post not found");
|
||||
}
|
||||
|
||||
$entityRelation = new EntityRelation();
|
||||
$entityRelation->deleteEntityRelation(entity: "post", model: $post);
|
||||
|
||||
$post->delete();
|
||||
$this->redirect("/admin/post/");
|
||||
}
|
||||
|
@ -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",
|
||||
|
@ -6,7 +6,7 @@
|
||||
use kernel\modules\post\models\Post;
|
||||
|
||||
$form = new \itguild\forms\ActiveForm();
|
||||
$form->beginForm(isset($model) ? "/admin/post/edit/" . $model->id : "/admin/post");
|
||||
$form->beginForm(isset($model) ? "/admin/post/edit/" . $model->id : "/admin/post", 'multipart/form-data');
|
||||
|
||||
$form->field(\itguild\forms\inputs\TextInput::class, 'title', [
|
||||
'class' => "form-control",
|
||||
@ -33,6 +33,12 @@ $form->field(class: \itguild\forms\inputs\Select::class, name: "user_id", params
|
||||
->setOptions(\kernel\modules\user\service\UserService::createUsernameArr())
|
||||
->render();
|
||||
|
||||
$entityRelations = new \kernel\EntityRelation();
|
||||
if (!isset($model)) {
|
||||
$model = new Post();
|
||||
}
|
||||
$entityRelations->renderEntityAdditionalPropertyFormBySlug("post", $model);
|
||||
|
||||
?>
|
||||
<div class="row">
|
||||
<div class="col-sm-2">
|
||||
|
@ -13,6 +13,10 @@ use kernel\modules\user\models\User;
|
||||
use Itguild\EloquentTable\EloquentDataProvider;
|
||||
use Itguild\EloquentTable\ListEloquentTable;
|
||||
use kernel\IGTabel\btn\PrimaryBtn;
|
||||
use kernel\widgets\IconBtn\IconBtnCreateWidget;
|
||||
use kernel\widgets\IconBtn\IconBtnDeleteWidget;
|
||||
use kernel\widgets\IconBtn\IconBtnEditWidget;
|
||||
use kernel\widgets\IconBtn\IconBtnViewWidget;
|
||||
|
||||
$table = new ListEloquentTable(new EloquentDataProvider(Post::class, [
|
||||
'currentPage' => $page_number,
|
||||
@ -20,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){
|
||||
@ -39,12 +53,18 @@ $table->columns([
|
||||
return User::find($data)->username;
|
||||
})
|
||||
]);
|
||||
|
||||
$table->beforePrint(function () {
|
||||
return PrimaryBtn::create("Создать", "/admin/post/create")->fetch();
|
||||
//return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch();
|
||||
return IconBtnCreateWidget::create(['url' => '/admin/post/create'])->run();
|
||||
});
|
||||
$table->addAction(function($row) {
|
||||
return IconBtnViewWidget::create(['url' => '/admin/post/view/' . $row['id']])->run();
|
||||
});
|
||||
$table->addAction(function($row) {
|
||||
return IconBtnEditWidget::create(['url' => '/admin/post/update/' . $row['id']])->run();
|
||||
});
|
||||
$table->addAction(function($row) {
|
||||
return IconBtnDeleteWidget::create(['url' => '/admin/post/delete/' . $row['id']])->run();
|
||||
});
|
||||
$table->addAction(ViewActionColumn::class);
|
||||
$table->addAction(EditActionColumn::class);
|
||||
$table->addAction(DeleteActionColumn::class);
|
||||
$table->create();
|
||||
$table->render();
|
@ -10,26 +10,39 @@ use Itguild\EloquentTable\ViewJsonTableEloquentModel;
|
||||
use kernel\IGTabel\btn\DangerBtn;
|
||||
use kernel\IGTabel\btn\PrimaryBtn;
|
||||
use kernel\IGTabel\btn\SuccessBtn;
|
||||
use kernel\widgets\IconBtn\IconBtnDeleteWidget;
|
||||
use kernel\widgets\IconBtn\IconBtnEditWidget;
|
||||
use kernel\widgets\IconBtn\IconBtnListWidget;
|
||||
|
||||
$table = new ViewEloquentTable(new ViewJsonTableEloquentModel($content, [
|
||||
'params' => ["class" => "table table-bordered", "border" => "2"],
|
||||
'baseUrl' => "/admin/post",
|
||||
]));
|
||||
$table->beforePrint(function () use ($content) {
|
||||
$btn = PrimaryBtn::create("Список", "/admin/post")->fetch();
|
||||
$btn .= SuccessBtn::create("Редактировать", "/admin/post/update/" . $content->id)->fetch();
|
||||
$btn .= DangerBtn::create("Удалить", "/admin/post/delete/" . $content->id)->fetch();
|
||||
$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();
|
||||
return $btn;
|
||||
});
|
||||
|
||||
$entityRelation = new \kernel\EntityRelation();
|
||||
$additionals = $entityRelation->getEntityAdditionalProperty("post", $content);
|
||||
|
||||
foreach ($additionals as $key => $additional) {
|
||||
$table->addRow($key, function () use ($additional) {
|
||||
return $additional;
|
||||
}, ['after' => 'user_id']);
|
||||
}
|
||||
|
||||
$table->rows([
|
||||
'created_at' => function ($data) {
|
||||
if (!$data){
|
||||
if (!$data) {
|
||||
return null;
|
||||
}
|
||||
return (new DateTimeImmutable($data))->format("d-m-Y");
|
||||
},
|
||||
'updated_at' => function ($data) {
|
||||
if (!$data){
|
||||
if (!$data) {
|
||||
return null;
|
||||
}
|
||||
return (new DateTimeImmutable($data))->format("d-m-Y");
|
||||
|
Reference in New Issue
Block a user