Permalink
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...
1 parent 8ba12d5 commit 8e0b42fb88512c471eb5df4b5b1abc868de6574d martinlanghoff committed Aug 26, 2005
Showing with 13 additions and 9 deletions.
  1. +7 −3 enrol/database/enrol.php
  2. +2 −2 enrol/enrol.class.php
  3. +4 −4 lib/moodlelib.php
View
@@ -60,16 +60,20 @@ 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
}
}
}
}
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
@@ -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
@@ -2539,14 +2539,17 @@ 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 ?
* @param int $timeend ?
* @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;

0 comments on commit 8e0b42f

Please sign in to comment.