Merge branch 'MDL-27860' of git://github.com/timhunt/moodle

This commit is contained in:
Eloy Lafuente (stronk7)
2011-06-22 02:57:50 +02:00
2 changed files with 5 additions and 28 deletions
-24
View File
@@ -129,30 +129,6 @@ function quiz_get_user_attempt_unfinished($quizid, $userid) {
}
}
/**
* Returns the most recent attempt by a given user on a given quiz.
* May be finished, or may not.
*
* @param int $quizid the id of the quiz.
* @param int $userid the id of the user.
*
* @return mixed the attempt if there is one, false if not.
*/
function quiz_get_latest_attempt_by_user($quizid, $userid) {
global $CFG, $DB;
$attempt = $DB->get_records_sql('
SELECT qa.*
FROM {quiz_attempts} qa
WHERE qa.quiz = ? AND qa.userid = ?
ORDER BY qa.timestart DESC, qa.id DESC',
array($quizid, $userid), 0, 1);
if ($attempt) {
return array_shift($attempt);
} else {
return false;
}
}
/**
* Delete a quiz attempt.
* @param mixed $attempt an integer attempt id or an attempt object
+5 -4
View File
@@ -78,10 +78,11 @@ if ($quizobj->is_preview_user() && $forcenew) {
}
// Look for an existing attempt.
$lastattempt = quiz_get_latest_attempt_by_user($quiz->id, $USER->id);
$attempts = quiz_get_user_attempts($quiz->id, $USER->id, 'all');
$lastattempt = end($attempts);
// If an in-progress attempt exists, check password then redirect to it.
if ($lastattempt && !$lastattempt->timefinish) {
// Continuation of an attempt - check password then redirect.
$accessmanager->do_password_check($quizobj->is_preview_user());
redirect($quizobj->attempt_url($lastattempt->id));
}
@@ -96,9 +97,9 @@ if ($lastattempt && !$lastattempt->preview && !$quizobj->is_preview_user()) {
// Check access.
$messages = $accessmanager->prevent_access() +
$accessmanager->prevent_new_attempt($attemptnumber - 1, $lastattempt);
$output = $PAGE->get_renderer('mod_quiz');
$accessmanager->prevent_new_attempt(count($attempts), $lastattempt);
if (!$quizobj->is_preview_user() && $messages) {
$output = $PAGE->get_renderer('mod_quiz');
print_error('attempterror', 'quiz', $quizobj->view_url(),
$output->print_messages($messages));
}