1 | <?php |
||
7 | class UserModel extends BitrixModel |
||
8 | { |
||
9 | /** |
||
10 | * Corresponding object class name. |
||
11 | * |
||
12 | * @var string |
||
13 | */ |
||
14 | protected static $objectClass = 'CUser'; |
||
15 | |||
16 | /** |
||
17 | * Current user cache. |
||
18 | * |
||
19 | * @var static |
||
20 | */ |
||
21 | protected static $currentUser = null; |
||
22 | |||
23 | /** |
||
24 | * Have groups been already fetched from DB? |
||
25 | * |
||
26 | * @var bool |
||
27 | */ |
||
28 | protected $groupsAreFetched = false; |
||
29 | |||
30 | /** |
||
31 | * Instantiate a query object for the model. |
||
32 | * |
||
33 | * @return UserQuery |
||
34 | */ |
||
35 | public static function query() |
||
39 | |||
40 | /** |
||
41 | * Get a new instance for the current user |
||
42 | * |
||
43 | * @return static |
||
44 | */ |
||
45 | public static function current() |
||
51 | |||
52 | /** |
||
53 | * Get a fresh instance for the current user and save it to local cache. |
||
54 | * |
||
55 | * @return static |
||
56 | */ |
||
57 | public static function freshCurrent() |
||
63 | |||
64 | /** |
||
65 | * Fill extra fields when $this->field is called. |
||
66 | * |
||
67 | * @return null |
||
68 | */ |
||
69 | protected function afterFill() |
||
75 | |||
76 | /** |
||
77 | * Fill model groups if they are already known. |
||
78 | * Saves DB queries. |
||
79 | * |
||
80 | * @param array $groups |
||
81 | * |
||
82 | * @return null |
||
83 | */ |
||
84 | public function fillGroups($groups) |
||
90 | |||
91 | /** |
||
92 | * Load model fields from database if they are not loaded yet. |
||
93 | * |
||
94 | * @return $this |
||
95 | */ |
||
96 | public function load() |
||
103 | |||
104 | /** |
||
105 | * Get user groups from cache or database. |
||
106 | * |
||
107 | * @return array |
||
108 | */ |
||
109 | public function getGroups() |
||
117 | |||
118 | /** |
||
119 | * Refresh model from database and place data to $this->fields. |
||
120 | * |
||
121 | * @return array |
||
122 | */ |
||
123 | public function refresh() |
||
131 | |||
132 | /** |
||
133 | * Refresh user fields and save them to a class field. |
||
134 | * |
||
135 | * @return array |
||
136 | */ |
||
137 | public function refreshFields() |
||
155 | |||
156 | /** |
||
157 | * Refresh user groups and save them to a class field. |
||
158 | * |
||
159 | * @return array |
||
160 | */ |
||
161 | public function refreshGroups() |
||
177 | |||
178 | /** |
||
179 | * Check if user is an admin. |
||
180 | */ |
||
181 | public function isAdmin() |
||
185 | |||
186 | /** |
||
187 | * Check if this user is the operating user. |
||
188 | */ |
||
189 | public function isCurrent() |
||
195 | |||
196 | /** |
||
197 | * Check if user has role with a given ID. |
||
198 | * |
||
199 | * @param $role_id |
||
200 | * |
||
201 | * @return bool |
||
202 | */ |
||
203 | public function hasGroupWithId($role_id) |
||
207 | |||
208 | /** |
||
209 | * Check if user is authorized. |
||
210 | * |
||
211 | * @return bool |
||
212 | */ |
||
213 | public function isAuthorized() |
||
219 | |||
220 | /** |
||
221 | * Check if user is guest. |
||
222 | * |
||
223 | * @return bool |
||
224 | */ |
||
225 | public function isGuest() |
||
229 | |||
230 | /** |
||
231 | * Logout user. |
||
232 | * |
||
233 | * @return void |
||
234 | */ |
||
235 | public function logout() |
||
241 | |||
242 | /** |
||
243 | * Scope to get only users from a given group / groups. |
||
244 | * |
||
245 | * @param UserQuery $query |
||
246 | * @param int|array $id |
||
247 | * |
||
248 | * @return UserQuery |
||
249 | */ |
||
250 | public function scopeFromGroup($query, $id) |
||
256 | |||
257 | /** |
||
258 | * Substitute old group with the new one. |
||
259 | * |
||
260 | * @param int $old |
||
261 | * @param int $new |
||
262 | * |
||
263 | * @return void |
||
264 | */ |
||
265 | public function substituteGroup($old, $new) |
||
279 | } |
||
280 |
Instead of relying on
global
state, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state