Skip to content

Commit

Permalink
MDL-40924 badges: added a print_error call to prevent PHP notices whe…
Browse files Browse the repository at this point in the history
…n no badges are found
  • Loading branch information
mdjnelson authored and danpoltawski committed Sep 5, 2013
1 parent bc16c7a commit 1eee7ee
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions badges/external.php
Expand Up @@ -51,8 +51,17 @@

// Get all external badges of a user.
$out = get_backpack_settings($userid);

// If we didn't find any badges then print an error.
if (is_null($out)) {
print_error('error:externalbadgedoesntexist', 'badges');
}

$badges = $out->badges;

// The variable to store the badge we want.
$badge = '';

// Loop through the badges and check if supplied badge hash exists in user external badges.
foreach ($badges as $b) {
if ($hash == hash("md5", $b->hostedUrl)) {
Expand All @@ -61,9 +70,9 @@
}
}

// If we didn't find the badge, a user might be trying to replace userid parameter.
if (is_null($badge)) {
print_error(get_string('error:externalbadgedoesntexist', 'badges'));
// If we didn't find the badge a user might be trying to replace the userid parameter.
if (empty($badge)) {
print_error('error:externalbadgedoesntexist', 'badges');
}

$PAGE->set_context(context_system::instance());
Expand Down

0 comments on commit 1eee7ee

Please sign in to comment.