2024-09-12 16:01:04 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace kernel\controllers;
|
|
|
|
|
|
|
|
use DirectoryIterator;
|
2024-11-19 12:27:52 +03:00
|
|
|
use JetBrains\PhpStorm\NoReturn;
|
2024-10-11 17:02:35 +03:00
|
|
|
use Josantonius\Session\Facades\Session;
|
2024-09-12 16:01:04 +03:00
|
|
|
use kernel\AdminController;
|
2024-11-20 16:48:13 +03:00
|
|
|
use kernel\EntityRelation;
|
2024-09-12 16:01:04 +03:00
|
|
|
use kernel\helpers\Debug;
|
|
|
|
use kernel\models\Option;
|
2024-10-29 14:53:52 +03:00
|
|
|
use kernel\modules\module_shop_client\services\ModuleShopClientService;
|
2024-09-12 16:01:04 +03:00
|
|
|
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;
|
2024-10-22 11:09:35 +03:00
|
|
|
$mi = $this->moduleService->getModuleInfo($fileInfo->getPathname());
|
|
|
|
if (isset($mi['show_in_admin'])){
|
|
|
|
if ($mi['show_in_admin'] == 0){
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2024-09-12 16:01:04 +03:00
|
|
|
$info['id'] = $i;
|
2024-10-22 11:09:35 +03:00
|
|
|
$modules_info[] = array_merge($info, $mi);
|
2024-09-12 16:01:04 +03:00
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
}
|
2024-10-29 14:53:52 +03:00
|
|
|
|
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-10-29 14:53:52 +03:00
|
|
|
|
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-11 17:02:35 +03:00
|
|
|
$active_res = $this->moduleService->setActiveModule($request->get("slug"));
|
2024-10-31 16:12:02 +03:00
|
|
|
if (!$active_res) {
|
2024-10-11 17:02:35 +03:00
|
|
|
Session::start();
|
|
|
|
Session::set("error", implode(";", $this->moduleService->getErrors()));
|
|
|
|
$this->redirect("/admin", 302);
|
|
|
|
}
|
2024-10-11 15:44:15 +03:00
|
|
|
$mod_info = $this->moduleService->getModuleInfoBySlug($request->get('slug'));
|
|
|
|
|
|
|
|
$this->cgView->render("view.php", ['data' => $mod_info]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function actionDeactivate(): void
|
|
|
|
{
|
|
|
|
$request = new Request();
|
2024-10-14 15:52:52 +03:00
|
|
|
$active_res = $this->moduleService->deactivateModule($request->get("slug"));
|
|
|
|
if (!$active_res){
|
|
|
|
Session::start();
|
|
|
|
Session::set("error", implode(";", $this->moduleService->getErrors()));
|
|
|
|
$this->redirect("/admin", 302);
|
|
|
|
}
|
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-11-19 12:27:52 +03:00
|
|
|
#[NoReturn] public function actionUpdate(): void
|
2024-10-14 15:52:52 +03:00
|
|
|
{
|
|
|
|
$request = new Request();
|
2024-11-18 15:55:43 +03:00
|
|
|
$slug = $request->get('slug');
|
2024-11-19 12:27:52 +03:00
|
|
|
$this->redirect("/admin/module_shop_client/update/?slug=" . $slug, 302);
|
2024-10-14 15:52:52 +03:00
|
|
|
}
|
|
|
|
|
2024-09-12 16:01:04 +03:00
|
|
|
}
|