| @@ 97-117 (lines=21) @@ | ||
| 94 | * @return array |
|
| 95 | * @throws \Exception |
|
| 96 | */ |
|
| 97 | public function linkGroup($circleUniqueId, $groupId) { |
|
| 98 | ||
| 99 | try { |
|
| 100 | $circle = $this->circlesRequest->getCircle($circleUniqueId, $this->userId); |
|
| 101 | $circle->getHigherViewer() |
|
| 102 | ->hasToBeAdmin(); |
|
| 103 | ||
| 104 | $group = $this->getFreshNewMember($circleUniqueId, $groupId); |
|
| 105 | } catch (\Exception $e) { |
|
| 106 | throw $e; |
|
| 107 | } |
|
| 108 | ||
| 109 | $group->setLevel(Member::LEVEL_MEMBER); |
|
| 110 | $this->membersRequest->updateGroup($group); |
|
| 111 | ||
| 112 | $this->eventsService->onGroupLink($circle, $group); |
|
| 113 | ||
| 114 | return $this->membersRequest->getGroupsFromCircle( |
|
| 115 | $circleUniqueId, $circle->getHigherViewer() |
|
| 116 | ); |
|
| 117 | } |
|
| 118 | ||
| 119 | ||
| 120 | /** |
|
| @@ 308-324 (lines=17) @@ | ||
| 305 | * @return null|Member |
|
| 306 | * @throws \Exception |
|
| 307 | */ |
|
| 308 | public function joinCircle($circleUniqueId) { |
|
| 309 | ||
| 310 | try { |
|
| 311 | $circle = $this->circlesRequest->getCircle($circleUniqueId, $this->userId); |
|
| 312 | ||
| 313 | $member = $this->membersRequest->getFreshNewMember( |
|
| 314 | $circleUniqueId, $this->userId, Member::TYPE_USER |
|
| 315 | ); |
|
| 316 | $member->hasToBeAbleToJoinTheCircle(); |
|
| 317 | $member->joinCircle($circle->getType()); |
|
| 318 | $this->membersRequest->updateMember($member); |
|
| 319 | ||
| 320 | $this->eventsService->onMemberNew($circle, $member); |
|
| 321 | } catch (\Exception $e) { |
|
| 322 | throw $e; |
|
| 323 | } |
|
| 324 | ||
| 325 | return $member; |
|
| 326 | } |
|
| 327 | ||
| @@ 337-357 (lines=21) @@ | ||
| 334 | * @return null|Member |
|
| 335 | * @throws \Exception |
|
| 336 | */ |
|
| 337 | public function leaveCircle($circleUniqueId) { |
|
| 338 | ||
| 339 | try { |
|
| 340 | $circle = $this->circlesRequest->getCircle($circleUniqueId, $this->userId); |
|
| 341 | $member = $circle->getViewer(); |
|
| 342 | ||
| 343 | $member->hasToBeMemberOrAlmost(); |
|
| 344 | $member->cantBeOwner(); |
|
| 345 | ||
| 346 | $this->eventsService->onMemberLeaving($circle, $member); |
|
| 347 | ||
| 348 | $member->setStatus(Member::STATUS_NONMEMBER); |
|
| 349 | $member->setLevel(Member::LEVEL_NONE); |
|
| 350 | $this->membersRequest->updateMember($member); |
|
| 351 | } catch (\Exception $e) { |
|
| 352 | throw $e; |
|
| 353 | } |
|
| 354 | ||
| 355 | return $member; |
|
| 356 | } |
|
| 357 | ||
| 358 | ||
| 359 | /** |
|
| 360 | * destroy a circle. |
|