1: <?php
2: /**
3: * This code is licensed under AGPLv3 license or Afterlogic Software License
4: * if commercial version of the product was purchased.
5: * For full statements of the licenses see LICENSE-AFTERLOGIC and LICENSE-AGPL3 files.
6: */
7:
8: namespace Aurora\Modules\CorporateFiles;
9:
10: /**
11: * Main Files module. It provides PHP and Web APIs for managing files.
12: *
13: * @license https://www.gnu.org/licenses/agpl-3.0.html AGPL-3.0
14: * @license https://afterlogic.com/products/common-licensing Afterlogic Software License
15: * @copyright Copyright (c) 2023, Afterlogic Corp.
16: *
17: * @package Modules
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: * Obtains list of module settings.
33: *
34: * @return array
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: * Updates module's settings - saves them to config.json file.
47: *
48: * @param int $SpaceLimitMb Space limit setting in Mb.
49: * @return bool
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: