2 /// Overview report: displays a big table of all the attempts
3 class hotpot_report
extends hotpot_default_report
{
4 function display(&$hotpot, &$cm, &$course, &$users, &$attempts, &$questions, &$options) {
8 $this->create_scores_table($hotpot, $course, $users, $attempts, $questions, $options, $tables);
9 $this->print_report($course, $hotpot, $tables, $options);
12 function create_scores_table(&$hotpot, &$course, &$users, &$attempts, &$questions, &$options, &$tables) {
14 $download = ($options['reportformat']=='htm') ?
false : true;
15 $is_html = ($options['reportformat']=='htm');
16 $blank = ($download ?
'' : ' ');
17 $no_value = ($download ?
'' : '-');
22 $table->head
= array();
23 $table->align
= array();
24 $table->size
= array();
25 // picture column, if required
27 $table->head
[] = ' ';
28 $table->align
[] = 'center';
31 // name, grade and attempt number
32 array_push($table->head
,
34 hotpot_grade_heading($hotpot, $options),
35 get_string("attempt", "quiz")
37 array_push($table->align
, "left", "center", "center");
38 array_push($table->size
, '', '', '');
40 $this->add_question_headings($questions, $table);
41 // penalties and raw score
42 array_push($table->head
,
43 get_string('penalties', 'hotpot'),
44 get_string('score', 'quiz')
46 array_push($table->align
, "center", "center");
47 array_push($table->size
, '', '');
48 $table->data
= array();
50 'grade' => array('count'=>0, 'total'=>0),
51 'penalties' => array('count'=>0, 'total'=>0),
52 'score' => array('count'=>0, 'total'=>0),
54 foreach ($users as $user) {
55 // shortcut to user info held in first attempt record
56 $u = &$user->attempts
[0];
60 $picture = print_user_picture($u->userid
, $course->id
, $u->picture
, false, true);
61 $name = '<a href="'.$CFG->wwwroot
.'/user/view.php?id='.$u->userid
.'&course='.$course->id
.'">'.$name.'</a>';
63 if (isset($user->grade
)) {
64 $grade = $user->grade
;
65 $q['grade']['count'] ++
;
66 if (is_numeric($grade)) {
67 $q['grade']['total'] +
= $grade;
72 $attemptcount = count($user->attempts
);
73 if ($attemptcount>1) {
77 $name->rowspan
= $attemptcount;
81 $grade->rowspan
= $attemptcount;
85 if ($attemptcount>1) {
88 $picture->text
= $text;
89 $picture->rowspan
= $attemptcount;
93 array_push($data, $name, $grade);
94 foreach ($user->attempts
as $attempt) {
95 // set flag if this is best grade
96 $is_best_grade = ($is_html && $attempt->score
==$user->grade
);
98 $attemptnumber= $attempt->attempt
;
99 if ($is_html && $allow_review) {
100 $attemptnumber = '<a href="review.php?hp='.$hotpot->id
.'&attempt='.$attempt->id
.'">'.$attemptnumber.'</a>';
102 if ($is_best_grade) {
103 $score = '<span class="highlight">'.$attemptnumber.'</span>';
105 $data[] = $attemptnumber;
106 // get responses to questions in this attempt by this user
107 foreach ($questions as $id=>$question) {
108 if (!isset($q[$id])) {
109 $q[$id] = array('count'=>0, 'total'=>0);
111 if (isset($attempt->responses
[$id])) {
112 $score = $attempt->responses
[$id]->score
;
113 if (is_numeric($score)) {
115 $q[$id]['total'] +
= $score;
116 if ($is_best_grade) {
117 $score = '<span class="highlight">'.$score.'</span>';
119 } else if (empty($score)) {
126 } // foreach $questions
127 if (isset($attempt->penalties
)) {
128 $penalties = $attempt->penalties
;
129 if (is_numeric($penalties)) {
130 $q['penalties']['count'] ++
;
131 $q['penalties']['total'] +
= $penalties;
133 if ($is_best_grade) {
134 $penalties = '<span class="highlight">'.$penalties.'</span>';
137 $penalties = $no_value;
139 $data[] = $penalties;
140 if (isset($attempt->score
)) {
141 $score = $attempt->score
;
142 if (is_numeric($score)) {
143 $q['score']['total'] +
= $score;
144 $q['score']['count'] ++
;
146 if ($is_best_grade) {
147 $score = '<span class="highlight">'.$score.'</span>';
153 // append data for this attempt
154 $table->data
[] = $data;
155 // reset data array for next attempt, if any
157 } // end foreach $attempt
158 $table->data
[] = 'hr';
159 } // end foreach $user
160 // remove final 'hr' from data rows
161 array_pop($table->data
);
162 // add averages to foot of table
165 $averages[] = $blank;
167 array_push($averages, get_string('average', 'hotpot'));
168 $col = count($averages);
169 if (empty($q['grade']['count'])) {
170 // remove score $col from $table
171 $this->remove_column($table, $col);
173 $precision = ($hotpot->grademethod
==HOTPOT_GRADEMETHOD_AVERAGE ||
$hotpot->grade
<100) ?
1 : 0;
174 $averages[] = round($q['grade']['total'] / $q['grade']['count'], $precision);
177 // skip the attempt number column
178 $averages[$col++
] = $blank;
179 foreach ($questions as $id=>$question) {
180 if (empty($q[$id]['count'])) {
181 // remove this question $col from $table
182 $this->remove_column($table, $col);
184 $averages[$col++
] = round($q[$id]['total'] / $q[$id]['count']);
187 if (empty($q['penalties']['count'])) {
188 // remove penalties $col from $table
189 $this->remove_column($table, $col);
191 $averages[$col++
] = round($q['penalties']['total'] / $q['penalties']['count']);
193 if (empty($q['score']['count'])) {
194 // remove score $col from $table
195 $this->remove_column($table, $col);
197 $averages[$col++
] = round($q['score']['total'] / $q['score']['count']);
199 $table->foot
= array($averages);