]> git.mjollnir.org Git - moodle.git/commitdiff
Code cleanup. Merged from MOODLE_16_STABLE.
authortjhunt <tjhunt>
Fri, 18 Aug 2006 22:26:04 +0000 (22:26 +0000)
committertjhunt <tjhunt>
Fri, 18 Aug 2006 22:26:04 +0000 (22:26 +0000)
lib/questionlib.php
mod/quiz/report/regrade/report.php

index 5d8691afcbb671dd85f5a76846a9c5539f8bfbf9..b1bb321522700ab6447a1fe153c7fa2c53b823ac 100644 (file)
@@ -675,16 +675,15 @@ function get_question_states(&$questions, $cmoptions, $attempt) {
 *
 * Extends the state objects for a question by calling
 * {@link restore_session_and_responses()}
-* @return boolean         Represents success or failure
 * @param object $question The question for which the state is needed
-* @param object $state   The state as loaded from the database
+* @param object $state The state as loaded from the database
+* @return boolean Represents success or failure
 */
 function restore_question_state(&$question, &$state) {
     global $QTYPES;
 
     // initialise response to the value in the answer field
-    $state->answer = addslashes($state->answer);
-    $state->responses = array('' => $state->answer);
+    $state->responses = array('' => addslashes($state->answer));
     unset($state->answer);
     $state->comment = isset($state->comment) ? addslashes($state->comment) : '';
 
@@ -697,7 +696,7 @@ function restore_question_state(&$question, &$state) {
 
     // Load the question type specific data
     return $QTYPES[$question->qtype]
-     ->restore_session_and_responses($question, $state);
+            ->restore_session_and_responses($question, $state);
 
 }
 
@@ -737,7 +736,7 @@ function save_question_session(&$question, &$state) {
 
     // create or update the session
     if (!$session = get_record('question_sessions', 'attemptid',
-     $state->attempt, 'questionid', $question->id)) {
+            $state->attempt, 'questionid', $question->id)) {
         $session->attemptid = $state->attempt;
         $session->questionid = $question->id;
         $session->newest = $state->id;
@@ -871,7 +870,8 @@ function regrade_question_in_attempt($question, $attempt, $cmoptions, $verbose=f
 
     // load all states for this question in this attempt, ordered in sequence
     if ($states = get_records_select('question_states',
-     "attempt = '{$attempt->uniqueid}' AND question = '{$question->id}'", 'seq_number ASC')) {
+            "attempt = '{$attempt->uniqueid}' AND question = '{$question->id}'",
+            'seq_number ASC')) {
         $states = array_values($states);
 
         // Subtract the grade for the latest state from $attempt->sumgrades to get the
@@ -896,8 +896,8 @@ function regrade_question_in_attempt($question, $attempt, $cmoptions, $verbose=f
 
             // Change event to submit so that it will be reprocessed
             if (QUESTION_EVENTCLOSE == $states[$j]->event
-                       or QUESTION_EVENTGRADE == $states[$j]->event
-                       or QUESTION_EVENTCLOSEANDGRADE == $states[$j]->event) {
+                    or QUESTION_EVENTGRADE == $states[$j]->event
+                    or QUESTION_EVENTCLOSEANDGRADE == $states[$j]->event) {
                 $action->event = QUESTION_EVENTSUBMIT;
 
             // By default take the event that was saved in the database
@@ -906,12 +906,13 @@ function regrade_question_in_attempt($question, $attempt, $cmoptions, $verbose=f
             }
 
             if ($action->event == QUESTION_EVENTMANUALGRADE) {
-                question_process_comment($question, $replaystate, $attempt, $replaystate->comment, $states[$j]->grade);
+                question_process_comment($question, $replaystate, $attempt,
+                        $replaystate->comment, $states[$j]->grade);
             } else {
 
                 // Reprocess (regrade) responses
-                if (!question_process_responses($question, $replaystate, $action, $cmoptions,
-                 $attempt)) {
+                if (!question_process_responses($question, $replaystate,
+                        $action, $cmoptions, $attempt)) {
                     $verbose && notify("Couldn't regrade state #{$state->id}!");
                 }
             }
@@ -919,8 +920,8 @@ function regrade_question_in_attempt($question, $attempt, $cmoptions, $verbose=f
             // We need rounding here because grades in the DB get truncated
             // e.g. 0.33333 != 0.3333333, but we want them to be equal here
             if ((round((float)$replaystate->raw_grade, 5) != round((float)$states[$j]->raw_grade, 5))
-                  or (round((float)$replaystate->penalty, 5) != round((float)$states[$j]->penalty, 5))
-                  or (round((float)$replaystate->grade, 5) != round((float)$states[$j]->grade, 5))) {
+                    or (round((float)$replaystate->penalty, 5) != round((float)$states[$j]->penalty, 5))
+                    or (round((float)$replaystate->grade, 5) != round((float)$states[$j]->grade, 5))) {
                 $changed = true;
             }
 
@@ -1185,7 +1186,6 @@ function question_process_comment($question, &$state, &$attempt, $comment, $grad
     if (!set_field('question_sessions', 'comment', $comment, 'attemptid', $attempt->uniqueid, 'questionid', $question->id)) {
         error("Cannot save comment");
     }
-
     // If the teacher has changed the grade then update the attempt and the state
     // The modified attempt is stored to the database, the state not yet but the
     // $state->changed flag is set 
index 1fabbc289f5ca656cfa59172babc2f8092c3d619..01a415ef2b3f4ba6427f66fba9f746566e3b9820 100644 (file)
@@ -1,24 +1,23 @@
 <?php  // $Id$
 
 // This script regrades all attempts at this quiz
-
-    require_once($CFG->libdir.'/tablelib.php');
+require_once($CFG->libdir.'/tablelib.php');
 
 class quiz_report extends quiz_default_report {
 
-    function display($quiz, $cm, $course) {     /// This function just displays the report
+    function display($quiz, $cm, $course) {
         global $CFG, $SESSION, $db, $QTYPES;
 
-    /// Print header
+        // Print header
         $this->print_header_and_tabs($cm, $course, $quiz, $reportmode="regrade");
 
-    /// Fetch all attempts
+        // Fetch all attempts
         if (!$attempts = get_records_select('quiz_attempts', "quiz = '$quiz->id' AND preview = 0")) {
             print_heading(get_string('noattempts', 'quiz'));
             return true;
         }
 
-    /// Fetch all questions
+        // Fetch all questions
         $sql = "SELECT q.*, i.grade AS maxgrade FROM {$CFG->prefix}question q,
                                          {$CFG->prefix}quiz_question_instances i
                 WHERE i.quiz = $quiz->id
@@ -29,13 +28,13 @@ class quiz_report extends quiz_default_report {
         }
         get_question_options($questions);
 
-    /// Print heading
+        // Print heading
         print_heading(get_string('regradingquiz', 'quiz', format_string($quiz->name)));
         echo '<center>';
         print_string('regradedisplayexplanation', 'quiz');
         echo '<center>';
 
-    /// Loop through all questions and all attempts and regrade while printing progress info
+        // Loop through all questions and all attempts and regrade while printing progress info
         foreach ($questions as $question) {
             echo '<b>'.get_string('regradingquestion', 'quiz', $question->name).'</b> '.get_string('attempts', 'quiz').": \n";
             foreach ($attempts as $attempt) {
@@ -53,7 +52,7 @@ class quiz_report extends quiz_default_report {
             @flush();@ob_flush();
         }
 
-    /// Loop through all questions and recalculate $attempt->sumgrade
+        // Loop through all questions and recalculate $attempt->sumgrade
         $attemptschanged = 0;
         foreach ($attempts as $attempt) {
             $sumgrades = 0;
@@ -68,7 +67,7 @@ class quiz_report extends quiz_default_report {
             }
         }
 
-    /// Update the overall quiz grades
+        // Update the overall quiz grades
         if ($grades = get_records('quiz_grades', 'quiz', $quiz->id)) {
             foreach($grades as $grade) {
                 quiz_save_best_grade($quiz, $grade->userid);