MDL-67462 badges: Fix badge alignments returned in external functions

This commit is contained in:
Albert Gasset
2025-02-07 09:13:05 +01:00
parent f0dd12e3b1
commit e0930fce1e
+16 -9
View File
@@ -454,19 +454,26 @@ function badges_prepare_badge_for_external(stdClass $badge, stdClass $user): obj
// Create a badge instance to be able to get the endorsement and other info.
$badgeinstance = new badge($badge->id);
$endorsement = $badgeinstance->get_endorsement();
$alignments = $badgeinstance->get_alignments();
$relatedbadges = $badgeinstance->get_related_badges();
$alignments = [];
foreach ($badgeinstance->get_alignments() as $alignment) {
$alignmentobj = (object) [
'id' => $alignment->id,
'badgeid' => $alignment->badgeid,
'targetName' => $alignment->targetname,
'targetUrl' => $alignment->targeturl,
];
// Include only the properties visible by the user.
if ($canconfiguredetails) {
$alignmentobj->targetDescription = $alignment->targetdescription;
$alignmentobj->targetFramework = $alignment->targetframework;
$alignmentobj->targetCode = $alignment->targetcode;
}
$alignments[] = $alignmentobj;
}
if (!$canconfiguredetails) {
// Return only the properties visible by the user.
if (!empty($alignments)) {
foreach ($alignments as $alignment) {
unset($alignment->targetdescription);
unset($alignment->targetframework);
unset($alignment->targetcode);
}
}
if (!empty($relatedbadges)) {
foreach ($relatedbadges as $relatedbadge) {
unset($relatedbadge->version);