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