diff --git a/lang/en_utf8/quiz.php b/lang/en_utf8/quiz.php index 8c02c9b8627..0ce45c0d032 100644 --- a/lang/en_utf8/quiz.php +++ b/lang/en_utf8/quiz.php @@ -96,6 +96,7 @@ $string['confirmstartattempttimelimit'] = 'This quiz has a time limit and is lim $string['confirmstarttimelimit'] = 'The Quiz has a time limit. Are you sure that you wish to start?'; $string['containercategorycreated'] = 'This category has been created to store all the original categories moved to site level due to the causes specified below.'; $string['continueattemptquiz'] = 'Continue the last attempt'; +$string['continuepreview'] = 'Continue the last preview'; $string['copyingfrom'] = 'Creating a copy of the question \'$a\''; $string['copyingquestion'] = 'Copying a question'; $string['correct'] = 'Correct'; @@ -353,6 +354,7 @@ $string['popupnotice'] = 'Students will see this quiz in a secure window'; $string['preview'] = 'Preview'; $string['previewquestion'] = 'Preview question'; $string['previewquiz'] = 'Preview $a'; +$string['previewquiznow'] = 'Preview quiz now'; $string['previous'] = 'Previous state'; $string['publish'] = 'Publish'; $string['publishedit'] = 'You must have permission in the publishing course to add or edit questions in this category'; diff --git a/mod/quiz/attempt.php b/mod/quiz/attempt.php index 75af863aa6e..9f157ab9039 100644 --- a/mod/quiz/attempt.php +++ b/mod/quiz/attempt.php @@ -198,8 +198,7 @@ set_field('quiz_attempts', 'timefinish', $timestamp, 'quiz', $quiz->id, 'userid', $USER->id); } - $attempt = get_record('quiz_attempts', 'quiz', $quiz->id, - 'userid', $USER->id, 'timefinish', 0); + $attempt = quiz_get_user_attempt_unfinished($quiz->id, $USER->id); $newattempt = false; if (!$attempt) { diff --git a/mod/quiz/locallib.php b/mod/quiz/locallib.php index 8aff3f4cf44..1d5f9f27f99 100644 --- a/mod/quiz/locallib.php +++ b/mod/quiz/locallib.php @@ -88,7 +88,7 @@ function quiz_create_attempt($quiz, $attemptnumber) { * @return mixed the unfinished attempt if there is one, false if not. */ function quiz_get_user_attempt_unfinished($quizid, $userid) { - $attempts = quiz_get_user_attempts($quizid, $userid, 'unfinished'); + $attempts = quiz_get_user_attempts($quizid, $userid, 'unfinished', true); if ($attempts) { return array_shift($attempts); } else { @@ -102,14 +102,18 @@ function quiz_get_user_attempt_unfinished($quizid, $userid) { * @param string $status 'all', 'finished' or 'unfinished' to control * @return an array of all the user's attempts at this quiz. Returns an empty array if there are none. */ -function quiz_get_user_attempts($quizid, $userid, $status = 'finished') { +function quiz_get_user_attempts($quizid, $userid, $status = 'finished', $includepreviews = false) { $status_condition = array( 'all' => '', 'finished' => ' AND timefinish > 0', 'unfinished' => ' AND timefinish = 0' ); + $previewclause = ''; + if (!$includepreviews) { + $previewclause = ' AND preview = 0'; + } if ($attempts = get_records_select('quiz_attempts', - "quiz = '$quizid' AND userid = '$userid' AND preview = 0" . $status_condition[$status], + "quiz = '$quizid' AND userid = '$userid'" . $previewclause . $status_condition[$status], 'attempt ASC')) { return $attempts; } else { diff --git a/mod/quiz/view.php b/mod/quiz/view.php index 1c164bde757..41a4db76e26 100644 --- a/mod/quiz/view.php +++ b/mod/quiz/view.php @@ -313,11 +313,17 @@ echo "
"; if ($unfinished) { - $buttontext = get_string('continueattemptquiz', 'quiz'); + if (has_capability('mod/quiz:preview', $context)) { + $buttontext = get_string('continuepreview', 'quiz'); + } else { + $buttontext = get_string('continueattemptquiz', 'quiz'); + } } else { // Work out the appropriate button caption. - if ($numattempts == 0) { + if (has_capability('mod/quiz:preview', $context)) { + $buttontext = get_string('previewquiznow', 'quiz'); + } else if ($numattempts == 0) { $buttontext = get_string('attemptquiznow', 'quiz'); } else { $buttontext = get_string('reattemptquiz', 'quiz');