From a6d114e600e8a5a9ccc1dc94bccf4cd400d490ed Mon Sep 17 00:00:00 2001 From: martinlanghoff Date: Fri, 26 Aug 2005 06:11:38 +0000 Subject: [PATCH] Merged from MOODLE_15_STABLE - enrolment fixes: We now have better handling of the enrol field when dealing with student enrolments. This fixes bugs 3912 and 3974. NOTE that enrol_student() now defaults to manual - this is to support the different pages that call enrol_student() to still work correctly when external enrolments are in use, by recording the enrolments as manual. Enrolment plugins are expected to know better and pass the correct parameter. --- enrol/database/enrol.php | 10 +++++++--- enrol/enrol.class.php | 4 ++-- lib/moodlelib.php | 8 ++++---- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/enrol/database/enrol.php b/enrol/database/enrol.php index 65f42edfe8f..f04881bc989 100644 --- a/enrol/database/enrol.php +++ b/enrol/database/enrol.php @@ -60,7 +60,7 @@ function get_student_courses(&$user) { if (isset($user->student[$course->id])) { /// We have it already unset($user->student[$course->id]); /// Remove from old list } else { - enrol_student($user->id, $course->id); /// Enrol the student + enrol_student($user->id, $course->id, 0, 0, 'database'); /// Enrol the student } } } @@ -68,8 +68,12 @@ function get_student_courses(&$user) { if (!empty($user->student)) { /// We have some courses left that we need to unenrol from foreach ($user->student as $courseid => $value) { - unenrol_student($user->id, $courseid); /// Unenrol the student - unset($user->student[$course->id]); /// Remove from old list + + // unenrol only if it's a record pulled from external db + if (get_record_select('user_students', 'userid', $user->id, 'courseid', $courseid, 'enrol', 'database')) { + unenrol_student($user->id, $courseid); /// Unenrol the student + unset($user->student[$course->id]); /// Remove from old list + } } } diff --git a/enrol/enrol.class.php b/enrol/enrol.class.php index c7fd99aac3e..b5cd8f59f01 100644 --- a/enrol/enrol.class.php +++ b/enrol/enrol.class.php @@ -145,7 +145,7 @@ function print_entry($course) { $timestart = $timeend = 0; } - if (! enrol_student($USER->id, $course->id, $timestart, $timeend)) { + if (! enrol_student($USER->id, $course->id, $timestart, $timeend, 'manual')) { error("An error occurred while trying to enrol you."); } @@ -226,7 +226,7 @@ function check_entry($form, $course) { $timestart = $timeend = 0; } - if (! enrol_student($USER->id, $course->id, $timestart, $timeend)) { + if (! enrol_student($USER->id, $course->id, $timestart, $timeend, 'manual')) { error("An error occurred while trying to enrol you."); } diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 5877f2d0b9f..954a13fcb29 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -2753,6 +2753,9 @@ function set_login_session_preferences() { /** * Enrols (or re-enrols) a student in a given course * + * NOTE: Defaults to 'manual' enrolment - enrolment plugins + * must set it explicitly. + * * @uses $CFG * @param int $userid The id of the user that is being tested against. Set this to 0 if you would just like to test against the currently logged in user. * @param int $courseid The id of the course that is being viewed @@ -2762,7 +2765,7 @@ function set_login_session_preferences() { * @return bool * @todo Finish documenting this function */ -function enrol_student($userid, $courseid, $timestart=0, $timeend=0, $enrol='') { +function enrol_student($userid, $courseid, $timestart=0, $timeend=0, $enrol='manual') { global $CFG; @@ -2779,9 +2782,6 @@ function enrol_student($userid, $courseid, $timestart=0, $timeend=0, $enrol='') } } - if (empty($enrol)) { - $enrol = $CFG->enrol; // Default current method - } if ($student = get_record('user_students', 'userid', $userid, 'course', $courseid)) { $student->timestart = $timestart; $student->timeend = $timeend;