Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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.
  • Loading branch information...
commit 8e0b42fb88512c471eb5df4b5b1abc868de6574d 1 parent 8ba12d5
martinlanghoff authored
View
10 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
+ }
}
}
View
4 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.");
}
View
8 lib/moodlelib.php
@@ -2539,6 +2539,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.
+ *
* @param int $courseid The id of the course that is being viewed
* @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 $timestart ?
@@ -2546,7 +2549,7 @@ function set_login_session_preferences() {
* @return boolean
* @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;
@@ -2563,9 +2566,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;
Please sign in to comment.
Something went wrong with that request. Please try again.