fix slider

This commit is contained in:
Билай Станислав 2024-12-10 11:56:33 +03:00
parent bfeb2d3c56
commit c7549c225f
11 changed files with 50 additions and 11 deletions

View File

@ -0,0 +1,12 @@
<?php
namespace app\modules\slider;
use kernel\Module;
use kernel\modules\menu\service\MenuService;
use kernel\services\MigrationService;
class SliderModule extends \kernel\app_modules\slider\SliderModule
{
}

View File

@ -0,0 +1,8 @@
<?php
namespace app\modules\slider\controllers;
class SliderController extends \kernel\app_modules\slider\controllers\SliderController
{
}

View File

@ -5,9 +5,9 @@
"slug": "slider", "slug": "slider",
"type": "entity", "type": "entity",
"description": "Slider module", "description": "Slider module",
"module_class": "kernel\\app_modules\\slider\\SliderModule", "app_module_path": "{APP}/modules/{slug}",
"module_class_file": "{KERNEL_APP_MODULES}/slider/SliderModule.php", "module_class": "app\\modules\\slider\\SliderModule",
"module_class_file": "{APP}/modules/slider/SliderModule.php",
"routs": "routs/slider.php", "routs": "routs/slider.php",
"migration_path": "migrations",
"dependence": "menu" "dependence": "menu"
} }

View File

@ -0,0 +1,2 @@
<?php
include KERNEL_APP_MODULES_DIR . "/slider/routs/slider.php";

View File

@ -1,6 +1,6 @@
<?php <?php
namespace kernel\modules\slider; namespace kernel\app_modules\slider;
use kernel\Module; use kernel\Module;
use kernel\modules\menu\service\MenuService; use kernel\modules\menu\service\MenuService;

View File

@ -18,7 +18,7 @@ class SliderController extends AdminController
protected function init(): void protected function init(): void
{ {
parent::init(); parent::init();
$this->cgView->viewPath = KERNEL_MODULES_DIR . "/slider/views/"; $this->cgView->viewPath = KERNEL_APP_MODULES_DIR . "/slider/views/";
$this->sliderService = new SliderService(); $this->sliderService = new SliderService();
} }
@ -35,7 +35,7 @@ class SliderController extends AdminController
$slider = $this->sliderService->create($sliderForm); $slider = $this->sliderService->create($sliderForm);
$entityRelation = new EntityRelation(); $entityRelation = new EntityRelation();
$entityRelation->saveEntityRelation(entity: "post", model: $slider, request: new Request()); $entityRelation->saveEntityRelation(entity: "slider", model: $slider, request: new Request());
if ($slider) { if ($slider) {
$this->redirect("/admin/slider/view/" . $slider->id); $this->redirect("/admin/slider/view/" . $slider->id);

View File

@ -18,9 +18,9 @@ class Slider extends Model
const int ACTIVE_STATUS = 1; const int ACTIVE_STATUS = 1;
protected $table = "slider"; 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 [ return [
'title' => 'Заголовок', 'title' => 'Заголовок',

View File

@ -4,8 +4,6 @@ namespace kernel\app_modules\slider\services;
use kernel\app_modules\slider\models\Slider; use kernel\app_modules\slider\models\Slider;
use kernel\helpers\Debug; use kernel\helpers\Debug;
use kernel\helpers\Slug;
use kernel\modules\post\models\Post;
use kernel\FormModel; use kernel\FormModel;
class SliderService class SliderService

View File

@ -1,6 +1,6 @@
<?php <?php
/** /**
* @var Slider $slider * @var Slider $model
*/ */
use kernel\app_modules\slider\models\Slider; use kernel\app_modules\slider\models\Slider;

View File

@ -23,6 +23,15 @@ $table->beforePrint(function () {
return IconBtnCreateWidget::create(['url' => '/admin/slider/create'])->run(); 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([ $table->columns([
"status" => [ "status" => [
"value" => function ($cell) { "value" => function ($cell) {

View File

@ -20,6 +20,16 @@ $table->beforePrint(function () use ($slider) {
$btn .= \kernel\widgets\IconBtn\IconBtnDeleteWidget::create(['url' => "/admin/slider/delete/" . $slider->id])->run(); $btn .= \kernel\widgets\IconBtn\IconBtnDeleteWidget::create(['url' => "/admin/slider/delete/" . $slider->id])->run();
return $btn; 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([ $table->rows([
'status' => (function ($data) { 'status' => (function ($data) {
return \kernel\app_modules\slider\models\Slider::getStatus()[$data]; return \kernel\app_modules\slider\models\Slider::getStatus()[$data];