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: * @property Settings $oModuleSettings
16: *
17: * @package Modules
18: */
19: class Module extends \Aurora\System\Module\AbstractLicensedModule
20: {
21: public function init()
22: {
23: $this->subscribeEvent('Core::UpdateSettings::after', array($this, 'onAfterUpdateSettings'));
24: }
25:
26: /**
27: * @return Module
28: */
29: public static function getInstance()
30: {
31: return parent::getInstance();
32: }
33:
34: /**
35: * @return Module
36: */
37: public static function Decorator()
38: {
39: return parent::Decorator();
40: }
41:
42: /**
43: * @return Settings
44: */
45: public function getModuleSettings()
46: {
47: return $this->oModuleSettings;
48: }
49:
50: public function GetSettings()
51: {
52: \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::Anonymous);
53:
54: $oUser = \Aurora\System\Api::getAuthenticatedUser();
55:
56: return array(
57: 'Theme' => $oUser && null !== $oUser->getExtendedProp(self::GetName() . '::Theme') ? $oUser->getExtendedProp(self::GetName() . '::Theme') : $this->oModuleSettings->Theme,
58: 'ThemeList' => $this->oModuleSettings->ThemeList,
59: );
60: }
61:
62: /**
63: *
64: * @param array $Args
65: * @param mixed $Result
66: */
67: public function onAfterUpdateSettings($Args, &$Result)
68: {
69: \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser);
70:
71: $oUser = \Aurora\System\Api::getAuthenticatedUser();
72: if ($oUser && $oUser->isNormalOrTenant()) {
73: if (isset($Args['MobileTheme'])) {
74: $oUser->setExtendedProp(self::GetName() . '::Theme', $Args['MobileTheme']);
75: }
76:
77: $oCoreDecorator = \Aurora\Modules\Core\Module::Decorator();
78: $Result = $oCoreDecorator->UpdateUserObject($oUser);
79: }
80:
81: if ($oUser && $oUser->Role === \Aurora\System\Enums\UserRole::SuperAdmin) {
82: if (isset($Args['MobileTheme'])) {
83: $this->setConfig('Theme', $Args['MobileTheme']);
84: }
85:
86: $Result = $this->saveModuleConfig();
87: }
88: }
89: }
90: