|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* For licensing terms, see /license.txt */ |
|
4
|
|
|
|
|
5
|
|
|
declare(strict_types=1); |
|
6
|
|
|
|
|
7
|
|
|
namespace Chamilo\CoreBundle\ServiceHelper; |
|
8
|
|
|
|
|
9
|
|
|
use Chamilo\CoreBundle\Settings\SettingsManager; |
|
10
|
|
|
use Chamilo\CourseBundle\Settings\SettingsCourseManager; |
|
11
|
|
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
|
12
|
|
|
use Symfony\Component\Routing\RouterInterface; |
|
13
|
|
|
|
|
14
|
|
|
final class ThemeHelper |
|
15
|
|
|
{ |
|
16
|
|
|
public const DEFAULT_THEME = 'chamilo'; |
|
17
|
|
|
|
|
18
|
|
|
public function __construct( |
|
19
|
|
|
private readonly AccessUrlHelper $accessUrlHelper, |
|
20
|
|
|
private readonly SettingsManager $settingsManager, |
|
21
|
|
|
private readonly UserHelper $userHelper, |
|
22
|
|
|
private readonly CidReqHelper $cidReqHelper, |
|
23
|
|
|
private readonly SettingsCourseManager $settingsCourseManager, |
|
24
|
|
|
private readonly RouterInterface $router, |
|
25
|
|
|
) {} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Returns the name of the color theme configured to be applied on the current page. |
|
29
|
|
|
* The returned name depends on the platform, course or user settings. |
|
30
|
|
|
*/ |
|
31
|
|
|
public function getVisualTheme(): string |
|
32
|
|
|
{ |
|
33
|
|
|
static $visualTheme; |
|
34
|
|
|
|
|
35
|
|
|
if (isset($visualTheme)) { |
|
36
|
|
|
return $visualTheme; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
$accessUrl = $this->accessUrlHelper->getCurrent(); |
|
40
|
|
|
|
|
41
|
|
|
$visualTheme = $accessUrl->getActiveColorTheme()?->getColorTheme()->getSlug(); |
|
42
|
|
|
|
|
43
|
|
|
if ('true' == $this->settingsManager->getSetting('profile.user_selected_theme')) { |
|
44
|
|
|
$visualTheme = $this->userHelper->getCurrent()?->getTheme(); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
if ('true' == $this->settingsManager->getSetting('course.allow_course_theme')) { |
|
48
|
|
|
$course = $this->cidReqHelper->getCourseEntity(); |
|
49
|
|
|
|
|
50
|
|
|
if ($course) { |
|
51
|
|
|
$this->settingsCourseManager->setCourse($course); |
|
52
|
|
|
|
|
53
|
|
|
$visualTheme = $this->settingsCourseManager->getSetting('course_theme'); |
|
54
|
|
|
|
|
55
|
|
|
if (1 === (int) $this->settingsCourseManager->getSetting('allow_learning_path_theme')) { |
|
56
|
|
|
global $lp_theme_css; |
|
57
|
|
|
|
|
58
|
|
|
$visualTheme = $lp_theme_css; |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
if (empty($visualTheme)) { |
|
64
|
|
|
return self::DEFAULT_THEME; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
return $visualTheme; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function getThemeAssetUrl(string $path, bool $absolute = false): string |
|
71
|
|
|
{ |
|
72
|
|
|
$themeName = $this->getVisualTheme(); |
|
73
|
|
|
|
|
74
|
|
|
if (empty($themeName)) { |
|
75
|
|
|
return ''; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
return $this->router->generate( |
|
79
|
|
|
'theme_asset', |
|
80
|
|
|
['name' => $themeName, 'path' => $path], |
|
81
|
|
|
$absolute ? UrlGeneratorInterface::ABSOLUTE_URL : UrlGeneratorInterface::ABSOLUTE_PATH |
|
82
|
|
|
); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function getThemeAssetLinkTag(string $path, bool $absoluteUrl = false): string |
|
86
|
|
|
{ |
|
87
|
|
|
$url = $this->getThemeAssetUrl($path, $absoluteUrl); |
|
88
|
|
|
|
|
89
|
|
|
if (empty($url)) { |
|
90
|
|
|
return ''; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
return sprintf('<link rel="stylesheet" href="%s">', $url); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|