MDL-15170 "convert to use new tablelib api"
[moodle.git] / mod / quiz / report / overview / overview_table.php
CommitLineData
c35f3afc 1<?php // $Id$
2
3class quiz_report_overview_table extends table_sql {
4
5 var $useridfield = 'userid';
6
7 var $candelete;
8 var $reporturl;
9 var $displayoptions;
10
11 function quiz_report_overview_table($quiz , $qmsubselect, $groupstudents,
12 $students, $detailedmarks, $questions, $candelete, $reporturl, $displayoptions){
13 parent::table_sql('mod-quiz-report-overview-report');
14 $this->quiz = $quiz;
15 $this->qmsubselect = $qmsubselect;
16 $this->groupstudents = $groupstudents;
17 $this->students = $students;
18 $this->detailedmarks = $detailedmarks;
19 $this->questions = $questions;
20 $this->candelete = $candelete;
21 $this->reporturl = $reporturl;
22 $this->displayoptions = $displayoptions;
23 }
24 function build_table(){
25 global $CFG;
26 if ($this->rawdata) {
27 // Define some things we need later to process raw data from db.
28 $this->strtimeformat = get_string('strftimedatetime');
29 parent::build_table();
30 //end of adding data from attempts data to table / download
31 //now add averages at bottom of table :
32 $averagesql = "SELECT AVG(qg.grade) AS grade " .
33 "FROM {$CFG->prefix}quiz_grades qg " .
34 "WHERE quiz=".$this->quiz->id;
35
36 $this->add_separator();
37 if ($this->is_downloading()){
38 $namekey = 'lastname';
39 } else {
40 $namekey = 'fullname';
41 }
42 if ($this->groupstudents){
43 $groupaveragesql = $averagesql." AND qg.userid IN ($this->groupstudents)";
44 $groupaverage = get_record_sql($groupaveragesql);
45 $groupaveragerow = array($namekey => get_string('groupavg', 'grades'),
46 'sumgrades' => round($groupaverage->grade, $this->quiz->decimalpoints),
47 'feedbacktext'=> strip_tags(quiz_report_feedback_for_grade($groupaverage->grade, $this->quiz->id)));
48 if($this->detailedmarks && $this->qmsubselect) {
49 $avggradebyq = quiz_get_average_grade_for_questions($this->quiz, $this->groupstudents);
50 $groupaveragerow += quiz_format_average_grade_for_questions($avggradebyq, $this->questions, $this->quiz, $this->is_downloading());
51 }
52 $this->add_data_keyed($groupaveragerow);
53 }
54 $overallaverage = get_record_sql($averagesql." AND qg.userid IN ($this->students)");
55 $overallaveragerow = array($namekey => get_string('overallaverage', 'grades'),
56 'sumgrades' => round($overallaverage->grade, $this->quiz->decimalpoints),
57 'feedbacktext'=> strip_tags(quiz_report_feedback_for_grade($overallaverage->grade, $this->quiz->id)));
58 if($this->detailedmarks && $this->qmsubselect) {
59 $avggradebyq = quiz_get_average_grade_for_questions($this->quiz, $this->students);
60 $overallaveragerow += quiz_format_average_grade_for_questions($avggradebyq, $this->questions, $this->quiz, $this->is_downloading());
61 }
62 $this->add_data_keyed($overallaveragerow);
63 }
64 }
65
66 function wrap_html_start(){
67 if (!$this->is_downloading()) {
68 if ($this->candelete) {
69 // Start form
70 $strreallydel = addslashes_js(get_string('deleteattemptcheck','quiz'));
71 echo '<div id="tablecontainer">';
72 echo '<form id="attemptsform" method="post" action="' . $this->reporturl->out(true) .
73 '" onsubmit="confirm(\''.$strreallydel.'\');">';
74 echo $this->reporturl->hidden_params_out(array(), 0, $this->displayoptions);
75 echo '<div>';
76 }
77 }
78 }
79 function wrap_html_finish(){
80 if (!$this->is_downloading()) {
81 // Print "Select all" etc.
82 if ($this->candelete) {
83 echo '<table id="commands">';
84 echo '<tr><td>';
85 echo '<a href="javascript:select_all_in(\'DIV\',null,\'tablecontainer\');">'.
86 get_string('selectall', 'quiz').'</a> / ';
87 echo '<a href="javascript:deselect_all_in(\'DIV\',null,\'tablecontainer\');">'.
88 get_string('selectnone', 'quiz').'</a> ';
89 echo '&nbsp;&nbsp;';
90 echo '<input type="submit" value="'.get_string('deleteselected', 'quiz_overview').'"/>';
91 echo '</td></tr></table>';
92 // Close form
93 echo '</div>';
94 echo '</form></div>';
95 }
96 }
97 }
98
99
100 function col_checkbox($attempt){
101 if ($attempt->attempt){
102 return '<input type="checkbox" name="attemptid[]" value="'.$attempt->attempt.'" />';
103 } else {
104 return '';
105 }
106 }
107
108 function col_picture($attempt){
109 global $COURSE;
110 return print_user_picture($attempt->userid, $COURSE->id, $attempt->picture, false, true);
111 }
112
113
114 function col_timestart($attempt){
115 if ($attempt->attempt) {
116 $startdate = userdate($attempt->timestart, $this->strtimeformat);
117 if (!$this->is_downloading()) {
118 return '<a href="review.php?q='.$this->quiz->id.'&amp;attempt='.$attempt->attempt.'">'.$startdate.'</a>';
119 } else {
120 return $startdate;
121 }
122 } else {
123 return '-';
124 }
125 }
126 function col_timefinish($attempt){
127 if ($attempt->attempt) {
128 if ($attempt->timefinish) {
129 $timefinish = userdate($attempt->timefinish, $this->strtimeformat);
130 if (!$this->is_downloading()) {
131 return '<a href="review.php?q='.$this->quiz->id.'&amp;attempt='.$attempt->attempt.'">'.$timefinish.'</a>';
132 } else {
133 return $timefinish;
134 }
135 } else {
136 return '-';
137 }
138 } else {
139 return '-';
140 }
141 }
142
143 function col_duration($attempt){
144 if ($attempt->timefinish) {
145 return format_time($attempt->duration);
146 } elseif ($attempt->timestart) {
147 return get_string('unfinished', 'quiz');
148 } else {
149 return '-';
150 }
151 }
152 function col_sumgrades($attempt){
153 if ($attempt->timefinish) {
154 $grade = quiz_rescale_grade($attempt->sumgrades, $this->quiz);
155 if (!$this->is_downloading()) {
156 $gradehtml = '<a href="review.php?q='.$this->quiz->id.'&amp;attempt='.$attempt->attempt.'">'.$grade.'</a>';
157 if ($this->qmsubselect && $attempt->gradedattempt){
158 $gradehtml = '<div class="highlight">'.$gradehtml.'</div>';
159 }
160 return $gradehtml;
161 } else {
162 return $grade;
163 }
164 } else {
165 return '-';
166 }
167 }
168 function other_cols($colname, $attempt){
169 if (preg_match('/^qsgrade([0-9]+)$/', $colname, $matches)){
170 $questionid = $matches[1];
171 $question = $this->questions[$questionid];
172 $state = new object();
173 $state->event = $attempt->{'qsevent'.$questionid};
174 if (question_state_is_graded($state)) {
175 $grade = quiz_rescale_grade($attempt->{'qsgrade'.$questionid}, $this->quiz);
176 } else {
177 $grade = '--';
178 }
179 if (!$this->is_downloading()) {
180 $grade = $grade.'/'.quiz_rescale_grade($question->grade, $this->quiz);
181 return link_to_popup_window('/mod/quiz/reviewquestion.php?state='.
182 $attempt->{'qsid'.$questionid}.'&amp;number='.$question->number,
183 'reviewquestion', $grade, 450, 650, get_string('reviewresponse', 'quiz'),
184 'none', true);
185 } else {
186 return $grade;
187 }
188 } else {
189 return NULL;
190 }
191 }
192
193 function col_feedbacktext($attempt){
194 if ($attempt->timefinish) {
195 if (!$this->is_downloading()) {
196 return quiz_report_feedback_for_grade(quiz_rescale_grade($attempt->sumgrades, $this->quiz), $this->quiz->id);
197 } else {
198 return strip_tags(quiz_report_feedback_for_grade(quiz_rescale_grade($attempt->sumgrades, $this->quiz), $this->quiz->id));
199 }
200 } else {
201 return '-';
202 }
203
204 }
205}
206?>