From 497c676f0efd3ee2813384dcf503511fc9bf7991 Mon Sep 17 00:00:00 2001 From: Yuliya Bozhko Date: Mon, 9 Sep 2013 11:21:39 +1200 Subject: [PATCH] MDL-41662 badges: Fix viewing user profile when not logged in --- lib/badgeslib.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/badgeslib.php b/lib/badgeslib.php index 061ecd327bc..db45e567f9c 100644 --- a/lib/badgeslib.php +++ b/lib/badgeslib.php @@ -1145,13 +1145,20 @@ function profile_display_badges($userid, $courseid = 0) { global $CFG, $PAGE, $USER, $SITE; require_once($CFG->dirroot . '/badges/renderer.php'); - if ($USER->id == $userid || has_capability('moodle/badges:viewotherbadges', context_user::instance($USER->id))) { + // Determine context. + if (isloggedin()) { + $context = context_user::instance($USER->id); + } else { + $context = context_system::instance(); + } + + if ($USER->id == $userid || has_capability('moodle/badges:viewotherbadges', $context)) { $records = badges_get_user_badges($userid, $courseid, null, null, null, true); $renderer = new core_badges_renderer($PAGE, ''); // Print local badges. if ($records) { - $left = get_string('localbadgesp', 'badges', $SITE->fullname); + $left = get_string('localbadgesp', 'badges', format_string($SITE->fullname)); $right = $renderer->print_badges_list($records, $userid, true); echo html_writer::tag('dt', $left); echo html_writer::tag('dd', $right);