1: | <?php |
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | namespace Aurora\Modules\Min; |
9: | |
10: | use Aurora\Modules\Min\Models\MinHash; |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | |
18: | |
19: | |
20: | |
21: | |
22: | |
23: | class Module extends \Aurora\System\Module\AbstractModule |
24: | { |
25: | public $oManager = null; |
26: | |
27: | |
28: | |
29: | |
30: | public static function getInstance() |
31: | { |
32: | return parent::getInstance(); |
33: | } |
34: | |
35: | |
36: | |
37: | |
38: | public static function Decorator() |
39: | { |
40: | return parent::Decorator(); |
41: | } |
42: | |
43: | |
44: | |
45: | |
46: | public function getModuleSettings() |
47: | { |
48: | return $this->oModuleSettings; |
49: | } |
50: | |
51: | |
52: | |
53: | |
54: | |
55: | |
56: | |
57: | public function init() |
58: | { |
59: | $this->oManager = new Manager($this); |
60: | |
61: | $this->aDeniedMethodsByWebApi = [ |
62: | 'CreateMin', |
63: | 'DeleteMinByHash', |
64: | 'DeleteMinByID', |
65: | 'GetMinByHash', |
66: | 'GetMinByID', |
67: | 'UpdateMinByHash', |
68: | 'UpdateMinByID', |
69: | 'DeleteExpiredHashes', |
70: | 'generateHashId' |
71: | ]; |
72: | $this->subscribeEvent('Core::DeleteUser::after', array($this, 'onAfterDeleteUser')); |
73: | } |
74: | |
75: | |
76: | |
77: | |
78: | public function onAfterDeleteUser($aArgs, &$mResult) |
79: | { |
80: | if ($mResult) { |
81: | MinHash::where('UserId', $aArgs['UserId'])->delete(); |
82: | } |
83: | } |
84: | |
85: | public static function generateHashId($aData) |
86: | { |
87: | return \md5(\implode('|', $aData)); |
88: | } |
89: | |
90: | |
91: | |
92: | |
93: | |
94: | |
95: | |
96: | |
97: | |
98: | |
99: | |
100: | public function CreateMin($HashId, $Parameters, $UserId = null, $ExpireDate = null) |
101: | { |
102: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
103: | |
104: | return $this->oManager->createMin($HashId, $Parameters, $UserId, $ExpireDate); |
105: | } |
106: | |
107: | |
108: | |
109: | |
110: | |
111: | |
112: | |
113: | public function GetMinByHash($sHash) |
114: | { |
115: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::Anonymous); |
116: | |
117: | return $this->oManager->getMinByHash($sHash); |
118: | } |
119: | |
120: | |
121: | |
122: | |
123: | |
124: | |
125: | |
126: | public function GetMinByID($Id) |
127: | { |
128: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::Anonymous); |
129: | |
130: | return $this->oManager->getMinByID($Id); |
131: | } |
132: | |
133: | |
134: | |
135: | |
136: | |
137: | |
138: | |
139: | public function GetMinListByUserId($UserId) |
140: | { |
141: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::Anonymous); |
142: | |
143: | return $this->oManager->getMinListByUserId($UserId); |
144: | } |
145: | |
146: | |
147: | |
148: | |
149: | |
150: | |
151: | |
152: | |
153: | |
154: | public function UpdateMinByID($Id, $Data, $NewId = null) |
155: | { |
156: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
157: | |
158: | return $this->oManager->updateMinByID($Id, $Data, $NewId); |
159: | } |
160: | |
161: | |
162: | |
163: | |
164: | |
165: | |
166: | |
167: | |
168: | |
169: | public function UpdateMinByHash($Hash, $Data, $NewHash = null) |
170: | { |
171: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::Anonymous); |
172: | |
173: | return $this->oManager->updateMinByHash($Hash, $Data, $NewHash); |
174: | } |
175: | |
176: | |
177: | |
178: | |
179: | |
180: | |
181: | |
182: | public function DeleteMinByID($Id) |
183: | { |
184: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
185: | |
186: | return $this->oManager->deleteMinByID($Id); |
187: | } |
188: | |
189: | public function DeleteMinByHash($Hash) |
190: | { |
191: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::Anonymous); |
192: | |
193: | return $this->oManager->deleteMinByHash($Hash); |
194: | } |
195: | |
196: | public function DeleteExpiredHashes($Time) |
197: | { |
198: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::Anonymous); |
199: | Models\MinHash::whereNotNull('ExpireDate')->where('ExpireDate', '<=', $Time)->delete(); |
200: | } |
201: | |
202: | } |
203: | |