MDL-15112 converted some skipped dml stuff
[moodle.git] / mod / quiz / report / overview / overview_table.php
CommitLineData
c35f3afc 1<?php // $Id$
2
3class quiz_report_overview_table extends table_sql {
9cf4a18b 4
c35f3afc 5 var $useridfield = 'userid';
9cf4a18b 6
c35f3afc 7 var $candelete;
8 var $reporturl;
9 var $displayoptions;
9cf4a18b 10
c35f3afc 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(){
9cf4a18b 25 global $CFG, $DB;
c35f3afc 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 :
9cf4a18b 32 $params = array($this->quiz->id);
c35f3afc 33 $averagesql = "SELECT AVG(qg.grade) AS grade " .
9cf4a18b 34 "FROM {quiz_grades} qg " .
35 "WHERE quiz=?";
36
c35f3afc 37 $this->add_separator();
38 if ($this->is_downloading()){
39 $namekey = 'lastname';
40 } else {
41 $namekey = 'fullname';
42 }
43 if ($this->groupstudents){
9cf4a18b 44 list($g_usql, $g_params) = $DB->get_in_or_equal(explode(',', $this->groupstudents));
45
46 $groupaveragesql = $averagesql." AND qg.userid $g_usql";
47 $groupaverage = $DB->get_record_sql($groupaveragesql, array_merge($params, $g_params));
c35f3afc 48 $groupaveragerow = array($namekey => get_string('groupavg', 'grades'),
49 'sumgrades' => round($groupaverage->grade, $this->quiz->decimalpoints),
50 'feedbacktext'=> strip_tags(quiz_report_feedback_for_grade($groupaverage->grade, $this->quiz->id)));
51 if($this->detailedmarks && $this->qmsubselect) {
52 $avggradebyq = quiz_get_average_grade_for_questions($this->quiz, $this->groupstudents);
53 $groupaveragerow += quiz_format_average_grade_for_questions($avggradebyq, $this->questions, $this->quiz, $this->is_downloading());
54 }
55 $this->add_data_keyed($groupaveragerow);
56 }
9cf4a18b 57
58 list($s_usql, $s_params) = $DB->get_in_or_equal(explode(',', $this->students));
59 $overallaverage = $DB->get_record_sql($averagesql." AND qg.userid $s_usql", array_merge($params, $s_params));
c35f3afc 60 $overallaveragerow = array($namekey => get_string('overallaverage', 'grades'),
61 'sumgrades' => round($overallaverage->grade, $this->quiz->decimalpoints),
62 'feedbacktext'=> strip_tags(quiz_report_feedback_for_grade($overallaverage->grade, $this->quiz->id)));
63 if($this->detailedmarks && $this->qmsubselect) {
64 $avggradebyq = quiz_get_average_grade_for_questions($this->quiz, $this->students);
65 $overallaveragerow += quiz_format_average_grade_for_questions($avggradebyq, $this->questions, $this->quiz, $this->is_downloading());
66 }
67 $this->add_data_keyed($overallaveragerow);
68 }
69 }
9cf4a18b 70
c35f3afc 71 function wrap_html_start(){
72 if (!$this->is_downloading()) {
73 if ($this->candelete) {
74 // Start form
75 $strreallydel = addslashes_js(get_string('deleteattemptcheck','quiz'));
76 echo '<div id="tablecontainer">';
77 echo '<form id="attemptsform" method="post" action="' . $this->reporturl->out(true) .
78 '" onsubmit="confirm(\''.$strreallydel.'\');">';
79 echo $this->reporturl->hidden_params_out(array(), 0, $this->displayoptions);
80 echo '<div>';
81 }
82 }
83 }
84 function wrap_html_finish(){
85 if (!$this->is_downloading()) {
86 // Print "Select all" etc.
87 if ($this->candelete) {
88 echo '<table id="commands">';
89 echo '<tr><td>';
90 echo '<a href="javascript:select_all_in(\'DIV\',null,\'tablecontainer\');">'.
91 get_string('selectall', 'quiz').'</a> / ';
92 echo '<a href="javascript:deselect_all_in(\'DIV\',null,\'tablecontainer\');">'.
93 get_string('selectnone', 'quiz').'</a> ';
94 echo '&nbsp;&nbsp;';
95 echo '<input type="submit" value="'.get_string('deleteselected', 'quiz_overview').'"/>';
96 echo '</td></tr></table>';
97 // Close form
98 echo '</div>';
99 echo '</form></div>';
100 }
101 }
102 }
103
9cf4a18b 104
c35f3afc 105 function col_checkbox($attempt){
106 if ($attempt->attempt){
107 return '<input type="checkbox" name="attemptid[]" value="'.$attempt->attempt.'" />';
108 } else {
109 return '';
110 }
111 }
9cf4a18b 112
c35f3afc 113 function col_picture($attempt){
114 global $COURSE;
115 return print_user_picture($attempt->userid, $COURSE->id, $attempt->picture, false, true);
116 }
117
9cf4a18b 118
c35f3afc 119 function col_timestart($attempt){
120 if ($attempt->attempt) {
121 $startdate = userdate($attempt->timestart, $this->strtimeformat);
122 if (!$this->is_downloading()) {
123 return '<a href="review.php?q='.$this->quiz->id.'&amp;attempt='.$attempt->attempt.'">'.$startdate.'</a>';
124 } else {
125 return $startdate;
126 }
127 } else {
128 return '-';
129 }
130 }
131 function col_timefinish($attempt){
132 if ($attempt->attempt) {
133 if ($attempt->timefinish) {
134 $timefinish = userdate($attempt->timefinish, $this->strtimeformat);
135 if (!$this->is_downloading()) {
136 return '<a href="review.php?q='.$this->quiz->id.'&amp;attempt='.$attempt->attempt.'">'.$timefinish.'</a>';
137 } else {
138 return $timefinish;
139 }
140 } else {
141 return '-';
142 }
143 } else {
144 return '-';
145 }
146 }
9cf4a18b 147
c35f3afc 148 function col_duration($attempt){
149 if ($attempt->timefinish) {
150 return format_time($attempt->duration);
151 } elseif ($attempt->timestart) {
152 return get_string('unfinished', 'quiz');
153 } else {
154 return '-';
155 }
156 }
157 function col_sumgrades($attempt){
158 if ($attempt->timefinish) {
159 $grade = quiz_rescale_grade($attempt->sumgrades, $this->quiz);
160 if (!$this->is_downloading()) {
161 $gradehtml = '<a href="review.php?q='.$this->quiz->id.'&amp;attempt='.$attempt->attempt.'">'.$grade.'</a>';
162 if ($this->qmsubselect && $attempt->gradedattempt){
163 $gradehtml = '<div class="highlight">'.$gradehtml.'</div>';
164 }
165 return $gradehtml;
166 } else {
167 return $grade;
168 }
169 } else {
170 return '-';
171 }
172 }
173 function other_cols($colname, $attempt){
181608b7 174 static $gradedstatesbyattempt = null;
175 if ($gradedstatesbyattempt === null){
176 //get all the attempt ids we want to display on this page
177 //or to export for download.
178 $attemptids = array();
179 foreach ($this->rawdata as $attempt){
180 if ($attempt->attemptuniqueid > 0){
181 $attemptids[] = $attempt->attemptuniqueid;
182 }
183 }
184 $gradedstatesbyattempt = quiz_get_newgraded_states($attemptids, true, 'qs.id, qs.grade, qs.event, qs.question, qs.attempt');
185 }
c35f3afc 186 if (preg_match('/^qsgrade([0-9]+)$/', $colname, $matches)){
187 $questionid = $matches[1];
188 $question = $this->questions[$questionid];
181608b7 189 $stateforqinattempt = $gradedstatesbyattempt[$attempt->attemptuniqueid][$questionid];
190 if (question_state_is_graded($stateforqinattempt)) {
191 $grade = quiz_rescale_grade($stateforqinattempt->grade, $this->quiz);
c35f3afc 192 } else {
193 $grade = '--';
194 }
195 if (!$this->is_downloading()) {
196 $grade = $grade.'/'.quiz_rescale_grade($question->grade, $this->quiz);
197 return link_to_popup_window('/mod/quiz/reviewquestion.php?state='.
181608b7 198 $stateforqinattempt->id.'&amp;number='.$question->number,
c35f3afc 199 'reviewquestion', $grade, 450, 650, get_string('reviewresponse', 'quiz'),
200 'none', true);
201 } else {
202 return $grade;
9cf4a18b 203 }
c35f3afc 204 } else {
205 return NULL;
206 }
207 }
9cf4a18b 208
c35f3afc 209 function col_feedbacktext($attempt){
210 if ($attempt->timefinish) {
211 if (!$this->is_downloading()) {
212 return quiz_report_feedback_for_grade(quiz_rescale_grade($attempt->sumgrades, $this->quiz), $this->quiz->id);
213 } else {
214 return strip_tags(quiz_report_feedback_for_grade(quiz_rescale_grade($attempt->sumgrades, $this->quiz), $this->quiz->id));
215 }
216 } else {
217 return '-';
218 }
9cf4a18b 219
c35f3afc 220 }
221}
222?>