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: | /** |
9: | * Aurora\Modules\OAuthIntegratorWebclient\Models\OauthAccount |
10: | * |
11: | * @property integer $Id |
12: | * @property integer $IdUser |
13: | * @property string $IdSocial |
14: | * @property string $Type |
15: | * @property string $Name |
16: | * @property string $Email |
17: | * @property string $AccessToken |
18: | * @property string|null $RefreshToken |
19: | * @property string $Scopes |
20: | * @property integer $Disabled |
21: | * @property string $AccountType |
22: | * @property \Illuminate\Support\Carbon|null $CreatedAt |
23: | * @property \Illuminate\Support\Carbon|null $UpdatedAt |
24: | * @property-read mixed $entity_id |
25: | * @method static int count(string $columns = '*') |
26: | * @method static \Illuminate\Database\Eloquent\Builder|\Aurora\Modules\OAuthIntegratorWebclient\Models\OauthAccount find(int|string $id, array|string $columns = ['*']) |
27: | * @method static \Illuminate\Database\Eloquent\Builder|\Aurora\Modules\OAuthIntegratorWebclient\Models\OauthAccount findOrFail(int|string $id, mixed $id, Closure|array|string $columns = ['*'], Closure $callback = null) |
28: | * @method static \Illuminate\Database\Eloquent\Builder|\Aurora\Modules\OAuthIntegratorWebclient\Models\OauthAccount first(array|string $columns = ['*']) |
29: | * @method static \Illuminate\Database\Eloquent\Builder|\Aurora\Modules\OAuthIntegratorWebclient\Models\OauthAccount firstWhere(Closure|string|array|\Illuminate\Database\Query\Expression $column, mixed $operator = null, mixed $value = null, string $boolean = 'and') |
30: | * @method static \Illuminate\Database\Eloquent\Builder|OauthAccount newModelQuery() |
31: | * @method static \Illuminate\Database\Eloquent\Builder|OauthAccount newQuery() |
32: | * @method static \Illuminate\Database\Eloquent\Builder|OauthAccount query() |
33: | * @method static \Illuminate\Database\Eloquent\Builder|\Aurora\Modules\OAuthIntegratorWebclient\Models\OauthAccount where(Closure|string|array|\Illuminate\Database\Query\Expression $column, mixed $operator = null, mixed $value = null, string $boolean = 'and') |
34: | * @method static \Illuminate\Database\Eloquent\Builder|OauthAccount whereAccessToken($value) |
35: | * @method static \Illuminate\Database\Eloquent\Builder|OauthAccount whereAccountType($value) |
36: | * @method static \Illuminate\Database\Eloquent\Builder|OauthAccount whereCreatedAt($value) |
37: | * @method static \Illuminate\Database\Eloquent\Builder|OauthAccount whereDisabled($value) |
38: | * @method static \Illuminate\Database\Eloquent\Builder|OauthAccount whereEmail($value) |
39: | * @method static \Illuminate\Database\Eloquent\Builder|OauthAccount whereId($value) |
40: | * @method static \Illuminate\Database\Eloquent\Builder|OauthAccount whereIdSocial($value) |
41: | * @method static \Illuminate\Database\Eloquent\Builder|OauthAccount whereIdUser($value) |
42: | * @method static \Illuminate\Database\Eloquent\Builder|\Aurora\Modules\OAuthIntegratorWebclient\Models\OauthAccount whereIn(string $column, mixed $values, string $boolean = 'and', bool $not = false) |
43: | * @method static \Illuminate\Database\Eloquent\Builder|OauthAccount whereName($value) |
44: | * @method static \Illuminate\Database\Eloquent\Builder|OauthAccount whereRefreshToken($value) |
45: | * @method static \Illuminate\Database\Eloquent\Builder|OauthAccount whereScopes($value) |
46: | * @method static \Illuminate\Database\Eloquent\Builder|OauthAccount whereType($value) |
47: | * @method static \Illuminate\Database\Eloquent\Builder|OauthAccount whereUpdatedAt($value) |
48: | * @mixin \Eloquent |
49: | */ |
50: | class OauthAccount extends Model |
51: | { |
52: | protected $foreignModel = User::class; |
53: | protected $foreignModelIdColumn = 'IdUser'; // Column that refers to an external table |
54: | |
55: | protected $fillable = [ |
56: | 'Id', |
57: | 'IdUser', |
58: | 'IdSocial', |
59: | 'Type', |
60: | 'Name', |
61: | 'Email', |
62: | 'AccessToken', |
63: | 'RefreshToken', |
64: | 'Scopes', |
65: | 'Disabled', |
66: | 'AccountType' |
67: | ]; |
68: | |
69: | public function getScopesAsArray() |
70: | { |
71: | $aResult = array(); |
72: | if (!$this->Disabled) { |
73: | $aResult = array_map( |
74: | function ($sValue) { |
75: | if (!empty($sValue)) { |
76: | return strtolower($sValue); |
77: | } |
78: | }, |
79: | explode(' ', $this->Scopes) |
80: | ); |
81: | } |
82: | |
83: | return $aResult; |
84: | } |
85: | |
86: | /** |
87: | * @param string $sScope |
88: | * |
89: | * @return bool |
90: | */ |
91: | public function issetScope($sScope) |
92: | { |
93: | return /*'' === $this->Scopes || */false !== strpos(strtolower($this->Scopes), strtolower($sScope)); |
94: | } |
95: | |
96: | /** |
97: | * @param string $sScope |
98: | */ |
99: | public function setScope($sScope) |
100: | { |
101: | $aScopes = $this->getScopesAsArray(); |
102: | if (!array_search($sScope, array_unique($aScopes))) { |
103: | $aScopes[] = $sScope; |
104: | $this->Scopes = implode(' ', array_unique($aScopes)); |
105: | } |
106: | } |
107: | |
108: | /** |
109: | * @param array $aScopes |
110: | */ |
111: | public function setScopes($aScopes) |
112: | { |
113: | $this->Scopes = implode(' ', array_unique(array_merge($aScopes, $this->getScopesAsArray()))); |
114: | } |
115: | |
116: | /** |
117: | * @param string $sScope |
118: | */ |
119: | public function unsetScope($sScope) |
120: | { |
121: | $aScopes = array_map( |
122: | function ($sValue) { |
123: | return strtolower($sValue); |
124: | }, |
125: | explode(' ', $this->Scopes) |
126: | ); |
127: | $mResult = array_search($sScope, $aScopes); |
128: | if ($mResult !== false) { |
129: | unset($aScopes[$mResult]); |
130: | $this->Scopes = implode(' ', $aScopes); |
131: | } |
132: | } |
133: | } |
134: |