Passed
Pull Request — master (#5614)
by Angel Fernando Quiroz
09:21
created

ThemeHelper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
nc 1
nop 5
dl 0
loc 7
rs 10
c 1
b 0
f 0
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