MDL-31910 Quiz : Error on Manual Grading report
authorM Kassaei <m.kassaei@open.ac.uk>
Fri, 9 Mar 2012 17:45:14 +0000 (17:45 +0000)
committerAparup Banerjee <aparup@moodle.com>
Tue, 13 Mar 2012 02:13:27 +0000 (10:13 +0800)
mod/quiz/report/grading/report.php

index 0ee9c33..28f4b3d 100644 (file)
@@ -126,11 +126,28 @@ class quiz_grading_report extends quiz_default_report {
                     $this->currentgroup, '', false);
         }
 
+        $questionsinquiz = quiz_questions_in_quiz($quiz->questions);
+        $counts = null;
+        if ($slot && $questionsinquiz) {
+            // Make sure there is something to do.
+            $statecounts = $this->get_question_state_summary(array($slot));
+            foreach ($statecounts as $record) {
+                if ($record->questionid == $questionid) {
+                    $counts = $record;
+                    break;
+                }
+            }
+            // If not, redirect back to the list.
+            if (!$counts || $counts->$grade == 0) {
+                redirect($this->list_questions_url(), get_string('alldoneredirecting', 'quiz_grading'));
+            }
+        }
+        
         // Start output.
         $this->print_header_and_tabs($cm, $course, $quiz, 'grading');
 
         // What sort of page to display?
-        if (!quiz_questions_in_quiz($quiz->questions)) {
+        if (!$questionsinquiz) {
             echo quiz_no_questions_message($quiz, $cm, $this->context);
 
         } else if (!$slot) {
@@ -138,7 +155,7 @@ class quiz_grading_report extends quiz_default_report {
 
         } else {
             $this->display_grading_interface($slot, $questionid, $grade,
-                    $pagesize, $page, $shownames, $showidnumbers, $order);
+                    $pagesize, $page, $shownames, $showidnumbers, $order, $counts);
         }
         return true;
     }
@@ -313,25 +330,9 @@ class quiz_grading_report extends quiz_default_report {
     }
 
     protected function display_grading_interface($slot, $questionid, $grade,
-            $pagesize, $page, $shownames, $showidnumbers, $order) {
+            $pagesize, $page, $shownames, $showidnumbers, $order, $counts) {
         global $OUTPUT;
 
-        // Make sure there is something to do.
-        $statecounts = $this->get_question_state_summary(array($slot));
-
-        $counts = null;
-        foreach ($statecounts as $record) {
-            if ($record->questionid == $questionid) {
-                $counts = $record;
-                break;
-            }
-        }
-
-        // If not, redirect back to the list.
-        if (!$counts || $counts->$grade == 0) {
-            redirect($this->list_questions_url(), get_string('alldoneredirecting', 'quiz_grading'));
-        }
-
         if ($pagesize * $page >= $counts->$grade) {
             $page = 0;
         }