$PAGE->blocks->show_only_fake_blocks(); } echo $output->start_attempt_page($quizobj, $mform); die; } } // Pre-flight check passed. $accessmanager->notify_preflight_check_passed($currentattemptid); } if ($currentattemptid) { redirect($quizobj->attempt_url($currentattemptid, $page)); } // Delete any previous preview attempts belonging to this user. quiz_delete_previews($quizobj->get_quiz(), $USER->id); $quba = question_engine::make_questions_usage_by_activity('mod_quiz', $quizobj->get_context()); $quba->set_preferred_behaviour($quizobj->get_quiz()->preferredbehaviour); // Create the new attempt and initialize the question sessions $timenow = time(); // Update time now, in case the server is running really slowly. $attempt = quiz_create_attempt($quizobj, $attemptnumber, $lastattempt, $timenow, $quizobj->is_preview_user()); if (!($quizobj->get_quiz()->attemptonlast && $lastattempt)) { $attempt = quiz_start_new_attempt($quizobj, $quba, $attempt, $attemptnumber, $timenow); } else { $attempt = quiz_start_attempt_built_on_last($quba, $attempt, $lastattempt); } $transaction = $DB->start_delegated_transaction(); $attempt = quiz_attempt_save_started($quizobj, $quba, $attempt); quiz_fire_attempt_started_event($attempt, $quizobj); $transaction->allow_commit(); // Redirect to the attempt page. redirect($quizobj->attempt_url($attempt->id, $page));
public function test_attempt_started() { global $USER; list($quizobj, $quba, $attempt) = $this->prepare_quiz_data(); $attemptobj = quiz_attempt::create($attempt->id); // Catch the event. $sink = $this->redirectEvents(); quiz_fire_attempt_started_event($attempt, $quizobj); $events = $sink->get_events(); $sink->close(); // Legacy event data. $legacydata = new stdClass(); $legacydata->component = 'mod_quiz'; $legacydata->attemptid = $attempt->id; $legacydata->timestart = $attempt->timestart; $legacydata->timestamp = $attempt->timestart; $legacydata->userid = $attempt->userid; $legacydata->quizid = $quizobj->get_quizid(); $legacydata->cmid = $quizobj->get_cmid(); $legacydata->courseid = $quizobj->get_courseid(); // Validate the event. $this->assertCount(1, $events); $event = $events[0]; $this->assertInstanceOf('\\mod_quiz\\event\\attempt_started', $event); $this->assertEquals('quiz_attempts', $event->objecttable); $this->assertEquals($attempt->id, $event->objectid); $this->assertEquals($attempt->userid, $event->relateduserid); $this->assertEquals($quizobj->get_context(), $event->get_context()); $this->assertEquals('quiz_attempt_started', $event->get_legacy_eventname()); $this->assertEventLegacyData($legacydata, $event); }