Skip to content

Commit 20d8220

Browse files
authored
Merge pull request #6857 from yverhenne/improve-session-inscription
Adjusted subscribeUsersToSession to preserve course-level unsubscript…
2 parents d1dcf0b + 8405a83 commit 20d8220

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

main/inc/lib/sessionmanager.lib.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2052,6 +2052,22 @@ public static function subscribeUsersToSession(
20522052
$course_list[] = $row['c_id'];
20532053
}
20542054

2055+
// Build list of users already subscribed to the session as students.
2056+
// This allows us to avoid re-enrolling them into all courses again
2057+
// when they are already part of the session (preserves manual
2058+
// unsubscriptions at the course level).
2059+
$usersAlreadyInSession = [];
2060+
if (!empty($userList)) {
2061+
$userIdsStr = "'".implode("','", $userList)."'";
2062+
$sql = "SELECT user_id FROM $tbl_session_rel_user
2063+
WHERE session_id = $sessionId AND relation_type = 0
2064+
AND user_id IN ($userIdsStr)";
2065+
$resUsersInSession = Database::query($sql);
2066+
while ($row = Database::fetch_array($resUsersInSession)) {
2067+
$usersAlreadyInSession[] = (int) $row['user_id'];
2068+
}
2069+
}
2070+
20552071
if ($session->getSendSubscriptionNotification() &&
20562072
is_array($userList)
20572073
) {
@@ -2154,8 +2170,8 @@ public static function subscribeUsersToSession(
21542170

21552171
$usersToSubscribeInCourse = array_filter(
21562172
$userList,
2157-
function ($userId) use ($existingUsers) {
2158-
return !in_array($userId, $existingUsers);
2173+
function ($userId) use ($existingUsers, $usersAlreadyInSession) {
2174+
return !in_array($userId, $existingUsers) && !in_array($userId, $usersAlreadyInSession);
21592175
}
21602176
);
21612177

0 commit comments

Comments
 (0)