Merge branch 'MDL-83432-405' of https://github.com/paulholden/moodle into MOODLE_405_STABLE

This commit is contained in:
Huong Nguyen 2024-10-24 10:13:12 +07:00
commit e271f67942
No known key found for this signature in database
GPG Key ID: 40D88AB693A3E72A
6 changed files with 25 additions and 3 deletions

View File

@ -0,0 +1,13 @@
issueNumber: MDL-83432
notes:
core_enrol:
- message: >-
The `after_user_enrolled` hook now contains a `roleid` property to allow
for listeners to determine which role was assigned during user enrolment
(if any)
The base enrolment `enrol_plugin::send_course_welcome_message_to_user`
method also now accepts a `$roleid` parameter in order to correctly
populate the `courserole` placeholder
type: changed

View File

@ -39,6 +39,8 @@ class after_user_enrolled {
public readonly stdClass $enrolinstance,
/** @var stdClass The user enrolment instance */
public readonly stdClass $userenrolmentinstance,
/** @var int|null The assigned role ID */
public readonly ?int $roleid = null,
) {
}

View File

@ -40,6 +40,7 @@ class user_enrolment_callbacks {
userid: $hook->get_userid(),
sendoption: $instance->customint1,
message: $instance->customtext1,
roleid: $hook->roleid,
);
}
}

View File

@ -2159,6 +2159,7 @@ abstract class enrol_plugin {
$hook = new \core_enrol\hook\after_user_enrolled(
enrolinstance: $instance,
userenrolmentinstance: $ue,
roleid: $roleid,
);
\core\di::get(\core\hook\manager::class)->dispatch($hook);
@ -3644,18 +3645,23 @@ abstract class enrol_plugin {
* @param int $userid User ID.
* @param int $sendoption Send email from constant ENROL_SEND_EMAIL_FROM_*
* @param null|string $message Message to send to the user.
* @param int|null $roleid The assigned role ID
*/
public function send_course_welcome_message_to_user(
stdClass $instance,
int $userid,
int $sendoption,
?string $message = '',
?int $roleid = null,
): void {
global $DB;
$context = context_course::instance($instance->courseid);
$user = core_user::get_user($userid);
$course = get_course($instance->courseid);
$courserole = $DB->get_record('role', ['id' => $instance->roleid]);
// Fallback to the instance role ID if parameter not specified.
$courseroleid = $roleid ?: $instance->roleid;
$courserole = $DB->get_record('role', ['id' => $courseroleid]);
$a = new stdClass();
$a->coursename = format_string($course->fullname, true, ['context' => $context, 'escape' => false]);

View File

@ -250,7 +250,7 @@ class locallib_test extends \advanced_testcase {
$this->assertEquals(true, $lesson->is_participant($USER->id),
'Admin is enrolled and can participate');
$this->getDataGenerator()->enrol_user(2, $course->id, [], 'manual', 0, 0, ENROL_USER_SUSPENDED);
$this->getDataGenerator()->enrol_user(2, $course->id, null, 'manual', 0, 0, ENROL_USER_SUSPENDED);
$this->assertEquals(true, $lesson->is_participant($USER->id),
'Admin is enrolled, suspended and can participate');
}

View File

@ -308,7 +308,7 @@ class attempt_test extends \advanced_testcase {
$this->assertEquals(true, $quizobj->is_participant($USER->id),
'Admin is enrolled and can participate');
$this->getDataGenerator()->enrol_user(2, $course->id, [], 'manual', 0, 0, ENROL_USER_SUSPENDED);
$this->getDataGenerator()->enrol_user(2, $course->id, null, 'manual', 0, 0, ENROL_USER_SUSPENDED);
$this->assertEquals(true, $quizobj->is_participant($USER->id),
'Admin is enrolled, suspended and can participate');
}