From: tjhunt Date: Fri, 13 Jul 2007 15:58:42 +0000 (+0000) Subject: MDL-10452 - start quiz UI is confusing if you have quiz:preview capability. Change... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=ed8bebce5a65ea12891d402ab2f28aaf7d058f36;p=moodle.git MDL-10452 - start quiz UI is confusing if you have quiz:preview capability. Change the 'start/continue attempt button' to say 'start/continue preview' in this case. Merged from MOODLE_17_STABLE. --- diff --git a/lang/en_utf8/quiz.php b/lang/en_utf8/quiz.php index 8cf4ff1591..9484ed4730 100644 --- a/lang/en_utf8/quiz.php +++ b/lang/en_utf8/quiz.php @@ -98,6 +98,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'; @@ -377,6 +378,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 51d2b41983..fd56984fb4 100644 --- a/mod/quiz/attempt.php +++ b/mod/quiz/attempt.php @@ -167,8 +167,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 942563e002..aad494f287 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 118627a64e..33931459d5 100644 --- a/mod/quiz/view.php +++ b/mod/quiz/view.php @@ -318,11 +318,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');