mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
Merge branch 'MDL-83432-405' of https://github.com/paulholden/moodle into MOODLE_405_STABLE
This commit is contained in:
commit
e271f67942
13
.upgradenotes/MDL-83432-2024101113112646.yml
Normal file
13
.upgradenotes/MDL-83432-2024101113112646.yml
Normal 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
|
@ -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,
|
||||
) {
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,7 @@ class user_enrolment_callbacks {
|
||||
userid: $hook->get_userid(),
|
||||
sendoption: $instance->customint1,
|
||||
message: $instance->customtext1,
|
||||
roleid: $hook->roleid,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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]);
|
||||
|
@ -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');
|
||||
}
|
||||
|
@ -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');
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user