$accessmanager->print_finish_review_link($canpreview);
}
-/// Print infobox
+/// Work out some time-related things.
$timelimit = (int)$quiz->timelimit * 60;
$overtime = 0;
- $grade = quiz_rescale_grade($attempt->sumgrades, $quiz);
- $feedback = quiz_feedback_for_grade($grade, $attempt->quiz);
if ($attempt->timefinish) {
if ($timetaken = ($attempt->timefinish - $attempt->timestart)) {
} else {
$timetaken = get_string('unfinished', 'quiz');
}
- echo '<table class="generaltable generalbox quizreviewsummary"><tbody>';
+
+/// Print summary table about the whole attempt.
+/// First we assemble all the rows that are appopriate to the current situation in
+/// an array, then later we only output the table if there are any rows to show.
+ $rows = array();
if ($attempt->userid <> $USER->id) {
$student = get_record('user', 'id', $attempt->userid);
$picture = print_user_picture($student, $course->id, $student->picture, false, true);
- echo '<tr><th scope="row" class="cell">', $picture, '</th><td class="cell"><a href="', $CFG->wwwroot,
- '/user/view.php?id=', $student->id, '&course='.$course->id.'">',
- fullname($student, true), '</a></td></tr>';
+ $rows[] = '<tr><th scope="row" class="cell">' . $picture . '</th><td class="cell"><a href="' .
+ $CFG->wwwroot . '/user/view.php?id=' . $student->id . '&course=' . $course->id . '">' .
+ fullname($student, true) . '</a></td></tr>';
}
- if (has_capability('mod/quiz:grade', $context) and
+ if (has_capability('mod/quiz:viewreports', $context) &&
count($attempts = get_records_select('quiz_attempts', "quiz = '$quiz->id' AND userid = '$attempt->userid'", 'attempt ASC')) > 1) {
- // print list of attempts
- $attemptlist = '';
+ /// List of all this user's attempts for people who can see reports.
+ $urloptions = '';
+ if ($showall) {
+ $urloptions .= '&showall=true';
+ } else if ($page > 0) {
+ $urloptions .= '&page=' . $page;
+ }
+ $attemptlist = array();
foreach ($attempts as $at) {
- $attemptlist .= ($at->id == $attempt->id)
- ? '<strong>'.$at->attempt.'</strong>, '
- : '<a href="review.php?attempt='.$at->id.($showall?'&showall=true':'').'">'.$at->attempt.'</a>, ';
+ if ($at->id == $attempt->id) {
+ $attemptlist[] = '<strong>' . $at->attempt . '</strong>';
+ } else {
+ $attemptlist[] = '<a href="review.php?attempt=' . $at->id . $urloptions . ' ">' . $at->attempt . '</a>';
+ }
}
- echo '<tr><th scope="row" class="cell">', get_string('attempts', 'quiz'), '</th><td class="cell">',
- trim($attemptlist, ' ,'), '</td></tr>';
+ $rows[] = '<tr><th scope="row" class="cell">' . get_string('attempts', 'quiz') .
+ '</th><td class="cell">' . implode(', ', $attemptlist) . '</td></tr>';
}
- echo '<tr><th scope="row" class="cell">', get_string('startedon', 'quiz'), '</th><td class="cell">',
- userdate($attempt->timestart), '</td></tr>';
+/// Timing information.
+ $rows[] = '<tr><th scope="row" class="cell">' . get_string('startedon', 'quiz') .
+ '</th><td class="cell">' . userdate($attempt->timestart) . '</td></tr>';
if ($attempt->timefinish) {
- echo '<tr><th scope="row" class="cell">', get_string('completedon', 'quiz'), '</th><td class="cell">',
- userdate($attempt->timefinish), '</td></tr>';
- echo '<tr><th scope="row" class="cell">', get_string('timetaken', 'quiz'), '</th><td class="cell">',
- $timetaken, '</td></tr>';
+ $rows[] = '<tr><th scope="row" class="cell">' . get_string('completedon', 'quiz') . '</th><td class="cell">' .
+ userdate($attempt->timefinish) . '</td></tr>';
+ $rows[] = '<tr><th scope="row" class="cell">' . get_string('timetaken', 'quiz') . '</th><td class="cell">' .
+ $timetaken . '</td></tr>';
}
if (!empty($overtime)) {
- echo '<tr><th scope="row" class="cell">', get_string('overdue', 'quiz'), '</th><td class="cell">',$overtime, '</td></tr>';
+ $rows[] = '<tr><th scope="row" class="cell">' . get_string('overdue', 'quiz') . '</th><td class="cell">' . $overtime . '</td></tr>';
}
- //if the student is allowed to see their score
+
+/// Show scores (if the user is allowed to see scores at the moment).
+ $grade = quiz_rescale_grade($attempt->sumgrades, $quiz);
if ($options->scores) {
if ($quiz->grade and $quiz->sumgrades) {
if($overtime) {
$result->grade = "0.0";
}
+ /// Show raw marks only if they are different from the grade (like on the view page.
+ if ($quiz->grade != $quiz->sumgrades) {
+ $a = new stdClass;
+ $a->grade = round($attempt->sumgrades, $CFG->quiz_decimalpoints);
+ $a->maxgrade = $quiz->sumgrades;
+ $rows[] = '<tr><th scope="row" class="cell">' . get_string('marks', 'quiz') . '</th><td class="cell">' .
+ get_string('outofshort', 'quiz', $a) . '</td></tr>';
+ }
+
+ /// Now the scaled grade.
$a = new stdClass;
- $percentage = round(($attempt->sumgrades/$quiz->sumgrades)*100, 0);
- $a->grade = $grade;
+ $a->grade = '<b>' . $grade . '</b>';
$a->maxgrade = $quiz->grade;
- $rawscore = round($attempt->sumgrades, $CFG->quiz_decimalpoints);
- echo '<tr><th scope="row" class="cell">', get_string('score', 'quiz'), '</th><td class="cell">',
- "$rawscore/$quiz->sumgrades ($percentage%)", '</td></tr>';
- echo '<tr><th scope="row" class="cell">', get_string('grade'), '</th><td class="cell">',
- get_string('outof', 'quiz', $a), '</td></tr>';
+ $a->percent = '<b>' . round(($attempt->sumgrades/$quiz->sumgrades)*100, 0) . '</b>';
+ $rows[] = '<tr><th scope="row" class="cell">' . get_string('grade') . '</th><td class="cell">' .
+ get_string('outofpercent', 'quiz', $a) . '</td></tr>';
}
}
+
+/// Feedback if there is any, and the user is allowed to see it now.
+ $feedback = quiz_feedback_for_grade($grade, $attempt->quiz);
if ($options->overallfeedback && $feedback) {
- echo '<tr><th scope="row" class="cell">', get_string('feedback', 'quiz'), '</th><td class="cell">',
- $feedback, '</td></tr>';
+ $rows[] = '<tr><th scope="row" class="cell">' . get_string('feedback', 'quiz') .
+ '</th><td class="cell">' . $feedback . '</td></tr>';
+ }
+
+/// Now output the summary table, if there are any rows to be shown.
+ if (!empty($rows)) {
+ echo '<table class="generaltable generalbox quizreviewsummary"><tbody>', "\n";
+ echo implode("\n", $rows);
+ echo "\n</tbody></table>\n";
}
- echo '</tbody></table>';
/// Print the navigation panel if required
$numpages = quiz_number_of_pages($attempt->layout);
print_heading(get_string('summaryofattempts', 'quiz'));
- // Get some strings.
- $strattempt = get_string("attempt", "quiz");
- $strtimetaken = get_string("timetaken", "quiz");
- $strtimecompleted = get_string("timecompleted", "quiz");
- $strgrade = get_string("grade");
- $strmarks = get_string('marks', 'quiz');
- $strfeedback = get_string('feedback', 'quiz');
-
// Work out which columns we need, taking account what data is available in each attempt.
list($someoptions, $alloptions) = quiz_get_combined_reviewoptions($quiz, $attempts, $context);
// Prepare table header
$table->class = 'generaltable quizattemptsummary';
- $table->head = array($strattempt, $strtimecompleted);
- $table->align = array("center", "left");
- $table->size = array("", "");
+ $table->head = array(get_string('attempt', 'quiz'), get_string('timecompleted', 'quiz'));
+ $table->align = array('center', 'left');
+ $table->size = array('', '');
if ($markcolumn) {
- $table->head[] = "$strmarks / $quiz->sumgrades";
+ $table->head[] = get_string('marks', 'quiz') . " / $quiz->sumgrades";
$table->align[] = 'center';
$table->size[] = '';
}
if ($gradecolumn) {
- $table->head[] = "$strgrade / $quiz->grade";
+ $table->head[] = get_string('grade') . " / $quiz->grade";
$table->align[] = 'center';
$table->size[] = '';
}
if ($feedbackcolumn) {
- $table->head[] = $strfeedback;
+ $table->head[] = get_string('feedback', 'quiz');
$table->align[] = 'left';
$table->size[] = '';
}
if (isset($quiz->showtimetaken)) {
- $table->head[] = $strtimetaken;
+ $table->head[] = get_string('timetaken', 'quiz');
$table->align[] = 'left';
$table->size[] = '';
}