Example #1
0
 function create_responses_table(&$hotpot, &$course, &$users, &$attempts, &$questions, &$options, &$tables)
 {
     global $CFG;
     $is_html = $options['reportformat'] == 'htm';
     // shortcuts for font tags
     $br = $is_html ? "<br />\n" : "\n";
     $blank = $is_html ? '&nbsp;' : "";
     $font_end = $is_html ? '</font>' : '';
     $font_red = $is_html ? '<font color="red">' : '';
     $font_blue = $is_html ? '<font color="blue">' : '';
     $font_brown = $is_html ? '<font color="brown">' : '';
     $font_green = $is_html ? '<font color="green">' : '';
     $font_small = $is_html ? '<font size="-2">' : '';
     $nobr_start = $is_html ? '<nobr>' : '';
     $nobr_end = $is_html ? '</nobr>' : '';
     // is review allowed? (do this once here, to save time later)
     $allow_review = $is_html && (has_capability('mod/hotpot:viewreport', get_context_instance(CONTEXT_COURSE, $course->id)) || $hotpot->review);
     // assume penalties column is NOT required
     $show_penalties = false;
     // initialize $table
     unset($table);
     $table->border = 1;
     $table->width = '100%';
     // initialize legend, if necessary
     if (!empty($options['reportshowlegend'])) {
         $table->legend = array();
     }
     // headings for name, attempt number, score/grade and penalties
     $table->head = array(get_string("name"), hotpot_grade_heading($hotpot, $options), get_string('attempt', 'quiz'));
     $table->align = array('left', 'center', 'center');
     $table->size = array(150, 80, 10);
     $table->wrap = array(0, 0, 0);
     $table->fontsize = array(0, 0, 0);
     // question headings
     $this->add_question_headings($questions, $table, 'left', 0, false, 2);
     // penalties (not always needed) and raw score
     array_push($table->head, get_string('penalties', 'hotpot'), get_string('score', 'quiz'));
     array_push($table->align, 'center', 'center');
     array_push($table->size, 50, 50);
     array_push($table->wrap, 0, 0);
     array_push($table->fontsize, 0, 0);
     // message strings
     $strnoresponse = get_string('noresponse', 'quiz');
     // array to map columns onto question ids ($col => $id)
     $questionids = array_keys($questions);
     // add details of users' responses
     foreach ($users as $user) {
         // shortcut to user info held in first attempt record
         $u =& $user->attempts[0];
         if (function_exists("fullname")) {
             $name = fullname($u);
         } else {
             $name = "{$u->firstname} {$u->lastname}";
         }
         if ($is_html) {
             $name = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $u->userid . '&amp;course=' . $course->id . '">' . $name . '</a>';
         }
         $grade = isset($user->grade) ? $user->grade : $blank;
         foreach ($user->attempts as $attempt) {
             $attemptnumber = $attempt->attempt;
             if ($allow_review) {
                 $attemptnumber = ' <a href="review.php?hp=' . $hotpot->id . '&amp;attempt=' . $attempt->id . '">' . $attemptnumber . '</a>';
             }
             $cells = array($name, $grade, $attemptnumber);
             // $name and $grade are only printed on first line per user
             $name = $blank;
             $grade = $blank;
             $start_col = count($cells);
             foreach ($questionids as $col => $id) {
                 $cells[$start_col + $col] = "{$font_brown}({$strnoresponse}){$font_end}";
             }
             if (isset($attempt->penalties)) {
                 $show_penalties = true;
                 $penalties = $attempt->penalties;
             } else {
                 $penalties = $blank;
             }
             array_push($cells, $penalties, hotpot_format_score($attempt));
             // get responses to questions in this attempt
             foreach ($attempt->responses as $response) {
                 // check this question id is OK (should be)
                 $col = array_search($response->question, $questionids);
                 if (is_numeric($col)) {
                     // correct
                     if ($value = hotpot_strings($response->correct)) {
                         $this->set_legend($table, $col, $value, $questions[$response->question]);
                     } else {
                         $value = "({$strnoresponse})";
                     }
                     $cell = $font_red . $value . $font_end;
                     // wrong
                     if ($value = hotpot_strings($response->wrong)) {
                         if (isset($table->legend)) {
                             $values = array();
                             foreach (explode(',', $value) as $v) {
                                 $this->set_legend($table, $col, $v, $questions[$response->question]);
                                 $values[] = $v;
                             }
                             $value = implode(',', $values);
                         }
                         $cell .= $br . $font_blue . $value . $font_end;
                     }
                     // ignored
                     if ($value = hotpot_strings($response->ignored)) {
                         if (isset($table->legend)) {
                             $values = array();
                             foreach (explode(',', $value) as $v) {
                                 $this->set_legend($table, $col, $v, $questions[$response->question]);
                                 $values[] = $v;
                             }
                             $value = implode(',', $values);
                         }
                         $cell .= $br . $font_brown . $value . $font_end;
                     }
                     // numeric
                     if (is_numeric($response->score)) {
                         if (empty($table->caption)) {
                             $table->caption = get_string('indivresp', 'quiz');
                             if ($is_html) {
                                 $table->caption .= helpbutton('responsestable', $table->caption, 'hotpot', true, false, '', true);
                             }
                         }
                         $hints = empty($response->hints) ? 0 : $response->hints;
                         $clues = empty($response->clues) ? 0 : $response->clues;
                         $checks = empty($response->checks) ? 0 : $response->checks;
                         $numeric = $response->score . '% ' . $blank . ' (' . $hints . ',' . $clues . ',' . $checks . ')';
                         $cell .= $br . $nobr_start . $font_green . $numeric . $font_end . $nobr_end;
                     }
                     $cells[$start_col + $col] = $cell;
                 }
             }
             $table->data[] = $cells;
         }
         // insert 'tabledivider' between users
         $table->data[] = 'hr';
     }
     // end foreach $users
     // remove final 'hr' from data rows
     array_pop($table->data);
     if (!$show_penalties) {
         $col = 3 + count($questionids);
         $this->remove_column($table, $col);
     }
     $tables[] =& $table;
 }
Example #2
0
 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 . '&amp;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 . '&amp;attempt=' . $attempt->id . '">' . $attemptnumber . '</a>';
                 $starttime = '<a href="review.php?hp=' . $hotpot->id . '&amp;attempt=' . $attempt->id . '">' . $starttime . '</a>';
             }
             if ($is_html && has_capability('mod/hotpot:viewreport', get_context_instance(CONTEXT_COURSE, $course->id))) {
                 $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" id="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_js(get_string('deleteabandonedcheck', 'hotpot', $abandoned)) . "', 'abandoned', true" . ')) document.getElementById(\'deleteform\').submit();" />' . "\n";
         }
         $table->finish .= '<input type="button" value="' . get_string("deleteall") . '" onClick="if(deletecheck(' . "'" . addslashes_js($strdeletecheck) . "', 'all', true" . '))document.getElementById(\'deleteform\').submit();" />' . "\n";
         $table->finish .= '</center>' . "\n";
         $table->finish .= '</form>' . "\n";
     }
     $tables[] =& $table;
 }
Example #3
0
 function create_scores_table(&$hotpot, &$course, &$users, &$attempts, &$questions, &$options, &$tables)
 {
     global $CFG;
     $download = $options['reportformat'] == 'htm' ? false : true;
     $is_html = $options['reportformat'] == 'htm';
     $blank = $download ? '' : '&nbsp;';
     $no_value = $download ? '' : '-';
     $allow_review = true;
     // start the table
     unset($table);
     $table->border = 1;
     $table->head = array();
     $table->align = array();
     $table->size = array();
     // picture column, if required
     if ($is_html) {
         $table->head[] = '&nbsp;';
         $table->align[] = 'center';
         $table->size[] = 10;
     }
     // name, grade and attempt number
     array_push($table->head, get_string("name"), hotpot_grade_heading($hotpot, $options), get_string("attempt", "quiz"));
     array_push($table->align, "left", "center", "center");
     array_push($table->size, '', '', '');
     // question headings
     $this->add_question_headings($questions, $table);
     // penalties and raw score
     array_push($table->head, get_string('penalties', 'hotpot'), get_string('score', 'quiz'));
     array_push($table->align, "center", "center");
     array_push($table->size, '', '');
     $table->data = array();
     $q = array('grade' => array('count' => 0, 'total' => 0), 'penalties' => array('count' => 0, 'total' => 0), 'score' => array('count' => 0, 'total' => 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>';
         }
         if (isset($user->grade)) {
             $grade = $user->grade;
             $q['grade']['count']++;
             if (is_numeric($grade)) {
                 $q['grade']['total'] += $grade;
             }
         } else {
             $grade = $no_value;
         }
         $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) {
             // set flag if this is best grade
             $is_best_grade = $is_html && $attempt->score == $user->grade;
             // get attempt number
             $attemptnumber = $attempt->attempt;
             if ($is_html && $allow_review) {
                 $attemptnumber = '<a href="review.php?hp=' . $hotpot->id . '&attempt=' . $attempt->id . '">' . $attemptnumber . '</a>';
             }
             if ($is_best_grade) {
                 $score = '<span class="highlight">' . $attemptnumber . '</span>';
             }
             $data[] = $attemptnumber;
             // get responses to questions in this attempt by this user
             foreach ($questions as $id => $question) {
                 if (!isset($q[$id])) {
                     $q[$id] = array('count' => 0, 'total' => 0);
                 }
                 if (isset($attempt->responses[$id])) {
                     $score = $attempt->responses[$id]->score;
                     if (is_numeric($score)) {
                         $q[$id]['count']++;
                         $q[$id]['total'] += $score;
                         if ($is_best_grade) {
                             $score = '<span class="highlight">' . $score . '</span>';
                         }
                     } else {
                         if (empty($score)) {
                             $score = $no_value;
                         }
                     }
                 } else {
                     $score = $no_value;
                 }
                 $data[] = $score;
             }
             // foreach $questions
             if (isset($attempt->penalties)) {
                 $penalties = $attempt->penalties;
                 if (is_numeric($penalties)) {
                     $q['penalties']['count']++;
                     $q['penalties']['total'] += $penalties;
                 }
                 if ($is_best_grade) {
                     $penalties = '<span class="highlight">' . $penalties . '</span>';
                 }
             } else {
                 $penalties = $no_value;
             }
             $data[] = $penalties;
             if (isset($attempt->score)) {
                 $score = $attempt->score;
                 if (is_numeric($score)) {
                     $q['score']['total'] += $score;
                     $q['score']['count']++;
                 }
                 if ($is_best_grade) {
                     $score = '<span class="highlight">' . $score . '</span>';
                 }
             } else {
                 $score = $no_value;
             }
             $data[] = $score;
             // append data for this attempt
             $table->data[] = $data;
             // reset data array for next attempt, if any
             $data = array();
         }
         // end foreach $attempt
         $table->data[] = 'hr';
     }
     // end foreach $user
     // remove final 'hr' from data rows
     array_pop($table->data);
     // add averages to foot of table
     $averages = array();
     if ($is_html) {
         $averages[] = $blank;
     }
     array_push($averages, get_string('average', 'hotpot'));
     $col = count($averages);
     if (empty($q['grade']['count'])) {
         // remove score $col from $table
         $this->remove_column($table, $col);
     } else {
         $precision = $hotpot->grademethod == HOTPOT_GRADEMETHOD_AVERAGE || $hotpot->grade < 100 ? 1 : 0;
         $averages[] = round($q['grade']['total'] / $q['grade']['count'], $precision);
         $col++;
     }
     // skip the attempt number column
     $averages[$col++] = $blank;
     foreach ($questions as $id => $question) {
         if (empty($q[$id]['count'])) {
             // remove this question $col from $table
             $this->remove_column($table, $col);
         } else {
             $averages[$col++] = round($q[$id]['total'] / $q[$id]['count']);
         }
     }
     if (empty($q['penalties']['count'])) {
         // remove penalties $col from $table
         $this->remove_column($table, $col);
     } else {
         $averages[$col++] = round($q['penalties']['total'] / $q['penalties']['count']);
     }
     if (empty($q['score']['count'])) {
         // remove score $col from $table
         $this->remove_column($table, $col);
     } else {
         $averages[$col++] = round($q['score']['total'] / $q['score']['count']);
     }
     $table->foot = array($averages);
     $tables[] =& $table;
 }