Example #1
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 ? ' ' : ' ';
     $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 #2
0
function hotpot_print_attempt_summary(&$hotpot, &$attempt)
{
    // start table
    print_simple_box_start("center", "80%", "#ffffff", 0);
    print '<table width="100%" border="1" valign="top" align="center" cellpadding="2" cellspacing="2" class="generaltable">' . "\n";
    // add attempt properties
    $fields = array('attempt', 'score', 'penalties', 'status', 'timetaken', 'timerecorded');
    foreach ($fields as $field) {
        switch ($field) {
            case 'score':
                $value = hotpot_format_score($attempt);
                break;
            case 'status':
                $value = hotpot_format_status($attempt);
                break;
            case 'timerecorded':
                $value = empty($attempt->timefinish) ? '-' : userdate($attempt->timefinish);
                break;
            case 'timetaken':
                $value = empty($attempt->timefinish) ? '-' : format_time($attempt->timefinish - $attempt->timestart);
                break;
            default:
                $value = isset($attempt->{$field}) ? $attempt->{$field} : NULL;
        }
        if (isset($value)) {
            switch ($field) {
                case 'status':
                case 'timerecorded':
                    $name = get_string('report' . $field, 'hotpot');
                    break;
                case 'penalties':
                    $name = get_string('penalties', 'hotpot');
                    break;
                default:
                    $name = get_string($field, 'quiz');
            }
            print '<tr><th align="right" width="100" class="generaltableheader" scope="row">' . $name . ':</th><td class="generaltablecell">' . $value . '</td></tr>';
        }
    }
    // finish table
    print '</table>';
    print_simple_box_end();
}