External DB enrollment, enroll one user in multiple courses

External DB enrollment, enroll one user in multiple courses

by Albert R. -
Number of replies: 1

Hi,


I'm developing a Moodle site and I'm using both external BD identification and enrollment plugins. It all seems to work fine so far for "simple" situations (one user in the external DB gets access to one course in Moodle)


However, now I'm starting to see the need of making this system a little better, since there are users in the external DB that should get access to more than one course in my Moodle site.


The big problem here is the structure of the users table in this external database (it was like this when I took on this project and can't be changed since it's being used for other purposes too).


The structure is as follows (simplified to the fields that really matter): user_id / login / course_id

The field course_id is the one that the enrollment plugin compares to the "Course ID" setting in the Moodle courses to know if a user is enrolled in one specific course. This works very well if I need to enroll users in just one course.

The problem is that there are users with multiple records, something like:

Record 1: 123 / username1 / 1

Record 2: 456 / username1 / 2

In that example, the user with login username1 should be enrolled in courses with id 1 and 2. However, Moodle only looks at the first record, so for Moodle this user is just enrolled in course with ID = 1.

Is there any way I can tell Moodle to look at ALL the records of a user (for example all records that match a specific username) and make it enroll that user for all of those courses?

I'm aware that the structure of this table doesn't help much, but I can't do anything about it...

Thanks for any advice!

Average of ratings: -
In reply to Albert R.

Re: External DB enrollment, enroll one user in multiple courses

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 Albert,

I can assure you that it *does* work for the scenario that you describe, as long as you configure it right. We are using the external database enrolment in our university (for the last 6 years) and students have several records in the external enrolment table (as many as courses they are supposed to be taking smile)

On the other hand, even if the table can't be changed, you can always create a new read-only view with the data in the format you need (in fact, that's what we did for several years, creating a view from several tables in our SIS database).

Por cierto, a juzgar por tu nombre diría que hablas español (y casi seguro que catalán también smile)

Saludos.
Iñaki.