mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
Merge branch 'MDL-82742-main' of https://github.com/albertgasset/moodle
This commit is contained in:
commit
b628db7abe
9
.upgradenotes/MDL-82742-2024080913015227.yml
Normal file
9
.upgradenotes/MDL-82742-2024080913015227.yml
Normal file
@ -0,0 +1,9 @@
|
||||
issueNumber: MDL-82742
|
||||
notes:
|
||||
core_badges:
|
||||
- message: >-
|
||||
Added fields `recipientid` and `recipientfullname` to
|
||||
`user_badge_exporter`, which is used in the return structure of
|
||||
external functions `core_badges_get_user_badge_by_hash` and
|
||||
`core_badges_get_user_badges`.
|
||||
type: changed
|
@ -181,6 +181,14 @@ class user_badge_exporter extends exporter {
|
||||
'optional' => true,
|
||||
'default' => 0,
|
||||
],
|
||||
'recipientid' => [
|
||||
'type' => PARAM_INT,
|
||||
'description' => 'Id of the awarded user',
|
||||
],
|
||||
'recipientfullname' => [
|
||||
'type' => PARAM_NOTAGS,
|
||||
'description' => 'Full name of the awarded user',
|
||||
],
|
||||
'email' => [
|
||||
'type' => PARAM_TEXT,
|
||||
'description' => 'User email',
|
||||
|
4
badges/tests/external/external_test.php
vendored
4
badges/tests/external/external_test.php
vendored
@ -209,6 +209,10 @@ class external_test extends externallib_advanced_testcase {
|
||||
}
|
||||
}
|
||||
|
||||
// Add recipient.
|
||||
$badge->recipientid = $this->student->id;
|
||||
$badge->recipientfullname = fullname($this->student);
|
||||
|
||||
$expectedbadges[] = (array) $badge;
|
||||
if (isset($badge->courseid)) {
|
||||
// Save the course badge to be able to compare it in our tests.
|
||||
|
@ -102,6 +102,10 @@ class get_user_badge_by_hash_test extends externallib_advanced_testcase {
|
||||
'f3')->out(false);
|
||||
$badge->status = BADGE_STATUS_ACTIVE_LOCKED;
|
||||
|
||||
// Add recipient.
|
||||
$badge->recipientid = $student1->id;
|
||||
$badge->recipientfullname = fullname($student1);
|
||||
|
||||
// Add an endorsement for the badge.
|
||||
$endorsement = new \stdClass();
|
||||
$endorsement->badgeid = $badgeid;
|
||||
@ -184,13 +188,13 @@ class get_user_badge_by_hash_test extends externallib_advanced_testcase {
|
||||
// Site badge.
|
||||
$result = get_user_badge_by_hash::execute($data['sitebadge'][0]['uniquehash']);
|
||||
$result = \core_external\external_api::clean_returnvalue(get_user_badge_by_hash::execute_returns(), $result);
|
||||
$this->assertEquals($data['sitebadge'][0]['uniquehash'], $result['badge'][0]['uniquehash']);
|
||||
$this->assertEquals($data['sitebadge'][0], $result['badge'][0]);
|
||||
$this->assertEmpty($result['warnings']);
|
||||
|
||||
// Course badge.
|
||||
$result = get_user_badge_by_hash::execute($data['coursebadge'][0]['uniquehash']);
|
||||
$result = \core_external\external_api::clean_returnvalue(get_user_badge_by_hash::execute_returns(), $result);
|
||||
$this->assertEquals($data['coursebadge'][0]['uniquehash'], $result['badge'][0]['uniquehash']);
|
||||
$this->assertEquals($data['coursebadge'][0], $result['badge'][0]);
|
||||
$this->assertEmpty($result['warnings']);
|
||||
|
||||
// Wrong hash.
|
||||
|
@ -421,7 +421,7 @@ function badges_get_badge_by_hash(string $hash): object|bool {
|
||||
* @return object
|
||||
*/
|
||||
function badges_prepare_badge_for_external(stdClass $badge, stdClass $user): object {
|
||||
global $PAGE, $USER;
|
||||
global $PAGE, $SITE, $USER;
|
||||
if ($badge->type == BADGE_TYPE_SITE) {
|
||||
$context = context_system::instance();
|
||||
} else {
|
||||
@ -450,6 +450,17 @@ function badges_prepare_badge_for_external(stdClass $badge, stdClass $user): obj
|
||||
];
|
||||
}
|
||||
|
||||
// Recipient (the badge was awarded to this person).
|
||||
$badge->recipientid = $user->id;
|
||||
if ($user->deleted) {
|
||||
$strdata = new stdClass();
|
||||
$strdata->user = fullname($user);
|
||||
$strdata->site = format_string($SITE->fullname, true, ['context' => context_system::instance()]);
|
||||
$badge->recipientfullname = get_string('error:userdeleted', 'badges', $strdata);
|
||||
} else {
|
||||
$badge->recipientfullname = fullname($user);
|
||||
}
|
||||
|
||||
// Create a badge instance to be able to get the endorsement and other info.
|
||||
$badgeinstance = new badge($badge->id);
|
||||
$endorsement = $badgeinstance->get_endorsement();
|
||||
|
Loading…
x
Reference in New Issue
Block a user