Hello everybody !
I'm trying to figure out in which table is the relationship between the course and the user/users enrolled in the course? I would like to check whether particular course and user are related somehow.
Thank you in advance.
Hello everybody !
I'm trying to figure out in which table is the relationship between the course and the user/users enrolled in the course? I would like to check whether particular course and user are related somehow.
Thank you in advance.
mdl_enrol - connects a course to a particular enrolment plugin instance
mdl_user_enrolments - connects a user to a enrolment plugin instance
You need to use both together to connect a user to a course (plus mdl_role_assignment and mdl_context if you want to know the role(s) the user has in the course).
So checking
mdl_course.id = mdl_enrol.courseid and
mdl_enrol.id = mdl_user_enrolment.enrolid and
mdl_user_enrolment.userid = mdl_user.id
is enough for user to be enrolled in a course not regarding the capabilities ?
That looks about right - I'd have to type it into a DB to be completely certain.
Well, not necessarily true. There are some fields in the user_enrolments table that you need to also check. If the status is 0, the enrolment is active, but 1 means suspended. Then there are the timestart/timeend fields that need to be checked.
In the enrol table there is also a status (0 is active and 1 is disabled) and each enrol entry also has a enrolstartdate/enrolenddate.
You are better off using the enrol APIs:
lib/accesslib.php: is_enrolled(), get_enrolled_users()
lib/enrollib.php: enrol_get_all_users_courses(), enrol_get_all_users_courses()