
Enrolment
Course enrolment can only take place if there is a user to enrol. The standard plugins are listed when, from the Site administration menu, you click on Plugins, then Enrolments, and finally select Manage enrol plugins. The available course enrolment plugins are displayed on the Manage enrol plugins page:

Check out the documentation on enrolment plugins at https://docs.moodle.org/dev/Enrolment_plugins. The best way of understanding the operation of enrolment plugins is by going back to the Moodle source in Eclipse in lib/enrollib.php. Take a look in enrollib.php for the enrol_plugin class declaration:

The first thing to notice is that enrolment plugins belong to courses and not to the system as a whole--this makes sense as this allows us to enroll users on a variety of courses by a variety of means. Also note that we can enable more than one enrolment plugin per course. For information on configuring course enrolment, see https://docs.moodle.org/31/en/Course_enrolment.
Users are enrolled on courses and allocated different roles (as in real life, it is the role a user is allocated that defines exactly what they are able to do--that is, users with the editing teacher role can edit the course and users with the student role can't), but note that enrolling and allocating roles are two separate processes in Moodle.
You will see from the documentation that enrolment plugins also need to handle the following:
- Suspended and expired users
- Self-enrolment (where a user enrolls themselves onto a course)
- Payment gateways
As with authentication, the enrolment process can be hooked: Events are fired at each stage of the enrolment process that our enrolment plugin can listen out for and, when it hears a specific type of event, it can perform some kind of event-specific task.
Now navigate through Eclipse PHP Explorer to the self-enrolment plugin located in /enrol/self:

Clearly one of the more obvious differences between an authentication and an enrolment plugin is the amount of complexity: There are far more PHP scripts to an enrolment plugin compared to an authentication plugin. The cli folder contains a cron script that calls the sync() function that, depending on the type of enrolment plugin, will allow us to set up timed synchronization of enrolments to, say, an external database during some quiet period. You will also see that the db folder contains scripts not only for upgrading, but also for installing. It also contains a script to manage access to enrolment functionality based on the capabilities of a user's role (access.php). There will be a deeper exploration of enrolment plugins, as well as development of our own, in Chapter 6, Managing Users - Letting in the Crowds.