@@ -36,68 +36,68 @@ |
||
36 | 36 | |
37 | 37 | class Personal implements ISettings { |
38 | 38 | |
39 | - protected string $appName; |
|
40 | - private IConfig $config; |
|
41 | - private IUserSession $userSession; |
|
42 | - private ThemesService $themesService; |
|
43 | - private IInitialState $initialStateService; |
|
39 | + protected string $appName; |
|
40 | + private IConfig $config; |
|
41 | + private IUserSession $userSession; |
|
42 | + private ThemesService $themesService; |
|
43 | + private IInitialState $initialStateService; |
|
44 | 44 | |
45 | - public function __construct(string $appName, |
|
46 | - IConfig $config, |
|
47 | - IUserSession $userSession, |
|
48 | - ThemesService $themesService, |
|
49 | - IInitialState $initialStateService) { |
|
50 | - $this->appName = $appName; |
|
51 | - $this->config = $config; |
|
52 | - $this->userSession = $userSession; |
|
53 | - $this->themesService = $themesService; |
|
54 | - $this->initialStateService = $initialStateService; |
|
55 | - } |
|
45 | + public function __construct(string $appName, |
|
46 | + IConfig $config, |
|
47 | + IUserSession $userSession, |
|
48 | + ThemesService $themesService, |
|
49 | + IInitialState $initialStateService) { |
|
50 | + $this->appName = $appName; |
|
51 | + $this->config = $config; |
|
52 | + $this->userSession = $userSession; |
|
53 | + $this->themesService = $themesService; |
|
54 | + $this->initialStateService = $initialStateService; |
|
55 | + } |
|
56 | 56 | |
57 | - public function getForm(): TemplateResponse { |
|
58 | - $enforcedTheme = $this->config->getSystemValueString('enforce_theme', ''); |
|
57 | + public function getForm(): TemplateResponse { |
|
58 | + $enforcedTheme = $this->config->getSystemValueString('enforce_theme', ''); |
|
59 | 59 | |
60 | - $themes = array_map(function($theme) { |
|
61 | - return [ |
|
62 | - 'id' => $theme->getId(), |
|
63 | - 'type' => $theme->getType(), |
|
64 | - 'title' => $theme->getTitle(), |
|
65 | - 'enableLabel' => $theme->getEnableLabel(), |
|
66 | - 'description' => $theme->getDescription(), |
|
67 | - 'enabled' => $this->themesService->isEnabled($theme), |
|
68 | - ]; |
|
69 | - }, $this->themesService->getThemes()); |
|
60 | + $themes = array_map(function($theme) { |
|
61 | + return [ |
|
62 | + 'id' => $theme->getId(), |
|
63 | + 'type' => $theme->getType(), |
|
64 | + 'title' => $theme->getTitle(), |
|
65 | + 'enableLabel' => $theme->getEnableLabel(), |
|
66 | + 'description' => $theme->getDescription(), |
|
67 | + 'enabled' => $this->themesService->isEnabled($theme), |
|
68 | + ]; |
|
69 | + }, $this->themesService->getThemes()); |
|
70 | 70 | |
71 | - if ($enforcedTheme !== '') { |
|
72 | - $themes = array_filter($themes, function($theme) use ($enforcedTheme) { |
|
73 | - return $theme['type'] !== ITheme::TYPE_THEME || $theme['id'] === $enforcedTheme; |
|
74 | - }); |
|
75 | - } |
|
71 | + if ($enforcedTheme !== '') { |
|
72 | + $themes = array_filter($themes, function($theme) use ($enforcedTheme) { |
|
73 | + return $theme['type'] !== ITheme::TYPE_THEME || $theme['id'] === $enforcedTheme; |
|
74 | + }); |
|
75 | + } |
|
76 | 76 | |
77 | - $this->initialStateService->provideInitialState('themes', array_values($themes)); |
|
78 | - $this->initialStateService->provideInitialState('enforceTheme', $enforcedTheme); |
|
79 | - Util::addScript($this->appName, 'theming-settings'); |
|
77 | + $this->initialStateService->provideInitialState('themes', array_values($themes)); |
|
78 | + $this->initialStateService->provideInitialState('enforceTheme', $enforcedTheme); |
|
79 | + Util::addScript($this->appName, 'theming-settings'); |
|
80 | 80 | |
81 | - return new TemplateResponse($this->appName, 'settings-personal'); |
|
82 | - } |
|
81 | + return new TemplateResponse($this->appName, 'settings-personal'); |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * @return string the section ID, e.g. 'sharing' |
|
86 | - * @since 9.1 |
|
87 | - */ |
|
88 | - public function getSection(): string { |
|
89 | - return $this->appName; |
|
90 | - } |
|
84 | + /** |
|
85 | + * @return string the section ID, e.g. 'sharing' |
|
86 | + * @since 9.1 |
|
87 | + */ |
|
88 | + public function getSection(): string { |
|
89 | + return $this->appName; |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * @return int whether the form should be rather on the top or bottom of |
|
94 | - * the admin section. The forms are arranged in ascending order of the |
|
95 | - * priority values. It is required to return a value between 0 and 100. |
|
96 | - * |
|
97 | - * E.g.: 70 |
|
98 | - * @since 9.1 |
|
99 | - */ |
|
100 | - public function getPriority(): int { |
|
101 | - return 40; |
|
102 | - } |
|
92 | + /** |
|
93 | + * @return int whether the form should be rather on the top or bottom of |
|
94 | + * the admin section. The forms are arranged in ascending order of the |
|
95 | + * priority values. It is required to return a value between 0 and 100. |
|
96 | + * |
|
97 | + * E.g.: 70 |
|
98 | + * @since 9.1 |
|
99 | + */ |
|
100 | + public function getPriority(): int { |
|
101 | + return 40; |
|
102 | + } |
|
103 | 103 | } |
@@ -43,85 +43,85 @@ |
||
43 | 43 | |
44 | 44 | class UserThemeController extends OCSController { |
45 | 45 | |
46 | - protected string $userId; |
|
47 | - private IConfig $config; |
|
48 | - private IUserSession $userSession; |
|
49 | - private ThemesService $themesService; |
|
46 | + protected string $userId; |
|
47 | + private IConfig $config; |
|
48 | + private IUserSession $userSession; |
|
49 | + private ThemesService $themesService; |
|
50 | 50 | |
51 | - /** |
|
52 | - * Config constructor. |
|
53 | - */ |
|
54 | - public function __construct(string $appName, |
|
55 | - IRequest $request, |
|
56 | - IConfig $config, |
|
57 | - IUserSession $userSession, |
|
58 | - ThemesService $themesService) { |
|
59 | - parent::__construct($appName, $request); |
|
60 | - $this->config = $config; |
|
61 | - $this->userSession = $userSession; |
|
62 | - $this->themesService = $themesService; |
|
63 | - $this->userId = $userSession->getUser()->getUID(); |
|
64 | - } |
|
51 | + /** |
|
52 | + * Config constructor. |
|
53 | + */ |
|
54 | + public function __construct(string $appName, |
|
55 | + IRequest $request, |
|
56 | + IConfig $config, |
|
57 | + IUserSession $userSession, |
|
58 | + ThemesService $themesService) { |
|
59 | + parent::__construct($appName, $request); |
|
60 | + $this->config = $config; |
|
61 | + $this->userSession = $userSession; |
|
62 | + $this->themesService = $themesService; |
|
63 | + $this->userId = $userSession->getUser()->getUID(); |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @NoAdminRequired |
|
68 | - * |
|
69 | - * Enable theme |
|
70 | - * |
|
71 | - * @param string $themeId the theme ID |
|
72 | - * @return DataResponse |
|
73 | - * @throws OCSBadRequestException|PreConditionNotMetException |
|
74 | - */ |
|
75 | - public function enableTheme(string $themeId): DataResponse { |
|
76 | - $theme = $this->validateTheme($themeId); |
|
66 | + /** |
|
67 | + * @NoAdminRequired |
|
68 | + * |
|
69 | + * Enable theme |
|
70 | + * |
|
71 | + * @param string $themeId the theme ID |
|
72 | + * @return DataResponse |
|
73 | + * @throws OCSBadRequestException|PreConditionNotMetException |
|
74 | + */ |
|
75 | + public function enableTheme(string $themeId): DataResponse { |
|
76 | + $theme = $this->validateTheme($themeId); |
|
77 | 77 | |
78 | - // Enable selected theme |
|
79 | - $this->themesService->enableTheme($theme); |
|
80 | - return new DataResponse(); |
|
81 | - } |
|
78 | + // Enable selected theme |
|
79 | + $this->themesService->enableTheme($theme); |
|
80 | + return new DataResponse(); |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * @NoAdminRequired |
|
85 | - * |
|
86 | - * Disable theme |
|
87 | - * |
|
88 | - * @param string $themeId the theme ID |
|
89 | - * @return DataResponse |
|
90 | - * @throws OCSBadRequestException|PreConditionNotMetException |
|
91 | - */ |
|
92 | - public function disableTheme(string $themeId): DataResponse { |
|
93 | - $theme = $this->validateTheme($themeId); |
|
83 | + /** |
|
84 | + * @NoAdminRequired |
|
85 | + * |
|
86 | + * Disable theme |
|
87 | + * |
|
88 | + * @param string $themeId the theme ID |
|
89 | + * @return DataResponse |
|
90 | + * @throws OCSBadRequestException|PreConditionNotMetException |
|
91 | + */ |
|
92 | + public function disableTheme(string $themeId): DataResponse { |
|
93 | + $theme = $this->validateTheme($themeId); |
|
94 | 94 | |
95 | - // Enable selected theme |
|
96 | - $this->themesService->disableTheme($theme); |
|
97 | - return new DataResponse(); |
|
98 | - } |
|
95 | + // Enable selected theme |
|
96 | + $this->themesService->disableTheme($theme); |
|
97 | + return new DataResponse(); |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * Validate and return the matching ITheme |
|
102 | - * |
|
103 | - * Disable theme |
|
104 | - * |
|
105 | - * @param string $themeId the theme ID |
|
106 | - * @return ITheme |
|
107 | - * @throws OCSBadRequestException|PreConditionNotMetException |
|
108 | - */ |
|
109 | - private function validateTheme(string $themeId): ITheme { |
|
110 | - if ($themeId === '' || !$themeId) { |
|
111 | - throw new OCSBadRequestException('Invalid theme id: ' . $themeId); |
|
112 | - } |
|
100 | + /** |
|
101 | + * Validate and return the matching ITheme |
|
102 | + * |
|
103 | + * Disable theme |
|
104 | + * |
|
105 | + * @param string $themeId the theme ID |
|
106 | + * @return ITheme |
|
107 | + * @throws OCSBadRequestException|PreConditionNotMetException |
|
108 | + */ |
|
109 | + private function validateTheme(string $themeId): ITheme { |
|
110 | + if ($themeId === '' || !$themeId) { |
|
111 | + throw new OCSBadRequestException('Invalid theme id: ' . $themeId); |
|
112 | + } |
|
113 | 113 | |
114 | - $themes = $this->themesService->getThemes(); |
|
115 | - if (!isset($themes[$themeId])) { |
|
116 | - throw new OCSBadRequestException('Invalid theme id: ' . $themeId); |
|
117 | - } |
|
114 | + $themes = $this->themesService->getThemes(); |
|
115 | + if (!isset($themes[$themeId])) { |
|
116 | + throw new OCSBadRequestException('Invalid theme id: ' . $themeId); |
|
117 | + } |
|
118 | 118 | |
119 | - // If trying to toggle another theme but this is enforced |
|
120 | - if ($this->config->getSystemValueString('enforce_theme', '') !== '' |
|
121 | - && $themes[$themeId]->getType() === ITheme::TYPE_THEME) { |
|
122 | - throw new OCSForbiddenException('Theme switching is disabled'); |
|
123 | - } |
|
119 | + // If trying to toggle another theme but this is enforced |
|
120 | + if ($this->config->getSystemValueString('enforce_theme', '') !== '' |
|
121 | + && $themes[$themeId]->getType() === ITheme::TYPE_THEME) { |
|
122 | + throw new OCSForbiddenException('Theme switching is disabled'); |
|
123 | + } |
|
124 | 124 | |
125 | - return $themes[$themeId]; |
|
126 | - } |
|
125 | + return $themes[$themeId]; |
|
126 | + } |
|
127 | 127 | } |
@@ -108,12 +108,12 @@ |
||
108 | 108 | */ |
109 | 109 | private function validateTheme(string $themeId): ITheme { |
110 | 110 | if ($themeId === '' || !$themeId) { |
111 | - throw new OCSBadRequestException('Invalid theme id: ' . $themeId); |
|
111 | + throw new OCSBadRequestException('Invalid theme id: '.$themeId); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | $themes = $this->themesService->getThemes(); |
115 | 115 | if (!isset($themes[$themeId])) { |
116 | - throw new OCSBadRequestException('Invalid theme id: ' . $themeId); |
|
116 | + throw new OCSBadRequestException('Invalid theme id: '.$themeId); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | // If trying to toggle another theme but this is enforced |
@@ -35,147 +35,147 @@ |
||
35 | 35 | use OCP\IUserSession; |
36 | 36 | |
37 | 37 | class ThemesService { |
38 | - private IUserSession $userSession; |
|
39 | - private IConfig $config; |
|
40 | - |
|
41 | - /** @var ITheme[] */ |
|
42 | - private array $themesProviders; |
|
43 | - |
|
44 | - public function __construct(IUserSession $userSession, |
|
45 | - IConfig $config, |
|
46 | - DefaultTheme $defaultTheme, |
|
47 | - LightTheme $lightTheme, |
|
48 | - DarkTheme $darkTheme, |
|
49 | - HighContrastTheme $highContrastTheme, |
|
50 | - DarkHighContrastTheme $darkHighContrastTheme, |
|
51 | - DyslexiaFont $dyslexiaFont) { |
|
52 | - $this->userSession = $userSession; |
|
53 | - $this->config = $config; |
|
54 | - |
|
55 | - // Register themes |
|
56 | - $this->themesProviders = [ |
|
57 | - $defaultTheme->getId() => $defaultTheme, |
|
58 | - $lightTheme->getId() => $lightTheme, |
|
59 | - $darkTheme->getId() => $darkTheme, |
|
60 | - $highContrastTheme->getId() => $highContrastTheme, |
|
61 | - $darkHighContrastTheme->getId() => $darkHighContrastTheme, |
|
62 | - $dyslexiaFont->getId() => $dyslexiaFont, |
|
63 | - ]; |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * Get the list of all registered themes |
|
68 | - * |
|
69 | - * @return ITheme[] |
|
70 | - */ |
|
71 | - public function getThemes(): array { |
|
72 | - return $this->themesProviders; |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Enable a theme for the logged-in user |
|
77 | - * |
|
78 | - * @param ITheme $theme the theme to enable |
|
79 | - * @return string[] the enabled themes |
|
80 | - */ |
|
81 | - public function enableTheme(ITheme $theme): array { |
|
82 | - $themesIds = $this->getEnabledThemes(); |
|
83 | - |
|
84 | - // If already enabled, ignore |
|
85 | - if (in_array($theme->getId(), $themesIds)) { |
|
86 | - return $themesIds; |
|
87 | - } |
|
88 | - |
|
89 | - /** @var ITheme[] */ |
|
90 | - $themes = array_map(function($themeId) { |
|
91 | - return $this->getThemes()[$themeId]; |
|
92 | - }, $themesIds); |
|
93 | - |
|
94 | - // Filtering all themes with the same type |
|
95 | - $filteredThemes = array_filter($themes, function(ITheme $t) use ($theme) { |
|
96 | - return $theme->getType() === $t->getType(); |
|
97 | - }); |
|
98 | - |
|
99 | - // Retrieve IDs only |
|
100 | - /** @var string[] */ |
|
101 | - $filteredThemesIds = array_map(function(ITheme $t) { |
|
102 | - return $t->getId(); |
|
103 | - }, array_values($filteredThemes)); |
|
104 | - |
|
105 | - $enabledThemes = array_merge(array_diff($themesIds, $filteredThemesIds), [$theme->getId()]); |
|
106 | - $this->setEnabledThemes($enabledThemes); |
|
107 | - |
|
108 | - return $enabledThemes; |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * Disable a theme for the logged-in user |
|
113 | - * |
|
114 | - * @param ITheme $theme the theme to disable |
|
115 | - * @return string[] the enabled themes |
|
116 | - */ |
|
117 | - public function disableTheme(ITheme $theme): array { |
|
118 | - $themesIds = $this->getEnabledThemes(); |
|
119 | - |
|
120 | - // If enabled, removing it |
|
121 | - if (in_array($theme->getId(), $themesIds)) { |
|
122 | - $enabledThemes = array_diff($themesIds, [$theme->getId()]); |
|
123 | - $this->setEnabledThemes($enabledThemes); |
|
124 | - return $enabledThemes; |
|
125 | - } |
|
38 | + private IUserSession $userSession; |
|
39 | + private IConfig $config; |
|
40 | + |
|
41 | + /** @var ITheme[] */ |
|
42 | + private array $themesProviders; |
|
43 | + |
|
44 | + public function __construct(IUserSession $userSession, |
|
45 | + IConfig $config, |
|
46 | + DefaultTheme $defaultTheme, |
|
47 | + LightTheme $lightTheme, |
|
48 | + DarkTheme $darkTheme, |
|
49 | + HighContrastTheme $highContrastTheme, |
|
50 | + DarkHighContrastTheme $darkHighContrastTheme, |
|
51 | + DyslexiaFont $dyslexiaFont) { |
|
52 | + $this->userSession = $userSession; |
|
53 | + $this->config = $config; |
|
54 | + |
|
55 | + // Register themes |
|
56 | + $this->themesProviders = [ |
|
57 | + $defaultTheme->getId() => $defaultTheme, |
|
58 | + $lightTheme->getId() => $lightTheme, |
|
59 | + $darkTheme->getId() => $darkTheme, |
|
60 | + $highContrastTheme->getId() => $highContrastTheme, |
|
61 | + $darkHighContrastTheme->getId() => $darkHighContrastTheme, |
|
62 | + $dyslexiaFont->getId() => $dyslexiaFont, |
|
63 | + ]; |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * Get the list of all registered themes |
|
68 | + * |
|
69 | + * @return ITheme[] |
|
70 | + */ |
|
71 | + public function getThemes(): array { |
|
72 | + return $this->themesProviders; |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Enable a theme for the logged-in user |
|
77 | + * |
|
78 | + * @param ITheme $theme the theme to enable |
|
79 | + * @return string[] the enabled themes |
|
80 | + */ |
|
81 | + public function enableTheme(ITheme $theme): array { |
|
82 | + $themesIds = $this->getEnabledThemes(); |
|
83 | + |
|
84 | + // If already enabled, ignore |
|
85 | + if (in_array($theme->getId(), $themesIds)) { |
|
86 | + return $themesIds; |
|
87 | + } |
|
88 | + |
|
89 | + /** @var ITheme[] */ |
|
90 | + $themes = array_map(function($themeId) { |
|
91 | + return $this->getThemes()[$themeId]; |
|
92 | + }, $themesIds); |
|
93 | + |
|
94 | + // Filtering all themes with the same type |
|
95 | + $filteredThemes = array_filter($themes, function(ITheme $t) use ($theme) { |
|
96 | + return $theme->getType() === $t->getType(); |
|
97 | + }); |
|
98 | + |
|
99 | + // Retrieve IDs only |
|
100 | + /** @var string[] */ |
|
101 | + $filteredThemesIds = array_map(function(ITheme $t) { |
|
102 | + return $t->getId(); |
|
103 | + }, array_values($filteredThemes)); |
|
104 | + |
|
105 | + $enabledThemes = array_merge(array_diff($themesIds, $filteredThemesIds), [$theme->getId()]); |
|
106 | + $this->setEnabledThemes($enabledThemes); |
|
107 | + |
|
108 | + return $enabledThemes; |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * Disable a theme for the logged-in user |
|
113 | + * |
|
114 | + * @param ITheme $theme the theme to disable |
|
115 | + * @return string[] the enabled themes |
|
116 | + */ |
|
117 | + public function disableTheme(ITheme $theme): array { |
|
118 | + $themesIds = $this->getEnabledThemes(); |
|
119 | + |
|
120 | + // If enabled, removing it |
|
121 | + if (in_array($theme->getId(), $themesIds)) { |
|
122 | + $enabledThemes = array_diff($themesIds, [$theme->getId()]); |
|
123 | + $this->setEnabledThemes($enabledThemes); |
|
124 | + return $enabledThemes; |
|
125 | + } |
|
126 | 126 | |
127 | - return $themesIds; |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * Check whether a theme is enabled or not |
|
132 | - * for the logged-in user |
|
133 | - * |
|
134 | - * @return bool |
|
135 | - */ |
|
136 | - public function isEnabled(ITheme $theme): bool { |
|
137 | - $user = $this->userSession->getUser(); |
|
138 | - if ($user instanceof IUser) { |
|
139 | - // Using keys as it's faster |
|
140 | - $themes = $this->getEnabledThemes(); |
|
141 | - return in_array($theme->getId(), $themes); |
|
142 | - } |
|
143 | - return false; |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * Get the list of all enabled themes IDs |
|
148 | - * for the logged-in user |
|
149 | - * |
|
150 | - * @return string[] |
|
151 | - */ |
|
152 | - public function getEnabledThemes(): array { |
|
153 | - $user = $this->userSession->getUser(); |
|
154 | - if ($user === null) { |
|
155 | - return []; |
|
156 | - } |
|
157 | - |
|
158 | - $enforcedTheme = $this->config->getSystemValueString('enforce_theme', ''); |
|
159 | - $enabledThemes = json_decode($this->config->getUserValue($user->getUID(), Application::APP_ID, 'enabled-themes', '[]')); |
|
160 | - if ($enforcedTheme !== '') { |
|
161 | - return array_merge([$enforcedTheme], $enabledThemes); |
|
162 | - } |
|
163 | - |
|
164 | - try { |
|
165 | - return $enabledThemes; |
|
166 | - } catch (\Exception $e) { |
|
167 | - return []; |
|
168 | - } |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * Set the list of enabled themes |
|
173 | - * for the logged-in user |
|
174 | - * |
|
175 | - * @param string[] $themes the list of enabled themes IDs |
|
176 | - */ |
|
177 | - private function setEnabledThemes(array $themes): void { |
|
178 | - $user = $this->userSession->getUser(); |
|
179 | - $this->config->setUserValue($user->getUID(), Application::APP_ID, 'enabled-themes', json_encode(array_values(array_unique($themes)))); |
|
180 | - } |
|
127 | + return $themesIds; |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * Check whether a theme is enabled or not |
|
132 | + * for the logged-in user |
|
133 | + * |
|
134 | + * @return bool |
|
135 | + */ |
|
136 | + public function isEnabled(ITheme $theme): bool { |
|
137 | + $user = $this->userSession->getUser(); |
|
138 | + if ($user instanceof IUser) { |
|
139 | + // Using keys as it's faster |
|
140 | + $themes = $this->getEnabledThemes(); |
|
141 | + return in_array($theme->getId(), $themes); |
|
142 | + } |
|
143 | + return false; |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * Get the list of all enabled themes IDs |
|
148 | + * for the logged-in user |
|
149 | + * |
|
150 | + * @return string[] |
|
151 | + */ |
|
152 | + public function getEnabledThemes(): array { |
|
153 | + $user = $this->userSession->getUser(); |
|
154 | + if ($user === null) { |
|
155 | + return []; |
|
156 | + } |
|
157 | + |
|
158 | + $enforcedTheme = $this->config->getSystemValueString('enforce_theme', ''); |
|
159 | + $enabledThemes = json_decode($this->config->getUserValue($user->getUID(), Application::APP_ID, 'enabled-themes', '[]')); |
|
160 | + if ($enforcedTheme !== '') { |
|
161 | + return array_merge([$enforcedTheme], $enabledThemes); |
|
162 | + } |
|
163 | + |
|
164 | + try { |
|
165 | + return $enabledThemes; |
|
166 | + } catch (\Exception $e) { |
|
167 | + return []; |
|
168 | + } |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * Set the list of enabled themes |
|
173 | + * for the logged-in user |
|
174 | + * |
|
175 | + * @param string[] $themes the list of enabled themes IDs |
|
176 | + */ |
|
177 | + private function setEnabledThemes(array $themes): void { |
|
178 | + $user = $this->userSession->getUser(); |
|
179 | + $this->config->setUserValue($user->getUID(), Application::APP_ID, 'enabled-themes', json_encode(array_values(array_unique($themes)))); |
|
180 | + } |
|
181 | 181 | } |