Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-9375 (and dups) - Each attempt builds on last with multi-page qui…

…zzes gives the wrong score on the second attempt. It turns out that this was already fixed in Moodle 1.9 (part of commit 1.115 -> 1.116) so I have just backported the relevant changes. I have tested that this fixes the reported problem. I have not had time to test that it does not break one of the other billion possible combinations of settings possible with the quiz. Code review and testing welcome.
  • Loading branch information...
commit 8d9e5477a48b213c888d157e9738aff415f0c93c 1 parent 0e3dd76
tjhunt authored
Showing with 26 additions and 30 deletions.
  1. +26 −30 mod/quiz/attempt.php
View
56 mod/quiz/attempt.php
@@ -335,6 +335,7 @@
foreach($questionidarray as $i) {
if (!isset($actions[$i])) {
$actions[$i]->responses = array('' => '');
+ $actions[$i]->event = QUESTION_EVENTOPEN;
}
$actions[$i]->timestamp = $timestamp;
question_process_responses($questions[$i], $states[$i], $actions[$i], $quiz, $attempt);
@@ -352,40 +353,35 @@
// Set the attempt to be finished
$attempt->timefinish = $timestamp;
- // Find all the questions for this attempt for which the newest
- // state is not also the newest graded state
- if ($closequestions = get_records_select('question_sessions',
- "attemptid = $attempt->uniqueid AND newest != newgraded", '', 'questionid, questionid')) {
-
- // load all the questions
- $closequestionlist = implode(',', array_keys($closequestions));
- $sql = "SELECT q.*, i.grade AS maxgrade, i.id AS instance".
- " FROM {$CFG->prefix}question q,".
- " {$CFG->prefix}quiz_question_instances i".
- " WHERE i.quiz = '$quiz->id' AND q.id = i.question".
- " AND q.id IN ($closequestionlist)";
- if (!$closequestions = get_records_sql($sql)) {
- error('Questions missing');
- }
+ // load all the questions
+ $closequestionlist = quiz_questions_in_quiz($attempt->layout);
+ $sql = "SELECT q.*, i.grade AS maxgrade, i.id AS instance".
+ " FROM {$CFG->prefix}question q,".
+ " {$CFG->prefix}quiz_question_instances i".
+ " WHERE i.quiz = '$quiz->id' AND q.id = i.question".
+ " AND q.id IN ($closequestionlist)";
+ if (!$closequestions = get_records_sql($sql)) {
+ error('Questions missing');
+ }
- // Load the question type specific information
- if (!get_question_options($closequestions)) {
- error('Could not load question options');
- }
+ // Load the question type specific information
+ if (!get_question_options($closequestions)) {
+ error('Could not load question options');
+ }
- // Restore the question sessions
- if (!$closestates = get_question_states($closequestions, $quiz, $attempt)) {
- error('Could not restore question sessions');
- }
+ // Restore the question sessions
+ if (!$closestates = get_question_states($closequestions, $quiz, $attempt)) {
+ error('Could not restore question sessions');
+ }
- foreach($closequestions as $key => $question) {
- $action->event = QUESTION_EVENTCLOSE;
- $action->responses = $closestates[$key]->responses;
- $action->timestamp = $closestates[$key]->timestamp;
- question_process_responses($question, $closestates[$key], $action, $quiz, $attempt);
- save_question_session($question, $closestates[$key]);
- }
+ foreach($closequestions as $key => $question) {
+ $action->event = QUESTION_EVENTCLOSE;
+ $action->responses = $closestates[$key]->responses;
+ $action->timestamp = $closestates[$key]->timestamp;
+ question_process_responses($question, $closestates[$key], $action, $quiz, $attempt);
+ save_question_session($question, $closestates[$key]);
}
+
add_to_log($course->id, 'quiz', 'close attempt',
"review.php?attempt=$attempt->id",
"$quiz->id", $cm->id);
Please sign in to comment.
Something went wrong with that request. Please try again.