diff --git a/_migrations/AnswerMigration.php b/_migrations/AnswerMigration.php deleted file mode 100644 index 8035762..0000000 --- a/_migrations/AnswerMigration.php +++ /dev/null @@ -1,37 +0,0 @@ -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'); - } -} \ No newline at end of file diff --git a/_migrations/QuestionMigration.php b/_migrations/QuestionMigration.php deleted file mode 100644 index a2ef3c8..0000000 --- a/_migrations/QuestionMigration.php +++ /dev/null @@ -1,36 +0,0 @@ -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'); - } -} \ No newline at end of file diff --git a/kernel/controllers/ModuleController.php b/kernel/controllers/ModuleController.php index 410f3d7..100e42b 100644 --- a/kernel/controllers/ModuleController.php +++ b/kernel/controllers/ModuleController.php @@ -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"))]); + } + } \ No newline at end of file diff --git a/kernel/routs/admin.php b/kernel/routs/admin.php index 7c83f4f..a4f89fd 100644 --- a/kernel/routs/admin.php +++ b/kernel/routs/admin.php @@ -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']); diff --git a/kernel/services/ModuleService.php b/kernel/services/ModuleService.php index 1255c65..89687cb 100644 --- a/kernel/services/ModuleService.php +++ b/kernel/services/ModuleService.php @@ -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(); + } + } \ No newline at end of file diff --git a/kernel/views/module/view.php b/kernel/views/module/view.php new file mode 100644 index 0000000..7fb4409 --- /dev/null +++ b/kernel/views/module/view.php @@ -0,0 +1,30 @@ + [ + "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(); \ No newline at end of file