|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 00027 defined('MOODLE_INTERNAL') || die(); 00028 00029 00036 class quiz_report_responses_table extends quiz_attempt_report_table { 00037 00038 public function __construct($quiz, $context, $qmsubselect, $qmfilter, 00039 $attemptsmode, $groupstudents, $students, 00040 $questions, $includecheckboxes, $reporturl, $displayoptions) { 00041 parent::__construct('mod-quiz-report-responses-report', $quiz, $context, 00042 $qmsubselect, $qmfilter, $attemptsmode, $groupstudents, $students, 00043 $questions, $includecheckboxes, $reporturl, $displayoptions); 00044 } 00045 00046 public function build_table() { 00047 if ($this->rawdata) { 00048 $this->strtimeformat = str_replace(',', ' ', get_string('strftimedatetime')); 00049 parent::build_table(); 00050 } 00051 } 00052 00053 public function col_sumgrades($attempt) { 00054 if (!$attempt->timefinish) { 00055 return '-'; 00056 } 00057 00058 $grade = quiz_rescale_grade($attempt->sumgrades, $this->quiz); 00059 if ($this->is_downloading()) { 00060 return $grade; 00061 } 00062 00063 $gradehtml = '<a href="review.php?q=' . $this->quiz->id . '&attempt=' . 00064 $attempt->attempt . '">' . $grade . '</a>'; 00065 return $gradehtml; 00066 } 00067 00068 public function data_col($slot, $field, $attempt) { 00069 global $CFG; 00070 00071 if ($attempt->usageid == 0) { 00072 return '-'; 00073 } 00074 00075 $question = $this->questions[$slot]; 00076 if (!isset($this->lateststeps[$attempt->usageid][$slot])) { 00077 return '-'; 00078 } 00079 00080 $stepdata = $this->lateststeps[$attempt->usageid][$slot]; 00081 00082 if (is_null($stepdata->$field)) { 00083 $summary = '-'; 00084 } else { 00085 $summary = trim($stepdata->$field); 00086 } 00087 00088 if ($this->is_downloading() || $field != 'responsesummary') { 00089 return $summary; 00090 } 00091 00092 return $this->make_review_link($summary, $attempt, $slot); 00093 } 00094 00095 public function other_cols($colname, $attempt) { 00096 if (preg_match('/^question(\d+)$/', $colname, $matches)) { 00097 return $this->data_col($matches[1], 'questionsummary', $attempt); 00098 00099 } else if (preg_match('/^response(\d+)$/', $colname, $matches)) { 00100 return $this->data_col($matches[1], 'responsesummary', $attempt); 00101 00102 } else if (preg_match('/^right(\d+)$/', $colname, $matches)) { 00103 return $this->data_col($matches[1], 'rightanswer', $attempt); 00104 00105 } else { 00106 return null; 00107 } 00108 } 00109 00110 protected function requires_latest_steps_loaded() { 00111 return true; 00112 } 00113 00114 protected function is_latest_step_column($column) { 00115 if (preg_match('/^(?:question|response|right)([0-9]+)/', $column, $matches)) { 00116 return $matches[1]; 00117 } 00118 return false; 00119 } 00120 00126 protected function get_required_latest_state_fields($slot, $alias) { 00127 return "$alias.questionsummary AS question$slot, 00128 $alias.rightanswer AS right$slot, 00129 $alias.responsesummary AS response$slot"; 00130 } 00131 }