1 | <?php |
||
39 | class User extends Model implements AuthenticatableContract, CanResetPasswordContract |
||
40 | { |
||
41 | use Authenticatable, |
||
42 | CanResetPassword, |
||
43 | Traits\User\CountTrait, |
||
44 | Traits\User\RelationTrait, |
||
45 | Traits\User\CrudTrait, |
||
46 | Traits\User\QueryTrait; |
||
47 | |||
48 | /** |
||
49 | * User name is private. |
||
50 | * |
||
51 | * @var int |
||
52 | */ |
||
53 | const PRIVATE_YES = 1; |
||
54 | |||
55 | /** |
||
56 | * User name is public. |
||
57 | * |
||
58 | * @var int |
||
59 | */ |
||
60 | const PRIVATE_NO = 0; |
||
61 | |||
62 | /** |
||
63 | * User status Deleted. |
||
64 | * |
||
65 | * @var int |
||
66 | */ |
||
67 | const DELETED_USERS = 1; |
||
68 | |||
69 | /** |
||
70 | * User status not deleted. |
||
71 | * |
||
72 | * @var int |
||
73 | */ |
||
74 | const NOT_DELETED_USERS = 0; |
||
75 | |||
76 | /** |
||
77 | * User status active. (Standard). |
||
78 | * |
||
79 | * @var int |
||
80 | */ |
||
81 | const ACTIVE_USER = 1; |
||
82 | |||
83 | /** |
||
84 | * User status blocked. (Too many login attempts). |
||
85 | * |
||
86 | * @var int |
||
87 | */ |
||
88 | const BLOCKED_USER = 2; |
||
89 | |||
90 | /** |
||
91 | * User status inactive. (Cannot login at the moment). |
||
92 | * |
||
93 | * @var int |
||
94 | */ |
||
95 | const INACTIVE_USER = 0; |
||
96 | |||
97 | /** |
||
98 | * The database table used by the model. |
||
99 | * |
||
100 | * @var string |
||
101 | */ |
||
102 | protected $table = 'users'; |
||
103 | |||
104 | /** |
||
105 | * The attributes that are mass assignable. |
||
106 | * |
||
107 | * @var array |
||
108 | */ |
||
109 | protected $fillable = ['deleted', 'email', 'password', 'firstname', 'lastname', 'role_id', 'private', 'language', 'status']; |
||
110 | |||
111 | /** |
||
112 | * The attributes excluded from the model's JSON form. |
||
113 | * |
||
114 | * @var array |
||
115 | */ |
||
116 | protected $hidden = ['password', 'remember_token']; |
||
117 | |||
118 | /** |
||
119 | * Collection of user permissions. |
||
120 | * |
||
121 | * @var Eloquent\Collection |
||
122 | */ |
||
123 | protected $permission; |
||
124 | |||
125 | /** |
||
126 | * Get available languages from translations folder. |
||
127 | * |
||
128 | * @return array |
||
129 | */ |
||
130 | 3 | public static function getLanguages() |
|
131 | { |
||
132 | 3 | $languages = []; |
|
133 | |||
134 | 3 | $cdir = scandir(__DIR__ . '/../../resources/lang'); |
|
135 | 3 | foreach ($cdir as $value) { |
|
136 | 3 | if (!in_array($value, ['.', '..'])) { |
|
137 | 3 | $languages[$value] = $value; |
|
138 | } |
||
139 | } |
||
140 | |||
141 | 3 | return $languages; |
|
142 | } |
||
143 | |||
144 | /** |
||
145 | * Checks to see if $this user is current user. |
||
146 | * |
||
147 | * @return bool |
||
148 | */ |
||
149 | 3 | public function me() |
|
150 | { |
||
151 | 3 | return $this->id == \Auth::user()->id; |
|
152 | } |
||
153 | |||
154 | /** |
||
155 | * Whether or not the user has a valid permission in current context |
||
156 | * e.g. can access the issue or the project. |
||
157 | * |
||
158 | * @param array $params |
||
159 | * |
||
160 | * @return bool |
||
161 | */ |
||
162 | 39 | public function permissionInContext(array $params) |
|
163 | { |
||
164 | // Can access all projects |
||
165 | 39 | if ($this->permission(Permission::PERM_PROJECT_ALL)) { |
|
166 | 35 | return true; |
|
167 | } |
||
168 | |||
169 | 8 | $project = array_get($params, 'project', function () use ($params) { |
|
170 | $issue = array_get($params, 'issue'); |
||
171 | if ($issue instanceof Issue) { |
||
172 | return $issue->project; |
||
173 | } |
||
174 | |||
175 | return; |
||
176 | 8 | }); |
|
177 | |||
178 | // Is member of the project |
||
179 | 8 | if ($project && !$project->isMember($this->id)) { |
|
180 | 5 | return false; |
|
181 | } |
||
182 | |||
183 | 7 | return true; |
|
184 | } |
||
185 | |||
186 | /** |
||
187 | * Whether or not the user has a permission. |
||
188 | * |
||
189 | * @param string $key |
||
190 | * |
||
191 | * @return bool |
||
192 | */ |
||
193 | 54 | public function permission($key) |
|
194 | { |
||
195 | 54 | $this->loadPermissions(); |
|
196 | 54 | foreach ($this->permission as $permission) { |
|
197 | 54 | if ($permission->permission->isEqual($key)) { |
|
198 | 54 | return true; |
|
199 | } |
||
200 | } |
||
201 | |||
202 | 26 | return false; |
|
203 | } |
||
204 | |||
205 | /** |
||
206 | * Return user full name with property "fullname". |
||
207 | * |
||
208 | * @return string |
||
209 | */ |
||
210 | 39 | public function getFullNameAttribute() |
|
211 | { |
||
212 | 39 | if ($this->private && (Auth::guest() || !Auth::user()->permission('administration'))) { |
|
|
|||
213 | 1 | return trans('tinyissue.anonymous'); |
|
214 | } |
||
215 | |||
216 | 39 | return $this->attributes['firstname'] . ' ' . $this->attributes['lastname']; |
|
217 | } |
||
218 | |||
219 | /** |
||
220 | * Return user image. |
||
221 | * |
||
222 | * @return string |
||
223 | */ |
||
224 | public function getImageAttribute() |
||
228 | |||
229 | /** |
||
230 | * Returns list of user statuses. |
||
231 | * |
||
232 | * @return array |
||
233 | */ |
||
234 | 2 | public static function getStatuses() |
|
242 | |||
243 | /** |
||
244 | * Whether or not the user is active. |
||
245 | * |
||
246 | * @return bool |
||
247 | */ |
||
248 | 7 | public function isActive() |
|
252 | |||
253 | /** |
||
254 | * Whether or not the user is inactive. |
||
255 | * |
||
256 | * @return bool |
||
257 | */ |
||
258 | public function isInactive() |
||
262 | |||
263 | /** |
||
264 | * Whether or not the user is blocked. |
||
265 | * |
||
266 | * @return bool |
||
267 | */ |
||
268 | public function isBlocked() |
||
272 | } |
||
273 |
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.