From 60abf0f6bdcd87872b73e1ea2be34a9c8f7e0db2 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Thu, 5 Sep 2013 00:37:51 +0800 Subject: [PATCH] MDL-40924 badges: added a print_error call to prevent PHP notices when no badges are found --- badges/external.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/badges/external.php b/badges/external.php index e9c4ab3580e..f18883bf42b 100644 --- a/badges/external.php +++ b/badges/external.php @@ -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());