Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error during self-enrollment if assigned role does not have roleid=5. #118

Open
spunkt1 opened this issue Sep 30, 2024 · 1 comment
Open

Comments

@spunkt1
Copy link

spunkt1 commented Sep 30, 2024

Hi,

If a course is created with self-enrollment and the participant role does not have rolid = 5, or a different role has been configured for self-enrollment, then a user can enroll in the course, but no role is assigned.

In the file “moodle/admin/tool/supporter/classes/external.php” the roleid “5” is hard-coded

$plugin->add_instance($createdcourse, [“password” => $selfenrolpassword, “roleid” => 5]);

Here is a suggestion on how to change this.
Instead of the “5”, the default role from “Enrol” should be used.

$selfenrolment = $DB->get_record(“enrol”, ['courseid' => $createdcourse->id, 'enrol' => 'self'], '*');
$plugin->add_instance($createdcourse, ['password' => $selfenrolpassword, 'roleid' => $defaulSelfenrolRoleid]);

Best regards,
Sybille

@my-curiosity
Copy link
Contributor

Hi Sybille,

sorry for the late reply. To clarify the issue, we currently handle 2 cases after creating a new course:

  1. If self-enrolment was automatically added to the course, we only set it to active, change roleid and password
$selfenrolment->status = 0; // 0 is active!
$selfenrolment->password = $selfenrolpassword; // The PW is saved as plain text.
$selfenrolment->roleid = 5; // Set the default role id for new users that enrol in the course.
$DB->update_record("enrol", $selfenrolment);
  1. Otherwise, we manually add a new instance with roleid=5
$plugin = enrol_get_plugin('self');
$plugin->add_instance($createdcourse, ["password" => $selfenrolpassword, "roleid" => 5]);

Should the default self-enrol role be used instead of 5 only in the first case? If not, do you have an idea how we can get it if $selfenrolment is empty? Maybe something like get_config('enrol_self', 'roleid')?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants