| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | namespace Aurora\Modules\OAuthIntegratorWebclient; |
| 9: | |
| 10: | use Aurora\Modules\OAuthIntegratorWebclient\Models\OauthAccount; |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | class Manager extends \Aurora\System\Managers\AbstractManager |
| 18: | { |
| 19: | public function __construct(\Aurora\System\Module\AbstractModule $oModule = null) |
| 20: | { |
| 21: | parent::__construct($oModule); |
| 22: | } |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | public function getAccount($iUserId, $sType, $sEmail = '') |
| 31: | { |
| 32: | $mResult = false; |
| 33: | |
| 34: | $oQuery = OauthAccount::where('IdUser', $iUserId)->where('Type', $sType); |
| 35: | if (!empty($sEmail)) { |
| 36: | $oQuery = $oQuery->where('Email', $sEmail); |
| 37: | } |
| 38: | try { |
| 39: | $mResult = $oQuery->first(); |
| 40: | } catch (\Aurora\System\Exceptions\BaseException $oException) { |
| 41: | $mResult = false; |
| 42: | $this->setLastException($oException); |
| 43: | } |
| 44: | return $mResult; |
| 45: | } |
| 46: | |
| 47: | |
| 48: | |
| 49: | |
| 50: | |
| 51: | |
| 52: | |
| 53: | public function getAccountById($sIdSocial, $sType) |
| 54: | { |
| 55: | $mResult = false; |
| 56: | try { |
| 57: | $mResult = OauthAccount::where('IdSocial', $sIdSocial)->where('Type', $sType)->first(); |
| 58: | } catch (\Aurora\System\Exceptions\BaseException $oException) { |
| 59: | $mResult = false; |
| 60: | $this->setLastException($oException); |
| 61: | } |
| 62: | return $mResult; |
| 63: | } |
| 64: | |
| 65: | |
| 66: | |
| 67: | |
| 68: | |
| 69: | |
| 70: | public function getAccounts($iIdUser) |
| 71: | { |
| 72: | $aResult = false; |
| 73: | try { |
| 74: | $aResult = OauthAccount::where('IdUser', $iIdUser)->get(); |
| 75: | } catch (\Aurora\System\Exceptions\BaseException $oException) { |
| 76: | $aResult = false; |
| 77: | $this->setLastException($oException); |
| 78: | } |
| 79: | return $aResult; |
| 80: | } |
| 81: | |
| 82: | |
| 83: | |
| 84: | |
| 85: | |
| 86: | |
| 87: | public function createAccount(OauthAccount &$oAccount) |
| 88: | { |
| 89: | $bResult = false; |
| 90: | try { |
| 91: | if ($oAccount->validate()) { |
| 92: | if (!$this->isExists($oAccount)) { |
| 93: | if (!$oAccount->save()) { |
| 94: | throw new \Aurora\System\Exceptions\ManagerException(0); |
| 95: | } |
| 96: | } else { |
| 97: | throw new \Aurora\System\Exceptions\ManagerException(0); |
| 98: | } |
| 99: | } |
| 100: | |
| 101: | $bResult = true; |
| 102: | } catch (\Aurora\System\Exceptions\BaseException $oException) { |
| 103: | $bResult = false; |
| 104: | $this->setLastException($oException); |
| 105: | } |
| 106: | |
| 107: | return $bResult; |
| 108: | } |
| 109: | |
| 110: | |
| 111: | |
| 112: | |
| 113: | |
| 114: | |
| 115: | public function updateAccount(OauthAccount &$oAccount) |
| 116: | { |
| 117: | $bResult = false; |
| 118: | try { |
| 119: | if ($oAccount->validate()) { |
| 120: | if (!$oAccount->save()) { |
| 121: | throw new \Aurora\System\Exceptions\ManagerException(0); |
| 122: | } |
| 123: | } |
| 124: | |
| 125: | $bResult = true; |
| 126: | } catch (\Aurora\System\Exceptions\BaseException $oException) { |
| 127: | $bResult = false; |
| 128: | $this->setLastException($oException); |
| 129: | } |
| 130: | |
| 131: | return $bResult; |
| 132: | } |
| 133: | |
| 134: | |
| 135: | |
| 136: | |
| 137: | |
| 138: | |
| 139: | |
| 140: | public function deleteAccount($iIdUser, $sType, $sEmail) |
| 141: | { |
| 142: | $bResult = false; |
| 143: | try { |
| 144: | $oSocial = $this->getAccount($iIdUser, $sType, $sEmail); |
| 145: | if ($oSocial) { |
| 146: | if (!$oSocial->delete()) { |
| 147: | throw new \Aurora\System\Exceptions\ManagerException(0); |
| 148: | } |
| 149: | $bResult = true; |
| 150: | } |
| 151: | } catch (\Aurora\System\Exceptions\BaseException $oException) { |
| 152: | $bResult = false; |
| 153: | $this->setLastException($oException); |
| 154: | } |
| 155: | |
| 156: | return $bResult; |
| 157: | } |
| 158: | |
| 159: | |
| 160: | |
| 161: | |
| 162: | |
| 163: | |
| 164: | public function deleteAccountByUserId($iIdUser) |
| 165: | { |
| 166: | return !!OauthAccount::where('IdUser', $iIdUser)->delete(); |
| 167: | } |
| 168: | |
| 169: | |
| 170: | |
| 171: | |
| 172: | |
| 173: | |
| 174: | public function isExists(OauthAccount $oAccount) |
| 175: | { |
| 176: | return (OauthAccount::find($oAccount->Id) instanceof OauthAccount); |
| 177: | } |
| 178: | } |
| 179: | |