theme dependence

This commit is contained in:
2025-01-21 16:41:48 +03:00
parent f421e0c649
commit 11c99be0f6
26 changed files with 96 additions and 908 deletions

View File

@ -3,6 +3,7 @@
namespace kernel\services;
use DirectoryIterator;
use kernel\Flash;
use kernel\helpers\Debug;
use kernel\helpers\Files;
use kernel\helpers\Manifest;
@ -19,12 +20,15 @@ class ThemeService
protected ModuleService $moduleService;
protected ModuleShopService $moduleShopService;
public function __construct()
{
$this->option = new Option();
$this->findActiveTheme();
$this->moduleService = new ModuleService();
$this->moduleShopService = new ModuleShopService();
}
/**
@ -55,7 +59,12 @@ class ThemeService
return $this->active_theme;
}
public function setActiveTheme(string $theme): void
/**
* @param string $theme
* @return bool
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function setActiveTheme(string $theme): bool
{
$activeTheme = $this->option::where("key", "active_theme")->first();
@ -63,21 +72,25 @@ class ThemeService
if (isset($themeInfo['dependence'])) {
$dependence_array = explode(',', $themeInfo['dependence']);
foreach ($dependence_array as $depend) {
$this->moduleService->runInitScript($depend);
}
}
$currentThemeInfo = $this->getActiveThemeInfo();
if (isset($currentThemeInfo['dependence'])) {
$dependence_array = explode(',', $currentThemeInfo['dependence']);
foreach ($dependence_array as $depend) {
$this->moduleService->runDeactivateScript($depend);
if (!$this->moduleService->isInstall($depend)) {
if ($this->moduleService->isShopModule($depend)) {
$this->moduleShopService->installModule($depend);
} else {
Flash::setMessage("error", "Модуль не найден в IT Guild Framework Shop.");
return false;
}
} else {
if (!$this->moduleService->isActive($depend)) {
$this->moduleService->setActiveModule($depend);
}
}
}
}
$activeTheme->value = getConst($theme);
$activeTheme->save();
return true;
}
public function getActiveThemeInfo(): false|array|string