Merge branch 'MDL-27860_2.0' of git://github.com/timhunt/moodle into MOODLE_20_STABLE
This commit is contained in:
@@ -141,26 +141,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 integer $quizid the id of the quiz.
|
||||
* @param integer $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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load an attempt by id. You need to use this method instead of $DB->get_record, because
|
||||
* of some ancient history to do with the upgrade from Moodle 1.4 to 1.5, See the comment
|
||||
|
||||
@@ -64,7 +64,8 @@ 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 ($lastattempt && !$lastattempt->timefinish) {
|
||||
/// Continuation of an attempt - check password then redirect.
|
||||
@@ -84,7 +85,7 @@ if ($lastattempt && !$lastattempt->preview && !$quizobj->is_preview_user()) {
|
||||
|
||||
/// Check access.
|
||||
$messages = $accessmanager->prevent_access() +
|
||||
$accessmanager->prevent_new_attempt($attemptnumber - 1, $lastattempt);
|
||||
$accessmanager->prevent_new_attempt(count($attempts), $lastattempt);
|
||||
if (!$quizobj->is_preview_user() && $messages) {
|
||||
print_error('attempterror', 'quiz', $quizobj->view_url(),
|
||||
$accessmanager->print_messages($messages, true));
|
||||
|
||||
Reference in New Issue
Block a user