1: | <?php |
2: | |
3: | namespace Aurora\Modules\OAuthIntegratorWebclient\Models; |
4: | |
5: | use Aurora\System\Classes\Model; |
6: | use Aurora\Modules\Core\Models\User; |
7: | |
8: | class OauthAccount extends Model |
9: | { |
10: | protected $foreignModel = User::class; |
11: | protected $foreignModelIdColumn = 'IdUser'; |
12: | |
13: | protected $fillable = [ |
14: | 'Id', |
15: | 'IdUser', |
16: | 'IdSocial', |
17: | 'Type', |
18: | 'Name', |
19: | 'Email', |
20: | 'AccessToken', |
21: | 'RefreshToken', |
22: | 'Scopes', |
23: | 'Disabled', |
24: | 'AccountType' |
25: | ]; |
26: | |
27: | public function getScopesAsArray() |
28: | { |
29: | $aResult = array(); |
30: | if (!$this->Disabled) { |
31: | $aResult = array_map( |
32: | function ($sValue) { |
33: | if (!empty($sValue)) { |
34: | return strtolower($sValue); |
35: | } |
36: | }, |
37: | explode(' ', $this->Scopes) |
38: | ); |
39: | } |
40: | |
41: | return $aResult; |
42: | } |
43: | |
44: | |
45: | |
46: | |
47: | |
48: | |
49: | public function issetScope($sScope) |
50: | { |
51: | return false !== strpos(strtolower($this->Scopes), strtolower($sScope)); |
52: | } |
53: | |
54: | |
55: | |
56: | |
57: | public function setScope($sScope) |
58: | { |
59: | $aScopes = $this->getScopesAsArray(); |
60: | if (!array_search($sScope, array_unique($aScopes))) { |
61: | $aScopes[] = $sScope; |
62: | $this->Scopes = implode(' ', array_unique($aScopes)); |
63: | } |
64: | } |
65: | |
66: | |
67: | |
68: | |
69: | public function setScopes($aScopes) |
70: | { |
71: | $this->Scopes = implode(' ', array_unique(array_merge($aScopes, $this->getScopesAsArray()))); |
72: | } |
73: | |
74: | |
75: | |
76: | |
77: | public function unsetScope($sScope) |
78: | { |
79: | $aScopes = array_map( |
80: | function ($sValue) { |
81: | return strtolower($sValue); |
82: | }, |
83: | explode(' ', $this->Scopes) |
84: | ); |
85: | $mResult = array_search($sScope, $aScopes); |
86: | if ($mResult !== false) { |
87: | unset($aScopes[$mResult]); |
88: | $this->Scopes = implode(' ', $aScopes); |
89: | } |
90: | } |
91: | } |
92: | |