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