MDL-68970 quiz: prevent page caching during attempts

This ensures that the page reloads if the student uses
the Back or Forwards buttons within an attempt. This
avoids questions being in a stale state, or
the timer showing the wrong time.

Thanks to Jake Dallimore and Russell Boyatt for suggestions
which lead to this fix.
This commit is contained in:
Tim Hunt 2021-01-25 18:16:14 +00:00
parent fd840ab59c
commit bdbe3cd268
5 changed files with 6 additions and 2 deletions

View File

@ -454,7 +454,6 @@ class quizaccess_seb extends quiz_access_rule_base {
*/
public function setup_attempt_page($page) {
$page->set_title($this->quizobj->get_course()->shortname . ': ' . $page->title);
$page->set_cacheable(false);
$page->set_popup_notification_allowed(false); // Prevent message notifications.
$page->set_heading($page->title);
$page->set_pagelayout('secure');

View File

@ -72,7 +72,6 @@ class quizaccess_securewindow extends quiz_access_rule_base {
public function setup_attempt_page($page) {
$page->set_popup_notification_allowed(false); // Prevent message notifications.
$page->set_title($this->quizobj->get_course()->shortname . ': ' . $page->title);
$page->set_cacheable(false);
$page->set_pagelayout('secure');
if ($this->quizobj->is_preview_user()) {

View File

@ -44,6 +44,8 @@ $cmid = optional_param('cmid', null, PARAM_INT);
$attemptobj = quiz_create_attempt_handling_errors($attemptid, $cmid);
$page = $attemptobj->force_page_number_into_range($page);
$PAGE->set_url($attemptobj->attempt_url(null, $page));
// During quiz attempts, the browser back/forwards buttons should force a reload.
$PAGE->set_cacheable(false);
// Check login.
require_login($attemptobj->get_course(), false, $attemptobj->get_cm());

View File

@ -44,6 +44,8 @@ if (!$course = $DB->get_record('course', array('id' => $cm->course))) {
$quizobj = quiz::create($cm->instance, $USER->id);
// This script should only ever be posted to, so set page URL to the view page.
$PAGE->set_url($quizobj->view_url());
// During quiz attempts, the browser back/forwards buttons should force a reload.
$PAGE->set_cacheable(false);
// Check login and sesskey.
require_login($quizobj->get_course(), false, $quizobj->get_cm());

View File

@ -30,6 +30,8 @@ $attemptid = required_param('attempt', PARAM_INT); // The attempt to summarise.
$cmid = optional_param('cmid', null, PARAM_INT);
$PAGE->set_url('/mod/quiz/summary.php', array('attempt' => $attemptid));
// During quiz attempts, the browser back/forwards buttons should force a reload.
$PAGE->set_cacheable(false);
$attemptobj = quiz_create_attempt_handling_errors($attemptid, $cmid);