multi-table enrolment plug-in

multi-table enrolment plug-in

by Scott Krajewski -
Number of replies: 0
I was wondering if anyone could provide a second set of eyes to my customized enrolment plugin?  We're 1.4.4.

Here's the deal.  This is operating in an external db to moodle.  We have an enrolment table populated by our registrar's system.  We also have a table for combining course section enrolments in the CMS.  This table maps say  MAT-101-A and MAT-101-B into MAT-101-AB in the CMS.  Simple table, 2 fields.  We also are going to create another table of enrolments in courses that aren't courses according to the registrar -- say a course for a cohort of students, or all the sophomores.  This table would have a student id and course id.  Usual stuff.
So that's 2 enrolment tables and 1 table to convert course ids.

Here's my extra fields to the base db enrolment plugin (this is from the language file):
$string['remoteconverttable'] = 'The table in the remote database we expect to find the CMS conversion fields';
$string['remoteconvertregistrar'] = 'The field in the remote database we expect to find the registrar course id';
$string['remoteconvertcms'] = 'The field in the remote database we expect to find the CMS course id';
$string['remoteexcepttable'] = 'The table in the remote database we expect to find the exception course ids';
$string['remoteexceptuserfield'] = 'The field in the remote database exceptions table we expect to find the user id';
$string['remoteexceptcoursefield'] = 'The field in the remote database exceptions table we expect to find the course id';

Basically I want to UNION on the two enrolment tables and check thecourse id against the translation table.  If the course id is inthe translation table I should use the translated course id forenrolment, otherwise leave as is.

Here's the modified parts of the function. Everything else is thesame except for  process_config which was modified to add the newvalues:

       /// Union on the two enrolment tables

if ($rs = $enroldb->Execute("SELECT $CFG->aug_enrol_remotecoursefield
FROM $CFG->aug_enrol_dbtable
WHERE $CFG->aug_enrol_remoteuserfield = '$useridnumber'
UNION
SELECT $CFG->aug_enrol_remoteexceptcoursefield
FROM $CFG->aug_enrol_remoteexcepttable
WHERE $CFG->aug_enrol_remoteexceptuserfield = '$useridnumber'")) {

if ($rs->RecordCount() > 0) {
while (!$rs->EOF) {
$courselist[] = $rs->fields[0];
$rs->MoveNext();
}

foreach ($courselist as $coursefield) {

/// look in remote CMS table for the course
/// if listed, it will be only once, use that courseid for the moodle one, otherwise stay as it
if ($cms = $enroldb->Execute("SELECT $CFG->aug_enrol_remoteconvertcms
FROM $CFG->aug_enrol_remoteconverttable
WHERE $CFG->aug_enrol_remoteconvertregistrar = '$coursefield'") {
if ($cms->RecordCount() > 0) {
$coursefield = $cms->fields[0];
}

}

if ($course = get_record('course', $CFG->aug_enrol_localcoursefield, $coursefield)) {
$newstudent[$course->id] = true; /// Add it to new list
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
}
}
}
}


Average of ratings: -