]> git.mjollnir.org Git - moodle.git/commitdiff
Updates to quiztimer
authorjulmis <julmis>
Tue, 22 Jun 2004 20:44:59 +0000 (20:44 +0000)
committerjulmis <julmis>
Tue, 22 Jun 2004 20:44:59 +0000 (20:44 +0000)
- mark question result to zero if time limit is exceeded

mod/quiz/attempt.php
mod/quiz/lib.php

index 2051fb0809b938b19a5de1a724190842344e0434..0df9ae7cece66b714250d277804281e050ab40d8 100644 (file)
         if (! $cm = get_record("course_modules", "id", $id)) {
             error("Course Module ID was incorrect");
         }
-    
+
         if (! $course = get_record("course", "id", $cm->course)) {
             error("Course is misconfigured");
         }
-    
+
         if (! $quiz = get_record("quiz", "id", $cm->instance)) {
             error("Course module is incorrect");
         }
@@ -62,8 +62,8 @@
     $strquiz  = get_string("modulename", "quiz");
 
     print_header("$course->shortname: $quiz->name", "$course->fullname",
-                 "$navigation <A HREF=index.php?id=$course->id>$strquizzes</A> -> 
-                  <A HREF=\"view.php?id=$cm->id\">$quiz->name</A> -> $strattemptnum", 
+                 "$navigation <A HREF=index.php?id=$course->id>$strquizzes</A> ->
+                  <A HREF=\"view.php?id=$cm->id\">$quiz->name</A> -> $strattemptnum",
                   "", "", true);
 
     echo '<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>'; // for overlib
             print_heading(get_string("noanswers", "quiz"));
             print_continue("attempt.php?q=$quiz->id");
             exit;
-        }   
+        }
 
         if (!$questions = get_records_list("quiz_questions", "id", $quiz->questions)) {
             error("No questions found!");
 
             } else if (ereg('^q([0-9]+)r([0-9]+)$', $key, $keyregs)) { // Random-style answers
                 $questions[$keyregs[1]]->answer[] = "$keyregs[2]-$value";
-        
+
             } else if (ereg('^q([0-9]+)ma([0-9]+)$', $key, $keyregs)) { // Multi-answer questions
                 $questions[$keyregs[1]]->answer[] = "$keyregs[2]-$value";
 
             } else if ('shuffleorder' == $key) {
                 $shuffleorder = explode(",", $value);   // Actual order questions were given in
-            
+
             } else {  // Useful for debugging new question types.  Must be last.
                 error("Answer received for non-existent question ($key -> $value)");
             }
         }
 
-        if (!$result = quiz_grade_attempt_results($quiz, $questions)) {
-            error("Could not grade your quiz attempt!");
-        }
-
         if($timelimit > 0) {
             if(($timelimit + 60) <= $timesincestart) {
-                $result->sumgrades = 0;
+                $quiz->timesincestart = $timesincestart;
             }
         }
 
+        if (!$result = quiz_grade_attempt_results($quiz, $questions)) {
+            error("Could not grade your quiz attempt!");
+        }
+
         if ($attempt = quiz_save_attempt($quiz, $questions, $result, $attemptnumber)) {
-            add_to_log($course->id, "quiz", "submit", 
+            add_to_log($course->id, "quiz", "submit",
                        "review.php?id=$cm->id&attempt=$attempt->id", "$quiz->id", $cm->id);
         } else {
             notice(get_string("alreadysubmitted", "quiz"), "view.php?id=$cm->id");
     }
 
 /// Actually seeing the questions marks the start of an attempt
+
     if (!$unfinished = quiz_get_user_attempt_unfinished($quiz->id, $USER->id)) {
         if ($newattemptid = quiz_start_attempt($quiz->id, $USER->id, $attemptnumber)) {
-            add_to_log($course->id, "quiz", "attempt", 
+            add_to_log($course->id, "quiz", "attempt",
                        "review.php?id=$cm->id&attempt=$newattemptid", "$quiz->id", $cm->id);
         } else {
             error("Sorry! Could not start the quiz (could not save starting time)");
                 $result->feedback = array(); // Not to be printed
                 $result->attemptbuildsonthelast = true;
             }
-            
+
         } else {
             // No latest attempt, or latest attempt was empty - Reset to defaults
             $questions = NULL;
index 22248f4f16470ccf6cf20124ec96e13ee6eacb1c..91421cdac7b56f8dbe5f05f7cca765bdc0bde9cd 100644 (file)
@@ -1365,7 +1365,7 @@ function quiz_category_select_menu($courseid,$published=false,$only_editable=fal
 
 function quiz_get_category_coursename($category) {
 /// if the category is published, adds on the course
-/// name 
+/// name
     $cname=$category->name;
     if ($category->publish) {
         if ($catcourse=get_record("course","id",$category->id)) {
@@ -1593,7 +1593,7 @@ function quiz_print_cat_question_list($categoryid, $quizselected=true) {
         echo '<td width="10" valign="top" align="right">';
         helpbutton("questiontypes", $strcreatenewquestion, "quiz");
         echo '</td></tr>';
-    
+
         echo '<tr><td colspan="3" align="right">';
         echo '<form method="get" action="import.php">';
         echo "<input type=\"hidden\" name=\"category\" value=\"$category->id\" />";
@@ -2162,6 +2162,12 @@ function quiz_grade_attempt_results($quiz, $questions) {
 
         $questionresult = quiz_grade_attempt_question_result($question,
                                                              $answers);
+        // if time limit is enabled and exceeded, return zero grades
+        if($quiz->timelimit > 0) {
+            if(($quiz->timelimit + 60) <= $quiz->timesincestart) {
+                $questionresult->grade = 0;
+            }
+        }
 
         $result->grades[$question->id] = round($questionresult->grade, 2);
         $result->sumgrades += $questionresult->grade;
@@ -2954,7 +2960,7 @@ function get_questions_category( $category ) {
     // get the list of questions for the category
     $questions = get_records("quiz_questions","category",$category->id);
 
-    // iterate through questions, getting stuff we need 
+    // iterate through questions, getting stuff we need
     foreach($questions as $question) {
         $new_question = get_question_data( $question );
         $qresults[] = $new_question;
@@ -2964,30 +2970,30 @@ function get_questions_category( $category ) {
 }
 
 // function to read single question, parameter is object view of
-// quiz_categories record, results is a combined object 
+// quiz_categories record, results is a combined object
 // defined as follows...
-// ->id                quiz_questions id
-// ->category  category
-// ->name      q name
+// ->id     quiz_questions id
+// ->category   category
+// ->name   q name
 // ->questiontext
 // ->image
-// ->qtype     see defines at the top of this file
-// ->stamp     not too sure
-// ->version   not sure
+// ->qtype  see defines at the top of this file
+// ->stamp  not too sure
+// ->version    not sure
 // ----SHORTANSWER
 // ->usecase
-// ->answers   array of answers
+// ->answers    array of answers
 // ----TRUEFALSE
-// ->trueanswer        truefalse answer
+// ->trueanswer truefalse answer
 // ->falseanswer truefalse answer
 // ----MULTICHOICE
 // ->layout
-// ->single    many or just one correct answer
-// ->answers   array of answer objects
+// ->single many or just one correct answer
+// ->answers    array of answer objects
 function get_question_data( $question ) {
     // what to do next depends of question type (qtype)
     switch ($question->qtype)  {
-    case SHORTANSWER: 
+    case SHORTANSWER:
         $shortanswer = get_record("quiz_shortanswer","question",$question->id);
         $question->usecase = $shortanswer->usecase;
         $question->answers = array();
@@ -3001,7 +3007,7 @@ function get_question_data( $question ) {
         break;
     case MULTICHOICE:
         if (!$multichoice = get_record("quiz_multichoice","question",$question->id)) {
-           error( "quiz_multichoice $question->id not found" );
+        error( "quiz_multichoice $question->id not found" );
             }
         $question->layout = $multichoice->layout;
         $question->single = $multichoice->single;
@@ -3014,8 +3020,8 @@ function get_question_data( $question ) {
 }
 
 // function to return single answer
-// ->id                answer id
-// ->question  question number
+// ->id     answer id
+// ->question   question number
 // ->answer
 // ->fraction
 // ->feedback