Merge branch 'MDL-45803_master' of https://github.com/markn86/moodle

This commit is contained in:
Damyon Wiese 2014-06-16 11:00:26 +08:00
commit 1df546a77e
4 changed files with 26 additions and 52 deletions

View File

@ -310,30 +310,12 @@ function quiz_attempt_save_started($quizobj, $quba, $attempt) {
// Trigger the event.
$event->add_record_snapshot('quiz', $quizobj->get_quiz());
$event->add_record_snapshot('quiz_attempts', $attempt);
$event->trigger();
return $attempt;
}
/**
* Fire an event to tell the rest of Moodle a quiz attempt has started.
*
* @param object $attempt
* @param quiz $quizobj
*/
function quiz_fire_attempt_started_event($attempt, $quizobj) {
// Trigger event.
$eventdata = array();
$eventdata['context'] = $quizobj->get_context();
$eventdata['courseid'] = $quizobj->get_courseid();
$eventdata['relateduserid'] = $attempt->userid;
$eventdata['objectid'] = $attempt->id;
$event = \mod_quiz\event\attempt_started::create($eventdata);
$event->add_record_snapshot('quiz', $quizobj->get_quiz());
$event->add_record_snapshot('quiz_attempts', $attempt);
$event->trigger();
}
/**
* Returns an unfinished attempt (if there is one) for the given
* user on the given quiz. This function does not return preview attempts.

View File

@ -183,7 +183,6 @@ if (!($quizobj->get_quiz()->attemptonlast && $lastattempt)) {
$transaction = $DB->start_delegated_transaction();
$attempt = quiz_attempt_save_started($quizobj, $quba, $attempt);
quiz_fire_attempt_started_event($attempt, $quizobj);
$transaction->allow_commit();

View File

@ -190,39 +190,7 @@ class mod_quiz_events_testcase extends advanced_testcase {
}
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);
$this->assertEventContextNotUsed($event);
// Create another attempt.
$attempt = quiz_create_attempt($quizobj, 1, false, time(), false, 2);
@ -235,10 +203,28 @@ class mod_quiz_events_testcase extends advanced_testcase {
// Check that the event data is valid.
$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->assertEquals(context_module::instance($quizobj->get_cmid()), $event->get_context());
// Check legacy log data.
$expected = array($quizobj->get_courseid(), 'quiz', 'attempt', 'review.php?attempt=' . $attempt->id,
$quizobj->get_quizid(), $quizobj->get_cmid());
$this->assertEventLegacyLogData($expected, $event);
// Check 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();
$this->assertEventLegacyData($legacydata, $event);
$this->assertEventContextNotUsed($event);
}
/**

View File

@ -1,5 +1,12 @@
This files describes API changes in the quiz code.
=== 2.7.1 ===
* The function quiz_fire_attempt_started_event has been removed. This function
should not have been used outside the quiz, but if you were using it, you should
trigger the event outside this function. Note that the appropriate start event is
fired automatically by the quiz_attempt_save_started function.
=== 2.7 ===
* The old quiz.questions database column (comma-separated list of question ids)