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 . '&course=' . $course->id . '">' . $name . '</a>'; } $grade = isset($user->grade) && $user->grade != ' ' ? $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->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") . '" /> ' . "\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; }
function hotpot_print_recent_mod_activity($activity, $course, $detail = false) { /// Basically, this function prints the results of "hotpot_get_recent_activity" global $CFG, $THEME, $USER; if (isset($THEME->cellcontent2)) { $bgcolor = ' bgcolor="' . $THEME->cellcontent2 . '"'; } else { $bgcolor = ''; } print '<table border="0" cellpadding="3" cellspacing="0">'; print '<tr><td' . $bgcolor . ' class="forumpostpicture" width="35" valign="top">'; print_user_picture($activity->user->userid, $course, $activity->user->picture); print '</td><td width="100%"><font size="2">'; if ($detail) { // activity icon $src = "{$CFG->modpixpath}/{$activity->type}/icon.gif"; print '<img src="' . $src . '" class="icon" alt="' . $activity->type . '" /> '; // link to activity $href = "{$CFG->wwwroot}/mod/hotpot/view.php?hp={$activity->instance}"; print '<a href="' . $href . '">' . $activity->name . '</a> - '; } if (has_capability('mod/hotpot:viewreport', get_context_instance(CONTEXT_COURSE, $course))) { // score (with link to attempt details) $href = "{$CFG->wwwroot}/mod/hotpot/review.php?hp={$activity->instance}&attempt=" . $activity->content->attemptid; print '<a href="' . $href . '">(' . hotpot_format_score($activity->content) . ')</a> '; // attempt number print get_string('attempt', 'quiz') . ' - ' . $activity->content->attempt . '<br />'; } // link to user $href = "{$CFG->wwwroot}/user/view.php?id={$activity->user}->userid&course={$course}"; print '<a href="' . $href . '">' . $activity->user->fullname . '</a> '; // time and date print ' - ' . userdate($activity->timestamp); // duration $duration = format_time($activity->content->timestart - $activity->content->timefinish); print " ({$duration})"; print "</font></td></tr>"; print "</table>"; }
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(); }
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 ? ' ' : ""; $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 . '&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 . '&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; }