Skip to content

Commit

Permalink
Correct handling of Moodle groups belonging to more than one grouping
Browse files Browse the repository at this point in the history
  • Loading branch information
spvickers committed May 12, 2022
1 parent 5e9bd65 commit 1466a95
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/ApiHook/moodle/MoodleApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,16 +279,18 @@ private function setGroups($users)
// Check that user is not a member of another group in the same grouping
if (in_array($setId, $sets)) {
// Remove grouping and groups
foreach ($users as $user2) {
foreach ($user2->groups as $groupId) {
if ($this->sourceObject->groups[$groupId]['set'] === $setId) {
unset($user2->groups[$groupId]);
foreach ($this->sourceObject->groupSets[$setId]['groups'] as $groupId) {
if (!is_array($this->sourceObject->groups[$groupId]['set']) && ($this->sourceObject->groups[$groupId]['set'] === $setId)) {
unset($this->sourceObject->groups[$groupId]['set']);
} else if (is_array($this->sourceObject->groups[$groupId]['set']) && in_array($setId,
$this->sourceObject->groups[$groupId]['set'])) {
$pos = array_search($setId, $this->sourceObject->groups[$groupId]['set']);
unset($this->sourceObject->groups[$groupId]['set'][$pos]);
if (empty($this->sourceObject->groups[$groupId]['set'])) {
unset($this->sourceObject->groups[$groupId]['set']);
}
}
}
foreach ($this->sourceObject->groupSets[$setId]['groups'] as $groupId) {
unset($this->sourceObject->groups[$groupId]);
}
unset($this->sourceObject->groupSets[$setId]);
} elseif (array_key_exists($group, $this->sourceObject->groups)) {
$this->sourceObject->groupSets[$setId]['num_members']++;
Expand Down

0 comments on commit 1466a95

Please sign in to comment.