diff --git a/app/modules/tag/manifest.json b/app/modules/tag/manifest.json index 3967dd6..87665ad 100644 --- a/app/modules/tag/manifest.json +++ b/app/modules/tag/manifest.json @@ -1,6 +1,6 @@ { "name": "Tags", - "version": "0.2", + "version": "0.1", "author": "ITGuild", "slug": "tag", "description": "Tags module", diff --git a/kernel/IGTabel/action_column/ViewActionColumn.php b/kernel/IGTabel/action_column/ViewActionColumn.php index bf17e93..c8a2b3e 100644 --- a/kernel/IGTabel/action_column/ViewActionColumn.php +++ b/kernel/IGTabel/action_column/ViewActionColumn.php @@ -3,10 +3,11 @@ namespace kernel\IGTabel\action_column; use Itguild\Tables\ActionColumn\ActionColumn; +use kernel\helpers\Debug; class ViewActionColumn extends ActionColumn { - protected string $prefix = '/'; + protected string $prefix = '/view/'; public function fetch(): string { diff --git a/kernel/controllers/ModuleController.php b/kernel/controllers/ModuleController.php index 2626620..45522ce 100644 --- a/kernel/controllers/ModuleController.php +++ b/kernel/controllers/ModuleController.php @@ -74,7 +74,7 @@ class ModuleController extends AdminController { $request = new Request(); $active_res = $this->moduleService->setActiveModule($request->get("slug")); - if (!$active_res){ + if (!$active_res) { Session::start(); Session::set("error", implode(";", $this->moduleService->getErrors())); $this->redirect("/admin", 302); diff --git a/kernel/modules/menu/controllers/MenuController.php b/kernel/modules/menu/controllers/MenuController.php index 3d36d5d..30d777c 100644 --- a/kernel/modules/menu/controllers/MenuController.php +++ b/kernel/modules/menu/controllers/MenuController.php @@ -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); diff --git a/kernel/modules/menu/routs/menu.php b/kernel/modules/menu/routs/menu.php index 94ea806..a552303 100644 --- a/kernel/modules/menu/routs/menu.php +++ b/kernel/modules/menu/routs/menu.php @@ -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']); diff --git a/kernel/modules/module_shop_client/controllers/ModuleShopClientController.php b/kernel/modules/module_shop_client/controllers/ModuleShopClientController.php index 0162d6e..2f69665 100644 --- a/kernel/modules/module_shop_client/controllers/ModuleShopClientController.php +++ b/kernel/modules/module_shop_client/controllers/ModuleShopClientController.php @@ -3,9 +3,11 @@ namespace kernel\modules\module_shop_client\controllers; use GuzzleHttp\Client; +use JetBrains\PhpStorm\NoReturn; use kernel\AdminController; use kernel\helpers\Debug; use kernel\modules\module_shop_client\services\ModuleShopClientService; +use kernel\Request; use kernel\services\ModuleService; class ModuleShopClientController extends AdminController @@ -37,6 +39,7 @@ class ModuleShopClientController extends AdminController $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, @@ -55,8 +58,10 @@ class ModuleShopClientController extends AdminController $this->cgView->render("view.php", ['data' => $module_info]); } - public function actionInstall(int $id): void + public function actionInstall(): void { + $request = new Request(); + $id = $request->get("id"); $token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.W10.POQZmGB7EZIayINtYhzu5r1rdgZhF9qPJpaQkl_g6pU'; $module_info = $this->client->request('GET', 'http://igfs.loc/api/module_shop/' . $id, [ 'headers' => [ @@ -69,4 +74,13 @@ class ModuleShopClientController extends AdminController } + #[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']); + $this->redirect('/admin/module_shop_client', 302); + } + } \ No newline at end of file diff --git a/kernel/modules/module_shop_client/routs/module_shop_client.php b/kernel/modules/module_shop_client/routs/module_shop_client.php index 52e87f1..19de0f0 100644 --- a/kernel/modules/module_shop_client/routs/module_shop_client.php +++ b/kernel/modules/module_shop_client/routs/module_shop_client.php @@ -11,13 +11,13 @@ App::$collector->group(["prefix" => "admin"], 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/{id}', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionInstall']); + App::$collector->get('/install', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionInstall']); // 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\module_shop_client\controllers\ModuleShopClientController::class, 'actionView']); + App::$collector->get('/view/{id}', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::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']); + App::$collector->get('/delete', [\kernel\modules\module_shop_client\controllers\ModuleShopClientController::class, 'actionDelete']); }); }); }); diff --git a/kernel/modules/module_shop_client/services/ModuleShopClientService.php b/kernel/modules/module_shop_client/services/ModuleShopClientService.php deleted file mode 100644 index 02517b4..0000000 --- a/kernel/modules/module_shop_client/services/ModuleShopClientService.php +++ /dev/null @@ -1,57 +0,0 @@ -request('GET', 'http://igfs.loc/api/module_shop/gb_slug', [ - 'headers' => [ - 'Authorization' => 'Bearer ' . $token, - ] - ]); - - - return json_decode($res->getBody()->getContents()); - } - - /** - * @throws \Exception - */ -// public static function getModuleShopClientTable(): ListJsonTable -// { -// $modules_info = json_decode(ModuleShopClientService::getModuleShopClientInfo()); -// -// $meta = []; -// $meta['columns'] = [ -// "name" => "Название", -// "author" => "Автор", -// "version" => "Версия", -// "description" => "Описание", -// "installations" => 'Установки', -// "views" => 'Просмотры' -// ]; -// $meta['params'] = ["class" => "table table-bordered"]; -// $meta['perPage'] = 3; -// $meta['baseUrl'] = "/admin/module_shop_client"; -// $meta['currentPage'] = 1; -// $meta['total'] = count($modules_info); -// -// $info_to_table['meta'] = $meta; -// $info_to_table['data'] = $modules_info; -// -// $table = new ListJsonTable(json_encode($info_to_table, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)); -// -// $table->create(); -// return $table; -// } - -} \ No newline at end of file diff --git a/kernel/modules/module_shop_client/views/index.php b/kernel/modules/module_shop_client/views/index.php index 0dd2fd8..37800fc 100644 --- a/kernel/modules/module_shop_client/views/index.php +++ b/kernel/modules/module_shop_client/views/index.php @@ -4,6 +4,7 @@ * @var int $module_count * @var int $page_number * @var int $per_page + * @var \kernel\services\ModuleService $moduleService */ use Itguild\Tables\ListJsonTable; @@ -28,26 +29,25 @@ $info_to_table['data'] = $modules_info; $table = new ListJsonTable(json_encode($info_to_table, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); - -//$table->addAction(function ($row, $url) use ($moduleService){ -// $slug = $row['slug']; -// if ($moduleService->isActive($slug)){ -// $label = "Деактивировать"; -// $btn_type = "warning"; -// $btn = "$label"; -// -// } -// else { -// $label = "Активировать"; -// $btn_type = "primary"; -// $btn = "$label"; -// } -// -// return $btn; -//}); - $table->addAction(\kernel\IGTabel\action_column\ViewActionColumn::class); -$table->addAction(\kernel\IGTabel\action_column\InstallActionColumn::class); + +$table->addAction(function ($row, $url) use ($moduleService){ + $slug = $row['slug']; + $id = $row['id']; + if ($moduleService->isInstall($slug)){ + $label = "Удалить"; + $btn_type = "danger"; + $btn = "$label"; + } + else { + $label = "Установить"; + $btn_type = "warning"; + $btn = "$label"; + } + + return $btn; +}); + $table->create(); $table->render(); diff --git a/kernel/modules/option/controllers/OptionController.php b/kernel/modules/option/controllers/OptionController.php index bc929df..7b1fe2e 100644 --- a/kernel/modules/option/controllers/OptionController.php +++ b/kernel/modules/option/controllers/OptionController.php @@ -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); } } diff --git a/kernel/modules/option/routs/option.php b/kernel/modules/option/routs/option.php index 639becf..9a8ee01 100644 --- a/kernel/modules/option/routs/option.php +++ b/kernel/modules/option/routs/option.php @@ -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']); diff --git a/kernel/modules/post/controllers/PostController.php b/kernel/modules/post/controllers/PostController.php index b65c628..ccd0d44 100644 --- a/kernel/modules/post/controllers/PostController.php +++ b/kernel/modules/post/controllers/PostController.php @@ -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); diff --git a/kernel/modules/post/routs/post.php b/kernel/modules/post/routs/post.php index c52a2bb..e5be155 100644 --- a/kernel/modules/post/routs/post.php +++ b/kernel/modules/post/routs/post.php @@ -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']); diff --git a/kernel/modules/post/table/columns/PostDeleteActionColumn.php b/kernel/modules/post/table/columns/PostDeleteActionColumn.php deleted file mode 100644 index c04ee6b..0000000 --- a/kernel/modules/post/table/columns/PostDeleteActionColumn.php +++ /dev/null @@ -1,16 +0,0 @@ -baseUrl . $this->prefix . $this->id; - return " Удалить "; - } -} \ No newline at end of file diff --git a/kernel/modules/post/table/columns/PostEditActionColumn.php b/kernel/modules/post/table/columns/PostEditActionColumn.php deleted file mode 100644 index d2802bb..0000000 --- a/kernel/modules/post/table/columns/PostEditActionColumn.php +++ /dev/null @@ -1,16 +0,0 @@ -baseUrl . $this->prefix . $this->id; - return " Редактировать "; - } -} \ No newline at end of file diff --git a/kernel/modules/post/table/columns/PostViewActionColumn.php b/kernel/modules/post/table/columns/PostViewActionColumn.php deleted file mode 100644 index ecdec5d..0000000 --- a/kernel/modules/post/table/columns/PostViewActionColumn.php +++ /dev/null @@ -1,16 +0,0 @@ -baseUrl . $this->prefix . $this->id; - return " Просмотр "; - } -} \ No newline at end of file diff --git a/kernel/modules/user/controllers/UserController.php b/kernel/modules/user/controllers/UserController.php index 36c6700..47d439f 100644 --- a/kernel/modules/user/controllers/UserController.php +++ b/kernel/modules/user/controllers/UserController.php @@ -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); diff --git a/kernel/modules/user/routs/user.php b/kernel/modules/user/routs/user.php index d7214fd..5572c92 100644 --- a/kernel/modules/user/routs/user.php +++ b/kernel/modules/user/routs/user.php @@ -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']); diff --git a/kernel/services/ModuleService.php b/kernel/services/ModuleService.php index 646f449..1cd6e73 100644 --- a/kernel/services/ModuleService.php +++ b/kernel/services/ModuleService.php @@ -411,4 +411,27 @@ class ModuleService return $dependence_array; } + public function isInstall(string $slug): bool + { + $module_paths = Option::where("key", "module_paths")->first(); + $dirs = []; + if ($module_paths){ + $path = json_decode($module_paths->value); + foreach ($path->paths as $p){ + $dirs[] = getConst($p); + } + } + + foreach ($dirs as $dir){ + foreach (new DirectoryIterator($dir) as $fileInfo) { + if($fileInfo->isDot()) continue; + if ($this->getModuleInfo($fileInfo->getPathname())['slug'] === $slug) { + return true; + }; + } + } + + return false; + } + } \ No newline at end of file