1 | <?php |
||
29 | class User extends Component |
||
30 | { |
||
31 | |||
32 | /** |
||
33 | * @event ManageOrganizationUserEvent The event that is triggered before a |
||
34 | * user is associated to an organization. |
||
35 | * |
||
36 | * You may set [[ManageOrganizationUserEvent::isValid]] to `false` to prevent the |
||
37 | * user from being associated to the organization. |
||
38 | */ |
||
39 | const EVENT_BEFORE_ASSOCIATE = 'beforeAssociate'; |
||
40 | |||
41 | /** |
||
42 | * @event ManageOrganizationUserEvent The event that is triggered after a |
||
43 | * user is associated to an organization. |
||
44 | * |
||
45 | * * You may set [[ManageOrganizationUserEvent::isValid]] to `false` to prevent the |
||
46 | * user from being associated to the organization. |
||
47 | */ |
||
48 | const EVENT_AFTER_ASSOCIATE = 'afterAssociate'; |
||
49 | |||
50 | /** |
||
51 | * @event ManageOrganizationUserEvent The event that is triggered before a |
||
52 | * user is remove from an organization. |
||
53 | * |
||
54 | * You may set [[ManageOrganizationUserEvent::isValid]] to `false` to prevent the |
||
55 | * user from being removed from the organization. |
||
56 | */ |
||
57 | const EVENT_BEFORE_DISSOCIATE = 'beforeDissociate'; |
||
58 | |||
59 | /** |
||
60 | * @event ManageOrganizationUserEvent The event that is triggered after a |
||
61 | * user is remove from an organization. |
||
62 | * |
||
63 | * * You may set [[ManageOrganizationUserEvent::isValid]] to `false` to prevent the |
||
64 | * user from being removed from the organization. |
||
65 | */ |
||
66 | const EVENT_AFTER_DISSOCIATE = 'afterDissociate'; |
||
67 | |||
68 | |||
69 | /** |
||
70 | * @inheritdoc |
||
71 | */ |
||
72 | public static function elementClass(): string |
||
76 | |||
77 | /******************************************* |
||
78 | * QUERY |
||
79 | *******************************************/ |
||
80 | |||
81 | /** |
||
82 | * Get query |
||
83 | * |
||
84 | * @param $criteria |
||
85 | * @return UserQuery |
||
86 | */ |
||
87 | public function getQuery($criteria = []) |
||
106 | |||
107 | /** |
||
108 | * @param array $ownerCriteria |
||
109 | * @param array $criteria |
||
110 | * @return UserQuery |
||
111 | */ |
||
112 | public function getOwnerQuery($ownerCriteria = [], $criteria = []) |
||
120 | |||
121 | /** |
||
122 | * @param array $userCriteria |
||
123 | * @param array $criteria |
||
124 | * @return UserQuery |
||
125 | */ |
||
126 | public function getUserQuery($userCriteria = [], $criteria = []) |
||
134 | |||
135 | /** |
||
136 | * @param array $memberCriteria |
||
137 | * @param array $criteria |
||
138 | * @return UserQuery |
||
139 | */ |
||
140 | public function getMemberQuery($memberCriteria = [], $criteria = []) |
||
148 | |||
149 | /******************************************* |
||
150 | * UTILITY |
||
151 | *******************************************/ |
||
152 | |||
153 | /** |
||
154 | * @param UserElement $user |
||
155 | * @param array $criteria |
||
156 | * @return bool |
||
157 | */ |
||
158 | public function isUser(UserElement $user, $criteria = []) |
||
169 | |||
170 | /** |
||
171 | * @param UserElement $user |
||
172 | * @param array $criteria |
||
173 | * @return bool |
||
174 | */ |
||
175 | public function isOwner(UserElement $user, $criteria = []) |
||
186 | |||
187 | /** |
||
188 | * @param UserElement $user |
||
189 | * @param array $criteria |
||
190 | * @return bool |
||
191 | */ |
||
192 | public function isMember(UserElement $user, $criteria = []) |
||
203 | |||
204 | /** |
||
205 | * @param UserElement $userElement |
||
206 | * @param OrganizationElement $organizationElement |
||
207 | * @param int|null $siteId |
||
208 | * @param int|null $sortOrder The order which the user should be positioned. |
||
209 | * If the value is zero (0) we position them last. |
||
210 | */ |
||
211 | protected function applySortOrder( |
||
281 | |||
282 | /************************************************************ |
||
283 | * ASSOCIATE |
||
284 | ************************************************************/ |
||
285 | |||
286 | /** |
||
287 | * Associate a user to an organization |
||
288 | * |
||
289 | * @param UserElement $userElement |
||
290 | * @param OrganizationElement $organizationElement |
||
291 | * @param int|null $siteId |
||
292 | * @param int|null $sortOrder |
||
293 | * @return bool |
||
294 | * @throws Exception |
||
295 | * @throws \yii\db\Exception |
||
296 | */ |
||
297 | public function associate( |
||
400 | |||
401 | |||
402 | /************************************************************ |
||
403 | * DISSOCIATE |
||
404 | ************************************************************/ |
||
405 | |||
406 | /** |
||
407 | * Dissociate a user to the organization |
||
408 | * |
||
409 | * @param $userElement |
||
410 | * @param $organizationElement |
||
411 | * @return bool |
||
412 | * @throws Exception |
||
413 | * @throws \yii\db\Exception |
||
414 | */ |
||
415 | public function dissociate(UserElement $userElement, OrganizationElement $organizationElement) |
||
478 | |||
479 | /** |
||
480 | * @param OrganizationElement $organizationElement |
||
481 | * @param int|null $siteId |
||
482 | * @return array |
||
483 | */ |
||
484 | private function getCurrentSortOrder(OrganizationElement $organizationElement, int $siteId = null): array |
||
503 | |||
504 | /******************************************* |
||
505 | * RECORD CHECKING |
||
506 | *******************************************/ |
||
507 | |||
508 | /** |
||
509 | * @param UserElement $userElement |
||
510 | * @param OrganizationElement $organizationElement |
||
511 | * @param int|null $siteId |
||
512 | * @return bool |
||
513 | */ |
||
514 | private function associationExists( |
||
525 | } |
||
526 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
integer
values, zero is a special case, in particular the following results might be unexpected: