module fix

This commit is contained in:
Kavalar 2024-10-10 22:40:09 +03:00
parent 94496910d7
commit d9c4cecd48
4 changed files with 20 additions and 8 deletions

View File

@ -84,7 +84,7 @@ class AdminConsoleController extends ConsoleController
$this->menuService->createItem([ $this->menuService->createItem([
"label" => "Настройки", "label" => "Настройки",
"url" => "/admin/settings", "url" => "#",
"slug" => "settings", "slug" => "settings",
]); ]);
$this->out->r("create item menu settings", "green"); $this->out->r("create item menu settings", "green");

View File

@ -22,8 +22,9 @@ class ModuleController extends AdminController
$this->moduleService = new ModuleService(); $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(); $module_paths = Option::where("key", "module_paths")->first();
$dirs = []; $dirs = [];
if ($module_paths){ if ($module_paths){
@ -34,8 +35,8 @@ class ModuleController extends AdminController
} }
$modules_info = []; $modules_info = [];
$i = 1;
foreach ($dirs as $dir){ foreach ($dirs as $dir){
$i = 1;
foreach (new DirectoryIterator($dir) as $fileInfo) { foreach (new DirectoryIterator($dir) as $fileInfo) {
$info = []; $info = [];
if($fileInfo->isDot()) continue; if($fileInfo->isDot()) continue;
@ -44,8 +45,15 @@ class ModuleController extends AdminController
$i++; $i++;
} }
} }
$module_count = count($modules_info);
$this->cgView->render("index.php", ['modules_info' => $modules_info, 'moduleService' => $this->moduleService]); $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 public function actionActivate(): void

View File

@ -8,6 +8,7 @@ App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
App::$collector->group(["before" => "auth"], function (RouteCollector $router){ App::$collector->group(["before" => "auth"], function (RouteCollector $router){
App::$collector->group(["prefix" => "module"], function (RouteCollector $router){ App::$collector->group(["prefix" => "module"], function (RouteCollector $router){
App::$collector->get('/', [\kernel\controllers\ModuleController::class, 'actionIndex']); 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('/activate', [\kernel\controllers\ModuleController::class, 'actionActivate']);
App::$collector->get('/view', [\kernel\controllers\ModuleController::class, 'actionView']); App::$collector->get('/view', [\kernel\controllers\ModuleController::class, 'actionView']);
}); });

View File

@ -1,6 +1,9 @@
<?php <?php
/** /**
* @var array $modules_info * @var array $modules_info
* @var int $module_count
* @var int $page_number
* @var int $per_page
* @var \kernel\services\ModuleService $moduleService * @var \kernel\services\ModuleService $moduleService
*/ */
@ -12,10 +15,10 @@ $meta['columns'] = [
"description" => "Описание" "description" => "Описание"
]; ];
$meta['params'] = ["class" => "table table-bordered"]; $meta['params'] = ["class" => "table table-bordered"];
$meta['perPage'] = 10; $meta['perPage'] = $per_page;
$meta['baseUrl'] = "/admin/module"; $meta['baseUrl'] = "/admin/module";
$meta['currentPage'] = 1; $meta['currentPage'] = $page_number;
$meta['total'] = count($modules_info); $meta['total'] = $module_count;
$info_to_table['meta'] = $meta; $info_to_table['meta'] = $meta;
$info_to_table['data'] = $modules_info; $info_to_table['data'] = $modules_info;