MDL-67462 badges: Fix badge alignments returned in external functions
This commit is contained in:
+16
-9
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user