| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php // $Id: report.php,v 1.6.8.2 2008/03/06 07:34:05 gbateson Exp $ 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) { 5 global $CFG; 6 // create the table 7 $tables = array(); 8 $this->create_scores_table($hotpot, $course, $users, $attempts, $questions, $options, $tables); 9 $this->print_report($course, $hotpot, $tables, $options); 10 return true; 11 } 12 function create_scores_table(&$hotpot, &$course, &$users, &$attempts, &$questions, &$options, &$tables) { 13 global $CFG; 14 $download = ($options['reportformat']=='htm') ? false : true; 15 $is_html = ($options['reportformat']=='htm'); 16 $blank = ($download ? '' : ' '); 17 $no_value = ($download ? '' : '-'); 18 $allow_review = true; 19 // start the table 20 unset($table); 21 $table->border = 1; 22 $table->head = array(); 23 $table->align = array(); 24 $table->size = array(); 25 // picture column, if required 26 if ($is_html) { 27 $table->head[] = ' '; 28 $table->align[] = 'center'; 29 $table->size[] = 10; 30 } 31 // name, grade and attempt number 32 array_push($table->head, 33 get_string("name"), 34 hotpot_grade_heading($hotpot, $options), 35 get_string("attempt", "quiz") 36 ); 37 array_push($table->align, "left", "center", "center"); 38 array_push($table->size, '', '', ''); 39 // question headings 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') 45 ); 46 array_push($table->align, "center", "center"); 47 array_push($table->size, '', ''); 48 $table->data = array(); 49 $q = array( 50 'grade' => array('count'=>0, 'total'=>0), 51 'penalties' => array('count'=>0, 'total'=>0), 52 'score' => array('count'=>0, 'total'=>0), 53 ); 54 foreach ($users as $user) { 55 // shortcut to user info held in first attempt record 56 $u = &$user->attempts[0]; 57 $picture = ''; 58 $name = fullname($u); 59 if ($is_html) { 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>'; 62 } 63 if (isset($user->grade)) { 64 $grade = $user->grade; 65 $q['grade']['count'] ++; 66 if (is_numeric($grade)) { 67 $q['grade']['total'] += $grade; 68 } 69 } else { 70 $grade = $no_value; 71 } 72 $attemptcount = count($user->attempts); 73 if ($attemptcount>1) { 74 $text = $name; 75 $name = NULL; 76 $name->text = $text; 77 $name->rowspan = $attemptcount; 78 $text = $grade; 79 $grade = NULL; 80 $grade->text = $text; 81 $grade->rowspan = $attemptcount; 82 } 83 $data = array(); 84 if ($is_html) { 85 if ($attemptcount>1) { 86 $text = $picture; 87 $picture = NULL; 88 $picture->text = $text; 89 $picture->rowspan = $attemptcount; 90 } 91 $data[] = $picture; 92 } 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); 97 // get attempt number 98 $attemptnumber= $attempt->attempt; 99 if ($is_html && $allow_review) { 100 $attemptnumber = '<a href="review.php?hp='.$hotpot->id.'&attempt='.$attempt->id.'">'.$attemptnumber.'</a>'; 101 } 102 if ($is_best_grade) { 103 $score = '<span class="highlight">'.$attemptnumber.'</span>'; 104 } 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); 110 } 111 if (isset($attempt->responses[$id])) { 112 $score = $attempt->responses[$id]->score; 113 if (is_numeric($score)) { 114 $q[$id]['count'] ++; 115 $q[$id]['total'] += $score; 116 if ($is_best_grade) { 117 $score = '<span class="highlight">'.$score.'</span>'; 118 } 119 } else if (empty($score)) { 120 $score = $no_value; 121 } 122 } else { 123 $score = $no_value; 124 } 125 $data[] = $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; 132 } 133 if ($is_best_grade) { 134 $penalties = '<span class="highlight">'.$penalties.'</span>'; 135 } 136 } else { 137 $penalties = $no_value; 138 } 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'] ++; 145 } 146 if ($is_best_grade) { 147 $score = '<span class="highlight">'.$score.'</span>'; 148 } 149 } else { 150 $score = $no_value; 151 } 152 $data[] = $score; 153 // append data for this attempt 154 $table->data[] = $data; 155 // reset data array for next attempt, if any 156 $data = array(); 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 163 $averages = array(); 164 if ($is_html) { 165 $averages[] = $blank; 166 } 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); 172 } else { 173 $precision = ($hotpot->grademethod==HOTPOT_GRADEMETHOD_AVERAGE || $hotpot->grade<100) ? 1 : 0; 174 $averages[] = round($q['grade']['total'] / $q['grade']['count'], $precision); 175 $col++; 176 } 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); 183 } else { 184 $averages[$col++] = round($q[$id]['total'] / $q[$id]['count']); 185 } 186 } 187 if (empty($q['penalties']['count'])) { 188 // remove penalties $col from $table 189 $this->remove_column($table, $col); 190 } else { 191 $averages[$col++] = round($q['penalties']['total'] / $q['penalties']['count']); 192 } 193 if (empty($q['score']['count'])) { 194 // remove score $col from $table 195 $this->remove_column($table, $col); 196 } else { 197 $averages[$col++] = round($q['score']['total'] / $q['score']['count']); 198 } 199 $table->foot = array($averages); 200 $tables[] = &$table; 201 } 202 } // end class 203 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 14 11:33:29 2009 | Cross-referenced by PHPXref 0.7 |