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