From b9b3aa94594dda47955b925592d085ec0c016e17 Mon Sep 17 00:00:00 2001 From: tjhunt Date: Thu, 10 Jul 2008 17:23:56 +0000 Subject: [PATCH] MDL-15452 - Fix regressions introduced by my recent work on this bug and its children. Thanks to Paul Johnson for his testing. --- mod/quiz/attempt.php | 16 +++++++++++----- mod/quiz/attemptlib.php | 6 ++++++ mod/quiz/review.php | 10 +++++----- mod/quiz/summary.php | 3 +++ mod/quiz/tabs.php | 5 +++-- 5 files changed, 28 insertions(+), 12 deletions(-) diff --git a/mod/quiz/attempt.php b/mod/quiz/attempt.php index ed64dc35276..985a7a7f5e8 100644 --- a/mod/quiz/attempt.php +++ b/mod/quiz/attempt.php @@ -44,9 +44,15 @@ /// 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. @@ -242,10 +248,10 @@ if ($page == -1) { } } 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())); } } diff --git a/mod/quiz/attemptlib.php b/mod/quiz/attemptlib.php index 5ad9179d96c..7d2169a1581 100644 --- a/mod/quiz/attemptlib.php +++ b/mod/quiz/attemptlib.php @@ -118,6 +118,11 @@ class quiz { 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; @@ -569,6 +574,7 @@ class quiz_attempt extends quiz { * 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) { diff --git a/mod/quiz/review.php b/mod/quiz/review.php index b7748e685fe..2891daa15b7 100644 --- a/mod/quiz/review.php +++ b/mod/quiz/review.php @@ -63,7 +63,7 @@ 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 @@ -125,11 +125,11 @@ /// 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[] = '' . $picture . '' . + $CFG->wwwroot . '/user/view.php?id=' . $student->id . '&course=' . $attemptobj->get_courseid() . '">' . fullname($student, true) . ''; } if (has_capability('mod/quiz:viewreports', $context) && diff --git a/mod/quiz/summary.php b/mod/quiz/summary.php index ee5fd23ec7a..a6fefe3b2fc 100644 --- a/mod/quiz/summary.php +++ b/mod/quiz/summary.php @@ -83,6 +83,9 @@ $table->data = array(); /// 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('' . $number . '', get_string($attemptobj->get_question_status($question->id), 'quiz')); if ($scorescolumn) { diff --git a/mod/quiz/tabs.php b/mod/quiz/tabs.php index 456a043f0fa..56a7dff896c 100644 --- a/mod/quiz/tabs.php +++ b/mod/quiz/tabs.php @@ -12,6 +12,7 @@ if (empty($quiz)) { print_error('cannotcallscript'); } $quiz = $attemptobj->get_quiz(); + $cm = $attemptobj->get_cm(); } if (!isset($currenttab)) { $currenttab = ''; @@ -32,13 +33,13 @@ $inactive = array(); $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'));