New enrolment method is not working properly in Totara (Moodle)

New enrolment method is not working properly in Totara (Moodle)

by Ward Vandevoort -
Number of replies: 4

I am trying to add a new custom enrolment method to a base Totara (Moodle) installation. I decided to copy the existing "Self enrolment" enrolment method, because it is relatively simple and therefore seemed to be a good starting point for my custom method.

I changed the name and all of the references to the "Self enrolment" method to my new method name. This seemed to have worked because when I logged into the Totara dashboard I got the popup for a new plugin installation.

I went through the installation process and didn't run into any errors. Next I activated my plugin in the "Enrolment plugin" menu. Everything seemed fine until I tried to add my new method to a course.

Firstly the new method should be displayed bij default on the "Enrolment methods" page of the course but it isn't, however I can select it with the dropdown located below. When I do I am redirected to the config page of the enrolment method, so far so good. But when I click the button on the bottom of the page to add the method to the course it still isn't visible on the "Enrolment methods" page of the course.

When I log in as a regular user I can't access the course through my new method, so the method and the course haven't been properly linked. However when I look in the database I do see that my new method has been added to the course in the enrol table.

The problem doesn't seem to be caching related because I have purged it a couple of times already but the method still won't show up.

I am working with Totara version 16.2 (Moodle 3.4.9)


Average of ratings: -
In reply to Ward Vandevoort

Re: New enrolment method is not working properly in Totara (Moodle)

by Ward Vandevoort -
I found the problem, it seems that the "Self enrolment" plugin uses the get_name() function of the /server/lib/enrollib.php by default. However this function is written in a way to avoid "fancy" plugin names according to a comment in the function. The function explodes your plugin name on "_" and only uses the first part of your name, which means the records in enrol won't be recognised as records of your plugin because the names don't match.

I solved this by adding my own get_name() to my plugin, which returns the whole name.

The function:

/**
* Returns name of this enrol plugin
* @return string
*/
public function get_name() {
// second word in class is always enrol name, sorry, no fancy plugin names with _
$words = explode('_', get_class($this));
return $words[1];
}
In reply to Ward Vandevoort

Re: New enrolment method is not working properly in Totara (Moodle)

by Dan Marsden -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators
While Totara was initially based on Moodle, a lot of the code is really quite different these days, they also have their own community forums - best to use those rather than the Moodle ones when asking for help with Totara in future... smile

Also - when creating your own plugins - it's important to keep the names short. - there's a character limit of 28 on table names, and tables inside your plugin need to be prefixed with the plugin name... so if you have a plugin like "enrol_dansenrolmenttool_withcoolfeatures" - it might work to install, but as soon as you try to add database tables to your plugin you wlll have to create tables that violate the naming guidelines because it's already too long.

why 28 chars? - well, for "reasons", Oracle is supported (kindof) and it has a table name limit of 30 characters... so we leave 2 chars for the mdl prefix and let tables use 28 chars.
Average of ratings: Useful (3)
In reply to Ward Vandevoort

Re: New enrolment method is not working properly in Totara (Moodle)

by mark Mickera -

  We are investigating this issue and we are seeing that there is an issue with the enrollment method.  I'm having trouble enrolling for my course. The enrolment system is not working properly in Totara.

In reply to mark Mickera

Re: New enrolment method is not working properly in Totara (Moodle)

by Dan Marsden -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators
Please contact your Totara partner(you pay them for this sort of help already!) smile - or use the Totara community forums on https://totara.community/ - this is the wrong place to ask for Totara help, thanks!
Average of ratings: Useful (1)