slider
This commit is contained in:
parent
aff394ae72
commit
6c124e9bb7
38
app/modules/slider/SliderModule.php
Normal file
38
app/modules/slider/SliderModule.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\modules\slider;
|
||||||
|
|
||||||
|
use kernel\Module;
|
||||||
|
use kernel\modules\menu\service\MenuService;
|
||||||
|
use kernel\services\MigrationService;
|
||||||
|
|
||||||
|
class SliderModule extends Module
|
||||||
|
{
|
||||||
|
public MenuService $menuService;
|
||||||
|
public MigrationService $migrationService;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->menuService = new MenuService();
|
||||||
|
$this->migrationService = new MigrationService();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function init(): void
|
||||||
|
{
|
||||||
|
$this->migrationService->runAtPath("{KERNEL_APP_MODULES}/slider/migrations");
|
||||||
|
|
||||||
|
$this->menuService->createItem([
|
||||||
|
"label" => "Слайдер",
|
||||||
|
"url" => "/admin/slider",
|
||||||
|
"slug" => "slider",
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deactivate(): void
|
||||||
|
{
|
||||||
|
$this->menuService->removeItemBySlug("slider");
|
||||||
|
}
|
||||||
|
}
|
35
app/modules/slider/controllers/SliderController.php
Normal file
35
app/modules/slider/controllers/SliderController.php
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\modules\slider\controllers;
|
||||||
|
|
||||||
|
use app\modules\slider\models\Slider;
|
||||||
|
use Exception;
|
||||||
|
use kernel\AdminController;
|
||||||
|
|
||||||
|
class SliderController extends AdminController
|
||||||
|
{
|
||||||
|
protected function init(): void
|
||||||
|
{
|
||||||
|
parent::init();
|
||||||
|
$this->cgView->viewPath = KERNEL_APP_MODULES_DIR . "/photo/views/";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function actionIndex($page_number = 1): void
|
||||||
|
{
|
||||||
|
$this->cgView->render("index.php", ['page_number' => $page_number]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function actionView($id): void
|
||||||
|
{
|
||||||
|
$slide = Slider::find($id);
|
||||||
|
|
||||||
|
if (!$slide){
|
||||||
|
throw new Exception(message: "The slide not found");
|
||||||
|
}
|
||||||
|
$this->cgView->render("view.php", ['slider' => $slide]);
|
||||||
|
}
|
||||||
|
}
|
13
app/modules/slider/manifest.json
Normal file
13
app/modules/slider/manifest.json
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"name": "Slider",
|
||||||
|
"version": "0.1",
|
||||||
|
"author": "ITGuild",
|
||||||
|
"slug": "slider",
|
||||||
|
"type": "entity",
|
||||||
|
"description": "Slider module",
|
||||||
|
"app_module_path": "{APP}/modules/{slug}",
|
||||||
|
"module_class": "app\\modules\\slider\\SliderModule",
|
||||||
|
"module_class_file": "{APP}/modules/slider/SliderModule.php",
|
||||||
|
"routs": "routs/slider.php",
|
||||||
|
"dependence": "menu, user"
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
\kernel\App::$db->schema->create('slider', function (Blueprint $table) {
|
||||||
|
$table->increments('id');
|
||||||
|
$table->string('title', 255)->nullable(false);
|
||||||
|
$table->string('additional_information', 255)->nullable(false);
|
||||||
|
$table->string('content', 255)->nullable(false);
|
||||||
|
$table->integer('status')->default(0);
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
\kernel\App::$db->schema->dropIfExists('slider');
|
||||||
|
}
|
||||||
|
};
|
39
app/modules/slider/models/Slider.php
Normal file
39
app/modules/slider/models/Slider.php
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\modules\slider\models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property int $id
|
||||||
|
* @property string $title
|
||||||
|
* @property string $additionalInformation
|
||||||
|
* @property string $content
|
||||||
|
*/
|
||||||
|
|
||||||
|
class Slider extends Model
|
||||||
|
{
|
||||||
|
const int DISABLE_STATUS = 0;
|
||||||
|
const int ACTIVE_STATUS = 1;
|
||||||
|
|
||||||
|
protected $table = "slider";
|
||||||
|
protected $fillable = ['title', 'additional_information', 'content'];
|
||||||
|
|
||||||
|
public static function labels()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'title' => 'Заголовок',
|
||||||
|
'additional_information' => 'Дополнительная информация',
|
||||||
|
'content' => 'Контент'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getStatus(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
self::DISABLE_STATUS => "Не активный",
|
||||||
|
self::ACTIVE_STATUS => "Активный",
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
20
app/modules/slider/routs/slider.php
Normal file
20
app/modules/slider/routs/slider.php
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use kernel\App;
|
||||||
|
use kernel\CgRouteCollector;
|
||||||
|
use Phroute\Phroute\RouteCollector;
|
||||||
|
|
||||||
|
App::$collector->group(["prefix" => "admin"], function (CgRouteCollector $router) {
|
||||||
|
App::$collector->group(["before" => "auth"], function (RouteCollector $router) {
|
||||||
|
App::$collector->group(["prefix" => "slider"], function (CGRouteCollector $router) {
|
||||||
|
App::$collector->get('/', [\app\modules\slider\controllers\SliderController::class, 'actionIndex']);
|
||||||
|
App::$collector->get('/page/{page_number}', [\app\modules\slider\controllers\SliderController::class, 'actionIndex']);
|
||||||
|
App::$collector->get('/create', [\app\modules\slider\controllers\SliderController::class, 'actionCreate']);
|
||||||
|
App::$collector->post("/", [\app\modules\slider\controllers\SliderController::class, 'actionAdd']);
|
||||||
|
App::$collector->get('/view/{id}', [\app\modules\slider\controllers\SliderController::class, 'actionView']);
|
||||||
|
App::$collector->any('/update/{id}', [\app\modules\slider\controllers\SliderController::class, 'actionUpdate']);
|
||||||
|
App::$collector->any("/edit/{id}", [\app\modules\slider\controllers\SliderController::class, 'actionEdit']);
|
||||||
|
App::$collector->get('/delete/{id}', [\app\modules\slider\controllers\SliderController::class]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
43
app/modules/slider/views/index.php
Normal file
43
app/modules/slider/views/index.php
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @var int $page_number
|
||||||
|
*/
|
||||||
|
|
||||||
|
use app\modules\slider\models\Slider;
|
||||||
|
use Itguild\EloquentTable\EloquentDataProvider;
|
||||||
|
use Itguild\EloquentTable\ListEloquentTable;
|
||||||
|
use kernel\app_modules\photo\models\Photo;
|
||||||
|
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(Slider::class, [
|
||||||
|
'currentPage' => $page_number,
|
||||||
|
'perPage' => 8,
|
||||||
|
'params' => ["class" => "table table-bordered", "border" => "2"],
|
||||||
|
'baseUrl' => "/admin/photo",
|
||||||
|
]));
|
||||||
|
|
||||||
|
$table->beforePrint(function () {
|
||||||
|
return IconBtnCreateWidget::create(['url' => '/admin/slider/create'])->run();
|
||||||
|
});
|
||||||
|
|
||||||
|
$table->columns([
|
||||||
|
"status" => [
|
||||||
|
"value" => function ($cell) {
|
||||||
|
return Slider::getStatus()[$cell];
|
||||||
|
}]
|
||||||
|
]);
|
||||||
|
|
||||||
|
$table->addAction(function($row) {
|
||||||
|
return IconBtnViewWidget::create(['url' => '/admin/slider/view/' . $row['id']])->run();
|
||||||
|
});
|
||||||
|
$table->addAction(function($row) {
|
||||||
|
return IconBtnEditWidget::create(['url' => '/admin/slider/update/' . $row['id']])->run();
|
||||||
|
});
|
||||||
|
$table->addAction(function($row) {
|
||||||
|
return IconBtnDeleteWidget::create(['url' => '/admin/slider/delete/' . $row['id']])->run();
|
||||||
|
});
|
||||||
|
$table->create();
|
||||||
|
$table->render();
|
29
app/modules/slider/views/view.php
Normal file
29
app/modules/slider/views/view.php
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \Illuminate\Database\Eloquent\Collection $slider
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Itguild\EloquentTable\ViewEloquentTable;
|
||||||
|
use Itguild\EloquentTable\ViewJsonTableEloquentModel;
|
||||||
|
use kernel\IGTabel\btn\DangerBtn;
|
||||||
|
use kernel\IGTabel\btn\PrimaryBtn;
|
||||||
|
use kernel\IGTabel\btn\SuccessBtn;
|
||||||
|
|
||||||
|
$table = new ViewEloquentTable(new ViewJsonTableEloquentModel($slider, [
|
||||||
|
'params' => ["class" => "table table-bordered", "border" => "2"],
|
||||||
|
'baseUrl' => "/admin/slider",
|
||||||
|
]));
|
||||||
|
$table->beforePrint(function () use ($slider) {
|
||||||
|
$btn = PrimaryBtn::create("Список", "/admin/slider")->fetch();
|
||||||
|
$btn .= SuccessBtn::create("Редактировать", "/admin/slider/update/" . $slider->id)->fetch();
|
||||||
|
$btn .= DangerBtn::create("Удалить", "/admin/slider/delete/" . $slider->id)->fetch();
|
||||||
|
return $btn;
|
||||||
|
});
|
||||||
|
$table->rows([
|
||||||
|
'status' => (function ($data) {
|
||||||
|
return \app\modules\slider\models\Slider::getStatus()[$data];
|
||||||
|
})
|
||||||
|
]);
|
||||||
|
$table->create();
|
||||||
|
$table->render();
|
Loading…
Reference in New Issue
Block a user