Compare commits
No commits in common. "f4971f1c7daef2f1f1d73cbccacf91a5e72f3a87" and "0f26b054430020ec9c390aa8cd88a282dab6a3ec" have entirely different histories.
f4971f1c7d
...
0f26b05443
@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\modules\tag;
|
||||
|
||||
use kernel\Module;
|
||||
use kernel\modules\menu\service\MenuService;
|
||||
|
||||
class TagModule extends Module
|
||||
{
|
||||
|
||||
public MenuService $menuService;
|
||||
public function __construct()
|
||||
{
|
||||
$this->menuService = new MenuService();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
$this->menuService->createItem([
|
||||
"label" => "Тэги",
|
||||
"url" => "/admin/tag",
|
||||
"slug" => "tag",
|
||||
]);
|
||||
}
|
||||
|
||||
public function deactivate(): void
|
||||
{
|
||||
$this->menuService->removeItemBySlug("tag");
|
||||
}
|
||||
}
|
@ -4,6 +4,5 @@
|
||||
"author": "ITGuild",
|
||||
"slug": "tag",
|
||||
"description": "Tags module",
|
||||
"module_class": "app\\modules\\tag\\TagModule",
|
||||
"module_class_file": "{APP}/modules/tag/TagModule.php"
|
||||
"module_class": "TagModule"
|
||||
}
|
@ -6,5 +6,4 @@ namespace kernel;
|
||||
abstract class Module
|
||||
{
|
||||
abstract public function init();
|
||||
abstract public function deactivate();
|
||||
}
|
@ -13,18 +13,10 @@ use Illuminate\Database\Migrations\MigrationCreator;
|
||||
use Illuminate\Database\Migrations\Migrator;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Schema\Builder;
|
||||
use kernel\services\ModuleService;
|
||||
|
||||
|
||||
class MigrationController extends ConsoleController
|
||||
{
|
||||
protected ModuleService $moduleService;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->moduleService = new ModuleService();
|
||||
}
|
||||
|
||||
//create migrations table
|
||||
public function actionCreateMigrationTable(): void
|
||||
{
|
||||
@ -71,8 +63,8 @@ class MigrationController extends ConsoleController
|
||||
$dmr = new DatabaseMigrationRepository(App::$db->capsule->getDatabaseManager(), 'migration');
|
||||
|
||||
$m = new Migrator($dmr, App::$db->capsule->getDatabaseManager(), new Filesystem());
|
||||
$migrationPaths = array_merge($this->moduleService->getModulesMigrationsPaths(), [ROOT_DIR . '/migrations']);
|
||||
//$migrationPaths = [ROOT_DIR . '/migrations'];
|
||||
//$migrationPaths = array_merge(App::$migrationsPaths, [ROOT_DIR . '/migrations']);
|
||||
$migrationPaths = [ROOT_DIR . '/migrations'];
|
||||
$res = $m->run($migrationPaths);
|
||||
foreach ($res as $re){
|
||||
$this->out->r(basename($re), 'green');
|
||||
|
@ -52,17 +52,8 @@ class ModuleController extends AdminController
|
||||
{
|
||||
$request = new Request();
|
||||
$this->moduleService->setActiveModule($request->get("slug"));
|
||||
$mod_info = $this->moduleService->getModuleInfoBySlug($request->get('slug'));
|
||||
|
||||
$this->cgView->render("view.php", ['data' => $mod_info]);
|
||||
}
|
||||
|
||||
public function actionView(): void
|
||||
{
|
||||
$request = new Request();
|
||||
$mod_info = $this->moduleService->getModuleInfoBySlug($request->get('slug'));
|
||||
|
||||
$this->cgView->render("view.php", ['data' => $mod_info]);
|
||||
$this->cgView->render("view.php", ['data' => $this->moduleService->getModuleInfo($this->moduleService->getModuleDir($request->get("slug")))]);
|
||||
}
|
||||
|
||||
}
|
@ -12,7 +12,6 @@ use Illuminate\Database\Eloquent\Model;
|
||||
* @property string label
|
||||
* @property string url
|
||||
* @property int status
|
||||
* @property string slug
|
||||
* @method static find($id)
|
||||
*/
|
||||
|
||||
@ -22,7 +21,7 @@ class Menu extends Model
|
||||
const ACTIVE_STATUS = 1;
|
||||
|
||||
protected $table = 'menu';
|
||||
protected $fillable = ['parent_id', 'icon_file', 'icon_font', 'label', 'url', 'status', 'slug'];
|
||||
protected $fillable = ['parent_id', 'icon_file', 'icon_font', 'label', 'url', 'status'];
|
||||
protected array $dates = ['deleted_at'];
|
||||
|
||||
public static function labels(): array
|
||||
@ -34,7 +33,6 @@ class Menu extends Model
|
||||
'icon_font' => 'Иконка',
|
||||
'url' => 'URL',
|
||||
'status' => 'Статус',
|
||||
'slug' => 'Slug',
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ class Menu extends Model
|
||||
const ACTIVE_STATUS = 1;
|
||||
|
||||
protected $table = 'menu';
|
||||
protected $fillable = ['parent_id', 'icon_file', 'icon_font', 'label', 'url', 'status', 'slug'];
|
||||
protected $fillable = ['parent_id', 'icon_file', 'icon_font', 'label', 'url', 'status'];
|
||||
protected array $dates = ['deleted_at'];
|
||||
|
||||
public static function labels(): array
|
||||
@ -33,7 +33,6 @@ class Menu extends Model
|
||||
'icon_font' => 'Иконка',
|
||||
'url' => 'URL',
|
||||
'status' => 'Статус',
|
||||
'slug' => 'Slug',
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -5,14 +5,12 @@ namespace kernel\modules\menu\models\forms;
|
||||
use kernel\FormModel;
|
||||
|
||||
/**
|
||||
* @property int $parent_id
|
||||
* @property string $icon_file
|
||||
* @property string $icon_font
|
||||
* @property string $label
|
||||
* @property string $url
|
||||
* @property int $status
|
||||
* @property string $slug
|
||||
* @property string $parent_slug
|
||||
* @property $parent_id
|
||||
* @property $icon_file
|
||||
* @property $icon_font
|
||||
* @property $label
|
||||
* @property $url
|
||||
* @property $status
|
||||
*/
|
||||
class CreateMenuForm extends FormModel
|
||||
{
|
||||
@ -24,9 +22,7 @@ class CreateMenuForm extends FormModel
|
||||
'icon_font' => '',
|
||||
'label' => 'required|min-str-len:1|max-str-len:50',
|
||||
'url' => 'required|min-str-len:1',
|
||||
'status' => '',
|
||||
'slug' => 'required|min-str-len:1|max-str-len:50',
|
||||
'parent_slug' => ''
|
||||
'status' => ''
|
||||
];
|
||||
}
|
||||
}
|
@ -2,11 +2,8 @@
|
||||
|
||||
namespace kernel\modules\menu\service;
|
||||
|
||||
use Exception;
|
||||
use kernel\FormModel;
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\models\Menu;
|
||||
use kernel\modules\menu\models\forms\CreateMenuForm;
|
||||
use kernel\Request;
|
||||
|
||||
class MenuService
|
||||
@ -14,13 +11,12 @@ class MenuService
|
||||
public function create(FormModel $form_model): false|Menu
|
||||
{
|
||||
$model = new Menu();
|
||||
$model->parent_id = $form_model->getItem('parent_id') ?? 0;
|
||||
$model->parent_id = $form_model->getItem('parent_id');
|
||||
$model->icon_file = $form_model->getItem('icon_file');
|
||||
$model->icon_font = $form_model->getItem('icon_font');
|
||||
$model->label = $form_model->getItem('label');
|
||||
$model->url = $form_model->getItem('url');
|
||||
$model->status = $form_model->getItem('status') ?? 1;
|
||||
$model->slug = $form_model->getItem('slug');
|
||||
$model->status = $form_model->getItem('status');
|
||||
if ($model->save()){
|
||||
return $model;
|
||||
}
|
||||
@ -28,39 +24,6 @@ class MenuService
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function createItem(array $item): false|Menu
|
||||
{
|
||||
$model = new CreateMenuForm();
|
||||
$model->load($item);
|
||||
if (!$model->validate()){
|
||||
throw new Exception('Ошибка создания пункта меню');
|
||||
}
|
||||
if ($model->getItem("parent_slug")){
|
||||
$parent = $this->getBySlug($model->getItem("parent_slug"));
|
||||
if ($parent){
|
||||
$model->setItem("parent_id", $parent->id);
|
||||
}
|
||||
else {
|
||||
$model->setItem("parent_id", 0);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->create($model);
|
||||
}
|
||||
|
||||
public function removeItemBySlug(string $slug)
|
||||
{
|
||||
return Menu::where("slug", $slug)->delete();
|
||||
}
|
||||
|
||||
public function getBySlug(string $slug)
|
||||
{
|
||||
return Menu::where("slug", $slug)->first();
|
||||
}
|
||||
|
||||
public function update(FormModel $form_model, Menu $menuItem): false|Menu
|
||||
{
|
||||
$menuItem->parent_id = $form_model->getItem('parent_id');
|
||||
@ -69,7 +32,6 @@ class MenuService
|
||||
$menuItem->label = $form_model->getItem('label');
|
||||
$menuItem->url = $form_model->getItem('url');
|
||||
$menuItem->status = $form_model->getItem('status');
|
||||
$menuItem->slug = $form_model->getItem('slug');
|
||||
if ($menuItem->save()){
|
||||
return $menuItem;
|
||||
}
|
||||
|
@ -48,13 +48,6 @@ $form->field(class: \itguild\forms\inputs\TextInput::class, name: "url", params:
|
||||
->setLabel("URL")
|
||||
->render();
|
||||
|
||||
$form->field(class: \itguild\forms\inputs\TextInput::class, name: "slug", params: [
|
||||
'class' => "form-control",
|
||||
'value' => $model->slug ?? ''
|
||||
])
|
||||
->setLabel("Slug")
|
||||
->render();
|
||||
|
||||
$form->field(class: \itguild\forms\inputs\Select::class, name: "status", params: [
|
||||
'class' => "form-control",
|
||||
'value' => $model->status ?? '1'
|
||||
|
@ -2,29 +2,13 @@
|
||||
|
||||
namespace kernel\modules\post;
|
||||
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\Module;
|
||||
use kernel\modules\menu\service\MenuService;
|
||||
|
||||
class PostModule extends Module
|
||||
{
|
||||
public MenuService $menuService;
|
||||
public function __construct()
|
||||
{
|
||||
$this->menuService = new MenuService();
|
||||
}
|
||||
|
||||
public function init(): void
|
||||
public function init()
|
||||
{
|
||||
$this->menuService->createItem([
|
||||
"label" => "Посты",
|
||||
"url" => "/admin/post",
|
||||
"slug" => "post",
|
||||
]);
|
||||
}
|
||||
|
||||
public function deactivate(): void
|
||||
{
|
||||
$this->menuService->removeItemBySlug("post");
|
||||
// TODO: Implement init() method.
|
||||
}
|
||||
}
|
@ -4,8 +4,6 @@
|
||||
"author": "ITGuild",
|
||||
"slug": "post",
|
||||
"description": "Post module",
|
||||
"module_class": "kernel\\modules\\post\\PostModule",
|
||||
"module_class_file": "{KERNEL_MODULES}/post/PostModule.php",
|
||||
"routs": "routs/post.php",
|
||||
"migration_path": "migrations"
|
||||
"module_class": "PostModule",
|
||||
"routs": "routs/post.php"
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
<?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('post', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->text('content')->nullable(false);
|
||||
$table->integer('user_id');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
\kernel\App::$db->schema->dropIfExists('post');
|
||||
}
|
||||
};
|
@ -3,7 +3,6 @@
|
||||
use kernel\App;
|
||||
use Phroute\Phroute\RouteCollector;
|
||||
|
||||
|
||||
App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
|
||||
App::$collector->group(["prefix" => "post"], function (RouteCollector $router){
|
||||
App::$collector->get('/', [\kernel\modules\post\controllers\PostController::class, 'actionIndex']);
|
||||
|
@ -3,46 +3,13 @@
|
||||
namespace kernel\modules\user;
|
||||
|
||||
use kernel\Module;
|
||||
use kernel\modules\menu\service\MenuService;
|
||||
|
||||
class UserModule extends Module
|
||||
{
|
||||
|
||||
|
||||
public MenuService $menuService;
|
||||
public function __construct()
|
||||
public function init()
|
||||
{
|
||||
$this->menuService = new MenuService();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
$this->menuService->createItem([
|
||||
"label" => "Пользователи",
|
||||
"url" => "/admin/user",
|
||||
"slug" => "user",
|
||||
]);
|
||||
$this->menuService->createItem([
|
||||
"label" => "Список",
|
||||
"url" => "/admin/user",
|
||||
"slug" => "user_list",
|
||||
"parent_slug" => "user",
|
||||
]);
|
||||
$this->menuService->createItem([
|
||||
"label" => "Создать",
|
||||
"url" => "/admin/user/create",
|
||||
"slug" => "user_create",
|
||||
"parent_slug" => "user",
|
||||
]);
|
||||
}
|
||||
|
||||
public function deactivate(): void
|
||||
{
|
||||
$this->menuService->removeItemBySlug("user_create");
|
||||
$this->menuService->removeItemBySlug("user_list");
|
||||
$this->menuService->removeItemBySlug("user");
|
||||
// TODO: Implement init() method.
|
||||
}
|
||||
}
|
@ -4,7 +4,6 @@
|
||||
"author": "ITGuild",
|
||||
"slug": "user",
|
||||
"description": "User module",
|
||||
"module_class": "kernel\\modules\\user\\UserModule",
|
||||
"module_class_file": "{KERNEL_MODULES}/user/UserModule.php",
|
||||
"module_class": "UserModule",
|
||||
"routs": "routs/user.php"
|
||||
}
|
@ -17,18 +17,12 @@ class ModuleService
|
||||
if (file_exists($module . "/manifest.json")) {
|
||||
$manifest = file_get_contents($module . "/manifest.json");
|
||||
$manifest = Manifest::getWithVars($manifest);
|
||||
$manifest = getConst($manifest);
|
||||
$info = array_merge($info, $manifest);
|
||||
}
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
public function getModuleInfoBySlug(string $slug): false|array|string
|
||||
{
|
||||
return $this->getModuleInfo($this->getModuleDir($slug));
|
||||
}
|
||||
|
||||
public function isActive(string $slug): bool
|
||||
{
|
||||
$active_modules = Option::where("key", "active_modules")->first();
|
||||
@ -51,10 +45,8 @@ class ModuleService
|
||||
if (in_array($module, $path->modules)) {
|
||||
unset($path->modules[array_search($module, $path->modules)]);
|
||||
$path->modules = array_values($path->modules);
|
||||
$this->runDeactivateScript($this->getModuleInfoBySlug($module));
|
||||
} else {
|
||||
$path->modules[] = $module;
|
||||
$this->runInitScript($this->getModuleInfoBySlug($module));
|
||||
}
|
||||
$active_modules->value = json_encode($path, JSON_UNESCAPED_UNICODE);
|
||||
$active_modules->save();
|
||||
@ -81,28 +73,6 @@ class ModuleService
|
||||
return false;
|
||||
}
|
||||
|
||||
public function runInitScript($mod_info): void
|
||||
{
|
||||
if (isset($mod_info['module_class'])){
|
||||
if (isset($mod_info['module_class_file'])){
|
||||
require_once $mod_info['module_class_file'];
|
||||
}
|
||||
$moduleClass = new $mod_info['module_class']();
|
||||
$moduleClass->init();
|
||||
}
|
||||
}
|
||||
|
||||
public function runDeactivateScript($mod_info): void
|
||||
{
|
||||
if (isset($mod_info['module_class'])){
|
||||
if (isset($mod_info['module_class_file'])){
|
||||
require_once $mod_info['module_class_file'];
|
||||
}
|
||||
$moduleClass = new $mod_info['module_class']();
|
||||
$moduleClass->deactivate();
|
||||
}
|
||||
}
|
||||
|
||||
public function getActiveModules(): array
|
||||
{
|
||||
$modules = [];
|
||||
@ -141,17 +111,4 @@ class ModuleService
|
||||
return $routs;
|
||||
}
|
||||
|
||||
public function getModulesMigrationsPaths(): array
|
||||
{
|
||||
$migrationsPaths = [];
|
||||
$modules = $this->getActiveModules();
|
||||
foreach ($modules as $module){
|
||||
if (isset($module['migration_path'])){
|
||||
$migrationsPaths[] = $module['path'] . "/" . $module['migration_path'];
|
||||
}
|
||||
}
|
||||
|
||||
return $migrationsPaths;
|
||||
}
|
||||
|
||||
}
|
@ -36,10 +36,6 @@ $table->addAction(function ($row, $url) use ($moduleService){
|
||||
|
||||
return $btn;
|
||||
});
|
||||
$table->addAction(function ($row, $url) use ($moduleService){
|
||||
$slug = $row['slug'];
|
||||
return "<a class='btn btn-primary' href='$url/view/?slug=$slug' style='margin: 3px; width: 150px;' >Просмотр</a>";
|
||||
});
|
||||
|
||||
$table->create();
|
||||
$table->render();
|
||||
|
@ -1,28 +0,0 @@
|
||||
<?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->table('menu', function (Blueprint $table) {
|
||||
$table->string('slug')->unique();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
\kernel\App::$db->schema->table('menu', function (Blueprint $table) {
|
||||
$table->dropColumn(['slug']);
|
||||
});
|
||||
}
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user