admine theme

This commit is contained in:
2024-12-18 12:27:29 +03:00
parent e152e0f193
commit aa913293ef
5 changed files with 73 additions and 2 deletions

View File

@ -2,20 +2,24 @@
namespace kernel\services;
use DirectoryIterator;
use kernel\helpers\Debug;
use kernel\helpers\Manifest;
use kernel\helpers\RESTClient;
use kernel\models\Option;
class AdminThemeService
{
protected Option $option;
protected string $active_theme;
protected ModuleService $moduleService;
public function __construct()
{
$this->option = new Option();
$this->findActiveAdminTheme();
$this->moduleService = new ModuleService();
}
public function findActiveAdminTheme(): void
@ -56,4 +60,43 @@ class AdminThemeService
return $info;
}
public function isInstall(string $slug): bool
{
$adminThemePaths = Option::where("key", "admin_theme_paths")->first();
$dirs = [];
if ($adminThemePaths) {
$path = json_decode($adminThemePaths->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->getAdminThemeInfo($fileInfo->getPathname())['slug'] === $slug) {
return true;
}
}
}
return false;
}
public function isLastVersion(string $slug): bool
{
if ($this->moduleService->isServerAvailable()) {
$modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug');
$modules_info = json_decode($modules_info->getBody()->getContents(), true);
$themeInfo = $this->getAdminThemeInfo($slug);
foreach ($modules_info as $mod) {
if ($mod['slug'] === $themeInfo['slug'] && $mod['version'] === $themeInfo['version']) {
return true;
}
}
}
return false;
}
}