NOBUG quiz - overview & responses reports fixes
authorEloy Lafuente <stronk7@moodle.org>
Fri, 17 Sep 2010 01:07:17 +0000 (01:07 +0000)
committerEloy Lafuente <stronk7@moodle.org>
Fri, 17 Sep 2010 01:07:17 +0000 (01:07 +0000)
mod/quiz/report/overview/overview_table.php
mod/quiz/report/reportlib.php
mod/quiz/report/responses/report.php
mod/quiz/report/responses/responses_table.php

index a7db49b..fed94b3 100644 (file)
@@ -49,7 +49,7 @@ class quiz_report_overview_table extends table_sql {
                 $groupaverage = $DB->get_record_sql($groupaveragesql, array_merge($params, $g_params));
                 $groupaveragerow = array($namekey => get_string('groupavg', 'grades'),
                         'sumgrades' => quiz_format_grade($this->quiz, $groupaverage->grade),
-                        'feedbacktext'=> strip_tags(quiz_report_feedback_for_grade($groupaverage->grade, $this->quiz->id)));
+                        'feedbacktext'=> strip_tags(quiz_report_feedback_for_grade($groupaverage->grade, $this->quiz->id, $this->context)));
                 if($this->detailedmarks && ($this->qmsubselect || $this->quiz->attempts == 1)) {
                     $avggradebyq = quiz_get_average_grade_for_questions($this->quiz, $this->groupstudents);
                     $groupaveragerow += quiz_format_average_grade_for_questions($avggradebyq, $this->questions, $this->quiz, $this->is_downloading());
@@ -61,7 +61,7 @@ class quiz_report_overview_table extends table_sql {
             $overallaverage = $DB->get_record_sql($averagesql." AND qg.userid $s_usql", array_merge($params, $s_params));
             $overallaveragerow = array($namekey => get_string('overallaverage', 'grades'),
                         'sumgrades' => quiz_format_grade($this->quiz, $overallaverage->grade),
-                        'feedbacktext'=> strip_tags(quiz_report_feedback_for_grade($overallaverage->grade, $this->quiz->id)));
+                        'feedbacktext'=> strip_tags(quiz_report_feedback_for_grade($overallaverage->grade, $this->quiz->id, $this->context)));
             if($this->detailedmarks && ($this->qmsubselect || $this->quiz->attempts == 1)) {
                 $avggradebyq = quiz_get_average_grade_for_questions($this->quiz, $this->students);
                 $overallaveragerow += quiz_format_average_grade_for_questions($avggradebyq, $this->questions, $this->quiz, $this->is_downloading());
@@ -269,9 +269,9 @@ class quiz_report_overview_table extends table_sql {
     function col_feedbacktext($attempt){
         if ($attempt->timefinish) {
             if (!$this->is_downloading()) {
-                return quiz_report_feedback_for_grade(quiz_rescale_grade($attempt->sumgrades, $this->quiz, false), $this->quiz->id);
+                return quiz_report_feedback_for_grade(quiz_rescale_grade($attempt->sumgrades, $this->quiz, false), $this->quiz->id, $this->context);
             } else {
-                return strip_tags(quiz_report_feedback_for_grade(quiz_rescale_grade($attempt->sumgrades, $this->quiz, false), $this->quiz->id));
+                return strip_tags(quiz_report_feedback_for_grade(quiz_rescale_grade($attempt->sumgrades, $this->quiz, false), $this->quiz->id, $this->context));
             }
         } else {
             return '-';
index e40201e..74a0ef5 100644 (file)
@@ -309,17 +309,21 @@ function quiz_report_highlighting_grading_method($quiz, $qmsubselect, $qmfilter)
  * @param integer $quizid the id of the quiz object.
  * @return string the comment that corresponds to this grade (empty string if there is not one.
  */
-function quiz_report_feedback_for_grade($grade, $quizid) {
+function quiz_report_feedback_for_grade($grade, $quizid, $context) {
     global $DB;
     static $feedbackcache = array();
     if (!isset($feedbackcache[$quizid])){
         $feedbackcache[$quizid] = $DB->get_records('quiz_feedback', array('quizid' => $quizid));
     }
     $feedbacks = $feedbackcache[$quizid];
+    $feedbackid = 0;
     $feedbacktext = '';
+    $feedbacktextformat = FORMAT_MOODLE;
     foreach ($feedbacks as $feedback) {
         if ($feedback->mingrade <= $grade && $grade < $feedback->maxgrade){
+            $feedbackid = $feedback->id;
             $feedbacktext = $feedback->feedbacktext;
+            $feedbacktextformat = $feedback->feedbacktextformat;
             break;
         }
     }
@@ -327,7 +331,8 @@ function quiz_report_feedback_for_grade($grade, $quizid) {
     // Clean the text, ready for display.
     $formatoptions = new stdClass;
     $formatoptions->noclean = true;
-    $feedbacktext = format_text($feedbacktext, FORMAT_MOODLE, $formatoptions);
+    $feedbacktext = file_rewrite_pluginfile_urls($feedbacktext, 'pluginfile.php', $context->id, 'mod_quiz', 'feedback', $feedbackid);
+    $feedbacktext = format_text($feedbacktext, $feedbacktextformat, $formatoptions);
 
     return $feedbacktext;
 }
index d74b52b..5f69e57 100644 (file)
@@ -132,7 +132,7 @@ class quiz_responses_report extends quiz_default_report {
         $questions = quiz_report_load_questions($quiz);
 
         $table = new quiz_report_responses_table($quiz , $qmsubselect, $groupstudents,
-                $students, $questions, $candelete, $reporturl, $displayoptions);
+                $students, $questions, $candelete, $reporturl, $displayoptions, $context);
         $table->is_downloading($download, get_string('reportresponses','quiz_responses'),
                     "$COURSE->shortname ".format_string($quiz->name,true));
         if (!$table->is_downloading()) {
index d44b380..8bb48e2 100644 (file)
@@ -9,7 +9,7 @@ class quiz_report_responses_table extends table_sql {
     var $displayoptions;
 
     function quiz_report_responses_table($quiz , $qmsubselect, $groupstudents,
-                $students, $questions, $candelete, $reporturl, $displayoptions){
+                $students, $questions, $candelete, $reporturl, $displayoptions, $context){
         parent::table_sql('mod-quiz-report-responses-report');
         $this->quiz = $quiz;
         $this->qmsubselect = $qmsubselect;
@@ -19,6 +19,7 @@ class quiz_report_responses_table extends table_sql {
         $this->candelete = $candelete;
         $this->reporturl = $reporturl;
         $this->displayoptions = $displayoptions;
+        $this->context = $context;
     }
     function build_table(){
         if ($this->rawdata) {
@@ -197,9 +198,9 @@ class quiz_report_responses_table extends table_sql {
     function col_feedbacktext($attempt){
         if ($attempt->timefinish) {
             if (!$this->is_downloading()) {
-                return quiz_report_feedback_for_grade(quiz_rescale_grade($attempt->sumgrades, $this->quiz, false), $this->quiz->id);
+                return quiz_report_feedback_for_grade(quiz_rescale_grade($attempt->sumgrades, $this->quiz, false), $this->quiz->id, $this->context);
             } else {
-                return strip_tags(quiz_report_feedback_for_grade(quiz_rescale_grade($attempt->sumgrades, $this->quiz, false), $this->quiz->id));
+                return strip_tags(quiz_report_feedback_for_grade(quiz_rescale_grade($attempt->sumgrades, $this->quiz, false), $this->quiz->id, $this->context));
             }
         } else {
             return '-';