]> git.mjollnir.org Git - moodle.git/commitdiff
Minor cleanups to the quiz code.
authortjhunt <tjhunt>
Tue, 10 Apr 2007 13:02:09 +0000 (13:02 +0000)
committertjhunt <tjhunt>
Tue, 10 Apr 2007 13:02:09 +0000 (13:02 +0000)
mod/quiz/attempt.php
mod/quiz/view.php

index 618148e6e7be9383855639173fe1b3801f02e97f..6d6b8e262ddd238e37e3fe25b33f250f52f3e2e3 100644 (file)
         if (! $cm = get_coursemodule_from_id('quiz', $id)) {
             error("There is no coursemodule with id $id");
         }
-
         if (! $course = get_record("course", "id", $cm->course)) {
             error("Course is misconfigured");
         }
-
         if (! $quiz = get_record("quiz", "id", $cm->instance)) {
             error("The quiz with id $cm->instance corresponding to this coursemodule $id is missing");
         }
-
     } else {
         if (! $quiz = get_record("quiz", "id", $q)) {
             error("There is no quiz with id $q");
@@ -57,7 +54,7 @@
     }
 
     require_login($course->id, false, $cm);
-    $isteacher = has_capability('mod/quiz:grade', get_context_instance(CONTEXT_MODULE, $cm->id));
+    $ispreviewing = has_capability('mod/quiz:preview', get_context_instance(CONTEXT_MODULE, $cm->id));
     
     $coursecontext = get_context_instance(CONTEXT_COURSE, $cm->course); // course context
     $context = get_context_instance(CONTEXT_MODULE, $cm->id);
@@ -76,7 +73,7 @@
 
     $strattemptnum = get_string('attempt', 'quiz', $attemptnumber);
     $strquizzes = get_string("modulenameplural", "quiz");
-    $popup = $isteacher ? 0 : $quiz->popup; // Controls whether this is shown in a javascript-protected window.
+    $popup = $quiz->popup && !$ispreviewing; // Controls whether this is shown in a javascript-protected window.
 
 /// Print the page header
     if (!empty($popup)) {
@@ -96,7 +93,7 @@
     echo '<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>'; // for overlib
 
     /// Print the quiz name heading and tabs for teacher
-    if (has_capability('mod/quiz:preview', $context)) {
+    if ($ispreviewing) {
         $currenttab = 'preview';
         include('tabs.php');
     } else {
 
 /// Check subnet access
     if ($quiz->subnet and !address_in_subnet(getremoteaddr(), $quiz->subnet)) {
-        if ($isteacher) {
+        if ($ispreviewing) {
             notify(get_string('subnetnotice', 'quiz'));
         } else {
             error(get_string("subneterror", "quiz"), "view.php?id=$cm->id");
 
 /// Load attempt or create a new attempt if there is no unfinished one
 
-    if (has_capability('mod/quiz:preview', $context) and $forcenew) { // teacher wants a new preview
+    if ($ispreviewing and $forcenew) { // teacher wants a new preview
         // so we set a finish time on the current attempt (if any).
         // It will then automatically be deleted below
         set_field('quiz_attempts', 'timefinish', $timestamp, 'quiz', $quiz->id, 'userid', $USER->id);
     if (!$attempt) {
         // Check if this is a preview request from a teacher
         // in which case the previous previews should be deleted
-        if (has_capability('mod/quiz:preview', $context)) {
+        if ($ispreviewing) {
             if ($oldattempts = get_records_select('quiz_attempts', "quiz = '$quiz->id'
              AND userid = '$USER->id'")) {
                 delete_records('quiz_attempts', 'quiz', $quiz->id, 'userid', $USER->id);
         // Start a new attempt and initialize the question sessions
         $attempt = quiz_create_attempt($quiz, $attemptnumber);
         // If this is an attempt by a teacher mark it as a preview
-        if (has_capability('mod/quiz:preview', $context)) {
+        if ($ispreviewing) {
             $attempt->preview = 1;
         }
         // Save the attempt
             error('Could not create new attempt');
         }
         // make log entries
-        if ($isteacher) {
+        if ($ispreviewing) {
             add_to_log($course->id, 'quiz', 'preview',
                            "attempt.php?id=$cm->id",
                            "$quiz->id", $cm->id);
 
     // check the quiz times
     if ($timestamp < $quiz->timeopen || ($quiz->timeclose and $timestamp > $quiz->timeclose)) {
-        if ($isteacher) {
+        if ($ispreviewing) {
             notify(get_string('notavailabletostudents', 'quiz'));
         } else {
             notice(get_string('notavailable', 'quiz'), "view.php?id={$cm->id}");
 /// Print the quiz page ////////////////////////////////////////////////////////
 
 /// Print the preview heading
-    if (has_capability('mod/quiz:preview', $context)) {
+    if ($ispreviewing) {
         print_heading(get_string('previewquiz', 'quiz', format_string($quiz->name)));
         unset($buttonoptions);
         $buttonoptions['q'] = $quiz->id;
     echo '</div>';
     echo "</form>\n";
 
-
     $secondsleft = ($quiz->timeclose ? $quiz->timeclose : 999999999999) - time();
-    if ($isteacher) {
+    if ($ispreviewing) {
         // For teachers ignore the quiz closing time
         $secondsleft = 999999999999;
     }
index 1c164bde757b8edfc199eec5e3b1b3aabc265c17..ece2acd2cf34904b399445ed305dac3273e13a1d 100644 (file)
         if (! $cm = get_coursemodule_from_id('quiz', $id)) {
             error("There is no coursemodule with id $id");
         }
-
         if (! $course = get_record("course", "id", $cm->course)) {
             error("Course is misconfigured");
         }
-
         if (! $quiz = get_record("quiz", "id", $cm->instance)) {
             error("The quiz with id $cm->instance corresponding to this coursemodule $id is missing");
         }
-
     } else {
         if (! $quiz = get_record("quiz", "id", $q)) {
             error("There is no quiz with id $q");