MDL-40924 badges: added a print_error call to prevent PHP notices when no badges are found

This commit is contained in:
Mark Nelson
2013-09-05 10:05:52 +08:00
committed by Dan Poltawski
parent 0c26302299
commit 60abf0f6bd
+12 -3
View File
@@ -51,8 +51,17 @@ if (!empty($CFG->forceloginforprofiles)) {
// 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)) {
@@ -61,9 +70,9 @@ foreach ($badges as $b) {
}
}
// 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());