]> git.mjollnir.org Git - moodle.git/commitdiff
remove   from blank cells when generating Excel sheet
authorgbateson <gbateson>
Thu, 14 Sep 2006 07:16:14 +0000 (07:16 +0000)
committergbateson <gbateson>
Thu, 14 Sep 2006 07:16:14 +0000 (07:16 +0000)
mod/hotpot/report/overview/report.php

index fd691c2a477b07f09caaa1eb40b7fc4fbee294f6..bd4a21e499bb2bc54eeb03cdb2903b5c87229dc8 100644 (file)
-<?php  // $Id$\r
-/// Overview report just displays a big table of all the attempts\r
-class hotpot_report extends hotpot_default_report {\r
-\r
-       function display(&$hotpot, &$cm, &$course, &$users, &$attempts, &$questions, &$options) {\r
-               $tables = array();\r
-               $this->create_overview_table($hotpot, $cm, $course, $users, $attempts, $questions, $options, $tables);\r
-               $this->print_report($course, $hotpot, $tables, $options);\r
-               return true;\r
-       }\r
-       function create_overview_table(&$hotpot, &$cm, &$course, &$users, &$attempts, &$questions, &$options, &$tables) {\r
-               global $CFG;\r
-               $strtimeformat = get_string('strftimedatetime');\r
-               $is_html = ($options['reportformat']=='htm');\r
-               $spacer = $is_html ? '&nbsp;' : ' ';\r
-               $br = $is_html ? "<br />\n" : "\n";\r
-               // initialize $table\r
-               unset($table);\r
-               $table->border = 1;\r
-               $table->width = 10;\r
-               $table->head = array();\r
-               $table->align = array();\r
-               $table->size = array();\r
-               $table->wrap = array();\r
-               // picture column, if required\r
-               if ($is_html) {\r
-                       $table->head[] = $spacer;\r
-                       $table->align[] = 'center';\r
-                       $table->size[] = 10;\r
-                       $table->wrap[] = "nowrap";\r
-               }\r
-               array_push($table->head, \r
-                       get_string("name"), \r
-                       hotpot_grade_heading($hotpot, $options),\r
-                       get_string("attempt", "quiz"), \r
-                       get_string("time", "quiz"), \r
-                       get_string("reportstatus", "hotpot"), \r
-                       get_string("timetaken", "quiz"), \r
-                       get_string("score", "quiz")\r
-               );\r
-               array_push($table->align, "left", "center", "center", "left", "center", "center", "center");\r
-               array_push($table->wrap, "nowrap", "nowrap", "nowrap", "nowrap", "nowrap", "nowrap", "nowrap");\r
-               array_push($table->size, "*", "*", "*", "*", "*", "*", "*");\r
-               $abandoned = 0;\r
-               foreach ($users as $user) {\r
-                       // shortcut to user info held in first attempt record\r
-                       $u = &$user->attempts[0];\r
-                       $picture = '';\r
-                       $name = fullname($u);\r
-                       if ($is_html) {\r
-                               $picture = print_user_picture($u->userid, $course->id, $u->picture, false, true);\r
-                               $name = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$u->userid.'&course='.$course->id.'">'.$name.'</a>';\r
-                       }\r
-                       $grade = isset($user->grade) ? $user->grade : $spacer;\r
-                       $attemptcount = count($user->attempts);\r
-                       if ($attemptcount>1) {\r
-                               $text = $name;\r
-                               $name = NULL;\r
-                               $name->text = $text;\r
-                               $name->rowspan = $attemptcount;\r
-                               $text = $grade;\r
-                               $grade = NULL;\r
-                               $grade->text = $text;\r
-                               $grade->rowspan = $attemptcount;\r
-                       }\r
-                       $data = array();\r
-                       if ($is_html) {\r
-                               if ($attemptcount>1) {\r
-                                       $text = $picture;\r
-                                       $picture = NULL;\r
-                                       $picture->text = $text;\r
-                                       $picture->rowspan = $attemptcount;\r
-                               }\r
-                               $data[] = $picture;\r
-                       }\r
-                       array_push($data, $name, $grade);\r
-                       foreach ($user->attempts as $attempt) {\r
-                               // increment count of abandoned attempts\r
-                               // if attempt is marked as finished but has no score\r
-                               if ($attempt->status==HOTPOT_STATUS_ABANDONED) {\r
-                                       $abandoned++;\r
-                               }\r
-                               $attemptnumber = $attempt->attempt;\r
-                               $starttime = trim(userdate($attempt->timestart, $strtimeformat));\r
-                               if ($is_html && isset($attempt->score) && (has_capability('mod/hotpot:viewreport',get_context_instance(CONTEXT_COURSE, $course->id)) || $hotpot->review)) {\r
-                                       $attemptnumber = '<a href="review.php?hp='.$hotpot->id.'&attempt='.$attempt->id.'">'.$attemptnumber.'</a>';\r
-                                       $starttime = '<a href="review.php?hp='.$hotpot->id.'&attempt='.$attempt->id.'">'.$starttime.'</a>';\r
-                               }\r
-                               if ($is_html && has_capability('mod/hotpot:viewreport',get_context_instance(CONTEXT_COURSE, $course))) {\r
-                                       $checkbox = '<input type=checkbox name="box'.$attempt->clickreportid.'" value="'.$attempt->clickreportid.'">'.$spacer;\r
-                               } else {\r
-                                       $checkbox = '';\r
-                               }\r
-                               $timetaken = empty($attempt->timefinish) ? $spacer : format_time($attempt->timefinish - $attempt->timestart);\r
-                               $score = hotpot_format_score($attempt);\r
-                               if ($is_html && is_numeric($score) && $score==$user->grade) { // best grade\r
-                                       $score = '<span class="highlight">'.$score.'</span>';\r
-                               }\r
-                               array_push($data, \r
-                                       $attemptnumber,\r
-                                       $checkbox.$starttime,\r
-                                       hotpot_format_status($attempt),\r
-                                       $timetaken,\r
-                                       $score\r
-                               );\r
-                               $table->data[] = $data;\r
-                               $data = array();\r
-                       } // end foreach $attempt\r
-                       $table->data[] = 'hr';\r
-               } // end foreach $user\r
-               // remove final 'hr' from data rows\r
-               array_pop($table->data);\r
-               // add the "delete" form to the table\r
-               if ($options['reportformat']=='htm' && has_capability('mod/hotpot:viewreport',get_context_instance(CONTEXT_COURSE, $course->id))) {\r
-                       $strdeletecheck = get_string('deleteattemptcheck','quiz');\r
-                       $table->start = $this->deleteform_javascript();\r
-                       $table->start .= '<form method="post" action="report.php" name="deleteform" onsubmit="'."return deletecheck('".$strdeletecheck."', 'selection')".'">'."\n";\r
-                       $table->start .= '<input type="hidden" name="del" value="selection">'."\n";\r
-                       $table->start .= '<input type="hidden" name="id" value="'.$cm->id.'">'."\n";\r
-                       $table->finish = '<center>'."\n";\r
-                       $table->finish .= '<input type="submit" value="'.get_string("deleteselected").'">&nbsp;'."\n";\r
-                       if ($abandoned) {\r
-                               $table->finish .= '<input type=button value="'.get_string('deleteabandoned', 'hotpot').'" onClick="if(deletecheck('."'".addslashes(get_string('deleteabandonedcheck', 'hotpot', $abandoned))."', 'abandoned', true".'))document.deleteform.submit();">'."\n";\r
-                       }\r
-                       $table->finish .= '<input type=button value="'.get_string("deleteall").'" onClick="if(deletecheck('."'".addslashes($strdeletecheck)."', 'all', true".'))document.deleteform.submit();">'."\n";\r
-                       $table->finish .= '</center>'."\n";\r
-                       $table->finish .= '</form>'."\n";\r
-               }\r
-               $tables[] = &$table;\r
-       }\r
-       function deleteform_javascript() {\r
-               $strselectattempt = addslashes(get_string('selectattempt','hotpot'));\r
-               return <<<END_OF_JAVASCRIPT\r
-<script type="text/javascript">\r
-<!--\r
-function deletecheck(p, v, x) {\r
-       var r = false; // result\r
-       // get length of form elements\r
-       var f = document.deleteform;\r
-       var l = f ? f.elements.length : 0;\r
-       // count selected items, if necessary\r
-       if (!x) {\r
-               x = 0;\r
-               for (var i=0; i<l; i++) {\r
-                       var obj = f.elements[i];\r
-                       if (obj.type && obj.type=='checkbox' && obj.checked) {\r
-                               x++;\r
-                       }\r
-               }\r
-       }\r
-       // confirm deletion\r
-       var n = navigator;\r
-       if (x || (n.appName=='Netscape' && parseint(n.appVersion)==2)) {\r
-               r = confirm(p);\r
-               if (r) {\r
-                       f.del.value = v;\r
-               }\r
-       } else {\r
-               alert('$strselectattempt');\r
-       }\r
-       return r;\r
-}\r
-//-->\r
-</script>\r
-END_OF_JAVASCRIPT\r
-;\r
-       } // end function\r
-} // end class\r
-?>\r
+<?php  // $Id$
+/// Overview report just displays a big table of all the attempts
+class hotpot_report extends hotpot_default_report {
+
+       function display(&$hotpot, &$cm, &$course, &$users, &$attempts, &$questions, &$options) {
+               $tables = array();
+               $this->create_overview_table($hotpot, $cm, $course, $users, $attempts, $questions, $options, $tables);
+               $this->print_report($course, $hotpot, $tables, $options);
+               return true;
+       }
+       function create_overview_table(&$hotpot, &$cm, &$course, &$users, &$attempts, &$questions, &$options, &$tables) {
+               global $CFG;
+               $strtimeformat = get_string('strftimedatetime');
+               $is_html = ($options['reportformat']=='htm');
+               $spacer = $is_html ? '&nbsp;' : ' ';
+               $br = $is_html ? "<br />\n" : "\n";
+               // initialize $table
+               unset($table);
+               $table->border = 1;
+               $table->width = 10;
+               $table->head = array();
+               $table->align = array();
+               $table->size = array();
+               $table->wrap = array();
+               // picture column, if required
+               if ($is_html) {
+                       $table->head[] = $spacer;
+                       $table->align[] = 'center';
+                       $table->size[] = 10;
+                       $table->wrap[] = "nowrap";
+               }
+               array_push($table->head, 
+                       get_string("name"), 
+                       hotpot_grade_heading($hotpot, $options),
+                       get_string("attempt", "quiz"), 
+                       get_string("time", "quiz"), 
+                       get_string("reportstatus", "hotpot"), 
+                       get_string("timetaken", "quiz"), 
+                       get_string("score", "quiz")
+               );
+               array_push($table->align, "left", "center", "center", "left", "center", "center", "center");
+               array_push($table->wrap, "nowrap", "nowrap", "nowrap", "nowrap", "nowrap", "nowrap", "nowrap");
+               array_push($table->size, "*", "*", "*", "*", "*", "*", "*");
+               $abandoned = 0;
+               foreach ($users as $user) {
+                       // shortcut to user info held in first attempt record
+                       $u = &$user->attempts[0];
+                       $picture = '';
+                       $name = fullname($u);
+                       if ($is_html) {
+                               $picture = print_user_picture($u->userid, $course->id, $u->picture, false, true);
+                               $name = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$u->userid.'&course='.$course->id.'">'.$name.'</a>';
+                       }
+                       $grade = isset($user->grade) && $user->grade<>'&nbsp;' ? $user->grade : $spacer;
+                       $attemptcount = count($user->attempts);
+                       if ($attemptcount>1) {
+                               $text = $name;
+                               $name = NULL;
+                               $name->text = $text;
+                               $name->rowspan = $attemptcount;
+                               $text = $grade;
+                               $grade = NULL;
+                               $grade->text = $text;
+                               $grade->rowspan = $attemptcount;
+                       }
+                       $data = array();
+                       if ($is_html) {
+                               if ($attemptcount>1) {
+                                       $text = $picture;
+                                       $picture = NULL;
+                                       $picture->text = $text;
+                                       $picture->rowspan = $attemptcount;
+                               }
+                               $data[] = $picture;
+                       }
+                       array_push($data, $name, $grade);
+                       foreach ($user->attempts as $attempt) {
+                               // increment count of abandoned attempts
+                               // if attempt is marked as finished but has no score
+                               if ($attempt->status==HOTPOT_STATUS_ABANDONED) {
+                                       $abandoned++;
+                               }
+                               $attemptnumber = $attempt->attempt;
+                               $starttime = trim(userdate($attempt->timestart, $strtimeformat));
+                               if ($is_html && isset($attempt->score) && (has_capability('mod/hotpot:viewreport',get_context_instance(CONTEXT_COURSE, $course->id)) || $hotpot->review)) {
+                                       $attemptnumber = '<a href="review.php?hp='.$hotpot->id.'&attempt='.$attempt->id.'">'.$attemptnumber.'</a>';
+                                       $starttime = '<a href="review.php?hp='.$hotpot->id.'&attempt='.$attempt->id.'">'.$starttime.'</a>';
+                               }
+                               if ($is_html && has_capability('mod/hotpot:viewreport',get_context_instance(CONTEXT_COURSE, $course))) {
+                                       $checkbox = '<input type=checkbox name="box'.$attempt->clickreportid.'" value="'.$attempt->clickreportid.'">'.$spacer;
+                               } else {
+                                       $checkbox = '';
+                               }
+                               $timetaken = empty($attempt->timefinish) ? $spacer : format_time($attempt->timefinish - $attempt->timestart);
+                               $score = hotpot_format_score($attempt);
+                               if ($is_html && is_numeric($score) && $score==$user->grade) { // best grade
+                                       $score = '<span class="highlight">'.$score.'</span>';
+                               }
+                               array_push($data, 
+                                       $attemptnumber,
+                                       $checkbox.$starttime,
+                                       hotpot_format_status($attempt),
+                                       $timetaken,
+                                       $score
+                               );
+                               $table->data[] = $data;
+                               $data = array();
+                       } // end foreach $attempt
+                       $table->data[] = 'hr';
+               } // end foreach $user
+               // remove final 'hr' from data rows
+               array_pop($table->data);
+               // add the "delete" form to the table
+               if ($options['reportformat']=='htm' && has_capability('mod/hotpot:viewreport',get_context_instance(CONTEXT_COURSE, $course->id))) {
+                       $strdeletecheck = get_string('deleteattemptcheck','quiz');
+                       $table->start = $this->deleteform_javascript();
+                       $table->start .= '<form method="post" action="report.php" name="deleteform" onsubmit="'."return deletecheck('".$strdeletecheck."', 'selection')".'">'."\n";
+                       $table->start .= '<input type="hidden" name="del" value="selection">'."\n";
+                       $table->start .= '<input type="hidden" name="id" value="'.$cm->id.'">'."\n";
+                       $table->finish = '<center>'."\n";
+                       $table->finish .= '<input type="submit" value="'.get_string("deleteselected").'">&nbsp;'."\n";
+                       if ($abandoned) {
+                               $table->finish .= '<input type=button value="'.get_string('deleteabandoned', 'hotpot').'" onClick="if(deletecheck('."'".addslashes(get_string('deleteabandonedcheck', 'hotpot', $abandoned))."', 'abandoned', true".'))document.deleteform.submit();">'."\n";
+                       }
+                       $table->finish .= '<input type=button value="'.get_string("deleteall").'" onClick="if(deletecheck('."'".addslashes($strdeletecheck)."', 'all', true".'))document.deleteform.submit();">'."\n";
+                       $table->finish .= '</center>'."\n";
+                       $table->finish .= '</form>'."\n";
+               }
+               $tables[] = &$table;
+       }
+       function deleteform_javascript() {
+               $strselectattempt = addslashes(get_string('selectattempt','hotpot'));
+               return <<<END_OF_JAVASCRIPT
+<script type="text/javascript">
+<!--
+function deletecheck(p, v, x) {
+       var r = false; // result
+       // get length of form elements
+       var f = document.deleteform;
+       var l = f ? f.elements.length : 0;
+       // count selected items, if necessary
+       if (!x) {
+               x = 0;
+               for (var i=0; i<l; i++) {
+                       var obj = f.elements[i];
+                       if (obj.type && obj.type=='checkbox' && obj.checked) {
+                               x++;
+                       }
+               }
+       }
+       // confirm deletion
+       var n = navigator;
+       if (x || (n.appName=='Netscape' && parseint(n.appVersion)==2)) {
+               r = confirm(p);
+               if (r) {
+                       f.del.value = v;
+               }
+       } else {
+               alert('$strselectattempt');
+       }
+       return r;
+}
+//-->
+</script>
+END_OF_JAVASCRIPT
+;
+       } // end function
+} // end class
+?>