2024-09-12 16:01:04 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace kernel\controllers;
|
|
|
|
|
|
|
|
use DirectoryIterator;
|
|
|
|
use kernel\AdminController;
|
|
|
|
use kernel\helpers\Debug;
|
|
|
|
use kernel\models\Option;
|
|
|
|
use kernel\modules\user\service\UserService;
|
2024-09-13 13:54:58 +03:00
|
|
|
use kernel\Request;
|
2024-09-12 16:01:04 +03:00
|
|
|
use kernel\services\ModuleService;
|
|
|
|
|
|
|
|
class ModuleController extends AdminController
|
|
|
|
{
|
|
|
|
protected ModuleService $moduleService;
|
|
|
|
|
|
|
|
protected function init(): void
|
|
|
|
{
|
|
|
|
parent::init();
|
|
|
|
$this->cgView->viewPath = KERNEL_DIR . "/views/module/";
|
|
|
|
|
|
|
|
$this->moduleService = new ModuleService();
|
|
|
|
}
|
|
|
|
|
2024-10-10 22:40:09 +03:00
|
|
|
public function actionIndex($page_number = 1): void
|
2024-09-12 16:01:04 +03:00
|
|
|
{
|
2024-10-10 22:40:09 +03:00
|
|
|
$per_page = 8;
|
2024-10-10 16:45:53 +03:00
|
|
|
$module_paths = Option::where("key", "module_paths")->first();
|
2024-09-12 16:01:04 +03:00
|
|
|
$dirs = [];
|
2024-10-10 16:45:53 +03:00
|
|
|
if ($module_paths){
|
|
|
|
$path = json_decode($module_paths->value);
|
2024-09-12 16:01:04 +03:00
|
|
|
foreach ($path->paths as $p){
|
|
|
|
$dirs[] = getConst($p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$modules_info = [];
|
2024-10-10 22:40:09 +03:00
|
|
|
$i = 1;
|
2024-09-12 16:01:04 +03:00
|
|
|
foreach ($dirs as $dir){
|
|
|
|
foreach (new DirectoryIterator($dir) as $fileInfo) {
|
|
|
|
$info = [];
|
|
|
|
if($fileInfo->isDot()) continue;
|
|
|
|
$info['id'] = $i;
|
|
|
|
$modules_info[] = array_merge($info, $this->moduleService->getModuleInfo($fileInfo->getPathname()));
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
}
|
2024-10-10 22:40:09 +03:00
|
|
|
$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,
|
|
|
|
]);
|
2024-09-12 16:01:04 +03:00
|
|
|
}
|
|
|
|
|
2024-09-13 13:54:58 +03:00
|
|
|
public function actionActivate(): void
|
|
|
|
{
|
|
|
|
$request = new Request();
|
2024-10-09 16:42:20 +03:00
|
|
|
$this->moduleService->toggleModule($request->get("slug"));
|
2024-09-23 12:50:50 +03:00
|
|
|
$mod_info = $this->moduleService->getModuleInfoBySlug($request->get('slug'));
|
2024-09-13 13:54:58 +03:00
|
|
|
|
2024-09-23 12:50:50 +03:00
|
|
|
$this->cgView->render("view.php", ['data' => $mod_info]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function actionView(): void
|
|
|
|
{
|
|
|
|
$request = new Request();
|
|
|
|
$mod_info = $this->moduleService->getModuleInfoBySlug($request->get('slug'));
|
|
|
|
|
|
|
|
$this->cgView->render("view.php", ['data' => $mod_info]);
|
2024-09-13 13:54:58 +03:00
|
|
|
}
|
|
|
|
|
2024-09-12 16:01:04 +03:00
|
|
|
}
|