Complex classes like Organization often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Organization, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
85 | class Organization extends User |
||
86 | { |
||
87 | use SelfBlameableTrait; |
||
88 | |||
89 | const TYPE_ORGANIZATION = 1; |
||
90 | const TYPE_DEPARTMENT = 2; |
||
91 | |||
92 | /** |
||
93 | * @var boolean Organization does not need password and corresponding features. |
||
94 | */ |
||
95 | public $passwordHashAttribute = false; |
||
96 | |||
97 | /** |
||
98 | * @var boolean Organization does not need password and corresponding features. |
||
99 | */ |
||
100 | public $passwordResetTokenAttribute = false; |
||
101 | |||
102 | /** |
||
103 | * @var boolean Organization does not need password and corresponding features. |
||
104 | */ |
||
105 | public $passwordHistoryClass = false; |
||
106 | |||
107 | /** |
||
108 | * @var boolean Organization does not need source. |
||
109 | */ |
||
110 | public $sourceAttribute = false; |
||
111 | |||
112 | /** |
||
113 | * @var boolean Organization does not need auth key. |
||
114 | */ |
||
115 | public $authKeyAttribute = false; |
||
116 | |||
117 | /** |
||
118 | * @var boolean Organization does not need access token. |
||
119 | */ |
||
120 | public $accessTokenAttribute = false; |
||
121 | |||
122 | /** |
||
123 | * @var boolean Organization does not need login log. |
||
124 | */ |
||
125 | public $loginLogClass = false; |
||
126 | |||
127 | /** |
||
128 | * @var string The Organization Profile Class |
||
129 | */ |
||
130 | public $profileClass = Profile::class; |
||
131 | |||
132 | /** |
||
133 | * @var string The Member Class. |
||
134 | */ |
||
135 | public $memberClass = Member::class; |
||
136 | |||
137 | /** |
||
138 | * @var string The Subordinate Limit Class |
||
139 | */ |
||
140 | public $subordinateLimitClass = SubordinateLimit::class; |
||
141 | |||
142 | /** |
||
143 | * @var string The Member Limit Class |
||
144 | */ |
||
145 | public $memberLimitClass = MemberLimit::class; |
||
146 | |||
147 | /** |
||
148 | * @var string The Organization Search Class |
||
149 | */ |
||
150 | public $searchClass = OrganizationSearch::class; |
||
151 | |||
152 | /** |
||
153 | * @var Member |
||
154 | */ |
||
155 | private $noInitMember; |
||
156 | |||
157 | /** |
||
158 | * @var SubordinateLimit |
||
159 | */ |
||
160 | private $noInitSubordinateLimit; |
||
161 | |||
162 | /** |
||
163 | * @var MemberLimit |
||
164 | */ |
||
165 | private $noInitMemberLimit; |
||
166 | |||
167 | /** |
||
168 | * @var User the creator of current Organization or Department. |
||
169 | * This property is only available after registration. |
||
170 | * Please do not access it at other times. |
||
171 | * If you want to get creator model except registration, please |
||
172 | * access [[$creator]] magic-property instead. |
||
173 | */ |
||
174 | public $creatorModel; |
||
175 | |||
176 | /** |
||
177 | * @var array The configuration array of Organization Profile. |
||
178 | * This property is only available after registration. |
||
179 | * Please do not access it at other times. |
||
180 | * If you want to get profile model except registration, please |
||
181 | * access [[$profile]] magic-property instead. |
||
182 | */ |
||
183 | public $profileConfig; |
||
184 | |||
185 | const EVENT_BEFORE_ADD_MEMBER = 'eventBeforeAddMember'; |
||
186 | const EVENT_AFTER_ADD_MEMBER = 'eventAfterAddMember'; |
||
187 | const EVENT_BEFORE_REMOVE_MEMBER = 'eventBeforeRemoveMember'; |
||
188 | const EVENT_AFTER_REMOVE_MEMBER = 'eventAfterRemoveMember'; |
||
189 | |||
190 | public $cacheTagPrefix = 'tag_organization_'; |
||
191 | |||
192 | /** |
||
193 | * @return Member |
||
194 | */ |
||
195 | 51 | public function getNoInitMember() |
|
196 | 17 | { |
|
197 | 51 | if (!$this->noInitMember) { |
|
198 | 51 | $class = $this->memberClass; |
|
199 | 51 | $this->noInitMember = $class::buildNoInitModel(); |
|
200 | 51 | } |
|
201 | 51 | return $this->noInitMember; |
|
202 | } |
||
203 | |||
204 | /** |
||
205 | * @return SubordinateLimit |
||
206 | */ |
||
207 | 19 | public function getNoInitSubordinateLimit() |
|
208 | 1 | { |
|
209 | 2 | if (!$this->noInitSubordinateLimit) { |
|
210 | 19 | $class = $this->subordinateLimitClass; |
|
211 | 2 | $this->noInitSubordinateLimit = $class::buildNoInitModel(); |
|
212 | 2 | } |
|
213 | 2 | return $this->noInitSubordinateLimit; |
|
214 | } |
||
215 | |||
216 | /** |
||
217 | * @return MemberLimit |
||
218 | */ |
||
219 | 1 | public function getNoInitMemberLimit() |
|
220 | { |
||
221 | 1 | if (!$this->noInitMemberLimit) { |
|
222 | 1 | $class = $this->memberLimitClass; |
|
223 | 1 | $this->noInitMemberLimit = $class::buildNoInitModel(); |
|
224 | 1 | } |
|
225 | 1 | return $this->noInitMemberLimit; |
|
226 | } |
||
227 | |||
228 | /** |
||
229 | * @return null|OrganizationSearch |
||
230 | */ |
||
231 | public function getSearchModel() |
||
239 | |||
240 | 52 | public function init() |
|
241 | { |
||
242 | 52 | $this->parentAttribute = 'parent_guid'; |
|
243 | 52 | if (class_exists($this->memberClass)) { |
|
244 | 52 | $this->addSubsidiaryClass('Member', ['class' => $this->memberClass]); |
|
245 | 52 | } |
|
246 | 52 | if ($this->skipInit) { |
|
247 | 52 | return; |
|
248 | } |
||
249 | 52 | $this->on(static::$eventAfterRegister, [$this, 'onAddProfile'], $this->profileConfig); |
|
250 | 52 | $this->on(static::$eventAfterRegister, [$this, 'onAssignCreator'], $this->creatorModel); |
|
251 | 52 | $this->on(static::EVENT_BEFORE_DELETE, [$this, 'onRevokeCreator']); |
|
252 | 52 | $this->on(static::EVENT_BEFORE_DELETE, [$this, 'onRevokeAdministrators']); |
|
253 | 52 | $this->on(static::EVENT_BEFORE_DELETE, [$this, 'onRevokePermissions']); |
|
254 | 52 | $this->initSelfBlameableEvents(); |
|
255 | 52 | parent::init(); |
|
256 | 52 | } |
|
257 | |||
258 | /** |
||
259 | * @inheritdoc |
||
260 | */ |
||
261 | 19 | public function attributeLabels() |
|
262 | { |
||
263 | return [ |
||
264 | 1 | 'guid' => Yii::t('user', 'GUID'), |
|
265 | 19 | 'id' => Yii::t('user', 'ID'), |
|
266 | 1 | 'ip' => Yii::t('user', 'IP Address'), |
|
267 | 1 | 'ip_type' => Yii::t('user', 'IP Address Type'), |
|
268 | 1 | 'parent' => Yii::t('organization', 'Parent'), |
|
269 | 1 | 'created_at' => Yii::t('user', 'Creation Time'), |
|
270 | 1 | 'updated_at' => Yii::t('user', 'Last Updated Time'), |
|
271 | 1 | 'status' => Yii::t('user', 'Status'), |
|
272 | 1 | 'type' => Yii::t('user', 'Type'), |
|
273 | 1 | 'isExcludeOtherMembers' => Yii::t('organization', 'Exclude Other Members'), |
|
274 | 1 | 'isDisallowMemberJoinOther' => Yii::t('organization', 'Disallow Member to Join in Other Organizations'), |
|
275 | 1 | 'isOnlyAcceptCurrentOrgMember' => Yii::t('organization', 'Only Accept Current Organization Members'), |
|
276 | 1 | 'isOnlyAcceptSuperiorOrgMember' => Yii::t('organization', 'Only Accept Superior Organization Members'), |
|
277 | 1 | ]; |
|
278 | } |
||
279 | |||
280 | /** |
||
281 | * @inheritdoc |
||
282 | */ |
||
283 | 52 | public static function tableName() |
|
287 | |||
288 | /** |
||
289 | * Find. |
||
290 | * Friendly to IDE. |
||
291 | * @return OrganizationQuery |
||
292 | */ |
||
293 | 52 | public static function find() |
|
297 | |||
298 | 51 | protected function getTypeRules() |
|
299 | { |
||
300 | 1 | return [ |
|
301 | 51 | ['type', 'default', 'value' => static::TYPE_ORGANIZATION], |
|
302 | 51 | ['type', 'required'], |
|
303 | 51 | ['type', 'in', 'range' => [static::TYPE_ORGANIZATION, static::TYPE_DEPARTMENT]], |
|
304 | 51 | [['eom', 'djo', 'oacm', 'oasm'], 'default', 'value' => 0], |
|
305 | 51 | ]; |
|
306 | } |
||
307 | |||
308 | 51 | public function rules() |
|
312 | |||
313 | /** |
||
314 | * Get Member Query. |
||
315 | * @return MemberQuery |
||
316 | */ |
||
317 | 50 | public function getMembers() |
|
323 | |||
324 | /** |
||
325 | * Get organization member users' query. |
||
326 | * @return BaseUserQuery |
||
327 | */ |
||
328 | 6 | public function getMemberUsers() |
|
337 | |||
338 | /** |
||
339 | * Get subordinate limit query. |
||
340 | * @return null|BaseBlameableQuery |
||
341 | */ |
||
342 | 2 | public function getSubordinateLimit() |
|
343 | { |
||
344 | 2 | if (empty($this->subordinateLimitClass)) { |
|
345 | return null; |
||
346 | } |
||
347 | 2 | return $this->hasOne($this->subordinateLimitClass, [ |
|
348 | 2 | $this->getNoInitSubordinateLimit()->createdByAttribute => $this->guidAttribute |
|
349 | 2 | ]); |
|
350 | } |
||
351 | |||
352 | /** |
||
353 | * Get member limit query. |
||
354 | * @return null|BaseBlameableQuery |
||
355 | */ |
||
356 | 1 | public function getMemberLimit() |
|
357 | { |
||
358 | 1 | if (empty($this->memberLimitClass)) { |
|
359 | return null; |
||
360 | } |
||
361 | 1 | return $this->hasOne($this->memberLimitClass, [ |
|
362 | 1 | $this->getNoInitMemberLimit()->createdByAttribute => $this->guidAttribute |
|
363 | 1 | ]); |
|
364 | } |
||
365 | |||
366 | /** |
||
367 | * Get member with specified user. |
||
368 | * @param User|string|integer $user |
||
369 | * @return Member Null if `user` is not in this organization. |
||
370 | */ |
||
371 | 50 | public function getMember($user) |
|
375 | |||
376 | /** |
||
377 | * Add member to organization. |
||
378 | * @param Member|User|string|integer $member Member or User model, or User ID or GUID. |
||
379 | * If member is created, it will be re-assigned to this parameter. |
||
380 | * @see createMemberModel |
||
381 | * @see createMemberModelWithUser |
||
382 | * @return boolean |
||
383 | * @throws DisallowMemberJoinOtherException |
||
384 | * @throws ExcludeOtherMembersException |
||
385 | * @throws OnlyAcceptCurrentOrgMemberException |
||
386 | * @throws OnlyAcceptSuperiorOrgMemberException |
||
387 | */ |
||
388 | 50 | public function addMember(&$member) |
|
389 | { |
||
390 | 50 | if ($this->getIsNewRecord()) { |
|
391 | return false; |
||
392 | } |
||
393 | 50 | if ($this->hasReachedMemberLimit()) { |
|
394 | 1 | return false; |
|
395 | } |
||
396 | 50 | $user = null; |
|
397 | 50 | if ($member instanceof Member) { |
|
398 | if ($member->getIsNewRecord()) { |
||
399 | return false; |
||
400 | } |
||
401 | $user = $member->memberUser; |
||
402 | } |
||
403 | 50 | if ($member instanceof User) { |
|
404 | 50 | $user = $member; |
|
405 | 50 | } |
|
406 | 50 | if (is_string($member) || is_int($member)) { |
|
407 | $class = Yii::$app->user->identityClass; |
||
408 | $user = $class::find()->guidOrId($member)->one(); |
||
409 | } |
||
410 | 50 | if ($this->hasMember($user)) { |
|
411 | return false; |
||
412 | } |
||
413 | 50 | $orgs = $user->getAtOrganizations()->all(); |
|
414 | /* @var $orgs Organization[] */ |
||
415 | 50 | foreach ($orgs as $org) { |
|
416 | 31 | if ($org->topOrganization->isDisallowMemberJoinOther && !$org->topOrganization->equals($this->topOrganization)) { |
|
417 | 1 | throw new DisallowMemberJoinOtherException(Yii::t('organization', "An organization in which the user is located does not allow its members to join other organizations.")); |
|
418 | } |
||
419 | 31 | if ($this->topOrganization->isExcludeOtherMembers && !$org->topOrganization->equals($this->topOrganization)) { |
|
420 | 1 | throw new ExcludeOtherMembersException(Yii::t('organization', "The organization does not allow users who have joined other organizations to join.")); |
|
421 | } |
||
422 | 50 | } |
|
423 | 50 | if ($this->isDepartment() && $this->isOnlyAcceptCurrentOrgMember && !$this->topOrganization->hasMember($user)) { |
|
424 | 1 | throw new OnlyAcceptCurrentOrgMemberException(Yii::t('organization' ,'This department is only accepted by members of the organization.')); |
|
425 | } |
||
426 | 50 | if ($this->isDepartment() && $this->isOnlyAcceptSuperiorOrgMember && !$this->parent->hasMember($user)) { |
|
427 | 1 | throw new OnlyAcceptSuperiorOrgMemberException(Yii::t('organization', 'This department only accepts members of the parent organization or department.')); |
|
428 | } |
||
429 | |||
430 | 50 | $this->trigger(self::EVENT_BEFORE_ADD_MEMBER); |
|
431 | 50 | $model = null; |
|
432 | 50 | if ($member instanceof Member) { |
|
433 | $model = $this->createMemberModel($member); |
||
434 | 50 | } elseif (($member instanceof User) || is_string($member) || is_int($member)) { |
|
435 | 50 | $model = $this->createMemberModelWithUser($member); |
|
436 | 50 | } |
|
437 | 50 | $member = $model; |
|
438 | 50 | $result = ($member instanceof Member) ? $member->save() : false; |
|
439 | 50 | $this->trigger(self::EVENT_AFTER_ADD_MEMBER); |
|
440 | 50 | return $result; |
|
441 | } |
||
442 | |||
443 | /** |
||
444 | * Create member model, and set organization with this. |
||
445 | * @param Member $member If this parameter is not new record, it's organization |
||
446 | * will be set with this, and return it. Otherwise, it will extract `User` |
||
447 | * model and create new `Member` model. |
||
448 | * @see createMemberModelWithUser |
||
449 | * @return Member |
||
450 | */ |
||
451 | public function createMemberModel($member) |
||
459 | |||
460 | /** |
||
461 | * Create member model with user, and set organization with this. |
||
462 | * @param User|string|integer $user |
||
463 | * @return Member |
||
464 | */ |
||
465 | 50 | public function createMemberModelWithUser($user) |
|
466 | { |
||
467 | $config = [ |
||
468 | 50 | 'memberUser' => $user, |
|
469 | 50 | 'organization' => $this, |
|
470 | 50 | 'nickname' => '', |
|
471 | 50 | ]; |
|
472 | 50 | $member = $this->createMember($config); |
|
473 | 50 | $member->nickname = $member->memberUser->profile->nickname; |
|
474 | 50 | return $member; |
|
475 | } |
||
476 | |||
477 | /** |
||
478 | * Remove member. |
||
479 | * Note: the creator cannot be removed. |
||
480 | * @param Member|User $member |
||
481 | * @return boolean |
||
482 | */ |
||
483 | 4 | public function removeMember(&$member) |
|
484 | { |
||
485 | 4 | if ($this->getIsNewRecord()) { |
|
486 | return false; |
||
487 | } |
||
488 | 4 | $this->trigger(self::EVENT_BEFORE_REMOVE_MEMBER); |
|
489 | 4 | if ($member instanceof $this->memberClass) { |
|
490 | 4 | $member = $member->{$member->memberAttribute}; |
|
491 | 4 | } |
|
492 | 4 | $member = $this->getMember($member); |
|
493 | 4 | if (!$member || $member->isCreator()) { |
|
494 | return false; |
||
495 | } |
||
496 | 4 | $result = $member->delete() > 0; |
|
497 | 4 | $this->trigger(self::EVENT_AFTER_REMOVE_MEMBER); |
|
498 | 4 | return $result; |
|
499 | } |
||
500 | |||
501 | /** |
||
502 | * Remove administrator. |
||
503 | * @param Member|User|integer|string $member Member instance, or User instance or its GUID or ID. |
||
504 | * @param boolean $keep Keep member after administrator being revoked. |
||
505 | * @return boolean |
||
506 | * @throws IntegrityException |
||
507 | */ |
||
508 | public function removeAdministrator(&$member, $keep = true) |
||
509 | { |
||
510 | if ($this->getIsNewRecord()) { |
||
511 | return false; |
||
512 | } |
||
513 | if ($member instanceof $this->memberClass) { |
||
514 | $member = $member->{$member->memberAttribute}; |
||
515 | } |
||
516 | $member = $this->getMember($member); |
||
517 | if ($member && $member->isAdministrator()) { |
||
518 | if ($keep) { |
||
519 | return $member->revokeAdministrator(); |
||
520 | } |
||
521 | return $this->removeMember($member); |
||
522 | } |
||
523 | return false; |
||
524 | } |
||
525 | |||
526 | /** |
||
527 | * |
||
528 | * @param Event $event |
||
529 | * @throws IntegrityException |
||
530 | * @return boolean |
||
531 | */ |
||
532 | 51 | public function onAddProfile($event) |
|
540 | |||
541 | /** |
||
542 | * |
||
543 | * @param Event $event |
||
544 | */ |
||
545 | 51 | public function onAssignCreator($event) |
|
549 | |||
550 | /** |
||
551 | * |
||
552 | * @param Event $event |
||
553 | * @return boolean |
||
554 | */ |
||
555 | 20 | public function onRevokeCreator($event) |
|
564 | |||
565 | /** |
||
566 | * |
||
567 | * @param Event $event |
||
568 | * @return boolean |
||
569 | */ |
||
570 | 20 | public function onRevokeAdministrators($event) |
|
571 | { |
||
572 | 20 | $sender = $event->sender; |
|
573 | /* @var $sender static */ |
||
574 | 20 | $members = $sender->getMemberAdministrators()->all(); |
|
575 | /* @var $members Member[] */ |
||
576 | 20 | foreach ($members as $member) |
|
577 | { |
||
578 | 1 | $member->revokeAdministrator(); |
|
579 | 20 | } |
|
580 | 20 | return true; |
|
581 | } |
||
582 | |||
583 | /** |
||
584 | * |
||
585 | * @param Event $event |
||
586 | */ |
||
587 | 20 | public function onRevokePermissions($event) |
|
591 | |||
592 | /** |
||
593 | * Check whether current instance is an organization. |
||
594 | * @return boolean |
||
595 | */ |
||
596 | 50 | public function isOrganization() |
|
600 | |||
601 | /** |
||
602 | * Check whether current instance if a department. |
||
603 | * @return boolean |
||
604 | */ |
||
605 | 50 | public function isDepartment() |
|
609 | |||
610 | /** |
||
611 | * Check whether the current organization has a member. |
||
612 | * @param User|string|integer $user User instance, GUID or ID. |
||
613 | * @return boolean |
||
614 | */ |
||
615 | 50 | public function hasMember($user) |
|
619 | |||
620 | /** |
||
621 | * Get member query which role is specified `Creator`. |
||
622 | * @return MemberQuery |
||
623 | */ |
||
624 | 24 | public function getMemberCreators() |
|
628 | |||
629 | /** |
||
630 | * Get member query which role is specified `Administrator`. |
||
631 | * @return MemberQuery |
||
632 | */ |
||
633 | 22 | public function getMemberAdministrators() |
|
637 | |||
638 | /** |
||
639 | * Get user query which role is specified `Creator`. |
||
640 | * @return BaseUserQuery |
||
641 | */ |
||
642 | 4 | public function getCreator() |
|
651 | |||
652 | /** |
||
653 | * Get user query which role is specified `Administrator`. |
||
654 | * @return BaseUserQuery |
||
655 | */ |
||
656 | 2 | public function getAdministrators() |
|
665 | |||
666 | /** |
||
667 | * |
||
668 | * @param User $user |
||
669 | * @return boolean |
||
670 | * @throws \Exception |
||
671 | * @throws IntegrityException |
||
672 | */ |
||
673 | 51 | protected function addCreator($user) |
|
674 | { |
||
675 | 51 | if (!$user) { |
|
676 | 1 | throw new InvalidParamException('Creator Invalid.'); |
|
677 | } |
||
678 | 50 | $member = $user; |
|
679 | 50 | $transaction = Yii::$app->db->beginTransaction(); |
|
680 | try { |
||
681 | 50 | if (!$this->addMember($member)) { |
|
682 | throw new IntegrityException('Failed to add member.'); |
||
683 | } |
||
684 | 50 | $role = $this->isOrganization() ? (new OrganizationCreator)->name : (new DepartmentCreator)->name; |
|
685 | 50 | $member->assignRole($role); |
|
686 | 50 | if (!$member->save()) { |
|
687 | throw new IntegrityException('Failed to assign creator.'); |
||
688 | } |
||
689 | 50 | $transaction->commit(); |
|
690 | 50 | } catch (\Exception $ex) { |
|
691 | $transaction->rollBack(); |
||
692 | Yii::error($ex->getMessage(), __METHOD__); |
||
693 | throw $ex; |
||
694 | } |
||
695 | 50 | return true; |
|
696 | } |
||
697 | |||
698 | /** |
||
699 | * Add administrator. |
||
700 | * @param User|integer|string $user User instance, or its GUID or ID. |
||
701 | * @return boolean |
||
702 | * @throws \Exception |
||
703 | * @throws IntegrityException |
||
704 | */ |
||
705 | 17 | public function addAdministrator($user) |
|
722 | |||
723 | /** |
||
724 | * Check whether the current organization has administrator. |
||
725 | * @param User|integer|string $user |
||
726 | * @return boolean |
||
727 | */ |
||
728 | 2 | public function hasAdministrator($user) |
|
736 | |||
737 | /** |
||
738 | * Check whether this organization has reached the upper limit of subordinates. |
||
739 | * @return boolean |
||
740 | */ |
||
741 | 19 | public function hasReachedSubordinateLimit() |
|
749 | |||
750 | /** |
||
751 | * Get the remaining places of subordinates. |
||
752 | * @return bool|int False if no limit |
||
753 | */ |
||
754 | 19 | public function getRemainingSubordinatePlaces() |
|
767 | |||
768 | /** |
||
769 | * Check whether this organization has reached the upper limit of members. |
||
770 | * @return boolean |
||
771 | */ |
||
772 | 50 | public function hasReachedMemberLimit() |
|
780 | |||
781 | /** |
||
782 | * Get the remaining places of members. |
||
783 | * @return bool|int False if no limit. |
||
784 | */ |
||
785 | 50 | public function getRemainingMemberPlaces() |
|
798 | |||
799 | /** |
||
800 | * @return bool |
||
801 | */ |
||
802 | 31 | public function getIsExcludeOtherMembers() |
|
806 | |||
807 | /** |
||
808 | * @param bool $value |
||
809 | */ |
||
810 | 2 | public function setIsExcludeOtherMembers($value = true) |
|
814 | |||
815 | /** |
||
816 | * @return bool |
||
817 | */ |
||
818 | 31 | public function getIsDisallowMemberJoinOther() |
|
822 | |||
823 | /** |
||
824 | * @param bool $value |
||
825 | */ |
||
826 | 2 | public function setIsDisallowMemberJoinOther($value = true) |
|
830 | |||
831 | /** |
||
832 | * @return bool |
||
833 | */ |
||
834 | 18 | public function getIsOnlyAcceptCurrentOrgMember() |
|
838 | |||
839 | /** |
||
840 | * @param bool $value |
||
841 | */ |
||
842 | 2 | public function setIsOnlyAcceptCurrentOrgMember($value = true) |
|
846 | |||
847 | /** |
||
848 | * @return bool |
||
849 | */ |
||
850 | 18 | public function getIsOnlyAcceptSuperiorOrgMember() |
|
854 | |||
855 | /** |
||
856 | * @param bool $value |
||
857 | */ |
||
858 | 2 | public function setIsOnlyAcceptSuperiorOrgMember($value = true) |
|
862 | |||
863 | /** |
||
864 | * @return $this|null|static |
||
865 | */ |
||
866 | 31 | public function getTopOrganization() |
|
874 | |||
875 | /** |
||
876 | * Check whether the subordinates have the [[$user]] |
||
877 | * Note, this operation may consume the quantity of database selection. |
||
878 | * @param User $user |
||
879 | * @return bool |
||
880 | */ |
||
881 | 2 | public function hasMemberInSubordinates($user) |
|
882 | { |
||
883 | 2 | if ($this->getChildren()->joinWith(['memberUsers mu_alias']) |
|
884 | 2 | ->andWhere(['mu_alias.' . $user->guidAttribute => $user->getGUID()])->exists()) { |
|
885 | 1 | return true; |
|
886 | } |
||
887 | 2 | $children = $this->children; |
|
888 | /* @var $children static[] */ |
||
896 | } |
||
897 |