]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-10452 - start quiz UI is confusing if you have quiz:preview capability. Change...
authortjhunt <tjhunt>
Fri, 13 Jul 2007 15:58:42 +0000 (15:58 +0000)
committertjhunt <tjhunt>
Fri, 13 Jul 2007 15:58:42 +0000 (15:58 +0000)
lang/en_utf8/quiz.php
mod/quiz/attempt.php
mod/quiz/locallib.php
mod/quiz/view.php

index 8cf4ff159105c8b4af6287b8445d2e6200a2ea07..9484ed4730d9f04ead99dfc3eae552241594f015 100644 (file)
@@ -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';
index 51d2b41983ffbb9c5334358bab177726a930b5c5..fd56984fb43b946015f775cd158a34e533b2dfbc 100644 (file)
         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) {
index 942563e00261e2519e9a607d8c51c29a8dd55b94..aad494f2871fa4d116fb3bf8ddd524013d6f319f 100644 (file)
@@ -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 {
index 118627a64e5c331d0072dfd40ca4d30c756e53ac..33931459d5a476de2c2a412eeb9bff21525c1b1d 100644 (file)
             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');