-
Notifications
You must be signed in to change notification settings - Fork 486
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Internal: Add ThemeHelper to get the current color theme - refs BT#21621
- Loading branch information
Showing
5 changed files
with
84 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
/* For licensing terms, see /license.txt */ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Chamilo\CoreBundle\ServiceHelper; | ||
|
||
use Chamilo\CoreBundle\Settings\SettingsManager; | ||
use Chamilo\CourseBundle\Settings\SettingsCourseManager; | ||
|
||
final class ThemeHelper | ||
{ | ||
public const DEFAULT_THEME = 'chamilo'; | ||
|
||
public function __construct( | ||
private readonly AccessUrlHelper $accessUrlHelper, | ||
private readonly SettingsManager $settingsManager, | ||
private readonly UserHelper $userHelper, | ||
private readonly CidReqHelper $cidReqHelper, | ||
private readonly SettingsCourseManager $settingsCourseManager, | ||
) {} | ||
|
||
/** | ||
* Returns the name of the color theme configured to be applied on the current page. | ||
* The returned name depends on the platform, course or user settings. | ||
*/ | ||
public function getVisualTheme(): string | ||
{ | ||
static $visualTheme; | ||
|
||
if (isset($visualTheme)) { | ||
return $visualTheme; | ||
} | ||
|
||
$accessUrl = $this->accessUrlHelper->getCurrent(); | ||
|
||
$visualTheme = $accessUrl->getActiveColorTheme()?->getColorTheme()->getSlug(); | ||
|
||
if ('true' == $this->settingsManager->getSetting('profile.user_selected_theme')) { | ||
$visualTheme = $this->userHelper->getCurrent()?->getTheme(); | ||
} | ||
|
||
if ('true' == $this->settingsManager->getSetting('course.allow_course_theme')) { | ||
$course = $this->cidReqHelper->getCourseEntity(); | ||
|
||
if ($course) { | ||
$this->settingsCourseManager->setCourse($course); | ||
|
||
$visualTheme = $this->settingsCourseManager->getSetting('course_theme'); | ||
|
||
if (1 === (int) $this->settingsCourseManager->getSetting('allow_learning_path_theme')) { | ||
global $lp_theme_css; | ||
Check failure on line 53 in src/CoreBundle/ServiceHelper/ThemeHelper.php GitHub Actions / PHP 8.1 Test on ubuntu-latestInvalidGlobal
|
||
|
||
$visualTheme = $lp_theme_css; | ||
} | ||
} | ||
} | ||
|
||
if (empty($visualTheme)) { | ||
return self::DEFAULT_THEME; | ||
} | ||
|
||
return $visualTheme; | ||
} | ||
} |