|
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 00043 class quiz_report_statistics_question_table extends flexible_table { 00045 protected $questiondata; 00046 00052 public function __construct($qid) { 00053 parent::__construct('mod-quiz-report-statistics-question-table' . $qid); 00054 } 00055 00064 public function setup($reporturl, $questiondata, 00065 quiz_statistics_response_analyser $responesstats) { 00066 $this->questiondata = $questiondata; 00067 00068 $this->define_baseurl($reporturl->out()); 00069 $this->collapsible(false); 00070 $this->set_attribute('class', 'generaltable generalbox boxaligncenter'); 00071 00072 // Define table columns 00073 $columns = array(); 00074 $headers = array(); 00075 00076 if ($responesstats->has_subparts()) { 00077 $columns[] = 'part'; 00078 $headers[] = 'Part of question'; 00079 } 00080 00081 if ($responesstats->has_response_classes()) { 00082 $columns[] = 'responseclass'; 00083 $headers[] = get_string('modelresponse', 'quiz_statistics'); 00084 00085 if ($responesstats->has_actual_responses()) { 00086 $columns[] = 'response'; 00087 $headers[] = get_string('actualresponse', 'quiz_statistics'); 00088 } 00089 00090 } else { 00091 $columns[] = 'response'; 00092 $headers[] = get_string('response', 'quiz_statistics'); 00093 } 00094 00095 $columns[] = 'fraction'; 00096 $headers[] = get_string('optiongrade', 'quiz_statistics'); 00097 00098 $columns[] = 'count'; 00099 $headers[] = get_string('count', 'quiz_statistics'); 00100 00101 $columns[] = 'frequency'; 00102 $headers[] = get_string('frequency', 'quiz_statistics'); 00103 00104 $this->define_columns($columns); 00105 $this->define_headers($headers); 00106 $this->sortable(false); 00107 00108 $this->column_class('fraction', 'numcol'); 00109 $this->column_class('count', 'numcol'); 00110 $this->column_class('frequency', 'numcol'); 00111 00112 $this->column_suppress('part'); 00113 $this->column_suppress('responseclass'); 00114 00115 parent::setup(); 00116 } 00117 00118 protected function format_percentage($fraction) { 00119 return format_float($fraction * 100, 2) . '%'; 00120 } 00121 00127 protected function col_fraction($response) { 00128 if (is_null($response->fraction)) { 00129 return ''; 00130 } 00131 00132 return $this->format_percentage($response->fraction); 00133 } 00134 00140 protected function col_frequency($response) { 00141 if (!$this->questiondata->_stats->s) { 00142 return ''; 00143 } 00144 00145 return $this->format_percentage($response->count / $this->questiondata->_stats->s); 00146 } 00147 }