1: <?php
2: /**
3: * This code is licensed under Afterlogic Software License.
4: * For full statements of the license see LICENSE file.
5: */
6:
7: namespace Aurora\Modules\CoreMobileWebclient;
8:
9: /**
10: * Mobile webclient for core view models.
11: *
12: * @license https://afterlogic.com/products/common-licensing Afterlogic Software License
13: * @copyright Copyright (c) 2023, Afterlogic Corp.
14: *
15: * @package Modules
16: */
17: class Module extends \Aurora\System\Module\AbstractLicensedModule
18: {
19: public function init()
20: {
21: $this->subscribeEvent('Core::UpdateSettings::after', array($this, 'onAfterUpdateSettings'));
22: }
23:
24: public function GetSettings()
25: {
26: \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::Anonymous);
27:
28: $oUser = \Aurora\System\Api::getAuthenticatedUser();
29:
30: return array(
31: 'Theme' => $oUser && isset($oUser->{self::GetName().'::Theme'}) ? $oUser->{self::GetName().'::Theme'} : $this->getConfig('Theme', 'Default'),
32: 'ThemeList' => $this->getConfig('ThemeList', ['Default']),
33: );
34: }
35:
36: /**
37: *
38: * @param array $Args
39: * @param mixed $Result
40: */
41: public function onAfterUpdateSettings($Args, &$Result)
42: {
43: \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser);
44:
45: $oUser = \Aurora\System\Api::getAuthenticatedUser();
46: if ($oUser && $oUser->isNormalOrTenant()) {
47: if (isset($Args['MobileTheme'])) {
48: $oUser->setExtendedProp(self::GetName().'::Theme', $Args['MobileTheme']);
49: }
50:
51: $oCoreDecorator = \Aurora\Modules\Core\Module::Decorator();
52: $Result = $oCoreDecorator->UpdateUserObject($oUser);
53: }
54:
55: if ($oUser && $oUser->Role === \Aurora\System\Enums\UserRole::SuperAdmin) {
56: if (isset($Args['MobileTheme'])) {
57: $this->setConfig('Theme', $Args['MobileTheme']);
58: }
59:
60: $Result = $this->saveModuleConfig();
61: }
62: }
63: }
64: