$PAGE->set_pagelayout('base'); $PAGE->set_title(get_string('issuedbadge', 'badges')); if (isloggedin()) { $PAGE->set_heading($badge->badgeclass['name']); $PAGE->navbar->add($badge->badgeclass['name']); if ($badge->recipient->id == $USER->id) { $url = new moodle_url('/badges/mybadges.php'); } else { $url = new moodle_url($CFG->wwwroot); } navigation_node::override_active_url($url); } else { $PAGE->set_heading($badge->badgeclass['name']); $PAGE->navbar->add($badge->badgeclass['name']); $url = new moodle_url($CFG->wwwroot); navigation_node::override_active_url($url); } // Include JS files for backpack support. badges_setup_backpack_js(); echo $OUTPUT->header(); echo $output->render($badge); // Trigger event, badge viewed. $other = array('badgeid' => $badge->badgeid, 'badgehash' => $id); $eventparams = array('context' => $PAGE->context, 'other' => $other); // If the badge does not belong to this user, log it appropriately. if ($badge->recipient->id != $USER->id) { $eventparams['relateduserid'] = $badge->recipient->id; } $event = \core\event\badge_viewed::create($eventparams); $event->trigger(); echo $OUTPUT->footer();
/** * Test the badge viewed event. * * There is no external API for viewing a badge, so the unit test will simply * create and trigger the event and ensure data is returned as expected. */ public function test_badge_viewed() { $badge = new badge($this->badgeid); // Trigger an event: badge viewed. $other = array('badgeid' => $badge->id, 'badgehash' => '12345678'); $eventparams = array('context' => $badge->get_context(), 'other' => $other); $event = \core\event\badge_viewed::create($eventparams); // Trigger and capture the event. $sink = $this->redirectEvents(); $event->trigger(); $events = $sink->get_events(); $event = reset($events); // Check that the event data is valid. $this->assertInstanceOf('\\core\\event\\badge_viewed', $event); $this->assertEquals('12345678', $event->other['badgehash']); $this->assertEquals($badge->id, $event->other['badgeid']); $this->assertDebuggingNotCalled(); $sink->close(); }