mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
MDL-71126 Quiz: Manual grading page size preference can get stuck at 0
Including in this change: - New positiveint regex rule to check if the value is a positive integer
This commit is contained in:
parent
3da88a7664
commit
46aece2b63
7 changed files with 52 additions and 7 deletions
|
@ -72,6 +72,7 @@ class quiz_grading_settings_form extends moodleform {
|
|||
|
||||
$mform->addElement('text', 'pagesize', get_string('questionsperpage', 'quiz_grading'),
|
||||
array('size' => 3));
|
||||
$mform->addRule('pagesize', null, 'positiveint', null, 'client');
|
||||
$mform->setType('pagesize', PARAM_INT);
|
||||
|
||||
$orderoptions = array(
|
||||
|
|
|
@ -42,6 +42,9 @@ class quiz_grading_report extends quiz_default_report {
|
|||
const DEFAULT_PAGE_SIZE = 5;
|
||||
const DEFAULT_ORDER = 'random';
|
||||
|
||||
/** @var string Positive integer regular expression. */
|
||||
const REGEX_POSITIVE_INT = '/^[1-9]\d*$/';
|
||||
|
||||
/** @var array URL parameters for what is being displayed when grading. */
|
||||
protected $viewoptions = [];
|
||||
|
||||
|
@ -99,6 +102,10 @@ class quiz_grading_report extends quiz_default_report {
|
|||
$this->viewoptions[$param] = $$param;
|
||||
}
|
||||
}
|
||||
if (!data_submitted() && !preg_match(self::REGEX_POSITIVE_INT, $pagesize)) {
|
||||
// We only validate if the user accesses the page via a cleaned-up GET URL here.
|
||||
throw new moodle_exception('invalidpagesize');
|
||||
}
|
||||
if ($pagesize != self::DEFAULT_PAGE_SIZE) {
|
||||
$this->viewoptions['pagesize'] = $pagesize;
|
||||
}
|
||||
|
@ -415,12 +422,18 @@ class quiz_grading_report extends quiz_default_report {
|
|||
$settings->order = $order;
|
||||
$mform->set_data($settings);
|
||||
|
||||
// If the form was submitted, save the user preferences, and
|
||||
// redirect to a cleaned-up GET URL.
|
||||
if ($mform->get_data()) {
|
||||
set_user_preference('quiz_grading_pagesize', $pagesize);
|
||||
set_user_preference('quiz_grading_order', $order);
|
||||
redirect($this->grade_question_url($slot, $questionid, $grade, $page));
|
||||
if ($mform->is_submitted()) {
|
||||
if ($mform->is_validated()) {
|
||||
// If the form was submitted and validated, save the user preferences, and
|
||||
// redirect to a cleaned-up GET URL.
|
||||
set_user_preference('quiz_grading_pagesize', $pagesize);
|
||||
set_user_preference('quiz_grading_order', $order);
|
||||
redirect($this->grade_question_url($slot, $questionid, $grade, $page));
|
||||
} else {
|
||||
// Set the pagesize back to the previous value, so the report page can continue the render
|
||||
// and the form can show the validation.
|
||||
$pagesize = get_user_preferences('quiz_grading_pagesize', self::DEFAULT_PAGE_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
list($qubaids, $count) = $this->get_usage_ids_where_question_in_state(
|
||||
|
|
|
@ -87,3 +87,28 @@ Feature: Basic use of the Manual grading report
|
|||
Then the following fields match these values:
|
||||
| Questions per page | 42 |
|
||||
| Order attempts | By date |
|
||||
|
||||
@javascript
|
||||
Scenario: Manual grading settings are validated
|
||||
Given user "student1" has attempted "Quiz 1" with responses:
|
||||
| slot | response |
|
||||
| 1 | Paris |
|
||||
And I am on the "Quiz 1" "mod_quiz > Manual grading report" page logged in as "teacher1"
|
||||
And I follow "Also show questions that have been graded automatically"
|
||||
And I click on "update grades" "link" in the "Short answer 001" "table_row"
|
||||
When I set the following fields to these values:
|
||||
| Questions per page | 0 |
|
||||
And I press "Change options"
|
||||
Then I should see "You must enter a number that greater than 0 here"
|
||||
And I set the following fields to these values:
|
||||
| Questions per page | -1 |
|
||||
And I press "Change options"
|
||||
And I should see "You must enter a number that greater than 0 here"
|
||||
And I set the following fields to these values:
|
||||
| Questions per page | abc |
|
||||
And I press "Change options"
|
||||
And I should see "You must enter a number that greater than 0 here"
|
||||
And I set the following fields to these values:
|
||||
| Questions per page | 1 |
|
||||
And I press "Change options"
|
||||
And I should not see "You must enter a number that greater than 0 here"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue