diff --git a/lib/badgeslib.php b/lib/badgeslib.php index 357aad0d363..c7bd011f7b7 100644 --- a/lib/badgeslib.php +++ b/lib/badgeslib.php @@ -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);