| @@ 162-193 (lines=32) @@ | ||
| 159 | * @return array |
|
| 160 | * @throws \Exception |
|
| 161 | */ |
|
| 162 | public function levelGroup($circleUniqueId, $groupId, $level) { |
|
| 163 | ||
| 164 | $level = (int)$level; |
|
| 165 | try { |
|
| 166 | $circle = $this->circlesRequest->getCircle($circleUniqueId, $this->userId); |
|
| 167 | if ($circle->getType() === Circle::CIRCLES_PERSONAL) { |
|
| 168 | throw new CircleTypeNotValidException( |
|
| 169 | $this->l10n->t('You cannot edit level in a personal circle') |
|
| 170 | ); |
|
| 171 | } |
|
| 172 | ||
| 173 | $group = $this->membersRequest->forceGetGroup($circle->getUniqueId(), $groupId); |
|
| 174 | if ($group->getLevel() !== $level) { |
|
| 175 | if ($level === Member::LEVEL_OWNER) { |
|
| 176 | throw new GroupCannotBeOwnerException( |
|
| 177 | $this->l10n->t('Group cannot be set as owner of a circle') |
|
| 178 | ); |
|
| 179 | } else { |
|
| 180 | $this->editGroupLevel($circle, $group, $level); |
|
| 181 | } |
|
| 182 | ||
| 183 | $this->eventsService->onGroupLevel($circle, $group); |
|
| 184 | } |
|
| 185 | ||
| 186 | return $this->membersRequest->getGroupsFromCircle( |
|
| 187 | $circle->getUniqueId(), $circle->getHigherViewer() |
|
| 188 | ); |
|
| 189 | } catch (\Exception $e) { |
|
| 190 | throw $e; |
|
| 191 | } |
|
| 192 | ||
| 193 | } |
|
| 194 | ||
| 195 | ||
| 196 | /** |
|
| @@ 279-306 (lines=28) @@ | ||
| 276 | * @return array |
|
| 277 | * @throws \Exception |
|
| 278 | */ |
|
| 279 | public function levelMember($circleUniqueId, $name, $level) { |
|
| 280 | ||
| 281 | $level = (int)$level; |
|
| 282 | try { |
|
| 283 | $circle = $this->circlesRequest->getCircle($circleUniqueId, $this->userId); |
|
| 284 | if ($circle->getType() === Circle::CIRCLES_PERSONAL) { |
|
| 285 | throw new CircleTypeNotValidException( |
|
| 286 | $this->l10n->t('You cannot edit level in a personal circle') |
|
| 287 | ); |
|
| 288 | } |
|
| 289 | ||
| 290 | $member = $this->membersRequest->forceGetMember($circle->getUniqueId(), $name); |
|
| 291 | if ($member->getLevel() !== $level) { |
|
| 292 | if ($level === Member::LEVEL_OWNER) { |
|
| 293 | $this->switchOwner($circle, $member); |
|
| 294 | } else { |
|
| 295 | $this->editMemberLevel($circle, $member, $level); |
|
| 296 | } |
|
| 297 | ||
| 298 | $this->eventsService->onMemberLevel($circle, $member); |
|
| 299 | } |
|
| 300 | ||
| 301 | return $this->membersRequest->getMembers($circle->getUniqueId(), $circle->getHigherViewer()); |
|
| 302 | } catch (\Exception $e) { |
|
| 303 | throw $e; |
|
| 304 | } |
|
| 305 | ||
| 306 | } |
|
| 307 | ||
| 308 | ||
| 309 | /** |
|