|
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 require_once($CFG->libdir.'/tablelib.php'); 00030 00031 00039 class quiz_report_statistics_table extends flexible_table { 00041 protected $quiz; 00042 00044 protected $cmid; 00045 00049 public function __construct() { 00050 parent::__construct('mod-quiz-report-statistics-report'); 00051 } 00052 00062 public function setup($quiz, $cmid, $reporturl, $s) { 00063 $this->quiz = $quiz; 00064 $this->cmid = $cmid; 00065 00066 // Define table columns 00067 $columns = array(); 00068 $headers = array(); 00069 00070 $columns[] = 'number'; 00071 $headers[] = get_string('questionnumber', 'quiz_statistics'); 00072 00073 if (!$this->is_downloading()) { 00074 $columns[] = 'icon'; 00075 $headers[] = ''; 00076 $columns[] = 'actions'; 00077 $headers[] = ''; 00078 } else { 00079 $columns[] = 'qtype'; 00080 $headers[] = get_string('questiontype', 'quiz_statistics'); 00081 } 00082 00083 $columns[] = 'name'; 00084 $headers[] = get_string('questionname', 'quiz'); 00085 00086 $columns[] = 's'; 00087 $headers[] = get_string('attempts', 'quiz_statistics'); 00088 00089 if ($s > 1) { 00090 $columns[] = 'facility'; 00091 $headers[] = get_string('facility', 'quiz_statistics'); 00092 00093 $columns[] = 'sd'; 00094 $headers[] = get_string('standarddeviationq', 'quiz_statistics'); 00095 } 00096 00097 $columns[] = 'random_guess_score'; 00098 $headers[] = get_string('random_guess_score', 'quiz_statistics'); 00099 00100 $columns[] = 'intended_weight'; 00101 $headers[] = get_string('intended_weight', 'quiz_statistics'); 00102 00103 $columns[] = 'effective_weight'; 00104 $headers[] = get_string('effective_weight', 'quiz_statistics'); 00105 00106 $columns[] = 'discrimination_index'; 00107 $headers[] = get_string('discrimination_index', 'quiz_statistics'); 00108 00109 $columns[] = 'discriminative_efficiency'; 00110 $headers[] = get_string('discriminative_efficiency', 'quiz_statistics'); 00111 00112 $this->define_columns($columns); 00113 $this->define_headers($headers); 00114 $this->sortable(false); 00115 00116 $this->column_class('s', 'numcol'); 00117 $this->column_class('facility', 'numcol'); 00118 $this->column_class('sd', 'numcol'); 00119 $this->column_class('random_guess_score', 'numcol'); 00120 $this->column_class('intended_weight', 'numcol'); 00121 $this->column_class('effective_weight', 'numcol'); 00122 $this->column_class('discrimination_index', 'numcol'); 00123 $this->column_class('discriminative_efficiency', 'numcol'); 00124 00125 // Set up the table 00126 $this->define_baseurl($reporturl->out()); 00127 00128 $this->collapsible(true); 00129 00130 $this->set_attribute('id', 'questionstatistics'); 00131 $this->set_attribute('class', 'generaltable generalbox boxaligncenter'); 00132 00133 parent::setup(); 00134 } 00135 00141 protected function col_number($question) { 00142 if ($question->_stats->subquestion) { 00143 return ''; 00144 } 00145 00146 return $question->number; 00147 } 00148 00154 protected function col_icon($question) { 00155 return print_question_icon($question, true); 00156 } 00157 00163 protected function col_actions($question) { 00164 return quiz_question_action_icons($this->quiz, $this->cmid, $question, $this->baseurl); 00165 } 00166 00172 protected function col_qtype($question) { 00173 return question_bank::get_qtype_name($question->qtype); 00174 } 00175 00181 protected function col_name($question) { 00182 $name = $question->name; 00183 00184 if ($this->is_downloading()) { 00185 return $name; 00186 } 00187 00188 $url = null; 00189 if ($question->_stats->subquestion) { 00190 $url = new moodle_url($this->baseurl, array('qid' => $question->id)); 00191 } else if ($question->_stats->slot && $question->qtype != 'random') { 00192 $url = new moodle_url($this->baseurl, array('slot' => $question->_stats->slot)); 00193 } 00194 00195 if ($url) { 00196 $name = html_writer::link($url, $name, 00197 array('title' => get_string('detailedanalysis', 'quiz_statistics'))); 00198 } 00199 00200 if ($this->is_dubious_question($question)) { 00201 $name = html_writer::tag('div', $name, array('class' => 'dubious')); 00202 } 00203 00204 return $name; 00205 } 00206 00212 protected function col_s($question) { 00213 if (!isset($question->_stats->s)) { 00214 return 0; 00215 } 00216 00217 return $question->_stats->s; 00218 } 00219 00225 protected function col_facility($question) { 00226 if (is_null($question->_stats->facility)) { 00227 return ''; 00228 } 00229 00230 return number_format($question->_stats->facility*100, 2) . '%'; 00231 } 00232 00238 protected function col_sd($question) { 00239 if (is_null($question->_stats->sd) || $question->_stats->maxmark == 0) { 00240 return ''; 00241 } 00242 00243 return number_format($question->_stats->sd*100 / $question->_stats->maxmark, 2) . '%'; 00244 } 00245 00251 protected function col_random_guess_score($question) { 00252 if (is_null($question->_stats->randomguessscore)) { 00253 return ''; 00254 } 00255 00256 return number_format($question->_stats->randomguessscore * 100, 2).'%'; 00257 } 00258 00266 protected function col_intended_weight($question) { 00267 return quiz_report_scale_summarks_as_percentage( 00268 $question->_stats->maxmark, $this->quiz); 00269 } 00270 00277 protected function col_effective_weight($question) { 00278 global $OUTPUT; 00279 00280 if ($question->_stats->subquestion) { 00281 return ''; 00282 } 00283 00284 if ($question->_stats->negcovar) { 00285 $negcovar = get_string('negcovar', 'quiz_statistics'); 00286 00287 if (!$this->is_downloading()) { 00288 $negcovar = html_writer::tag('div', 00289 $negcovar . $OUTPUT->help_icon('negcovar', 'quiz_statistics'), 00290 array('class' => 'negcovar')); 00291 } 00292 00293 return $negcovar; 00294 } 00295 00296 return number_format($question->_stats->effectiveweight, 2) . '%'; 00297 } 00298 00306 protected function col_discrimination_index($question) { 00307 if (!is_numeric($question->_stats->discriminationindex)) { 00308 return $question->_stats->discriminationindex; 00309 } 00310 00311 return number_format($question->_stats->discriminationindex, 2) . '%'; 00312 } 00313 00319 protected function col_discriminative_efficiency($question) { 00320 if (!is_numeric($question->_stats->discriminativeefficiency)) { 00321 return ''; 00322 } 00323 00324 return number_format($question->_stats->discriminativeefficiency, 2) . '%'; 00325 } 00326 00333 protected function is_dubious_question($question) { 00334 if (!is_numeric($question->_stats->discriminativeefficiency)) { 00335 return false; 00336 } 00337 00338 return $question->_stats->discriminativeefficiency < 15; 00339 } 00340 00341 public function wrap_html_start() { 00342 // Horrible Moodle 2.0 wide-content work-around. 00343 if (!$this->is_downloading()) { 00344 echo html_writer::start_tag('div', array('id' => 'tablecontainer', 00345 'class' => 'statistics-tablecontainer')); 00346 } 00347 } 00348 00349 public function wrap_html_finish() { 00350 if (!$this->is_downloading()) { 00351 echo html_writer::end_tag('div'); 00352 } 00353 } 00354 }