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!