module activate

This commit is contained in:
Билай Станислав 2024-09-13 13:54:58 +03:00
parent 95e80ab87b
commit fc80a63a6d
6 changed files with 56 additions and 74 deletions

View File

@ -1,37 +0,0 @@
<?php
namespace _migrations;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Capsule\Manager;
class AnswerMigration extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public static function up(): void
{
Manager::schema()->create('answer', function (Blueprint $table) {
$table->increments('id');
$table->string('answer', 255)->nullable(false);
$table->integer('user_id');
$table->integer('question_id');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public static function down(): void
{
Manager::schema()->dropIfExists('user');
}
}

View File

@ -1,36 +0,0 @@
<?php
namespace _migrations;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Capsule\Manager;
class QuestionMigration extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public static function up(): void
{
Manager::schema()->create('question', function (Blueprint $table) {
$table->increments('id');
$table->string('question', 255)->nullable(false);
$table->integer('user_id');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public static function down(): void
{
Manager::schema()->dropIfExists('user');
}
}

View File

@ -7,6 +7,7 @@ use kernel\AdminController;
use kernel\helpers\Debug;
use kernel\models\Option;
use kernel\modules\user\service\UserService;
use kernel\Request;
use kernel\services\ModuleService;
class ModuleController extends AdminController
@ -47,4 +48,12 @@ class ModuleController extends AdminController
$this->cgView->render("index.php", ['modules_info' => $modules_info, 'moduleService' => $this->moduleService]);
}
public function actionActivate(): void
{
$request = new Request();
$this->moduleService->setActiveModule($request->get("slug"));
$this->cgView->render("view.php", ['data' => $this->moduleService->getModuleInfo(KERNEL_MODULES_DIR . '/' . $request->get("slug"))]);
}
}

View File

@ -9,6 +9,7 @@ use Phroute\Phroute\RouteCollector;
App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
App::$collector->group(["prefix" => "module"], function (RouteCollector $router){
App::$collector->get('/', [\kernel\controllers\ModuleController::class, 'actionIndex']);
App::$collector->get('/activate', [\kernel\controllers\ModuleController::class, 'actionActivate']);
});
App::$collector->group(["prefix" => "post"], function (RouteCollector $router){
App::$collector->get('/', [\kernel\modules\post\controllers\PostController::class, 'actionIndex']);

View File

@ -2,6 +2,7 @@
namespace kernel\services;
use kernel\helpers\Debug;
use kernel\helpers\Manifest;
use kernel\models\Option;
@ -23,7 +24,7 @@ class ModuleService
public function isActive(string $slug): bool
{
$active_modules= Option::where("key", "active_modules")->first();
$active_modules = Option::where("key", "active_modules")->first();
if ($active_modules){
$path = json_decode($active_modules->value);
foreach ($path->modules as $p){
@ -36,4 +37,18 @@ class ModuleService
return false;
}
public function setActiveModule(string $module): void
{
$active_modules = Option::where("key", "active_modules")->first();
$path = json_decode($active_modules->value);
if (in_array($module, $path->modules)) {
unset($path->modules[array_search($module, $path->modules)]);
$path->modules = array_values($path->modules);
} else {
$path->modules[] = $module;
}
$active_modules->value = json_encode($path, JSON_UNESCAPED_UNICODE);
$active_modules->save();
}
}

View File

@ -0,0 +1,30 @@
<?php
/**
* @var array $data
*/
use kernel\IGTabel\btn\DangerBtn;
use kernel\IGTabel\btn\PrimaryBtn;
use kernel\IGTabel\btn\SuccessBtn;
$table_info = [
"meta" => [
"rows" => [
"name" => "Название",
"author" => "Автор",
"version" => "Версия",
"description" => "Описание"
],
"params" => ["class" => "table table-bordered"],
"baseUrl" => "/admin/module",
],
"data" => $data
];
$table = new \Itguild\Tables\ViewJsonTable(json_encode($table_info, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
$table->beforePrint(function () {
$btn = PrimaryBtn::create("Список", "/admin/module")->fetch();
return $btn;
});
$table->create();
$table->render();