$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';
$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';
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) {
* @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 {
* @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 {
echo "<div class=\"quizattempt\">";
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');