Controlling access to courses based upon enrolment method

Re: Controlling access to courses based upon enrolment method

by Jason Hollowell -
Number of replies: 0
Picture of Particularly helpful Moodlers

Dan, all,

I am answering my inquiry here to (a.) inform you that I have almost figured out the correct setup and (b.) to document the process here in case others may be having similar difficulties.

The following are my current settings:

In "Main Template" I have:

{{auth}}

In "Replace array" I have:

email|Guest

manual|Student

This creates a unique cohort for each enrollment method and renames the "email" cohort to "Guest" and the "manual" cohort to "Student".

Then in "Ignore users" I have:

admin, manager

All other roles will be added to a cohort.

I was planning to add the following to "Replace array" on my live site:

ldap|Student

and hoped that there would be no problem with renaming two groups with the same name...but...I tried this, for experimental purposes with:

email|Guest

manual|Guest

and, unfortunately, discovered that two cohorts named "Guest" are created. sad I'm looking in the following area (code snippet from auth.php below) to see why the plugin is creating another Cohort when one with the same name already exists but can't quite figure it out...

$cid = array_search($cohortname, $cohortslist);

            if ($cid !== false) {


                if (!$DB->record_exists('cohort_members', array('cohortid' => $cid, 'userid' => $user->id))) {

                    cohort_add_member($cid, $user->id);

                };

            } else {

                // Cohort not exist so create a new one.

                $newcohort = new stdClass();

                $newcohort->name = $cohortname;

                $newcohort->description = "created ".date("d-m-Y");

                $newcohort->contextid = $context->id;

                if ($this->config->enableunenrol == 1) {

                    $newcohort->component = "auth_mcae";

                };

                $cid = cohort_add_cohort($newcohort);

                cohort_add_member($cid, $user->id);


                // Prevent creation new cohorts with same names.

                $cohortslist[$cid] = $cohortname;

            };

Any help available will be appreciated.

Regards

Jason