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.

This commit is contained in:
martinlanghoff 2005-08-26 06:11:38 +00:00
parent d23d0398fe
commit a6d114e600
3 changed files with 13 additions and 9 deletions

View File

@ -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
}
}
}

View File

@ -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.");
}

View File

@ -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;