Skip to content

Commit 2e6c00f

Browse files
Merge pull request #5736 from christianbeeznest/fixes-updates43
Internal: Fix Coach Assignment Logic in Course Session
2 parents 96ed0e1 + a589801 commit 2e6c00f

File tree

1 file changed

+22
-38
lines changed

1 file changed

+22
-38
lines changed

public/main/inc/lib/sessionmanager.lib.php

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3562,37 +3562,33 @@ public static function set_coach_to_course_session(
35623562
}
35633563

35643564
if ($noCoach) {
3565-
// check if user_id exists in session_rel_user (if the user is
3566-
// subscribed to the session in any manner)
3567-
$sql = "SELECT count(user_id) count FROM $tblSessionRelUser
3568-
WHERE
3569-
session_id = $sessionId AND
3570-
user_id = $userId";
3571-
$res = Database::query($sql);
3565+
// Delete the course-specific coach record
3566+
$sql = "DELETE FROM $tblSessionRelCourseRelUser
3567+
WHERE
3568+
session_id = $sessionId AND
3569+
c_id = $courseId AND
3570+
user_id = $userId AND
3571+
status = ".Session::COURSE_COACH;
3572+
$result = Database::query($sql);
35723573

3573-
if (Database::num_rows($res) > 0) {
3574-
$resultRow = Database::fetch_assoc($res);
3575-
// If the user is only connected to a course coach then deleted it.
3576-
if (1 === (int) $resultRow['count']) {
3577-
$sql = "DELETE FROM $tblSessionRelUser
3578-
WHERE
3579-
session_id = $sessionId AND
3580-
user_id = $userId ";
3581-
Database::query($sql);
3582-
}
3583-
}
3574+
// Check if the user is still a coach for any course in this session
3575+
$sql = "SELECT COUNT(*) AS count FROM $tblSessionRelCourseRelUser
3576+
WHERE
3577+
session_id = $sessionId AND
3578+
user_id = $userId AND
3579+
status = ".Session::COURSE_COACH;
3580+
$res = Database::query($sql);
3581+
$resultRow = Database::fetch_assoc($res);
35843582

3585-
// The user is not subscribed to the session, so make sure
3586-
// he isn't subscribed to a course in this session either
3587-
// and then exit
3588-
$sql = "DELETE FROM $tblSessionRelCourseRelUser
3583+
// If the user is no longer a coach for any course in this session, remove the session relationship
3584+
if (0 === (int) $resultRow['count']) {
3585+
$sql = "DELETE FROM $tblSessionRelUser
35893586
WHERE
35903587
session_id = $sessionId AND
3591-
c_id = $courseId AND
35923588
user_id = $userId AND
3593-
status = ".Session::COURSE_COACH."
3594-
";
3595-
$result = Database::query($sql);
3589+
relation_type = ".Session::COURSE_COACH;
3590+
Database::query($sql);
3591+
}
35963592

35973593
return Database::affected_rows($result) > 0;
35983594
}
@@ -3631,18 +3627,6 @@ public static function set_coach_to_course_session(
36313627
);
36323628

36333629
$sessionRepo->update($session);
3634-
/*
3635-
$em = Database::getManager();
3636-
$sessionRelCourseRelUser = new SessionRelCourseRelUser();
3637-
$sessionRelCourseRelUser
3638-
->setSession(api_get_session_entity($sessionId))
3639-
->setCourse(api_get_course_entity($courseId))
3640-
->setUser(api_get_user_entity($userId))
3641-
->setStatus(2)
3642-
->setVisibility(1)
3643-
;
3644-
$em->persist($sessionRelCourseRelUser);
3645-
$em->flush();*/
36463630

36473631
return true;
36483632
}

0 commit comments

Comments
 (0)