diff --git a/mod/quiz/accessmanager_form.php b/mod/quiz/accessmanager_form.php index e2e6fc5e241..df1c42fe9f1 100644 --- a/mod/quiz/accessmanager_form.php +++ b/mod/quiz/accessmanager_form.php @@ -15,58 +15,11 @@ // along with Moodle. If not, see . /** - * Defines the form that limits student's access to attempt a quiz. + * File only retained to prevent fatal errors in code that tries to require/include this. * - * @package mod_quiz - * @copyright 2011 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @todo MDL-76612 delete this file as part of Moodle 4.6 development. + * @deprecated This file is no longer required in Moodle 4.2+. */ - - defined('MOODLE_INTERNAL') || die(); -require_once($CFG->libdir.'/formslib.php'); - - -/** - * A form that limits student's access to attempt a quiz. - * - * @copyright 2011 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class mod_quiz_preflight_check_form extends moodleform { - - protected function definition() { - $mform = $this->_form; - $this->_form->updateAttributes(array('id' => 'mod_quiz_preflight_form')); - - foreach ($this->_customdata['hidden'] as $name => $value) { - if ($name === 'sesskey') { - continue; - } - $mform->addElement('hidden', $name, $value); - $mform->setType($name, PARAM_INT); - } - - foreach ($this->_customdata['rules'] as $rule) { - if ($rule->is_preflight_check_required($this->_customdata['attemptid'])) { - $rule->add_preflight_check_form_fields($this, $mform, - $this->_customdata['attemptid']); - } - } - - $this->add_action_buttons(true, get_string('startattempt', 'quiz')); - $this->set_display_vertical(); - $mform->setDisableShortforms(); - } - - public function validation($data, $files) { - $errors = parent::validation($data, $files); - - $timenow = time(); - $accessmanager = $this->_customdata['quizobj']->get_access_manager($timenow); - $errors = array_merge($errors, $accessmanager->validate_preflight_check($data, $files, $this->_customdata['attemptid'])); - - return $errors; - } -} +debugging('This file is no longer required in Moodle 4.2+. Please do not include/require it.', DEBUG_DEVELOPER); diff --git a/mod/quiz/accessrule/accessrulebase.php b/mod/quiz/accessrule/accessrulebase.php index 3bccd0181f8..c433c9f8092 100644 --- a/mod/quiz/accessrule/accessrulebase.php +++ b/mod/quiz/accessrule/accessrulebase.php @@ -22,6 +22,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +use mod_quiz\form\preflight_check_form; defined('MOODLE_INTERNAL') || die(); @@ -108,12 +109,12 @@ abstract class quiz_access_rule_base { * Add any field you want to pre-flight check form. You should only do * something here if {@link is_preflight_check_required()} returned true. * - * @param mod_quiz_preflight_check_form $quizform the form being built. + * @param preflight_check_form $quizform the form being built. * @param MoodleQuickForm $mform The wrapped MoodleQuickForm. * @param int|null $attemptid the id of the current attempt, if there is one, * otherwise null. */ - public function add_preflight_check_form_fields(mod_quiz_preflight_check_form $quizform, + public function add_preflight_check_form_fields(preflight_check_form $quizform, MoodleQuickForm $mform, $attemptid) { // Do nothing by default. } diff --git a/mod/quiz/accessrule/offlineattempts/rule.php b/mod/quiz/accessrule/offlineattempts/rule.php index 511be30f145..f88f3832854 100644 --- a/mod/quiz/accessrule/offlineattempts/rule.php +++ b/mod/quiz/accessrule/offlineattempts/rule.php @@ -22,6 +22,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +use mod_quiz\form\preflight_check_form; defined('MOODLE_INTERNAL') || die(); @@ -63,7 +64,7 @@ class quizaccess_offlineattempts extends quiz_access_rule_base { } } - public function add_preflight_check_form_fields(mod_quiz_preflight_check_form $quizform, + public function add_preflight_check_form_fields(preflight_check_form $quizform, MoodleQuickForm $mform, $attemptid) { global $DB; diff --git a/mod/quiz/accessrule/password/rule.php b/mod/quiz/accessrule/password/rule.php index 778e3902891..6e48b904178 100644 --- a/mod/quiz/accessrule/password/rule.php +++ b/mod/quiz/accessrule/password/rule.php @@ -23,6 +23,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +use mod_quiz\form\preflight_check_form; defined('MOODLE_INTERNAL') || die(); @@ -54,7 +55,7 @@ class quizaccess_password extends quiz_access_rule_base { return empty($SESSION->passwordcheckedquizzes[$this->quiz->id]); } - public function add_preflight_check_form_fields(mod_quiz_preflight_check_form $quizform, + public function add_preflight_check_form_fields(preflight_check_form $quizform, MoodleQuickForm $mform, $attemptid) { $mform->addElement('header', 'passwordheader', get_string('password')); diff --git a/mod/quiz/accessrule/timelimit/rule.php b/mod/quiz/accessrule/timelimit/rule.php index ea061398801..08dd92d4a6b 100644 --- a/mod/quiz/accessrule/timelimit/rule.php +++ b/mod/quiz/accessrule/timelimit/rule.php @@ -23,6 +23,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +use mod_quiz\form\preflight_check_form; defined('MOODLE_INTERNAL') || die(); @@ -74,7 +75,7 @@ class quizaccess_timelimit extends quiz_access_rule_base { return $attemptid === null; } - public function add_preflight_check_form_fields(mod_quiz_preflight_check_form $quizform, + public function add_preflight_check_form_fields(preflight_check_form $quizform, MoodleQuickForm $mform, $attemptid) { $mform->addElement('header', 'honestycheckheader', get_string('confirmstartheader', 'quizaccess_timelimit')); diff --git a/mod/quiz/accessrule/upgrade.txt b/mod/quiz/accessrule/upgrade.txt index f883b6e1143..41e505834bd 100644 --- a/mod/quiz/accessrule/upgrade.txt +++ b/mod/quiz/accessrule/upgrade.txt @@ -2,6 +2,12 @@ This files describes API changes for quiz access rule plugins. Overview of this plugin type at http://docs.moodle.org/dev/Quiz_access_rules +=== 4.2 === + +* Note that class mod_quiz_preflight_check_form has been renamed to + mod_quiz\form\preflight_check_form. + + === 2.8, 2.7.1, 2.6.4 and 2.5.7 === * New static method delete_settings for access rules, which is called when a diff --git a/mod/quiz/classes/access_manager.php b/mod/quiz/classes/access_manager.php index 2f40e81ed70..ea1c6e7fadc 100644 --- a/mod/quiz/classes/access_manager.php +++ b/mod/quiz/classes/access_manager.php @@ -17,9 +17,9 @@ namespace mod_quiz; use core_component; +use mod_quiz\form\preflight_check_form; use mod_quiz\question\display_options; use mod_quiz_mod_form; -use mod_quiz_preflight_check_form; use mod_quiz_renderer; use moodle_page; use moodle_url; @@ -384,17 +384,17 @@ class access_manager { * @param moodle_url $url the form action URL. * @param int|null $attemptid the id of the current attempt, if there is one, * otherwise null. - * @return mod_quiz_preflight_check_form the form. + * @return preflight_check_form the form. */ - public function get_preflight_check_form(moodle_url $url, ?int $attemptid): mod_quiz_preflight_check_form { + public function get_preflight_check_form(moodle_url $url, ?int $attemptid): preflight_check_form { // This form normally wants POST submissions. However, it also needs to // accept GET submissions. Since formslib is strict, we have to detect // which case we are in, and set the form property appropriately. $method = 'post'; - if (!empty($_GET['_qf__mod_quiz_preflight_check_form'])) { + if (!empty($_GET['_qf__preflight_check_form'])) { $method = 'get'; } - return new mod_quiz_preflight_check_form($url->out_omit_querystring(), + return new preflight_check_form($url->out_omit_querystring(), ['rules' => $this->rules, 'quizobj' => $this->quizobj, 'attemptid' => $attemptid, 'hidden' => $url->params()], $method); } diff --git a/mod/quiz/classes/form/preflight_check_form.php b/mod/quiz/classes/form/preflight_check_form.php new file mode 100644 index 00000000000..a734d137fec --- /dev/null +++ b/mod/quiz/classes/form/preflight_check_form.php @@ -0,0 +1,64 @@ +. + +namespace mod_quiz\form; + +use moodleform; + +defined('MOODLE_INTERNAL') || die(); + +require_once($CFG->libdir.'/formslib.php'); + +/** + * A form that limits student's access to attempt a quiz. + * + * @package mod_quiz + * @copyright 2011 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class preflight_check_form extends moodleform { + + protected function definition() { + $mform = $this->_form; + $this->_form->updateAttributes(array('id' => 'mod_quiz_preflight_form')); + + foreach ($this->_customdata['hidden'] as $name => $value) { + if ($name === 'sesskey') { + continue; + } + $mform->addElement('hidden', $name, $value); + $mform->setType($name, PARAM_INT); + } + + foreach ($this->_customdata['rules'] as $rule) { + if ($rule->is_preflight_check_required($this->_customdata['attemptid'])) { + $rule->add_preflight_check_form_fields($this, $mform, + $this->_customdata['attemptid']); + } + } + + $this->add_action_buttons(true, get_string('startattempt', 'quiz')); + $this->set_display_vertical(); + $mform->setDisableShortforms(); + } + + public function validation($data, $files): array { + $errors = parent::validation($data, $files); + $accessmanager = $this->_customdata['quizobj']->get_access_manager(time()); + return array_merge($errors, $accessmanager->validate_preflight_check( + $data, $files, $this->_customdata['attemptid'])); + } +} diff --git a/mod/quiz/db/renamedclasses.php b/mod/quiz/db/renamedclasses.php index 9d953c12f9b..7256a8b8890 100644 --- a/mod/quiz/db/renamedclasses.php +++ b/mod/quiz/db/renamedclasses.php @@ -52,4 +52,5 @@ $renamedclasses = [ 'mod_quiz_attempts_report_options' => 'mod_quiz\local\reports\attempts_report_options', 'quiz_attempts_report_table' => 'mod_quiz\local\reports\attempts_report_table', 'quiz_access_manager' => 'mod_quiz\access_manager', + 'mod_quiz_preflight_check_form' => 'mod_quiz\form\preflight_check_form', ]; diff --git a/mod/quiz/locallib.php b/mod/quiz/locallib.php index f7abd0a28e7..db534cc1a68 100644 --- a/mod/quiz/locallib.php +++ b/mod/quiz/locallib.php @@ -31,7 +31,6 @@ defined('MOODLE_INTERNAL') || die(); require_once($CFG->dirroot . '/mod/quiz/lib.php'); -require_once($CFG->dirroot . '/mod/quiz/accessmanager_form.php'); require_once($CFG->dirroot . '/mod/quiz/renderer.php'); require_once($CFG->dirroot . '/mod/quiz/attemptlib.php'); require_once($CFG->libdir . '/completionlib.php'); diff --git a/mod/quiz/renderer.php b/mod/quiz/renderer.php index 3c33af87a05..be7f147b816 100644 --- a/mod/quiz/renderer.php +++ b/mod/quiz/renderer.php @@ -26,6 +26,7 @@ defined('MOODLE_INTERNAL') || die(); use mod_quiz\access_manager; +use mod_quiz\form\preflight_check_form; use mod_quiz\question\display_options; @@ -428,7 +429,17 @@ class mod_quiz_renderer extends plugin_renderer_base { return implode(', ', $attemptlinks); } - public function start_attempt_page(quiz $quizobj, mod_quiz_preflight_check_form $mform) { + /** + * Render the 'start attempt' page. + * + * The student gets here if their interaction with the preflight check + * from fails in some way (e.g. they typed the wrong password). + * + * @param quiz $quizobj + * @param preflight_check_form $mform + * @return string + */ + public function start_attempt_page(quiz $quizobj, preflight_check_form $mform) { $output = ''; $output .= $this->header(); $output .= $this->during_attempt_tertiary_nav($quizobj->view_url()); @@ -900,22 +911,15 @@ class mod_quiz_renderer extends plugin_renderer_base { * * @param string $buttontext the label to display on the button. * @param moodle_url $url The URL to POST to in order to start the attempt. - * @param mod_quiz_preflight_check_form $preflightcheckform deprecated. + * @param preflight_check_form $preflightcheckform deprecated. * @param bool $popuprequired whether the attempt needs to be opened in a pop-up. * @param array $popupoptions the options to use if we are opening a popup. * @return string HTML fragment. */ public function start_attempt_button($buttontext, moodle_url $url, - mod_quiz_preflight_check_form $preflightcheckform = null, + preflight_check_form $preflightcheckform = null, $popuprequired = false, $popupoptions = null) { - if (is_string($preflightcheckform)) { - // Calling code was not updated since the API change. - debugging('The third argument to start_attempt_button should now be the ' . - 'mod_quiz_preflight_check_form from ' . - 'access_manager::get_preflight_check_form, not a warning message string.'); - } - $button = new single_button($url, $buttontext, 'post', true); $button->class .= ' quizstartbuttondiv'; if ($popuprequired) { @@ -1474,7 +1478,7 @@ class mod_quiz_view_object { public $buttontext; /** @var moodle_url $startattempturl URL to start an attempt. */ public $startattempturl; - /** @var mod_quiz_preflight_check_form|null $preflightcheckform confirmation form that must be + /** @var preflight_check_form|null $preflightcheckform confirmation form that must be * submitted before an attempt is started, if required. */ public $preflightcheckform; /** @var moodle_url $startattempturl URL for any Back to the course button. */ diff --git a/mod/quiz/upgrade.txt b/mod/quiz/upgrade.txt index f9b020dabf0..2eaa0eebfc6 100644 --- a/mod/quiz/upgrade.txt +++ b/mod/quiz/upgrade.txt @@ -36,6 +36,7 @@ This files describes API changes in the quiz code. - mod_quiz_attempts_report_options => mod_quiz\local\reports\attempts_report_options - quiz_attempts_report_table => mod_quiz\local\reports\attempts_report_table - quiz_access_manager => mod_quiz\access_manager + - mod_quiz_preflight_check_form => mod_quiz\form\preflight_check_form * As part of the clean-up, the following files are no longer required, and if you try to include them, you will get a debugging notices telling you not to: @@ -45,6 +46,7 @@ This files describes API changes in the quiz code. - mod/quiz/report/attemptsreport_table.php - mod/quiz/report/default.php - mod/quiz/accessmanager.php + - mod/quiz/accessmanager_form.php === 4.1 ===