MDL-15452 - Fix regressions introduced by my recent work on this bug and its children. Thanks to Paul Johnson for his testing.

This commit is contained in:
tjhunt 2008-07-10 17:23:56 +00:00
parent 9289e44cd2
commit b9b3aa9459
5 changed files with 28 additions and 12 deletions

View File

@ -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()));
}
}

View 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) {

View 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
@ -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[] = '<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) &&

View 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) {

View 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'));