Open pmatabiau opened 2 months ago
I added this in _class enrol_autoenrolplugin (autoenrol/lib.php). Does this make sense ? Maybe I forget something
public function try_autoenrol(\stdClass $instance) {
global $USER, $CFG;
if (!$this->enrol_allowed($instance, $USER))
return false;
if ($this->user_autoenrol($instance, $USER)) {
$context = context_course::instance($instance->courseid);
load_temp_course_role($context, $instance->roleid);
return ENROL_MAX_TIMESTAMP;
}
return false;
}
Hi, try_autoenrol method was defined til a couple of years ago but it enrols all users that do a course search in Moodle App and match the rules, without enter courses. See Issue #42 and commit fc1b594daa57ba2cf619f8878c251739e51cf16e
Hi ok. I added breakpoints in _requirelogin() (in my IDE). With our Moodle version (4.1.11), _enrol_autoenrol_plugin::tryautoenrol() isn't called when we're in /course/index.php or /course/search.php. Maybe Moodle team have changed something.
Anyway, _enrol_autoenrol_plugin::tryautoenrol() work fine only if we use a direct link to the course. But when we use the page /course/index.php to find the link, the call to try_autoenrol() is skipped. In _requirelogin(), juste before that, there are a condition
else if ($USER->enrol['tempguest'][$course->id] > time())
who is "true". So with $access = true, the next condition skip the call to _tryautoenrol().
I'm trying to find where $USER->enrol['tempguest'][$course->id] is defined when we cross /course/index.php .. but without success for the moment.
Hi, in first, sorry for my english :-) We saw a problem when, in a course, we've methods Autoenrol and Guest actived. If guest method is not active, autoenrol method work fine. But when we active Guest method, even if it has low priority, user will be a guest in course. With this issue, for example, a teacher is always with Guest role if is not previously enroled manually with another role.
In the code, in function _requirelogin(), there are a call to _try_autoenrol()_. If enrol plugin don't implement the method, it's the method of the _abstract class enrolplugin who is used. In the Moodle process (lib/moodlelib.php, fct require_login()), just after the foreach with the call to _tryautoenrol(), we've another foreach with a _tryguestaccess(). Guest method implement this and return something before the redirect at the end of function, where the autoenrol plugin will do the user enrol.
I think we can add a _public function tryautoenrol() {....} in _class enrol_autoenrolplugin (autoenrol/lib.php), but I don't know what we write inside to run a nice enrolment.
Thanks