DB Enrolment Problem

DB Enrolment Problem

by Andrew Emmett -
Number of replies: 1

Dear Anybody

I'm new to moodle & have been setting up a new installation for my college using moodle 1.9.2. The DB enrolment plugin the comes by default with dosen't support categories in the enrolment DB for courses, so I downloaded Iñaki Arenaza's enrolment plugin from: http://orodruin.escomposlinux.org/~iarenaza/moodle/enrol_db/enrol_db_files_for_19/

Things seemed to be working great until on of my lecturers told me they were not getting all their courses. I checked on here for similar experiences, but didn't see any so I had a look myself & think I have found the problem.

In my event log, the following messages were constantly being displayed:

User enrolled to course 08/09|33429|NSE1A, but there is more than one course with that value in the enrolment database (in field courseid)

In enrol.php in the get_course_details function, there is an SQL statement that reads:

$query = "SELECT $columns FROM {$CFG->enrol_coursetable} " .
"WHERE {$CFG->enrol_courseid} = '$courseid'";

I think, because my enroloment table has multiple entries against it (a tutor & multiple students), more than 1 row is being returned & the enclosed IF statement is returning an error... I added a DISTINCT statement to the query & every started working properly.

$query = "SELECT DISTINCT $columns FROM {$CFG->enrol_coursetable} " .
"WHERE {$CFG->enrol_courseid} = '$courseid'";

I'm not sure if there are any other implications to this, but if you are reading this Iñaki, perhaps you can tell me if I did the right thing? Also, do you know if your code will be added to the main Moodle distribution? I find it a bit strange that this functionality is not already there?

PS.. Thanks for all the work you do... This enrolment plugin is great..

Average of ratings: -
In reply to Andrew Emmett

Re: DB Enrolment Problem

by Iñaki Arenaza -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Hi Andrew,

I almost missed your post! (a bit busy with the start of the semester and all that smile)

The plugin assumes you have two different tables:

  • One with the enrolment data, where you have your tutor/students/whatever-roles-you-use related to their courses
  • A different table with just the course data (shortname, fullname, category, etc.)

This second table is assumed to have unique records for each course, and that's why there's no DISTINCT qualifier in the SQL query: there is (supposedly) no need for it.

I think I'm going to add the DISTINCT qualifier anyway. It doesn't hurt when you don't have multiples entries for the same course (what the plugin has assumed so far) and it helps a lot when you do smile

Regarding the question about adding the code to the main Moodle distribution, we have tried in the past, although not too much. Given that we have added another interesting feature(*), maybe we'll try again this October, when Martin Dougiamas comes to Spain to the Spanish Moot smile

(*) You can use existing courses as templates for the newly autocreated course. But the feature is that is completely copies the template course to the new course, including sections, activities, blocks, course settings (visibility, etc.). Given that the copy operation is quite heavy, you can decide if you autocreate courses during user login or only during batch processing via enrol_database_sync.php. I inted to publish a patch as soon as the my work load decreases a bit smile In the meantime, those brave enough can browse the patch at this temporary git repository: http://git.eteo.mondragon.edu/gitweb?p=enrol-db.git;a=summary

Saludos. Iñaki.