kernel update
This commit is contained in:
@ -43,7 +43,7 @@ class MenuController extends AdminController
|
||||
if ($menuForm->validate()){
|
||||
$menuItem = $this->menuService->create($menuForm);
|
||||
if ($menuItem){
|
||||
$this->redirect("/admin/settings/menu/" . $menuItem->id, code: 302);
|
||||
$this->redirect("/admin/settings/menu/view/" . $menuItem->id, code: 302);
|
||||
}
|
||||
}
|
||||
$this->redirect("/admin/settings/menu/create", code: 302);
|
||||
@ -107,7 +107,7 @@ class MenuController extends AdminController
|
||||
if ($menuForm->validate()){
|
||||
$menuItem = $this->menuService->update($menuForm, $menuItem);
|
||||
if ($menuItem){
|
||||
$this->redirect("/admin/settings/menu/" . $menuItem->id, code: 302);
|
||||
$this->redirect("/admin/settings/menu/view/" . $menuItem->id, code: 302);
|
||||
}
|
||||
}
|
||||
$this->redirect("/admin/settings/menu/update/" . $id, code: 302);
|
||||
|
@ -14,7 +14,7 @@ App::$collector->group(["prefix" => "admin"], function (RouteCollector $router)
|
||||
App::$collector->get('/page/{page_number}', [\kernel\modules\menu\controllers\MenuController::class, 'actionIndex']);
|
||||
App::$collector->get('/create', [\kernel\modules\menu\controllers\MenuController::class, 'actionCreate']);
|
||||
App::$collector->post("/", [\kernel\modules\menu\controllers\MenuController::class, 'actionAdd']);
|
||||
App::$collector->get('/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionView']);
|
||||
App::$collector->get('/view/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionView']);
|
||||
App::$collector->any('/update/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionUpdate']);
|
||||
App::$collector->any("/edit/{id}", [\kernel\modules\menu\controllers\MenuController::class, 'actionEdit']);
|
||||
App::$collector->get('/delete/{id}', [\kernel\modules\menu\controllers\MenuController::class, 'actionDelete']);
|
||||
|
@ -105,9 +105,6 @@ class MenuService
|
||||
$child = self::getChild($id);
|
||||
if (!$child->isEmpty()){
|
||||
foreach ($child as $item){
|
||||
// if ($item->url === \kernel\Request::getUrlPath()){
|
||||
// return true;
|
||||
// }
|
||||
if (strripos(Request::getUrlPath(), $item->url) !== false) {
|
||||
return true;
|
||||
}
|
||||
|
@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\modules\module_shop_client\controllers;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use JetBrains\PhpStorm\NoReturn;
|
||||
use kernel\AdminController;
|
||||
use kernel\Flash;
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\helpers\Files;
|
||||
use kernel\helpers\RESTClient;
|
||||
use kernel\modules\module_shop_client\services\ModuleShopClientService;
|
||||
use kernel\Request;
|
||||
use kernel\services\ModuleService;
|
||||
|
||||
class ModuleShopClientController extends AdminController
|
||||
{
|
||||
|
||||
protected Client $client;
|
||||
protected ModuleService $moduleService;
|
||||
|
||||
protected function init(): void
|
||||
{
|
||||
parent::init();
|
||||
$this->cgView->viewPath = KERNEL_MODULES_DIR . "/module_shop_client/views/";
|
||||
|
||||
$this->client = new Client();
|
||||
$this->moduleService = new ModuleService();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function actionIndex(int $page_number = 1): void
|
||||
{
|
||||
$per_page = 8;
|
||||
$modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug');
|
||||
$modules_info = json_decode($modules_info->getBody()->getContents(), true);
|
||||
$module_count = count($modules_info);
|
||||
$modules_info = array_slice($modules_info, $per_page*($page_number-1), $per_page);
|
||||
$this->cgView->render("index.php", [
|
||||
'modules_info' => $modules_info,
|
||||
'moduleService' => $this->moduleService,
|
||||
'page_number' => $page_number,
|
||||
'module_count' => $module_count,
|
||||
'per_page' => $per_page,
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionView(int $id): void
|
||||
{
|
||||
$module_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/' . $id);
|
||||
$module_info = json_decode($module_info->getBody()->getContents(), true);
|
||||
$this->cgView->render("view.php", ['data' => $module_info]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
#[NoReturn] public function actionInstall(): void
|
||||
{
|
||||
$request = new Request();
|
||||
$id = $request->get("id");
|
||||
$module_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/install/' . $id);
|
||||
|
||||
$module_info = json_decode($module_info->getBody()->getContents(), true);
|
||||
Files::uploadByUrl($_ENV['MODULE_SHOP_URL'] . $module_info['path_to_archive'], RESOURCES_DIR . "/tmp/modules");
|
||||
$this->moduleService->installModule('/resources/tmp/modules/' . basename($module_info['path_to_archive']));
|
||||
|
||||
Flash::setMessage("success", "Модуль успешно установлен.");
|
||||
$this->redirect('/admin/module_shop_client', 302);
|
||||
}
|
||||
|
||||
#[NoReturn] public function actionUpdate(): void
|
||||
{
|
||||
$request = new Request();
|
||||
$slug = $request->get("slug");
|
||||
$modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug');
|
||||
|
||||
$modules_info = json_decode($modules_info->getBody()->getContents(), true);
|
||||
foreach ($modules_info as $module) {
|
||||
if ($module['slug'] === $slug) {
|
||||
$path = $module['path_to_archive'];
|
||||
}
|
||||
}
|
||||
if (isset($path)) {
|
||||
Files::uploadByUrl($_ENV['MODULE_SHOP_URL'] . $path, RESOURCES_DIR . "/tmp/modules");
|
||||
$this->moduleService->updateModule('/resources/tmp/modules/' . basename($path));
|
||||
Flash::setMessage("success", "Модуль успешно обновлен.");
|
||||
} else {
|
||||
Flash::setMessage("error", "Ошибка обновления модуля.");
|
||||
}
|
||||
|
||||
$this->redirect('/admin/module_shop_client', 302);
|
||||
}
|
||||
|
||||
#[NoReturn] public function actionDelete(): void
|
||||
{
|
||||
$request = new Request();
|
||||
$slug = $request->get("slug");
|
||||
$module_info = $this->moduleService->getModuleInfoBySlug($slug);
|
||||
$this->moduleService->uninstallModule($module_info['app_module_path']);
|
||||
|
||||
Flash::setMessage("success", "Модуль успешно удален.");
|
||||
$this->redirect('/admin/module_shop_client', 302);
|
||||
}
|
||||
|
||||
}
|
10
kernel/modules/module_shop_client/manifest.json
Normal file
10
kernel/modules/module_shop_client/manifest.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "Module shop client",
|
||||
"version": "0.1",
|
||||
"author": "ITGuild",
|
||||
"slug": "module_shop_client",
|
||||
"description": "Module shop client module",
|
||||
"routs": "routs/module_shop_client.php",
|
||||
"migration_path": "migrations",
|
||||
"dependence": "menu"
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
use kernel\App;
|
||||
use kernel\CgRouteCollector;
|
||||
use Phroute\Phroute\RouteCollector;
|
||||
|
||||
App::$collector->filter('bearer', [\kernel\modules\secure\middlewares\BearerAuthMiddleware::class, "handler"]);
|
||||
|
||||
App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
|
||||
App::$collector->group(["before" => "auth"], function (RouteCollector $router) {
|
||||
App::$collector->group(["prefix" => "module_shop_client"], function (RouteCollector $router) {
|
||||
App::$collector->get('/', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionIndex']);
|
||||
App::$collector->get('/page/{page_number}', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionIndex']);
|
||||
App::$collector->get('/install', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionInstall']);
|
||||
App::$collector->get('/view/{id}', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionView']);
|
||||
App::$collector->get('/delete', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionDelete']);
|
||||
App::$collector->get('/update', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionUpdate']);
|
||||
});
|
||||
});
|
||||
});
|
68
kernel/modules/module_shop_client/views/index.php
Normal file
68
kernel/modules/module_shop_client/views/index.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* @var array $modules_info
|
||||
* @var int $module_count
|
||||
* @var int $page_number
|
||||
* @var int $per_page
|
||||
* @var \kernel\services\ModuleService $moduleService
|
||||
*/
|
||||
|
||||
use Itguild\Tables\ListJsonTable;
|
||||
|
||||
$meta = [];
|
||||
$meta['columns'] = [
|
||||
"name" => "Название",
|
||||
"author" => "Автор",
|
||||
"version" => "Версия",
|
||||
"description" => "Описание",
|
||||
"installations" => "Установки",
|
||||
"views" => "Просмотры"
|
||||
];
|
||||
$meta['params'] = ["class" => "table table-bordered"];
|
||||
$meta['perPage'] = $per_page;
|
||||
$meta['baseUrl'] = "/admin/module_shop_client";
|
||||
$meta['currentPage'] = $page_number;
|
||||
$meta['total'] = $module_count;
|
||||
|
||||
$info_to_table['meta'] = $meta;
|
||||
$info_to_table['data'] = $modules_info;
|
||||
|
||||
$table = new ListJsonTable(json_encode($info_to_table, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
|
||||
|
||||
$table->addAction(\kernel\IGTabel\action_column\ViewActionColumn::class);
|
||||
|
||||
$table->addAction(function ($row, $url) use ($moduleService){
|
||||
$slug = $row['slug'];
|
||||
$id = $row['id'];
|
||||
if ($moduleService->isInstall($slug)){
|
||||
$label = "Удалить";
|
||||
$btn_type = "danger";
|
||||
$btn = "<a class='btn btn-$btn_type' href='$url/delete/?slug=$slug' style='margin: 3px; width: 150px;' >$label</a>";
|
||||
}
|
||||
else {
|
||||
$label = "Установить";
|
||||
$btn_type = "success";
|
||||
$btn = "<a class='btn btn-$btn_type' href='$url/install/?id=$id' style='margin: 3px; width: 150px;' >$label</a>";
|
||||
}
|
||||
|
||||
return $btn;
|
||||
});
|
||||
|
||||
$table->addAction(function ($row, $url) use ($moduleService){
|
||||
$slug = $row['slug'];
|
||||
if ($moduleService->isInstall($slug)){
|
||||
if (!$moduleService->isLastVersion($slug)) {
|
||||
$label = "Обновить";
|
||||
$btn_type = "info";
|
||||
return "<a class='btn btn-$btn_type' href='$url/update/?slug=$slug' style='margin: 3px; width: 150px;' >$label</a>";
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
|
||||
$table->create();
|
||||
|
||||
\kernel\widgets\ModuleTabsWidget::create()->run();
|
||||
$table->render();
|
32
kernel/modules/module_shop_client/views/view.php
Normal file
32
kernel/modules/module_shop_client/views/view.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?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" => "Описание",
|
||||
"installations" => "Установки",
|
||||
"views" => "Просмотры"
|
||||
],
|
||||
"params" => ["class" => "table table-bordered"],
|
||||
"baseUrl" => "/admin/module_shop_client",
|
||||
],
|
||||
"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_shop_client")->fetch();
|
||||
return $btn;
|
||||
});
|
||||
$table->create();
|
||||
$table->render();
|
@ -88,7 +88,7 @@ class OptionController extends AdminController
|
||||
if ($optionForm->validate()) {
|
||||
$option = $this->optionService->update($optionForm, $option);
|
||||
if ($option) {
|
||||
$this->redirect('/admin/option/' . $option->id);
|
||||
$this->redirect('/admin/option/view/' . $option->id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ App::$collector->group(["prefix" => "admin"], function (RouteCollector $router)
|
||||
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->get('/view/{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']);
|
||||
|
@ -32,7 +32,7 @@ class PostController extends AdminController
|
||||
if ($postForm->validate()) {
|
||||
$post = $this->postService->create($postForm);
|
||||
if ($post) {
|
||||
$this->redirect("/admin/post/" . $post->id);
|
||||
$this->redirect("/admin/post/view/" . $post->id);
|
||||
}
|
||||
}
|
||||
$this->redirect("/admin/post/create");
|
||||
@ -87,7 +87,7 @@ class PostController extends AdminController
|
||||
if ($postForm->validate()) {
|
||||
$post = $this->postService->update($postForm, $post);
|
||||
if ($post) {
|
||||
$this->redirect("/admin/post/" . $post->id);
|
||||
$this->redirect("/admin/post/view/" . $post->id);
|
||||
}
|
||||
}
|
||||
$this->redirect("/admin/post/update/" . $id);
|
||||
|
@ -13,7 +13,7 @@ App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
|
||||
App::$collector->get('/page/{page_number}', [\kernel\modules\post\controllers\PostController::class, 'actionIndex']);
|
||||
App::$collector->get('/create', [\kernel\modules\post\controllers\PostController::class, 'actionCreate']);
|
||||
App::$collector->post("/", [\kernel\modules\post\controllers\PostController::class, 'actionAdd']);
|
||||
App::$collector->get('/{id}', [\kernel\modules\post\controllers\PostController::class, 'actionView']);
|
||||
App::$collector->get('/view/{id}', [\kernel\modules\post\controllers\PostController::class, 'actionView']);
|
||||
App::$collector->any('/update/{id}', [\kernel\modules\post\controllers\PostController::class, 'actionUpdate']);
|
||||
App::$collector->any("/edit/{id}", [\kernel\modules\post\controllers\PostController::class, 'actionEdit']);
|
||||
App::$collector->get('/delete/{id}', [\kernel\modules\post\controllers\PostController::class, 'actionDelete']);
|
||||
|
@ -1,16 +0,0 @@
|
||||
<?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> ";
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
<?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> ";
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
<?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> ";
|
||||
}
|
||||
}
|
@ -36,7 +36,7 @@ class UserController extends AdminController
|
||||
if ($userForm->validate()){
|
||||
$user = $this->userService->create($userForm);
|
||||
if ($user){
|
||||
$this->redirect("/admin/user/" . $user->id);
|
||||
$this->redirect("/admin/user/view/" . $user->id);
|
||||
}
|
||||
}
|
||||
$this->redirect("/admin/user/create");
|
||||
@ -94,7 +94,7 @@ class UserController extends AdminController
|
||||
if ($userForm->validate()){
|
||||
$user = $userService->update($userForm, $user);
|
||||
if ($user){
|
||||
$this->redirect("/admin/user/" . $user->id);
|
||||
$this->redirect("/admin/user/view/" . $user->id);
|
||||
}
|
||||
}
|
||||
$this->redirect("/admin/user/update/" . $id);
|
||||
|
@ -13,7 +13,7 @@ App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
|
||||
App::$collector->get('/page/{page_number}', [\kernel\modules\user\controllers\UserController::class, 'actionIndex']);
|
||||
App::$collector->get('/create', [\kernel\modules\user\controllers\UserController::class, 'actionCreate']);
|
||||
App::$collector->post("/", [\kernel\modules\user\controllers\UserController::class, 'actionAdd']);
|
||||
App::$collector->get('/{id}', [\kernel\modules\user\controllers\UserController::class, 'actionView']);
|
||||
App::$collector->get('/view/{id}', [\kernel\modules\user\controllers\UserController::class, 'actionView']);
|
||||
App::$collector->any('/update/{id}', [\kernel\modules\user\controllers\UserController::class, 'actionUpdate']);
|
||||
App::$collector->any("/edit/{id}", [\kernel\modules\user\controllers\UserController::class, 'actionEdit']);
|
||||
App::$collector->get('/delete/{id}', [\kernel\modules\user\controllers\UserController::class, 'actionDelete']);
|
||||
|
Reference in New Issue
Block a user