]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-15452 - Fix regressions introduced by my recent work on this bug and its children...
authortjhunt <tjhunt>
Thu, 10 Jul 2008 17:23:56 +0000 (17:23 +0000)
committertjhunt <tjhunt>
Thu, 10 Jul 2008 17:23:56 +0000 (17:23 +0000)
mod/quiz/attempt.php
mod/quiz/attemptlib.php
mod/quiz/review.php
mod/quiz/summary.php
mod/quiz/tabs.php

index ed64dc35276dc9a92df820fbbf9b7e2c70492d77..985a7a7f5e83487cf00a79612f47d74864a4520c 100644 (file)
 /// 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()));
         }
     }
 
index 5ad9179d96cc5a6b1c68a6807ddce272790b4e5e..7d2169a1581bb6ead60d1fd4be4760cb13ac51f7 100644 (file)
@@ -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) {
index b7748e685fe297ff7e5d213a2561aa9ad8e9a632..2891daa15b7a79c30e6d9f4d3ebea72ffa96d22a 100644 (file)
@@ -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
 /// 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 . '&amp;course=' . $course->id . '">' .
+                $CFG->wwwroot . '/user/view.php?id=' . $student->id . '&amp;course=' . $attemptobj->get_courseid() . '">' .
                 fullname($student, true) . '</a></td></tr>';
     }
     if (has_capability('mod/quiz:viewreports', $context) &&
index ee5fd23ec7a52bf92d4b29df99f4b3088e87efa8..a6fefe3b2fc7cbde746c7a48e49b5d684af2e4d0 100644 (file)
@@ -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('<a href="' . $attemptobj->attempt_url($question->id) . '">' . $number . '</a>',
             get_string($attemptobj->get_question_status($question->id), 'quiz'));
     if ($scorescolumn) {
index 456a043f0fa8ff0e9fb0b611cc7c8590cbeca3a9..56a7dff896c622a3843c183d874708918d811808 100644 (file)
@@ -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'));