2 /// Overview report just displays a big table of all the attempts
3 class hotpot_report
extends hotpot_default_report
{
5 function display(&$hotpot, &$cm, &$course, &$users, &$attempts, &$questions, &$options) {
7 $this->create_overview_table($hotpot, $cm, $course, $users, $attempts, $questions, $options, $tables);
8 $this->print_report($course, $hotpot, $tables, $options);
11 function create_overview_table(&$hotpot, &$cm, &$course, &$users, &$attempts, &$questions, &$options, &$tables) {
13 $strtimeformat = get_string('strftimedatetime');
14 $is_html = ($options['reportformat']=='htm');
15 $spacer = $is_html ?
' ' : ' ';
16 $br = $is_html ?
"<br />\n" : "\n";
21 $table->head
= array();
22 $table->align
= array();
23 $table->size
= array();
24 $table->wrap
= array();
25 // picture column, if required
27 $table->head
[] = $spacer;
28 $table->align
[] = 'center';
30 $table->wrap
[] = "nowrap";
32 array_push($table->head
,
34 hotpot_grade_heading($hotpot, $options),
35 get_string("attempt", "quiz"),
36 get_string("time", "quiz"),
37 get_string("reportstatus", "hotpot"),
38 get_string("timetaken", "quiz"),
39 get_string("score", "quiz")
41 array_push($table->align
, "left", "center", "center", "left", "center", "center", "center");
42 array_push($table->wrap
, "nowrap", "nowrap", "nowrap", "nowrap", "nowrap", "nowrap", "nowrap");
43 array_push($table->size
, "*", "*", "*", "*", "*", "*", "*");
45 foreach ($users as $user) {
46 // shortcut to user info held in first attempt record
47 $u = &$user->attempts
[0];
51 $picture = print_user_picture($u->userid
, $course->id
, $u->picture
, false, true);
52 $name = '<a href="'.$CFG->wwwroot
.'/user/view.php?id='.$u->userid
.'&course='.$course->id
.'">'.$name.'</a>';
54 $grade = isset($user->grade
) && $user->grade
<>' ' ?
$user->grade
: $spacer;
55 $attemptcount = count($user->attempts
);
56 if ($attemptcount>1) {
60 $name->rowspan
= $attemptcount;
64 $grade->rowspan
= $attemptcount;
68 if ($attemptcount>1) {
71 $picture->text
= $text;
72 $picture->rowspan
= $attemptcount;
76 array_push($data, $name, $grade);
77 foreach ($user->attempts
as $attempt) {
78 // increment count of abandoned attempts
79 // if attempt is marked as finished but has no score
80 if ($attempt->status
==HOTPOT_STATUS_ABANDONED
) {
83 $attemptnumber = $attempt->attempt
;
84 $starttime = trim(userdate($attempt->timestart
, $strtimeformat));
85 if ($is_html && isset($attempt->score
) && (has_capability('mod/hotpot:viewreport',get_context_instance(CONTEXT_COURSE
, $course->id
)) ||
$hotpot->review
)) {
86 $attemptnumber = '<a href="review.php?hp='.$hotpot->id
.'&attempt='.$attempt->id
.'">'.$attemptnumber.'</a>';
87 $starttime = '<a href="review.php?hp='.$hotpot->id
.'&attempt='.$attempt->id
.'">'.$starttime.'</a>';
89 if ($is_html && has_capability('mod/hotpot:viewreport',get_context_instance(CONTEXT_COURSE
, $course->id
))) {
90 $checkbox = '<input type="checkbox" name="box'.$attempt->clickreportid
.'" value="'.$attempt->clickreportid
.'" />'.$spacer;
94 $timetaken = empty($attempt->timefinish
) ?
$spacer : format_time($attempt->timefinish
- $attempt->timestart
);
95 $score = hotpot_format_score($attempt);
96 if ($is_html && is_numeric($score) && $score==$user->grade
) { // best grade
97 $score = '<span class="highlight">'.$score.'</span>';
101 $checkbox.$starttime,
102 hotpot_format_status($attempt),
106 $table->data
[] = $data;
108 } // end foreach $attempt
109 $table->data
[] = 'hr';
110 } // end foreach $user
111 // remove final 'hr' from data rows
112 array_pop($table->data
);
113 // add the "delete" form to the table
114 if ($options['reportformat']=='htm' && has_capability('mod/hotpot:viewreport',get_context_instance(CONTEXT_COURSE
, $course->id
))) {
115 $strdeletecheck = get_string('deleteattemptcheck','quiz');
116 $table->start
= $this->deleteform_javascript();
117 $table->start
.= '<form method="post" action="report.php" id="deleteform" onsubmit="'."return deletecheck('".$strdeletecheck."', 'selection')".'">'."\n";
118 $table->start
.= '<input type="hidden" name="del" value="selection" />'."\n";
119 $table->start
.= '<input type="hidden" name="id" value="'.$cm->id
.'" />'."\n";
120 $table->finish
= '<center>'."\n";
121 $table->finish
.= '<input type="submit" value="'.get_string("deleteselected").'" /> '."\n";
123 $table->finish
.= '<input type="button" value="'.get_string('deleteabandoned', 'hotpot').'" onClick="if(deletecheck('."'".addslashes(get_string('deleteabandonedcheck', 'hotpot', $abandoned))."', 'abandoned', true".')) document.getElementById(\'deleteform\').submit();" />'."\n";
125 $table->finish
.= '<input type="button" value="'.get_string("deleteall").'" onClick="if(deletecheck('."'".addslashes($strdeletecheck)."', 'all', true".'))document.getElementById(\'deleteform\').submit();" />'."\n";
126 $table->finish
.= '</center>'."\n";
127 $table->finish
.= '</form>'."\n";
131 function deleteform_javascript() {
132 $strselectattempt = addslashes(get_string('selectattempt','hotpot'));
133 return <<<END_OF_JAVASCRIPT
134 <script type="text/javascript">
136 function deletecheck(p, v, x) {
137 var r = false; // result
138 // get length of form elements
139 var f = document.getElementById('deleteform');
140 var l = f ? f.elements.length : 0;
141 // count selected items, if necessary
144 for (var i=0; i<l; i++) {
145 var obj = f.elements[i];
146 if (obj.type && obj.type=='checkbox' && obj.checked) {
153 if (x || (n.appName=='Netscape' && parseInt(n.appVersion)==2)) {
159 alert('$strselectattempt');