mirror of
https://github.com/moodle/moodle.git
synced 2025-04-23 09:23:09 +02:00
MDL-76614 quiz: move mod_quiz_preflight_check_form to classes & clean up
This commit is contained in:
parent
b3d59e5ad8
commit
91c913debc
mod/quiz
@ -15,58 +15,11 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
@ -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.
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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'));
|
||||
|
@ -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'));
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
64
mod/quiz/classes/form/preflight_check_form.php
Normal file
64
mod/quiz/classes/form/preflight_check_form.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
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']));
|
||||
}
|
||||
}
|
@ -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',
|
||||
];
|
||||
|
@ -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');
|
||||
|
@ -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. */
|
||||
|
@ -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 ===
|
||||
|
Loading…
x
Reference in New Issue
Block a user