Activate enrollment plugin on all courses

Activate enrollment plugin on all courses

by Chris Kenniburg -
Number of replies: 2
Picture of Particularly helpful Moodlers Picture of Plugin developers

We have a plugin in development which will need to be activated across all courses and forced to be used on all courses without the ability to delete.

Our developer is looking into it and may have a solution but if we release this plugin we were hoping there was a way to do it within Moodle itself instead of hacking the database

Is there an easy way that we don't know about to ensure the plugin is global on all courses and cannot be deleted?  

I should point out this plugin operates completely separate of all other enrollment plugins so you can still do self-enroll, manual, cohort, etc.  


Our plugin generates 6 digit unique codes for every course and group on a site.  When the code is entered on a form on the homepage the student is instantly enrolled into the corresponding course/group.  Our amazing developer took it a step further and has integrated a QR CODE reader into the form which will allow the student to hold up a printed qr code into the camera on a chromebook and instantly be enrolled into the course as well.  This is tremendously important for K-12 sites where you have hundreds of courses and 6 year olds trying to navigate around to find a proper course.  

Average of ratings: -
In reply to Chris Kenniburg

Re: Activate enrollment plugin on all courses

by Darko Miletić -

You need to do 2 things:

* Develop your enrollment plugin to have defaultenrol setting (see guest enroll settings page for example)

* Write a script that will go over all courses and add enrollment instance where needed. No hacking here standard API should be used.

$plugin = 'myenrolplugin';
$manualplugin = enrol_get_plugin($plugin);

$courses = $DB->get_recordset_select('course', 'category > 0', null, '', 'id');
foreach ($courses as $course) {
    $instanceid = null;
    $instances = enrol_get_instances($course->id, true);
    foreach ($instances as $inst) {
        if ($inst->enrol == $plugin) {
            $instanceid = (int)$inst->id;
            break;
        }
    }
    if (empty($instanceid)) {
        $instanceid = $manualplugin->add_default_instance($course);
        if (empty($instanceid)) {
            $instanceid = $manualplugin->add_instance($course);
        }
    }

    if (!empty($instanceid)) {
        // Do additional config of instance if needed.
        ($instanceid);
    }
}


In reply to Darko Miletić

Re: Activate enrollment plugin on all courses

by Chris Kenniburg -
Picture of Particularly helpful Moodlers Picture of Plugin developers

Thank you.  This might be exactly what he needs.