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.

This commit is contained in:
tjhunt 2007-07-13 15:58:42 +00:00
parent 774d92ebce
commit ed8bebce5a
4 changed files with 18 additions and 7 deletions

View 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';

View File

@ -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) {

View 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 {

View File

@ -318,11 +318,17 @@
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');