admin init command
This commit is contained in:
@ -3,12 +3,32 @@
|
||||
namespace kernel\modules\admin_themes;
|
||||
|
||||
use kernel\Module;
|
||||
use kernel\modules\menu\service\MenuService;
|
||||
|
||||
class AdminThemesModule extends Module
|
||||
{
|
||||
|
||||
public function init()
|
||||
public MenuService $menuService;
|
||||
public function __construct()
|
||||
{
|
||||
// TODO: Implement init() method.
|
||||
$this->menuService = new MenuService();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
$this->menuService->createItem([
|
||||
"label" => "Темы админпанели",
|
||||
"url" => "/admin/settings/admin-themes",
|
||||
"slug" => "admin-themes",
|
||||
"parent_slug" => "settings"
|
||||
]);
|
||||
}
|
||||
|
||||
public function deactivate(): void
|
||||
{
|
||||
$this->menuService->removeItemBySlug("admin-themes");
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@
|
||||
"author": "ITGuild",
|
||||
"slug": "admin_themes",
|
||||
"description": "Admin themes module",
|
||||
"module_class": "AdminThemesModule",
|
||||
"module_class": "kernel\\modules\\admin_themes\\AdminThemesModule",
|
||||
"module_class_file": "{KERNEL_MODULES}/admin_themes/AdminThemesModule.php",
|
||||
"routs": "routs/adminThemes.php"
|
||||
}
|
@ -3,12 +3,32 @@
|
||||
namespace kernel\modules\menu;
|
||||
|
||||
use kernel\Module;
|
||||
use kernel\modules\menu\service\MenuService;
|
||||
|
||||
class MenuModule extends Module
|
||||
{
|
||||
|
||||
public function init()
|
||||
public MenuService $menuService;
|
||||
public function __construct()
|
||||
{
|
||||
// TODO: Implement init() method.
|
||||
$this->menuService = new MenuService();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
$this->menuService->createItem([
|
||||
"label" => "Меню",
|
||||
"url" => "/admin/settings/menu",
|
||||
"slug" => "menu",
|
||||
"parent_slug" => "settings"
|
||||
]);
|
||||
}
|
||||
|
||||
public function deactivate(): void
|
||||
{
|
||||
$this->menuService->removeItemBySlug("menu");
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@
|
||||
"author": "ITGuild",
|
||||
"slug": "menu",
|
||||
"description": "Menu module",
|
||||
"module_class": "MenuModule",
|
||||
"module_class": "kernel\\modules\\menu\\MenuModule",
|
||||
"module_class_file": "{KERNEL_MODULES}/menu/MenuModule.php",
|
||||
"routs": "routs/menu.php"
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
<?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('menu', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('parent_id')->default(0);
|
||||
$table->string('icon_file', 255)->nullable();
|
||||
$table->string('icon_font', 255)->nullable();
|
||||
$table->string('label', 255);
|
||||
$table->string('url', 255);
|
||||
$table->string('slug', 255)->unique();
|
||||
$table->integer('status')->default(1);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
\kernel\App::$db->schema->dropIfExists('menu');
|
||||
}
|
||||
};
|
@ -76,21 +76,20 @@ class OptionController extends AdminController
|
||||
*/
|
||||
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);
|
||||
$option = $this->optionService->update($optionForm, $option);
|
||||
if ($option) {
|
||||
$this->redirect('/admin/option' . $option->id);
|
||||
$this->redirect('/admin/option/' . $option->id);
|
||||
}
|
||||
}
|
||||
$this->redirect('/admin/option/update' . $id);
|
||||
|
||||
$this->redirect('/admin/option/update/' . $id);
|
||||
}
|
||||
|
||||
#[NoReturn] public function actionDelete(int $id): void
|
||||
|
@ -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('option', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('key', 255);
|
||||
$table->text('value')->nullable();
|
||||
$table->string('label', 255)->nullable();
|
||||
$table->integer('status')->default(1);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
\kernel\App::$db->schema->dropIfExists('option');
|
||||
}
|
||||
};
|
@ -14,6 +14,8 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Option extends Model
|
||||
{
|
||||
const DISABLE_STATUS = 0;
|
||||
const ACTIVE_STATUS = 1;
|
||||
|
||||
protected $table = 'option';
|
||||
protected $fillable = ['key', 'value', 'label', 'status'];
|
||||
@ -29,4 +31,15 @@ class Option extends Model
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public static function getStatus(): array
|
||||
{
|
||||
return [
|
||||
self::DISABLE_STATUS => "Не активный",
|
||||
self::ACTIVE_STATUS => "Активный",
|
||||
];
|
||||
}
|
||||
|
||||
}
|
@ -4,16 +4,22 @@ namespace kernel\modules\option\models\forms;
|
||||
|
||||
use kernel\FormModel;
|
||||
|
||||
/**
|
||||
* @property string $key
|
||||
* @property string $value
|
||||
* @property string $label
|
||||
* @property integer $status
|
||||
*/
|
||||
class CreateOptionForm extends FormModel
|
||||
{
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'admin_theme_paths' => '',
|
||||
'active_admin_theme' => '',
|
||||
'module_paths' => '',
|
||||
'active_modules' => ''
|
||||
'key' => 'required|min-str-len:1|max-str-len:50',
|
||||
'value' => '',
|
||||
'label' => '',
|
||||
'status' => ''
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -3,8 +3,8 @@
|
||||
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->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']);
|
||||
@ -13,5 +13,5 @@ App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
|
||||
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']);
|
||||
});
|
||||
});
|
||||
});
|
@ -35,6 +35,20 @@ class OptionService
|
||||
return false;
|
||||
}
|
||||
|
||||
public function createFromParams(string $key, string $value, string $label): false|Option
|
||||
{
|
||||
$model = new Option();
|
||||
$model->key = $key;
|
||||
$model->value = $value;
|
||||
$model->label = $label;
|
||||
|
||||
if ($model->save()) {
|
||||
return $model;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// public function createOptionArr(): array
|
||||
// {
|
||||
// foreach (Option::all()->toArray() as $option) {
|
||||
|
@ -38,7 +38,7 @@ $form->field(\itguild\forms\inputs\Select::class, 'status', [
|
||||
'value' => $model->status ?? ''
|
||||
])
|
||||
->setLabel("Статус")
|
||||
->setOptions(['1', '2'])
|
||||
->setOptions(Option::getStatus())
|
||||
->render();
|
||||
|
||||
?>
|
||||
|
@ -13,6 +13,8 @@ return new class extends Migration
|
||||
{
|
||||
\kernel\App::$db->schema->create('post', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('title', 255)->nullable(false);
|
||||
$table->string('slug', 255)->unique();
|
||||
$table->text('content')->nullable(false);
|
||||
$table->integer('user_id');
|
||||
$table->timestamps();
|
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function up(): void
|
||||
{
|
||||
\kernel\App::$db->schema->create('user', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('username', 255)->nullable(false);
|
||||
$table->string('email', 255);
|
||||
$table->string('password_hash', 255);
|
||||
$table->integer('role')->default(1);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function down(): void
|
||||
{
|
||||
\kernel\App::$db->schema->dropIfExists('user');
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user