DEV Community


Posted on

Moodle: from (auto) registration to teacher in no time (no one else involved)

For a special Moodle instance, I needed to allow a new user to be an editing teacher in a course, actually, in several courses if needed. At the same time, this should apply to some users only, meaning not everyone would have the same rights.

Nothing unusual except for the fact that no manager or admin should intervene in the process.

I immediately thought about the course request feature which I didn't know very well besides it exists. Luckily there's also a small plugin to allow course requests to be automatically approved by David Mudrák himself- it's a simple Moodle's scheduled task. Exactly what I needed!

With the auto-approval requirement taken care of, it was only a matter of thinking about the workflow. So, anyone can register on the site but only some users should be able to request courses. This meant I had to add a user custom field to differentiate users upfront and ask for this information in the registering process. As an example, the field can be named "Position" and the options "Manager", "Officer" and "Assistant". Let's assume only managers should be allowed to request courses.

Custom Field example

The next step was to use the Auto Cohort plugin to gather all users of a given position on its cohort. It's a great plugin by Catalyst that gives me peace of mind. After that, we need to use another plugin to assign cohort users a specific system role. Once again HQ member maintains an excellent solution: Cohort role synchronization. This simply loads cohorts members and assigns them a given system role, in my case the course requester role! Finally, the workflow is complete.

So when a user autoregister having the position of "Manager" is added to the manager cohort, and then, since is a member of that cohort, is assigned the system context course requester role.

In my case, there were additional requirements that I won't address here, but lead me to develop an alternative course request system, mostly because I needed to validate the requests against some rules, and because I needed a new request form. Of course, I wouldn't change Moodle core, so I developed a new local plugin, with new tables, tasks, and events (more on that in my next post).

What I wanted to share is that by mixing Moodle Core's own functionalities and 2 trustful plugins, one can dismiss managers or admins (for the process of registration and enrolment!!)

Top comments (0)