From c7549c225f0bb3fca7fb86beb2b216058e10b585 Mon Sep 17 00:00:00 2001 From: stasbilay02 Date: Tue, 10 Dec 2024 11:56:33 +0300 Subject: [PATCH] fix slider --- app/modules/slider/SliderModule.php | 12 ++++++++++++ app/modules/slider/controllers/SliderController.php | 8 ++++++++ .../app_modules => app/modules}/slider/manifest.json | 6 +++--- app/modules/slider/routs/slider.php | 2 ++ kernel/app_modules/slider/SliderModule.php | 2 +- .../slider/controllers/SliderController.php | 4 ++-- kernel/app_modules/slider/models/Slider.php | 4 ++-- kernel/app_modules/slider/services/SliderService.php | 2 -- kernel/app_modules/slider/views/form.php | 2 +- kernel/app_modules/slider/views/index.php | 9 +++++++++ kernel/app_modules/slider/views/view.php | 10 ++++++++++ 11 files changed, 50 insertions(+), 11 deletions(-) create mode 100644 app/modules/slider/SliderModule.php create mode 100644 app/modules/slider/controllers/SliderController.php rename {kernel/app_modules => app/modules}/slider/manifest.json (53%) create mode 100644 app/modules/slider/routs/slider.php diff --git a/app/modules/slider/SliderModule.php b/app/modules/slider/SliderModule.php new file mode 100644 index 0000000..413ae33 --- /dev/null +++ b/app/modules/slider/SliderModule.php @@ -0,0 +1,12 @@ +cgView->viewPath = KERNEL_MODULES_DIR . "/slider/views/"; + $this->cgView->viewPath = KERNEL_APP_MODULES_DIR . "/slider/views/"; $this->sliderService = new SliderService(); } @@ -35,7 +35,7 @@ class SliderController extends AdminController $slider = $this->sliderService->create($sliderForm); $entityRelation = new EntityRelation(); - $entityRelation->saveEntityRelation(entity: "post", model: $slider, request: new Request()); + $entityRelation->saveEntityRelation(entity: "slider", model: $slider, request: new Request()); if ($slider) { $this->redirect("/admin/slider/view/" . $slider->id); diff --git a/kernel/app_modules/slider/models/Slider.php b/kernel/app_modules/slider/models/Slider.php index b5347e0..bdef227 100644 --- a/kernel/app_modules/slider/models/Slider.php +++ b/kernel/app_modules/slider/models/Slider.php @@ -18,9 +18,9 @@ class Slider extends Model const int ACTIVE_STATUS = 1; protected $table = "slider"; - protected $fillable = ['title', 'additional_information', 'content', 'link']; + protected $fillable = ['title', 'additional_information', 'content', 'link', 'status']; - public static function labels() + public static function labels(): array { return [ 'title' => 'Заголовок', diff --git a/kernel/app_modules/slider/services/SliderService.php b/kernel/app_modules/slider/services/SliderService.php index 1298ba8..ad801ca 100644 --- a/kernel/app_modules/slider/services/SliderService.php +++ b/kernel/app_modules/slider/services/SliderService.php @@ -4,8 +4,6 @@ namespace kernel\app_modules\slider\services; use kernel\app_modules\slider\models\Slider; use kernel\helpers\Debug; -use kernel\helpers\Slug; -use kernel\modules\post\models\Post; use kernel\FormModel; class SliderService diff --git a/kernel/app_modules/slider/views/form.php b/kernel/app_modules/slider/views/form.php index 56518ca..ae1260f 100644 --- a/kernel/app_modules/slider/views/form.php +++ b/kernel/app_modules/slider/views/form.php @@ -1,6 +1,6 @@ beforePrint(function () { return IconBtnCreateWidget::create(['url' => '/admin/slider/create'])->run(); }); +$entityRelation = new \kernel\EntityRelation(); +$additionals = $entityRelation->getEntityRelationsBySlug("slider"); + +foreach ($additionals as $additional) { + $table->addColumn($additional, $additional, function ($id) use ($entityRelation, $additional) { + return $entityRelation->getAdditionalPropertyByEntityId("slider", $id, $additional); + }); +} + $table->columns([ "status" => [ "value" => function ($cell) { diff --git a/kernel/app_modules/slider/views/view.php b/kernel/app_modules/slider/views/view.php index 91bc9cd..5357289 100644 --- a/kernel/app_modules/slider/views/view.php +++ b/kernel/app_modules/slider/views/view.php @@ -20,6 +20,16 @@ $table->beforePrint(function () use ($slider) { $btn .= \kernel\widgets\IconBtn\IconBtnDeleteWidget::create(['url' => "/admin/slider/delete/" . $slider->id])->run(); return $btn; }); + +$entityRelation = new \kernel\EntityRelation(); +$additionals = $entityRelation->getEntityAdditionalProperty("slider", $slider); + +foreach ($additionals as $key => $additional) { + $table->addRow($key, function () use ($additional) { + return $additional; + }, ['after' => 'status']); +} + $table->rows([ 'status' => (function ($data) { return \kernel\app_modules\slider\models\Slider::getStatus()[$data];