/// Check login.
require_login($attemptobj->get_courseid(), false, $attemptobj->get_cm());
+/// Check that this attempt belongs to this user.
+ if ($attemptobj->get_userid() != $USER->id) {
+ redirect($attemptobj->review_url(0, $page));
+ }
+
/// Check capabilites.
- if (!$attemptobj->is_preview_user()) {
- require_capability('mod/quiz:attempt', $context);
+ if ($attemptobj->is_preview_user()) {
+ } else {
+ $attemptobj->require_capability('mod/quiz:attempt');
}
/// Log continuation of the attempt, but only if some time has passed.
}
} else {
/// Just a heading.
- if ($quiz->attempts != 1) {
- print_heading(format_string($quiz->name).' - '.$title);
+ if ($attemptobj->get_num_attempts_allowed() != 1) {
+ print_heading(format_string($attemptobj->get_quiz_name()).' - '.$title);
} else {
- print_heading(format_string($quiz->name));
+ print_heading(format_string($attemptobj->get_quiz_name()));
}
}
return $this->quiz->name;
}
+ /** @return integer the number of attempts allowed at this quiz (0 = infinite). */
+ public function get_num_attempts_allowed() {
+ return $this->quiz->attempts;
+ }
+
/** @return integer the course_module id. */
public function get_cmid() {
return $this->cm->id;
* to jump to a particuar question on the page.
* @param boolean $showall if true, the URL will be to review the entire attempt on one page,
* and $page will be ignored.
+ * @param $otherattemptid if given, link to another attempt, instead of the one we represent.
* @return string the URL to review this attempt.
*/
public function review_url($questionid = 0, $page = -1, $showall = false, $otherattemptid = null) {
if ($attemptobj->is_preview_user() && $reviewofownattempt) {
$strreviewtitle = get_string('reviewofpreview', 'quiz');
} else {
- $strreviewtitle = get_string('reviewofattempt', 'quiz', $attempt->attempt);
+ $strreviewtitle = get_string('reviewofattempt', 'quiz', $attemptobj->get_attempt_number());
}
/// Print the page header
/// 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 = $DB->get_record('user', array('id' => $attempt->userid));
- $picture = print_user_picture($student, $course->id, $student->picture, false, true);
+ if ($attemptobj->get_userid() <> $USER->id) {
+ $student = $DB->get_record('user', array('id' => $attemptobj->get_userid()));
+ $picture = print_user_picture($student, $attemptobj->get_courseid(), $student->picture, false, true);
$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 . '">' .
+ $CFG->wwwroot . '/user/view.php?id=' . $student->id . '&course=' . $attemptobj->get_courseid() . '">' .
fullname($student, true) . '</a></td></tr>';
}
if (has_capability('mod/quiz:viewreports', $context) &&
/// Get the summary info for each question.
$questionids = $attemptobj->get_question_ids();
foreach ($attemptobj->get_question_iterator() as $number => $question) {
+ if ($question->length == 0) {
+ continue;
+ }
$row = array('<a href="' . $attemptobj->attempt_url($question->id) . '">' . $number . '</a>',
get_string($attemptobj->get_question_status($question->id), 'quiz'));
if ($scorescolumn) {
print_error('cannotcallscript');
}
$quiz = $attemptobj->get_quiz();
+ $cm = $attemptobj->get_cm();
}
if (!isset($currenttab)) {
$currenttab = '';
$activated = array();
if (has_capability('mod/quiz:view', $context)) {
- $row[] = new tabobject('info', "$CFG->wwwroot/mod/quiz/view.php?q=$quiz->id", get_string('info', 'quiz'));
+ $row[] = new tabobject('info', "$CFG->wwwroot/mod/quiz/view.php?id=$cm->id", get_string('info', 'quiz'));
}
if (has_capability('mod/quiz:viewreports', $context)) {
$row[] = new tabobject('reports', "$CFG->wwwroot/mod/quiz/report.php?q=$quiz->id", get_string('results', 'quiz'));
}
if (has_capability('mod/quiz:preview', $context)) {
- $row[] = new tabobject('preview', "$CFG->wwwroot/mod/quiz/startattempt.php?q=$quiz->id", get_string('preview', 'quiz'));
+ $row[] = new tabobject('preview', "$CFG->wwwroot/mod/quiz/startattempt.php?cmid=$cm->id&sesskey=" . sesskey(), get_string('preview', 'quiz'));
}
if (has_capability('mod/quiz:manage', $context)) {
$row[] = new tabobject('edit', "$CFG->wwwroot/mod/quiz/edit.php?cmid=$cm->id", get_string('edit'));