1: | <?php |
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | namespace Aurora\Modules\CorporateFiles; |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | |
18: | |
19: | |
20: | |
21: | class Module extends \Aurora\Modules\PersonalFiles\Module |
22: | { |
23: | protected static $sStorageType = 'corporate'; |
24: | protected static $iStorageOrder = 20; |
25: | |
26: | public function init() |
27: | { |
28: | parent::init(); |
29: | |
30: | $this->subscribeEvent('Files::GetQuota::after', array($this, 'onAfterGetQuota')); |
31: | } |
32: | |
33: | |
34: | |
35: | |
36: | public static function getInstance() |
37: | { |
38: | return parent::getInstance(); |
39: | } |
40: | |
41: | |
42: | |
43: | |
44: | public static function Decorator() |
45: | { |
46: | return parent::Decorator(); |
47: | } |
48: | |
49: | |
50: | |
51: | |
52: | public function getModuleSettings() |
53: | { |
54: | return $this->oModuleSettings; |
55: | } |
56: | |
57: | |
58: | |
59: | |
60: | |
61: | |
62: | public function GetSettings() |
63: | { |
64: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::Anonymous); |
65: | |
66: | return array( |
67: | 'SpaceLimitMb' => $this->oModuleSettings->SpaceLimitMb, |
68: | ); |
69: | } |
70: | |
71: | |
72: | |
73: | |
74: | |
75: | |
76: | |
77: | public function UpdateSettings($SpaceLimitMb) |
78: | { |
79: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::TenantAdmin); |
80: | |
81: | $this->setConfig('SpaceLimitMb', $SpaceLimitMb); |
82: | return (bool) $this->saveModuleConfig(); |
83: | } |
84: | |
85: | public function UpdateUsedSpace() |
86: | { |
87: | $iResult = 0; |
88: | |
89: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
90: | $oUser = \Aurora\System\Api::getAuthenticatedUser(); |
91: | |
92: | if ($oUser) { |
93: | $oTenant = \Aurora\Modules\Core\Module::Decorator()->GetTenantWithoutRoleCheck($oUser->IdTenant); |
94: | |
95: | if ($oTenant) { |
96: | $iResult = $this->getManager()->getUserSpaceUsed($oUser->PublicId, [\Aurora\System\Enums\FileStorageType::Corporate]); |
97: | $oTenant->setExtendedProp(self::GetName() . '::UsedSpace', $iResult); |
98: | $oTenant->save(); |
99: | } |
100: | } |
101: | |
102: | return $iResult; |
103: | } |
104: | |
105: | |
106: | public function onAfterGetQuota($aArgs, &$mResult) |
107: | { |
108: | if ($this->checkStorageType($aArgs['Type'])) { |
109: | $iSize = 0; |
110: | |
111: | $oUser = \Aurora\Modules\Core\Module::Decorator()->GetUserWithoutRoleCheck((int)$aArgs['UserId']); |
112: | |
113: | if ($oUser) { |
114: | $oTenant = \Aurora\Modules\Core\Module::Decorator()->GetTenantWithoutRoleCheck($oUser->IdTenant); |
115: | |
116: | if ($oTenant) { |
117: | $iSize = null !== $oTenant->getExtendedProp(self::GetName() . '::UsedSpace') ? (int) $oTenant->getExtendedProp(self::GetName() . '::UsedSpace') : 0; |
118: | } |
119: | } |
120: | |
121: | $mResult = array( |
122: | 'Used' => (int) $iSize, |
123: | 'Limit' => $this->oModuleSettings->SpaceLimitMb * 1024 * 1024 |
124: | ); |
125: | } |
126: | } |
127: | } |
128: | |