MDL-43539 quiz statistics : coding error from progress bar
authorJames Pratt <me@jamiep.org>
Thu, 2 Jan 2014 11:31:44 +0000 (18:31 +0700)
committerJames Pratt <me@jamiep.org>
Fri, 14 Feb 2014 08:24:37 +0000 (15:24 +0700)
when no sub-questions - "parent progress count must be at least 1"

mod/quiz/report/statistics/report.php

index 5a93759..daa540c 100644 (file)
@@ -547,7 +547,7 @@ class quiz_statistics_report extends quiz_default_report {
             $progress->progress(2);
             if ($quizstats->s()) {
                 $subquestions = $questionstats->get_sub_questions();
             $progress->progress(2);
             if ($quizstats->s()) {
                 $subquestions = $questionstats->get_sub_questions();
-                $this->analyse_responses_for_all_questions_and_subquestions($qubaids, $questions, $subquestions, $progress);
+                $this->analyse_responses_for_all_questions_and_subquestions($questions, $subquestions, $qubaids, $progress);
             }
             $progress->progress(3);
             $progress->end_progress();
             }
             $progress->progress(3);
             $progress->end_progress();
@@ -576,9 +576,7 @@ class quiz_statistics_report extends quiz_default_report {
         return $this->progress;
     }
 
         return $this->progress;
     }
 
-    protected function analyse_responses_for_all_questions_and_subquestions($qubaids, $questions, $subquestions,
-                                                                            $progress = null) {
-
+    protected function analyse_responses_for_all_questions_and_subquestions($questions, $subquestions, $qubaids, $progress = null) {
         if ($progress === null) {
             $progress = new \core\progress\null();
         }
         if ($progress === null) {
             $progress = new \core\progress\null();
         }
@@ -586,45 +584,33 @@ class quiz_statistics_report extends quiz_default_report {
         // Starting response analysis tasks.
         $progress->start_progress('', count($questions) + count($subquestions));
 
         // Starting response analysis tasks.
         $progress->start_progress('', count($questions) + count($subquestions));
 
-        // Starting response analysis of main questions.
-        $progress->start_progress('', count($questions), count($questions));
+        $done = $this->analyse_responses_for_questions($questions, $qubaids, $progress);
 
 
-        $done = array();
-        $donecount = 1;
-        foreach ($questions as $question) {
-            $progress->progress($donecount);
-            $donecount++;
-            if (!question_bank::get_qtype($question->qtype, false)->can_analyse_responses()) {
-                continue;
-            }
-            $done[$question->id] = 1;
+        $this->analyse_responses_for_questions($subquestions, $qubaids, $progress, $done);
 
 
-            $responesstats = new \core_question\statistics\responses\analyser($question);
-            $responesstats->calculate($qubaids);
-        }
+        // Finished all response analysis tasks.
         $progress->end_progress();
         $progress->end_progress();
+    }
 
 
-        // Starting response analysis of sub-questions.
-        $countsubquestions = count($subquestions);
-        $progress->start_progress('', $countsubquestions, $countsubquestions);
-        $donecount = 1;
-        foreach ($subquestions as $subquestion) {
-            $progress->progress($donecount);
-            $donecount++;
-            if (!question_bank::get_qtype($subquestion->qtype, false)->can_analyse_responses() ||
-                    isset($done[$subquestion->id])) {
-                continue;
+    protected function analyse_responses_for_questions($questions, $qubaids, $progress = null, $done = array()) {
+        $countquestions = count($questions);
+        if (!$countquestions) {
+            return array();
+        }
+        if ($progress === null) {
+            $progress = new \core\progress\null();
+        }
+        $progress->start_progress('', $countquestions, $countquestions);
+        foreach ($questions as $question) {
+            $progress->increment_progress();
+            if (question_bank::get_qtype($question->qtype, false)->can_analyse_responses()  && !isset($done[$question->id])) {
+                $responesstats = new \core_question\statistics\responses\analyser($question);
+                $responesstats->calculate($qubaids);
             }
             }
-            $done[$subquestion->id] = 1;
-
-            $responesstats = new \core_question\statistics\responses\analyser($subquestion);
-            $responesstats->calculate($qubaids);
+            $done[$question->id] = 1;
         }
         }
-        // Finished sub-question tasks.
-        $progress->end_progress();
-
-        // Finished all response analysis tasks.
         $progress->end_progress();
         $progress->end_progress();
+        return $done;
     }
 
     /**
     }
 
     /**