/** * Test the question manually graded event. * * There is no external API for manually grading a question, so the unit test will simply * create and trigger the event and ensure the event data is returned as expected. */ public function test_question_manually_graded() { list($quizobj, $quba, $attempt) = $this->prepare_quiz_data(); $params = array('objectid' => 1, 'courseid' => $quizobj->get_courseid(), 'context' => context_module::instance($quizobj->get_cmid()), 'other' => array('quizid' => $quizobj->get_quizid(), 'attemptid' => 2, 'slot' => 3)); $event = \mod_quiz\event\question_manually_graded::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\\question_manually_graded', $event); $this->assertEquals(context_module::instance($quizobj->get_cmid()), $event->get_context()); $expected = array($quizobj->get_courseid(), 'quiz', 'manualgrade', 'comment.php?attempt=2&slot=3', $quizobj->get_quizid(), $quizobj->get_cmid()); $this->assertEventLegacyLogData($expected, $event); $this->assertEventContextNotUsed($event); }
protected function process_submitted_data() { global $DB; $qubaids = optional_param('qubaids', null, PARAM_SEQUENCE); $assumedslotforevents = optional_param('slot', null, PARAM_INT); if (!$qubaids) { return; } $qubaids = clean_param_array(explode(',', $qubaids), PARAM_INT); $attempts = $this->load_attempts_by_usage_ids($qubaids); $events = array(); $transaction = $DB->start_delegated_transaction(); foreach ($qubaids as $qubaid) { $attempt = $attempts[$qubaid]; $attemptobj = new quiz_attempt($attempt, $this->quiz, $this->cm, $this->course); $attemptobj->process_submitted_actions(time()); // Add the event we will trigger later. $params = array('objectid' => $attemptobj->get_question_attempt($assumedslotforevents)->get_question()->id, 'courseid' => $attemptobj->get_courseid(), 'context' => context_module::instance($attemptobj->get_cmid()), 'other' => array('quizid' => $attemptobj->get_quizid(), 'attemptid' => $attemptobj->get_attemptid(), 'slot' => $assumedslotforevents)); $events[] = \mod_quiz\event\question_manually_graded::create($params); } $transaction->allow_commit(); // Trigger events for all the questions we manually marked. foreach ($events as $event) { $event->trigger(); } }
echo $output->header(); // Prepare summary information about this question attempt. $summarydata = array(); // Quiz name. $summarydata['quizname'] = array('title' => get_string('modulename', 'quiz'), 'content' => format_string($attemptobj->get_quiz_name())); // Question name. $summarydata['questionname'] = array('title' => get_string('question', 'quiz'), 'content' => $attemptobj->get_question_name($slot)); // Process any data that was submitted. if (data_submitted() && confirm_sesskey()) { if (optional_param('submit', false, PARAM_BOOL) && question_engine::is_manual_grade_in_range($attemptobj->get_uniqueid(), $slot)) { $transaction = $DB->start_delegated_transaction(); $attemptobj->process_submitted_actions(time()); $transaction->allow_commit(); // Log this action. $params = array('objectid' => $attemptobj->get_question_attempt($slot)->get_question()->id, 'courseid' => $attemptobj->get_courseid(), 'context' => context_module::instance($attemptobj->get_cmid()), 'other' => array('quizid' => $attemptobj->get_quizid(), 'attemptid' => $attemptobj->get_attemptid(), 'slot' => $slot)); $event = \mod_quiz\event\question_manually_graded::create($params); $event->trigger(); echo $output->notification(get_string('changessaved'), 'notifysuccess'); close_window(2, true); die; } } // Print quiz information. echo $output->review_summary_table($summarydata, 0); // Print the comment form. echo '<form method="post" class="mform" id="manualgradingform" action="' . $CFG->wwwroot . '/mod/quiz/comment.php">'; echo $attemptobj->render_question_for_commenting($slot); ?> <div> <input type="hidden" name="attempt" value="<?php echo $attemptobj->get_attemptid();