|
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
|
|
|
|
|
12
|
|
|
final class ThemeHelper |
|
13
|
|
|
{ |
|
14
|
|
|
public const DEFAULT_THEME = 'chamilo'; |
|
15
|
|
|
|
|
16
|
|
|
public function __construct( |
|
17
|
|
|
private readonly AccessUrlHelper $accessUrlHelper, |
|
18
|
|
|
private readonly SettingsManager $settingsManager, |
|
19
|
|
|
private readonly UserHelper $userHelper, |
|
20
|
|
|
private readonly CidReqHelper $cidReqHelper, |
|
21
|
|
|
private readonly SettingsCourseManager $settingsCourseManager, |
|
22
|
|
|
) {} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Returns the name of the color theme configured to be applied on the current page. |
|
26
|
|
|
* The returned name depends on the platform, course or user settings. |
|
27
|
|
|
*/ |
|
28
|
|
|
public function getVisualTheme(): string |
|
29
|
|
|
{ |
|
30
|
|
|
static $visualTheme; |
|
31
|
|
|
|
|
32
|
|
|
if (isset($visualTheme)) { |
|
33
|
|
|
return $visualTheme; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
$accessUrl = $this->accessUrlHelper->getCurrent(); |
|
37
|
|
|
|
|
38
|
|
|
$visualTheme = $accessUrl->getActiveColorTheme()?->getColorTheme()->getSlug(); |
|
39
|
|
|
|
|
40
|
|
|
if ('true' == $this->settingsManager->getSetting('profile.user_selected_theme')) { |
|
41
|
|
|
$visualTheme = $this->userHelper->getCurrent()?->getTheme(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
if ('true' == $this->settingsManager->getSetting('course.allow_course_theme')) { |
|
45
|
|
|
$course = $this->cidReqHelper->getCourseEntity(); |
|
46
|
|
|
|
|
47
|
|
|
if ($course) { |
|
48
|
|
|
$this->settingsCourseManager->setCourse($course); |
|
49
|
|
|
|
|
50
|
|
|
$visualTheme = $this->settingsCourseManager->getSetting('course_theme'); |
|
51
|
|
|
|
|
52
|
|
|
if (1 === (int) $this->settingsCourseManager->getSetting('allow_learning_path_theme')) { |
|
53
|
|
|
global $lp_theme_css; |
|
54
|
|
|
|
|
55
|
|
|
$visualTheme = $lp_theme_css; |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
if (empty($visualTheme)) { |
|
61
|
|
|
return self::DEFAULT_THEME; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
return $visualTheme; |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|