From d9c4cecd48c0bca2ed8fc9c459b0b15e22f89bca Mon Sep 17 00:00:00 2001 From: Kavalar Date: Thu, 10 Oct 2024 22:40:09 +0300 Subject: [PATCH] module fix --- .../controllers/AdminConsoleController.php | 2 +- kernel/controllers/ModuleController.php | 16 ++++++++++++---- kernel/routs/admin.php | 1 + kernel/views/module/index.php | 9 ++++++--- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/kernel/console/controllers/AdminConsoleController.php b/kernel/console/controllers/AdminConsoleController.php index 21e3f8f..e1c3bfe 100644 --- a/kernel/console/controllers/AdminConsoleController.php +++ b/kernel/console/controllers/AdminConsoleController.php @@ -84,7 +84,7 @@ class AdminConsoleController extends ConsoleController $this->menuService->createItem([ "label" => "Настройки", - "url" => "/admin/settings", + "url" => "#", "slug" => "settings", ]); $this->out->r("create item menu settings", "green"); diff --git a/kernel/controllers/ModuleController.php b/kernel/controllers/ModuleController.php index 458671e..4b415d6 100644 --- a/kernel/controllers/ModuleController.php +++ b/kernel/controllers/ModuleController.php @@ -22,8 +22,9 @@ class ModuleController extends AdminController $this->moduleService = new ModuleService(); } - public function actionIndex(): void + public function actionIndex($page_number = 1): void { + $per_page = 8; $module_paths = Option::where("key", "module_paths")->first(); $dirs = []; if ($module_paths){ @@ -34,8 +35,8 @@ class ModuleController extends AdminController } $modules_info = []; + $i = 1; foreach ($dirs as $dir){ - $i = 1; foreach (new DirectoryIterator($dir) as $fileInfo) { $info = []; if($fileInfo->isDot()) continue; @@ -44,8 +45,15 @@ class ModuleController extends AdminController $i++; } } - - $this->cgView->render("index.php", ['modules_info' => $modules_info, 'moduleService' => $this->moduleService]); + $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 actionActivate(): void diff --git a/kernel/routs/admin.php b/kernel/routs/admin.php index 7e238d7..121395c 100644 --- a/kernel/routs/admin.php +++ b/kernel/routs/admin.php @@ -8,6 +8,7 @@ App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){ App::$collector->group(["before" => "auth"], function (RouteCollector $router){ App::$collector->group(["prefix" => "module"], function (RouteCollector $router){ App::$collector->get('/', [\kernel\controllers\ModuleController::class, 'actionIndex']); + App::$collector->get('/page/{page_number}', [\kernel\controllers\ModuleController::class, 'actionIndex']); App::$collector->get('/activate', [\kernel\controllers\ModuleController::class, 'actionActivate']); App::$collector->get('/view', [\kernel\controllers\ModuleController::class, 'actionView']); }); diff --git a/kernel/views/module/index.php b/kernel/views/module/index.php index 7d69978..52a6647 100644 --- a/kernel/views/module/index.php +++ b/kernel/views/module/index.php @@ -1,6 +1,9 @@ "Описание" ]; $meta['params'] = ["class" => "table table-bordered"]; -$meta['perPage'] = 10; +$meta['perPage'] = $per_page; $meta['baseUrl'] = "/admin/module"; -$meta['currentPage'] = 1; -$meta['total'] = count($modules_info); +$meta['currentPage'] = $page_number; +$meta['total'] = $module_count; $info_to_table['meta'] = $meta; $info_to_table['data'] = $modules_info;