@@ -2052,6 +2052,22 @@ public static function subscribeUsersToSession(
2052
2052
$ course_list [] = $ row ['c_id ' ];
2053
2053
}
2054
2054
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
+
2055
2071
if ($ session ->getSendSubscriptionNotification () &&
2056
2072
is_array ($ userList )
2057
2073
) {
@@ -2154,8 +2170,8 @@ public static function subscribeUsersToSession(
2154
2170
2155
2171
$ usersToSubscribeInCourse = array_filter (
2156
2172
$ 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 ) ;
2159
2175
}
2160
2176
);
2161
2177
0 commit comments