aeb15530 |
1 | <?php |
869309b8 |
2 | require_once($CFG->libdir.'/tablelib.php'); |
3 | |
4 | class quiz_report_statistics_question_table extends flexible_table { |
5 | /** |
6 | * @var object this question with _stats object. |
7 | */ |
8 | var $question; |
9 | |
10 | function quiz_report_statistics_question_table($qid){ |
11 | parent::flexible_table('mod-quiz-report-statistics-question-table'.$qid); |
12 | } |
13 | |
14 | /** |
15 | * Setup the columns and headers and other properties of the table and then |
16 | * call flexible_table::setup() method. |
17 | */ |
18 | function setup($reporturl, $question, $hassubqs){ |
19 | $this->question = $question; |
20 | // Define table columns |
21 | $columns = array(); |
22 | $headers = array(); |
aeb15530 |
23 | |
869309b8 |
24 | if ($hassubqs){ |
25 | $columns[]= 'subq'; |
26 | $headers[]= ''; |
27 | } |
28 | |
29 | $columns[]= 'response'; |
30 | $headers[]= get_string('response', 'quiz_statistics'); |
aeb15530 |
31 | |
869309b8 |
32 | |
33 | $columns[]= 'credit'; |
34 | $headers[]= get_string('optiongrade', 'quiz_statistics'); |
aeb15530 |
35 | |
869309b8 |
36 | $columns[]= 'rcount'; |
37 | $headers[]= get_string('count', 'quiz_statistics'); |
38 | |
39 | $columns[]= 'frequency'; |
40 | $headers[]= get_string('frequency', 'quiz_statistics'); |
41 | |
42 | $this->define_columns($columns); |
43 | $this->define_headers($headers); |
44 | $this->sortable(false); |
45 | |
46 | $this->column_class('credit', 'numcol'); |
47 | $this->column_class('rcount', 'numcol'); |
48 | $this->column_class('frequency', 'numcol'); |
49 | |
50 | // Set up the table |
51 | $this->define_baseurl($reporturl->out()); |
52 | |
53 | $this->collapsible(false); |
54 | |
55 | $this->set_attribute('class', 'generaltable generalbox boxaligncenter'); |
56 | |
57 | parent::setup(); |
58 | } |
aeb15530 |
59 | |
2280e147 |
60 | function col_response($response){ |
61 | global $QTYPES; |
62 | if (!$this->is_downloading() || $this->is_downloading() == 'xhtml'){ |
4033062b |
63 | return $response->indent . $QTYPES[$this->question->qtype]->format_response($response->response, $this->question->questiontextformat); |
2280e147 |
64 | } else { |
4033062b |
65 | return $response->indent . $response->response; |
2280e147 |
66 | } |
67 | } |
aeb15530 |
68 | |
869309b8 |
69 | function col_subq($response){ |
70 | return $response->subq; |
71 | } |
aeb15530 |
72 | |
869309b8 |
73 | function col_credit($response){ |
74 | if (!is_null($response->credit)){ |
75 | return ($response->credit*100).'%'; |
76 | } else { |
77 | return ''; |
78 | } |
79 | } |
aeb15530 |
80 | |
869309b8 |
81 | function col_frequency($response){ |
82 | if ($this->question->_stats->s){ |
83 | return format_float((($response->rcount / $this->question->_stats->s)*100),2).'%'; |
84 | } else { |
85 | return ''; |
86 | } |
87 | } |
88 | |
89 | |
90 | |
91 | } |
aeb15530 |
92 | |