| <?php |
|
|
| namespace Kanboard\Core\User; |
|
|
| use Kanboard\Core\Base; |
|
|
| |
| |
| |
| |
| |
| |
| class GroupSync extends Base |
| { |
| |
| |
| |
| |
| |
| |
| |
| public function synchronize($userId, array $externalGroupIds) |
| { |
| $userGroups = $this->groupMemberModel->getGroups($userId); |
| $this->addGroups($userId, $userGroups, $externalGroupIds); |
| $this->removeGroups($userId, $userGroups, $externalGroupIds); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| protected function addGroups($userId, array $userGroups, array $externalGroupIds) |
| { |
| $userGroupIds = array_column($userGroups, 'external_id', 'external_id'); |
| $externalGroups = $this->groupModel->getByExternalIds($externalGroupIds); |
|
|
| foreach ($externalGroups as $externalGroup) { |
| if (! isset($userGroupIds[$externalGroup['external_id']])) { |
| $this->groupMemberModel->addUser($externalGroup['id'], $userId); |
| } |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| protected function removeGroups($userId, array $userGroups, array $externalGroupIds) |
| { |
| foreach ($userGroups as $userGroup) { |
| if (! empty($userGroup['external_id']) && ! in_array($userGroup['external_id'], $externalGroupIds)) { |
| $this->groupMemberModel->removeUser($userGroup['id'], $userId); |
| } |
| } |
| } |
| } |
|
|