option CRUD
This commit is contained in:
parent
f4971f1c7d
commit
0f05bc2391
@ -1,17 +1,17 @@
|
|||||||
<?php
|
<?php
|
||||||
|
//
|
||||||
namespace app\tables\columns\menu;
|
//namespace app\tables\columns\menu;
|
||||||
|
//
|
||||||
use Itguild\Tables\ActionColumn\ActionColumn;
|
//use Itguild\Tables\ActionColumn\ActionColumn;
|
||||||
|
//
|
||||||
class MenuDeleteActionColumn extends ActionColumn
|
//class MenuDeleteActionColumn extends ActionColumn
|
||||||
{
|
//{
|
||||||
|
//
|
||||||
protected string $prefix = "/delete/";
|
// protected string $prefix = "/delete/";
|
||||||
|
//
|
||||||
public function fetch(): string
|
// public function fetch(): string
|
||||||
{
|
// {
|
||||||
$link = $this->baseUrl . $this->prefix . $this->id;
|
// $link = $this->baseUrl . $this->prefix . $this->id;
|
||||||
return " <a href='$link' class='btn btn-danger'>Удалить</a> ";
|
// return " <a href='$link' class='btn btn-danger'>Удалить</a> ";
|
||||||
}
|
// }
|
||||||
}
|
//}
|
@ -1,17 +1,17 @@
|
|||||||
<?php
|
<?php
|
||||||
|
//
|
||||||
namespace app\tables\columns\menu;
|
//namespace app\tables\columns\menu;
|
||||||
|
//
|
||||||
use Itguild\Tables\ActionColumn\ActionColumn;
|
//use Itguild\Tables\ActionColumn\ActionColumn;
|
||||||
|
//
|
||||||
class MenuEditActionColumn extends ActionColumn
|
//class MenuEditActionColumn extends ActionColumn
|
||||||
{
|
//{
|
||||||
|
//
|
||||||
protected string $prefix = "/update/";
|
// protected string $prefix = "/update/";
|
||||||
|
//
|
||||||
public function fetch(): string
|
// public function fetch(): string
|
||||||
{
|
// {
|
||||||
$link = $this->baseUrl . $this->prefix . $this->id;
|
// $link = $this->baseUrl . $this->prefix . $this->id;
|
||||||
return " <a href='$link' class='btn btn-success'>Редактировать</a> ";
|
// return " <a href='$link' class='btn btn-success'>Редактировать</a> ";
|
||||||
}
|
// }
|
||||||
}
|
//}
|
@ -1,17 +1,17 @@
|
|||||||
<?php
|
<?php
|
||||||
|
//
|
||||||
namespace app\tables\columns\menu;
|
//namespace app\tables\columns\menu;
|
||||||
|
//
|
||||||
use Itguild\Tables\ActionColumn\ActionColumn;
|
//use Itguild\Tables\ActionColumn\ActionColumn;
|
||||||
|
//
|
||||||
class MenuViewActionColumn extends ActionColumn
|
//class MenuViewActionColumn extends ActionColumn
|
||||||
{
|
//{
|
||||||
|
//
|
||||||
protected string $prefix = "/";
|
// protected string $prefix = "/";
|
||||||
|
//
|
||||||
public function fetch(): string
|
// public function fetch(): string
|
||||||
{
|
// {
|
||||||
$link = $this->baseUrl . $this->prefix . $this->id;
|
// $link = $this->baseUrl . $this->prefix . $this->id;
|
||||||
return " <a href='$link' class='btn btn-primary'>Просмотр</a> ";
|
// return " <a href='$link' class='btn btn-primary'>Просмотр</a> ";
|
||||||
}
|
// }
|
||||||
}
|
//}
|
@ -1,16 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
|
//
|
||||||
namespace app\tables\columns\post;
|
//namespace app\tables\columns\post;
|
||||||
|
//
|
||||||
use Itguild\Tables\ActionColumn\ActionColumn;
|
//use Itguild\Tables\ActionColumn\ActionColumn;
|
||||||
|
//
|
||||||
class PostDeleteActionColumn extends ActionColumn
|
//class PostDeleteActionColumn extends ActionColumn
|
||||||
{
|
//{
|
||||||
protected string $prefix = "/delete/";
|
// protected string $prefix = "/delete/";
|
||||||
|
//
|
||||||
public function fetch(): string
|
// public function fetch(): string
|
||||||
{
|
// {
|
||||||
$link = $this->baseUrl . $this->prefix . $this->id;
|
// $link = $this->baseUrl . $this->prefix . $this->id;
|
||||||
return " <a href='$link' class='btn btn-danger'>Удалить</a> ";
|
// return " <a href='$link' class='btn btn-danger'>Удалить</a> ";
|
||||||
}
|
// }
|
||||||
}
|
//}
|
@ -1,16 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
|
//
|
||||||
namespace app\tables\columns\post;
|
//namespace app\tables\columns\post;
|
||||||
|
//
|
||||||
use Itguild\Tables\ActionColumn\ActionColumn;
|
//use Itguild\Tables\ActionColumn\ActionColumn;
|
||||||
|
//
|
||||||
class PostEditActionColumn extends ActionColumn
|
//class PostEditActionColumn extends ActionColumn
|
||||||
{
|
//{
|
||||||
protected string $prefix = "/update/";
|
// protected string $prefix = "/update/";
|
||||||
|
//
|
||||||
public function fetch(): string
|
// public function fetch(): string
|
||||||
{
|
// {
|
||||||
$link = $this->baseUrl . $this->prefix . $this->id;
|
// $link = $this->baseUrl . $this->prefix . $this->id;
|
||||||
return " <a href='$link' class='btn btn-success'>Редактировать</a> ";
|
// return " <a href='$link' class='btn btn-success'>Редактировать</a> ";
|
||||||
}
|
// }
|
||||||
}
|
//}
|
@ -1,16 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
|
//
|
||||||
namespace app\tables\columns\post;
|
//namespace app\tables\columns\post;
|
||||||
|
//
|
||||||
use Itguild\Tables\ActionColumn\ActionColumn;
|
//use Itguild\Tables\ActionColumn\ActionColumn;
|
||||||
|
//
|
||||||
class PostViewActionColumn extends actionColumn
|
//class PostViewActionColumn extends actionColumn
|
||||||
{
|
//{
|
||||||
protected string $prefix = "/";
|
// protected string $prefix = "/";
|
||||||
|
//
|
||||||
public function fetch(): string
|
// public function fetch(): string
|
||||||
{
|
// {
|
||||||
$link = $this->baseUrl . $this->prefix . $this->id;
|
// $link = $this->baseUrl . $this->prefix . $this->id;
|
||||||
return " <a href='$link' class='btn btn-primary'>Просмотр</a> ";
|
// return " <a href='$link' class='btn btn-primary'>Просмотр</a> ";
|
||||||
}
|
// }
|
||||||
}
|
//}
|
@ -1,16 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
|
//
|
||||||
namespace app\tables\columns\user;
|
//namespace app\tables\columns\user;
|
||||||
|
//
|
||||||
use Itguild\Tables\ActionColumn\ActionColumn;
|
//use Itguild\Tables\ActionColumn\ActionColumn;
|
||||||
|
//
|
||||||
class UserDeleteActionColumn extends ActionColumn
|
//class UserDeleteActionColumn extends ActionColumn
|
||||||
{
|
//{
|
||||||
protected string $prefix = "/delete/";
|
// protected string $prefix = "/delete/";
|
||||||
|
//
|
||||||
public function fetch(): string
|
// public function fetch(): string
|
||||||
{
|
// {
|
||||||
$link = $this->baseUrl . $this->prefix . $this->id;
|
// $link = $this->baseUrl . $this->prefix . $this->id;
|
||||||
return " <a href='$link' class='btn btn-danger'>Удалить</a> ";
|
// return " <a href='$link' class='btn btn-danger'>Удалить</a> ";
|
||||||
}
|
// }
|
||||||
}
|
//}
|
@ -1,16 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
|
//
|
||||||
namespace app\tables\columns\user;
|
//namespace app\tables\columns\user;
|
||||||
|
//
|
||||||
use Itguild\Tables\ActionColumn\ActionColumn;
|
//use Itguild\Tables\ActionColumn\ActionColumn;
|
||||||
|
//
|
||||||
class UserEditActionColumn extends ActionColumn
|
//class UserEditActionColumn extends ActionColumn
|
||||||
{
|
//{
|
||||||
protected string $prefix = "/update/";
|
// protected string $prefix = "/update/";
|
||||||
|
//
|
||||||
public function fetch(): string
|
// public function fetch(): string
|
||||||
{
|
// {
|
||||||
$link = $this->baseUrl . $this->prefix . $this->id;
|
// $link = $this->baseUrl . $this->prefix . $this->id;
|
||||||
return " <a href='$link' class='btn btn-success'>Редактировать</a> ";
|
// return " <a href='$link' class='btn btn-success'>Редактировать</a> ";
|
||||||
}
|
// }
|
||||||
}
|
//}
|
@ -1,16 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
|
//
|
||||||
namespace app\tables\columns\user;
|
//namespace app\tables\columns\user;
|
||||||
|
//
|
||||||
use Itguild\Tables\ActionColumn\ActionColumn;
|
//use Itguild\Tables\ActionColumn\ActionColumn;
|
||||||
|
//
|
||||||
class UserViewActionColumn extends ActionColumn
|
//class UserViewActionColumn extends ActionColumn
|
||||||
{
|
//{
|
||||||
protected string $prefix = "/";
|
// protected string $prefix = "/";
|
||||||
|
//
|
||||||
public function fetch(): string
|
// public function fetch(): string
|
||||||
{
|
// {
|
||||||
$link = $this->baseUrl . $this->prefix . $this->id;
|
// $link = $this->baseUrl . $this->prefix . $this->id;
|
||||||
return " <a href='$link' class='btn btn-primary'>Просмотр</a> ";
|
// return " <a href='$link' class='btn btn-primary'>Просмотр</a> ";
|
||||||
}
|
// }
|
||||||
}
|
//}
|
17
kernel/modules/menu/table/columns/MenuDeleteActionColumn.php
Normal file
17
kernel/modules/menu/table/columns/MenuDeleteActionColumn.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel\modules\menu\table\columns;
|
||||||
|
|
||||||
|
use Itguild\Tables\ActionColumn\ActionColumn;
|
||||||
|
|
||||||
|
class MenuDeleteActionColumn extends ActionColumn
|
||||||
|
{
|
||||||
|
|
||||||
|
protected string $prefix = "/delete/";
|
||||||
|
|
||||||
|
public function fetch(): string
|
||||||
|
{
|
||||||
|
$link = $this->baseUrl . $this->prefix . $this->id;
|
||||||
|
return " <a href='$link' class='btn btn-danger'>Удалить</a> ";
|
||||||
|
}
|
||||||
|
}
|
17
kernel/modules/menu/table/columns/MenuEditActionColumn.php
Normal file
17
kernel/modules/menu/table/columns/MenuEditActionColumn.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel\modules\menu\table\columns;
|
||||||
|
|
||||||
|
use Itguild\Tables\ActionColumn\ActionColumn;
|
||||||
|
|
||||||
|
class MenuEditActionColumn extends ActionColumn
|
||||||
|
{
|
||||||
|
|
||||||
|
protected string $prefix = "/update/";
|
||||||
|
|
||||||
|
public function fetch(): string
|
||||||
|
{
|
||||||
|
$link = $this->baseUrl . $this->prefix . $this->id;
|
||||||
|
return " <a href='$link' class='btn btn-success'>Редактировать</a> ";
|
||||||
|
}
|
||||||
|
}
|
17
kernel/modules/menu/table/columns/MenuViewActionColumn.php
Normal file
17
kernel/modules/menu/table/columns/MenuViewActionColumn.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel\modules\menu\table\columns;
|
||||||
|
|
||||||
|
use Itguild\Tables\ActionColumn\ActionColumn;
|
||||||
|
|
||||||
|
class MenuViewActionColumn extends ActionColumn
|
||||||
|
{
|
||||||
|
|
||||||
|
protected string $prefix = "/";
|
||||||
|
|
||||||
|
public function fetch(): string
|
||||||
|
{
|
||||||
|
$link = $this->baseUrl . $this->prefix . $this->id;
|
||||||
|
return " <a href='$link' class='btn btn-primary'>Просмотр</a> ";
|
||||||
|
}
|
||||||
|
}
|
@ -4,13 +4,16 @@
|
|||||||
* @var int $page_number
|
* @var int $page_number
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use app\tables\columns\menu\MenuDeleteActionColumn;
|
//use app\tables\columns\menu\MenuDeleteActionColumn;
|
||||||
use app\tables\columns\menu\MenuEditActionColumn;
|
//use app\tables\columns\menu\MenuEditActionColumn;
|
||||||
use app\tables\columns\menu\MenuViewActionColumn;
|
//use app\tables\columns\menu\MenuViewActionColumn;
|
||||||
use Itguild\EloquentTable\EloquentDataProvider;
|
use Itguild\EloquentTable\EloquentDataProvider;
|
||||||
use Itguild\EloquentTable\ListEloquentTable;
|
use Itguild\EloquentTable\ListEloquentTable;
|
||||||
use kernel\IGTabel\btn\PrimaryBtn;
|
use kernel\IGTabel\btn\PrimaryBtn;
|
||||||
use kernel\models\Menu;
|
use kernel\models\Menu;
|
||||||
|
use kernel\modules\menu\table\columns\MenuDeleteActionColumn;
|
||||||
|
use kernel\modules\menu\table\columns\MenuEditActionColumn;
|
||||||
|
use kernel\modules\menu\table\columns\MenuViewActionColumn;
|
||||||
|
|
||||||
$table = new ListEloquentTable(new EloquentDataProvider(Menu::class, [
|
$table = new ListEloquentTable(new EloquentDataProvider(Menu::class, [
|
||||||
'currentPage' => $page_number,
|
'currentPage' => $page_number,
|
||||||
|
33
kernel/modules/option/OptionModule.php
Normal file
33
kernel/modules/option/OptionModule.php
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel\modules\option;
|
||||||
|
|
||||||
|
use kernel\Module;
|
||||||
|
use kernel\modules\menu\service\MenuService;
|
||||||
|
|
||||||
|
class OptionModule extends Module
|
||||||
|
{
|
||||||
|
|
||||||
|
public MenuService $menuService;
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->menuService = new MenuService();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function init(): void
|
||||||
|
{
|
||||||
|
$this->menuService->createItem([
|
||||||
|
"label" => "Опции",
|
||||||
|
"url" => "/admin/option",
|
||||||
|
"slug" => "option"
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deactivate(): void
|
||||||
|
{
|
||||||
|
$this->menuService->removeItemBySlug("option");
|
||||||
|
}
|
||||||
|
}
|
102
kernel/modules/option/controllers/OptionController.php
Normal file
102
kernel/modules/option/controllers/OptionController.php
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel\modules\option\controllers;
|
||||||
|
|
||||||
|
use JetBrains\PhpStorm\NoReturn;
|
||||||
|
use kernel\AdminController;
|
||||||
|
use kernel\helpers\Debug;
|
||||||
|
use kernel\modules\option\models\forms\CreateOptionForm;
|
||||||
|
use kernel\modules\option\models\Option;
|
||||||
|
use kernel\modules\option\service\OptionService;
|
||||||
|
|
||||||
|
class OptionController extends AdminController
|
||||||
|
{
|
||||||
|
|
||||||
|
private OptionService $optionService;
|
||||||
|
|
||||||
|
public function init(): void
|
||||||
|
{
|
||||||
|
parent::init();
|
||||||
|
$this->cgView->viewPath = KERNEL_MODULES_DIR . '/option/views/';
|
||||||
|
$this->optionService = new OptionService();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function actionCreate(): void
|
||||||
|
{
|
||||||
|
$this->cgView->render('form.php');
|
||||||
|
}
|
||||||
|
|
||||||
|
#[NoReturn] public function actionAdd(): void
|
||||||
|
{
|
||||||
|
$optionForm = new CreateOptionForm();
|
||||||
|
$optionForm->load($_REQUEST);
|
||||||
|
if ($optionForm->validate()) {
|
||||||
|
$option = $this->optionService->create($optionForm);
|
||||||
|
if ($option) {
|
||||||
|
$this->redirect('/admin/option');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->redirect('/admin/option/create');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function actionIndex($page_number = 1): void
|
||||||
|
{
|
||||||
|
$this->cgView->render('index.php', ['page_number' => $page_number]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function actionView(int $id): void
|
||||||
|
{
|
||||||
|
$option = Option::find($id);
|
||||||
|
|
||||||
|
if (!$option) {
|
||||||
|
throw new \Exception('Option not found');
|
||||||
|
}
|
||||||
|
$this->cgView->render("view.php", ['option' => $option]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function actionUpdate(int $id): void
|
||||||
|
{
|
||||||
|
$model = Option::find($id);
|
||||||
|
|
||||||
|
if (!$model) {
|
||||||
|
throw new \Exception('Option not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->cgView->render("form.php", ['model' => $model]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function actionEdit(int $id): void
|
||||||
|
{
|
||||||
|
Debug::prn($_REQUEST);
|
||||||
|
$option = Option::find($id);
|
||||||
|
if (!$option) {
|
||||||
|
throw new \Exception('Option not found');
|
||||||
|
}
|
||||||
|
$optionForm = new CreateOptionForm();
|
||||||
|
$optionService = new OptionService();
|
||||||
|
$optionForm->load($_REQUEST);
|
||||||
|
if ($optionForm->validate()) {
|
||||||
|
$option = $optionService->update($optionForm, $option);
|
||||||
|
if ($option) {
|
||||||
|
$this->redirect('/admin/option' . $option->id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->redirect('/admin/option/update' . $id);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[NoReturn] public function actionDelete(int $id): void
|
||||||
|
{
|
||||||
|
Option::find($id)->delete();
|
||||||
|
$this->redirect('/admin/option');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
10
kernel/modules/option/manifest.json
Normal file
10
kernel/modules/option/manifest.json
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"name": "Option",
|
||||||
|
"version": "0.1",
|
||||||
|
"author": "ITGuild",
|
||||||
|
"slug": "option",
|
||||||
|
"description": "Option module",
|
||||||
|
"module_class": "kernel\\modules\\option\\OptionModule",
|
||||||
|
"module_class_file": "{KERNEL_MODULES}/option/OptionModule.php",
|
||||||
|
"routs": "routs/option.php"
|
||||||
|
}
|
32
kernel/modules/option/models/Option.php
Normal file
32
kernel/modules/option/models/Option.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel\modules\option\models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property int $id
|
||||||
|
* @property string $key
|
||||||
|
* @property array|string $value
|
||||||
|
* @property string $label
|
||||||
|
* @property int $status
|
||||||
|
*/
|
||||||
|
|
||||||
|
class Option extends Model
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $table = 'option';
|
||||||
|
protected $fillable = ['key', 'value', 'label', 'status'];
|
||||||
|
protected array $dates = ['created_at', 'updated_at'];
|
||||||
|
|
||||||
|
public static function labels()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'key' => 'Ключ',
|
||||||
|
'value' => 'Значение',
|
||||||
|
'label' => 'Название',
|
||||||
|
'status' => 'Статус'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
20
kernel/modules/option/models/forms/CreateOptionForm.php
Normal file
20
kernel/modules/option/models/forms/CreateOptionForm.php
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel\modules\option\models\forms;
|
||||||
|
|
||||||
|
use kernel\FormModel;
|
||||||
|
|
||||||
|
class CreateOptionForm extends FormModel
|
||||||
|
{
|
||||||
|
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'admin_theme_paths' => '',
|
||||||
|
'active_admin_theme' => '',
|
||||||
|
'module_paths' => '',
|
||||||
|
'active_modules' => ''
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
17
kernel/modules/option/routs/option.php
Normal file
17
kernel/modules/option/routs/option.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use kernel\App;
|
||||||
|
use Phroute\Phroute\RouteCollector;
|
||||||
|
|
||||||
|
App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
|
||||||
|
App::$collector->group(["prefix" => "option"], callback: function (RouteCollector $router){
|
||||||
|
App::$collector->get('/', [\kernel\modules\option\controllers\OptionController::class, 'actionIndex']);
|
||||||
|
App::$collector->get('/page/{page_number}', [\kernel\modules\option\controllers\OptionController::class, 'actionIndex']);
|
||||||
|
App::$collector->get('/create', [\kernel\modules\option\controllers\OptionController::class, 'actionCreate']);
|
||||||
|
App::$collector->post("/", [\kernel\modules\option\controllers\OptionController::class, 'actionAdd']);
|
||||||
|
App::$collector->get('/{id}', [\kernel\modules\option\controllers\OptionController::class, 'actionView']);
|
||||||
|
App::$collector->any('/update/{id}', [\kernel\modules\option\controllers\OptionController::class, 'actionUpdate']);
|
||||||
|
App::$collector->any("/edit/{id}", [\kernel\modules\option\controllers\OptionController::class, 'actionEdit']);
|
||||||
|
App::$collector->get('/delete/{id}', [\kernel\modules\option\controllers\OptionController::class, 'actionDelete']);
|
||||||
|
});
|
||||||
|
});
|
49
kernel/modules/option/service/OptionService.php
Normal file
49
kernel/modules/option/service/OptionService.php
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel\modules\option\service;
|
||||||
|
|
||||||
|
use kernel\FormModel;
|
||||||
|
use kernel\modules\option\models\Option;
|
||||||
|
|
||||||
|
class OptionService
|
||||||
|
{
|
||||||
|
|
||||||
|
public function create(FormModel $form_model): false|Option
|
||||||
|
{
|
||||||
|
$model = new Option();
|
||||||
|
$model->key = $form_model->getItem('key');
|
||||||
|
$model->value = $form_model->getItem('value');
|
||||||
|
$model->label = $form_model->getItem('label');
|
||||||
|
$model->status = $form_model->getItem('status');
|
||||||
|
if ($model->save()) {
|
||||||
|
return $model;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(FormModel $form_model, Option $option): false|Option
|
||||||
|
{
|
||||||
|
$option->key = $form_model->getItem('key');
|
||||||
|
$option->value = $form_model->getItem('value');
|
||||||
|
$option->label = $form_model->getItem('label');
|
||||||
|
$option->status = $form_model->getItem('status');
|
||||||
|
if ($option->save()) {
|
||||||
|
return $option;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// public function createOptionArr(): array
|
||||||
|
// {
|
||||||
|
// foreach (Option::all()->toArray() as $option) {
|
||||||
|
// $optionArr[$option['id']] = $option['key'];
|
||||||
|
// }
|
||||||
|
// if (!empty($optionArr)) {
|
||||||
|
// return $optionArr;
|
||||||
|
// }
|
||||||
|
// return [];
|
||||||
|
// }
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel\modules\option\table\columns;
|
||||||
|
|
||||||
|
use Itguild\Tables\ActionColumn\ActionColumn;
|
||||||
|
|
||||||
|
class OptionDeleteActionColumn extends ActionColumn
|
||||||
|
{
|
||||||
|
protected string $prefix = "/delete/";
|
||||||
|
|
||||||
|
public function fetch(): string
|
||||||
|
{
|
||||||
|
$link = $this->baseUrl . $this->prefix . $this->id;
|
||||||
|
return " <a href='$link' class='btn btn-danger'>Удалить</a> ";
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel\modules\option\table\columns;
|
||||||
|
|
||||||
|
use Itguild\Tables\ActionColumn\ActionColumn;
|
||||||
|
|
||||||
|
class OptionEditActionColumn extends ActionColumn
|
||||||
|
{
|
||||||
|
protected string $prefix = "/update/";
|
||||||
|
|
||||||
|
public function fetch(): string
|
||||||
|
{
|
||||||
|
$link = $this->baseUrl . $this->prefix . $this->id;
|
||||||
|
return " <a href='$link' class='btn btn-success'>Редактировать</a> ";
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel\modules\option\table\columns;
|
||||||
|
|
||||||
|
use Itguild\Tables\ActionColumn\ActionColumn;
|
||||||
|
|
||||||
|
class OptionViewActionColumn extends ActionColumn
|
||||||
|
{
|
||||||
|
|
||||||
|
protected string $prefix = "/";
|
||||||
|
|
||||||
|
public function fetch()
|
||||||
|
{
|
||||||
|
$link = $this->baseUrl . $this->prefix . $this->id;
|
||||||
|
return " <a href='$link' class='btn btn-primary'>Просмотр</a> ";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
68
kernel/modules/option/views/form.php
Normal file
68
kernel/modules/option/views/form.php
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @var Option $model
|
||||||
|
*/
|
||||||
|
|
||||||
|
use itguild\forms\ActiveForm;
|
||||||
|
use kernel\modules\option\models\Option;
|
||||||
|
|
||||||
|
$form = new ActiveForm();
|
||||||
|
$form->beginForm(isset($model) ? "/admin/option/edit/" . $model->id : "/admin/option");
|
||||||
|
|
||||||
|
$form->field(\itguild\forms\inputs\TextInput::class, 'key', [
|
||||||
|
'class' => "form-control",
|
||||||
|
'placeholder' => 'Ключ',
|
||||||
|
'value' => $model->key ?? ''
|
||||||
|
])
|
||||||
|
->setLabel("Ключ")
|
||||||
|
->render();
|
||||||
|
|
||||||
|
$form->field(\itguild\forms\inputs\TextInput::class, 'value', [
|
||||||
|
'class' => "form-control",
|
||||||
|
'placeholder' => 'Значение',
|
||||||
|
'value' => $model->value ?? ''
|
||||||
|
])
|
||||||
|
->setLabel("Значение")
|
||||||
|
->render();
|
||||||
|
|
||||||
|
$form->field(\itguild\forms\inputs\TextInput::class, 'label', [
|
||||||
|
'class' => "form-control",
|
||||||
|
'placeholder' => "Заголовок",
|
||||||
|
'value' => $model->label ?? ''
|
||||||
|
])
|
||||||
|
->setLabel("Заголовок")
|
||||||
|
->render();
|
||||||
|
|
||||||
|
$form->field(\itguild\forms\inputs\Select::class, 'status', [
|
||||||
|
'class' => "form-control",
|
||||||
|
'value' => $model->status ?? ''
|
||||||
|
])
|
||||||
|
->setLabel("Статус")
|
||||||
|
->setOptions(['1', '2'])
|
||||||
|
->render();
|
||||||
|
|
||||||
|
?>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-sm-2">
|
||||||
|
<?php
|
||||||
|
$form->field(\itguild\forms\inputs\Button::class, name: "btn-submit", params: [
|
||||||
|
'class' => "btn btn-primary ",
|
||||||
|
'value' => 'Отправить',
|
||||||
|
'typeInput' => 'submit'
|
||||||
|
])
|
||||||
|
->render();
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-2">
|
||||||
|
<?php
|
||||||
|
$form->field(\itguild\forms\inputs\Button::class, name: "btn-reset", params: [
|
||||||
|
'class' => "btn btn-warning",
|
||||||
|
'value' => 'Сбросить',
|
||||||
|
'typeInput' => 'reset'
|
||||||
|
])
|
||||||
|
->render();
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
$form->endForm();
|
31
kernel/modules/option/views/index.php
Normal file
31
kernel/modules/option/views/index.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @var \Illuminate\Database\Eloquent\Collection $options
|
||||||
|
* @var int $page_number
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Itguild\EloquentTable\EloquentDataProvider;
|
||||||
|
use Itguild\EloquentTable\ListEloquentTable;
|
||||||
|
use kernel\IGTabel\btn\PrimaryBtn;
|
||||||
|
use kernel\modules\option\models\Option;
|
||||||
|
use kernel\modules\option\table\columns\OptionDeleteActionColumn;
|
||||||
|
use kernel\modules\option\table\columns\OptionEditActionColumn;
|
||||||
|
use kernel\modules\option\table\columns\OptionViewActionColumn;
|
||||||
|
|
||||||
|
$table = new ListEloquentTable(new EloquentDataProvider(Option::class, [
|
||||||
|
'current_page' => $page_number,
|
||||||
|
'per_page' => 5,
|
||||||
|
'params' => ["class" => "table table-bordered", "border" => "2"],
|
||||||
|
'baseUrl' => "/admin/option",
|
||||||
|
]));
|
||||||
|
|
||||||
|
$table->beforePrint(function () {
|
||||||
|
return PrimaryBtn::create("Создать", "/admin/option/create")->fetch();
|
||||||
|
//return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch();
|
||||||
|
});
|
||||||
|
|
||||||
|
$table->addAction(OptionViewActionColumn::class);
|
||||||
|
$table->addAction(OptionEditActionColumn::class);
|
||||||
|
$table->addAction(OptionDeleteActionColumn::class);
|
||||||
|
$table->create();
|
||||||
|
$table->render();
|
23
kernel/modules/option/views/view.php
Normal file
23
kernel/modules/option/views/view.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @var \Illuminate\Database\Eloquent\Collection $option
|
||||||
|
*/
|
||||||
|
|
||||||
|
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($option, [
|
||||||
|
'params' => ["class" => "table table-bordered", "border" => "2"],
|
||||||
|
'baseUrl' => "/admin/user",
|
||||||
|
]));
|
||||||
|
$table->beforePrint(function () use ($option) {
|
||||||
|
$btn = PrimaryBtn::create("Список", "/admin/option")->fetch();
|
||||||
|
$btn .= SuccessBtn::create("Редактировать", "/admin/option/update/" . $option->id)->fetch();
|
||||||
|
$btn .= DangerBtn::create("Удалить", "/admin/option/delete/" . $option->id)->fetch();
|
||||||
|
return $btn;
|
||||||
|
});
|
||||||
|
$table->create();
|
||||||
|
$table->render();
|
16
kernel/modules/post/table/columns/PostDeleteActionColumn.php
Normal file
16
kernel/modules/post/table/columns/PostDeleteActionColumn.php
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel\modules\post\table\columns;
|
||||||
|
|
||||||
|
use Itguild\Tables\ActionColumn\ActionColumn;
|
||||||
|
|
||||||
|
class PostDeleteActionColumn extends ActionColumn
|
||||||
|
{
|
||||||
|
protected string $prefix = "/delete/";
|
||||||
|
|
||||||
|
public function fetch(): string
|
||||||
|
{
|
||||||
|
$link = $this->baseUrl . $this->prefix . $this->id;
|
||||||
|
return " <a href='$link' class='btn btn-danger'>Удалить</a> ";
|
||||||
|
}
|
||||||
|
}
|
16
kernel/modules/post/table/columns/PostEditActionColumn.php
Normal file
16
kernel/modules/post/table/columns/PostEditActionColumn.php
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel\modules\post\table\columns;
|
||||||
|
|
||||||
|
use Itguild\Tables\ActionColumn\ActionColumn;
|
||||||
|
|
||||||
|
class PostEditActionColumn extends ActionColumn
|
||||||
|
{
|
||||||
|
protected string $prefix = "/update/";
|
||||||
|
|
||||||
|
public function fetch(): string
|
||||||
|
{
|
||||||
|
$link = $this->baseUrl . $this->prefix . $this->id;
|
||||||
|
return " <a href='$link' class='btn btn-success'>Редактировать</a> ";
|
||||||
|
}
|
||||||
|
}
|
16
kernel/modules/post/table/columns/PostViewActionColumn.php
Normal file
16
kernel/modules/post/table/columns/PostViewActionColumn.php
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel\modules\post\table\columns;
|
||||||
|
|
||||||
|
use Itguild\Tables\ActionColumn\ActionColumn;
|
||||||
|
|
||||||
|
class PostViewActionColumn extends actionColumn
|
||||||
|
{
|
||||||
|
protected string $prefix = "/";
|
||||||
|
|
||||||
|
public function fetch(): string
|
||||||
|
{
|
||||||
|
$link = $this->baseUrl . $this->prefix . $this->id;
|
||||||
|
return " <a href='$link' class='btn btn-primary'>Просмотр</a> ";
|
||||||
|
}
|
||||||
|
}
|
@ -6,10 +6,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
use kernel\modules\post\models\Post;
|
use kernel\modules\post\models\Post;
|
||||||
|
use kernel\modules\post\table\columns\PostDeleteActionColumn;
|
||||||
|
use kernel\modules\post\table\columns\PostEditActionColumn;
|
||||||
|
use kernel\modules\post\table\columns\PostViewActionColumn;
|
||||||
use kernel\modules\user\models\User;
|
use kernel\modules\user\models\User;
|
||||||
use app\tables\columns\post\PostDeleteActionColumn;
|
//use app\tables\columns\post\PostDeleteActionColumn;
|
||||||
use app\tables\columns\post\PostEditActionColumn;
|
//use app\tables\columns\post\PostEditActionColumn;
|
||||||
use app\tables\columns\post\PostViewActionColumn;
|
//use app\tables\columns\post\PostViewActionColumn;
|
||||||
use Itguild\EloquentTable\EloquentDataProvider;
|
use Itguild\EloquentTable\EloquentDataProvider;
|
||||||
use Itguild\EloquentTable\ListEloquentTable;
|
use Itguild\EloquentTable\ListEloquentTable;
|
||||||
use kernel\IGTabel\btn\PrimaryBtn;
|
use kernel\IGTabel\btn\PrimaryBtn;
|
||||||
|
@ -67,6 +67,7 @@ class UserController extends AdminController
|
|||||||
* @throws RuntimeError
|
* @throws RuntimeError
|
||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
* @throws LoaderError
|
* @throws LoaderError
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function actionUpdate($id): void
|
public function actionUpdate($id): void
|
||||||
{
|
{
|
||||||
|
16
kernel/modules/user/table/columns/UserDeleteActionColumn.php
Normal file
16
kernel/modules/user/table/columns/UserDeleteActionColumn.php
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel\modules\user\table\columns;
|
||||||
|
|
||||||
|
use Itguild\Tables\ActionColumn\ActionColumn;
|
||||||
|
|
||||||
|
class UserDeleteActionColumn extends ActionColumn
|
||||||
|
{
|
||||||
|
protected string $prefix = "/delete/";
|
||||||
|
|
||||||
|
public function fetch(): string
|
||||||
|
{
|
||||||
|
$link = $this->baseUrl . $this->prefix . $this->id;
|
||||||
|
return " <a href='$link' class='btn btn-danger'>Удалить</a> ";
|
||||||
|
}
|
||||||
|
}
|
16
kernel/modules/user/table/columns/UserEditActionColumn.php
Normal file
16
kernel/modules/user/table/columns/UserEditActionColumn.php
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel\modules\user\table\columns;
|
||||||
|
|
||||||
|
use Itguild\Tables\ActionColumn\ActionColumn;
|
||||||
|
|
||||||
|
class UserEditActionColumn extends ActionColumn
|
||||||
|
{
|
||||||
|
protected string $prefix = "/update/";
|
||||||
|
|
||||||
|
public function fetch(): string
|
||||||
|
{
|
||||||
|
$link = $this->baseUrl . $this->prefix . $this->id;
|
||||||
|
return " <a href='$link' class='btn btn-success'>Редактировать</a> ";
|
||||||
|
}
|
||||||
|
}
|
16
kernel/modules/user/table/columns/UserViewActionColumn.php
Normal file
16
kernel/modules/user/table/columns/UserViewActionColumn.php
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace kernel\modules\user\table\columns;
|
||||||
|
|
||||||
|
use Itguild\Tables\ActionColumn\ActionColumn;
|
||||||
|
|
||||||
|
class UserViewActionColumn extends ActionColumn
|
||||||
|
{
|
||||||
|
protected string $prefix = "/";
|
||||||
|
|
||||||
|
public function fetch(): string
|
||||||
|
{
|
||||||
|
$link = $this->baseUrl . $this->prefix . $this->id;
|
||||||
|
return " <a href='$link' class='btn btn-primary'>Просмотр</a> ";
|
||||||
|
}
|
||||||
|
}
|
@ -4,13 +4,14 @@
|
|||||||
* @var int $page_number
|
* @var int $page_number
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use app\tables\columns\user\UserDeleteActionColumn;
|
|
||||||
use app\tables\columns\user\UserEditActionColumn;
|
|
||||||
use app\tables\columns\user\UserViewActionColumn;
|
|
||||||
use Itguild\EloquentTable\EloquentDataProvider;
|
use Itguild\EloquentTable\EloquentDataProvider;
|
||||||
use Itguild\EloquentTable\ListEloquentTable;
|
use Itguild\EloquentTable\ListEloquentTable;
|
||||||
use kernel\IGTabel\btn\PrimaryBtn;
|
use kernel\IGTabel\btn\PrimaryBtn;
|
||||||
use kernel\modules\user\models\User;
|
use kernel\modules\user\models\User;
|
||||||
|
use kernel\modules\user\table\columns\UserDeleteActionColumn;
|
||||||
|
use kernel\modules\user\table\columns\UserEditActionColumn;
|
||||||
|
use kernel\modules\user\table\columns\UserViewActionColumn;
|
||||||
|
|
||||||
$table = new ListEloquentTable(new EloquentDataProvider(User::class, [
|
$table = new ListEloquentTable(new EloquentDataProvider(User::class, [
|
||||||
'currentPage' => $page_number,
|
'currentPage' => $page_number,
|
||||||
|
Loading…
Reference in New Issue
Block a user