/** * Trigger the attempt_reviewed event. * * @since Moodle 3.1 */ public function fire_attempt_reviewed_event() { $params = array('objectid' => $this->get_attemptid(), 'relateduserid' => $this->get_userid(), 'courseid' => $this->get_courseid(), 'context' => context_module::instance($this->get_cmid()), 'other' => array('quizid' => $this->get_quizid())); $event = \mod_quiz\event\attempt_reviewed::create($params); $event->add_record_snapshot('quiz_attempts', $this->get_attempt()); $event->trigger(); }
} $summarydata['grade'] = array('title' => get_string('grade', 'quiz'), 'content' => $formattedgrade); } } } // Any additional summary data from the behaviour. $summarydata = array_merge($summarydata, $attemptobj->get_additional_summary_data($options)); // Feedback if there is any, and the user is allowed to see it now. $feedback = $attemptobj->get_overall_feedback($grade); if ($options->overallfeedback && $feedback) { $summarydata['feedback'] = array('title' => get_string('feedback', 'quiz'), 'content' => $feedback); } // Summary table end. ============================================================================== if ($showall) { $slots = $attemptobj->get_slots(); $lastpage = true; } else { $slots = $attemptobj->get_slots($page); $lastpage = $attemptobj->is_last_page($page); } $output = $PAGE->get_renderer('mod_quiz'); // Arrange for the navigation to be displayed. $navbc = $attemptobj->get_navigation_panel($output, 'quiz_review_nav_panel', $page, $showall); $regions = $PAGE->blocks->get_regions(); $PAGE->blocks->add_fake_block($navbc, reset($regions)); echo $output->review_page($attemptobj, $slots, $page, $showall, $lastpage, $options, $summarydata); // Trigger an event for this review. $params = array('objectid' => $attemptobj->get_attemptid(), 'relateduserid' => $attemptobj->get_userid(), 'courseid' => $attemptobj->get_courseid(), 'context' => context_module::instance($attemptobj->get_cmid()), 'other' => array('quizid' => $attemptobj->get_quizid())); $event = \mod_quiz\event\attempt_reviewed::create($params); $event->add_record_snapshot('quiz_attempts', $attemptobj->get_attempt()); $event->trigger();
/** * Test the attempt reviewed event. * * There is no external API for reviewing attempts, so the unit test will simply * create and trigger the event and ensure the event data is returned as expected. */ public function test_attempt_reviewed() { $this->resetAfterTest(); $this->setAdminUser(); $course = $this->getDataGenerator()->create_course(); $quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $course->id)); $params = array('objectid' => 1, 'relateduserid' => 2, 'courseid' => $course->id, 'context' => context_module::instance($quiz->cmid), 'other' => array('quizid' => $quiz->id)); $event = \mod_quiz\event\attempt_reviewed::create($params); // 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('\\mod_quiz\\event\\attempt_reviewed', $event); $this->assertEquals(context_module::instance($quiz->cmid), $event->get_context()); $expected = array($course->id, 'quiz', 'review', 'review.php?attempt=1', $quiz->id, $quiz->cmid); $this->assertEventLegacyLogData($expected, $event); $this->assertEventContextNotUsed($event); }