Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'MDL-27860_2.0' of git://github.com/timhunt/moodle into …

…MOODLE_20_STABLE
  • Loading branch information...
commit 6ce26b03e75cd2cb54f148a6969b2031c1752366 2 parents 5def8d5 + f4bc50d
@stronk7 stronk7 authored
Showing with 3 additions and 22 deletions.
  1. +0 −20 mod/quiz/locallib.php
  2. +3 −2 mod/quiz/startattempt.php
View
20 mod/quiz/locallib.php
@@ -142,26 +142,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
* after CREATE TABLE `prefix_quiz_newest_states` in mod/quiz/db/mysql.php.
View
5 mod/quiz/startattempt.php
@@ -64,7 +64,8 @@
}
/// 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 @@
/// 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));
Please sign in to comment.
Something went wrong with that request. Please try again.