mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-50394 core_course: fixed form validation of 'gradepass'
This commit is contained in:
parent
0c6faf4b51
commit
9758da6ed5
2 changed files with 18 additions and 4 deletions
|
@ -262,6 +262,12 @@ if ($mform->is_cancelled()) {
|
||||||
redirect(course_get_url($course, $cw->section, array('sr' => $sectionreturn)));
|
redirect(course_get_url($course, $cw->section, array('sr' => $sectionreturn)));
|
||||||
}
|
}
|
||||||
} else if ($fromform = $mform->get_data()) {
|
} else if ($fromform = $mform->get_data()) {
|
||||||
|
// Convert the grade pass value - we may be using a language which uses commas,
|
||||||
|
// rather than decimal points, in numbers. These need to be converted so that
|
||||||
|
// they can be added to the DB.
|
||||||
|
if (isset($fromform->gradepass)) {
|
||||||
|
$fromform->gradepass = unformat_float($fromform->gradepass);
|
||||||
|
}
|
||||||
|
|
||||||
if (!empty($fromform->update)) {
|
if (!empty($fromform->update)) {
|
||||||
list($cm, $fromform) = update_moduleinfo($cm, $fromform, $course, $mform);
|
list($cm, $fromform) = update_moduleinfo($cm, $fromform, $course, $mform);
|
||||||
|
|
|
@ -299,10 +299,19 @@ abstract class moodleform_mod extends moodleform {
|
||||||
$errors['assessed'] = get_string('scaleselectionrequired', 'rating');
|
$errors['assessed'] = get_string('scaleselectionrequired', 'rating');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check that the grade pass is a valid number.
|
||||||
|
$gradepassvalid = false;
|
||||||
|
if (isset($data['gradepass'])) {
|
||||||
|
if (unformat_float($data['gradepass'], true) === false) {
|
||||||
|
$errors['gradepass'] = get_string('err_numeric', 'form');
|
||||||
|
} else {
|
||||||
|
$gradepassvalid = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Grade to pass: ensure that the grade to pass is valid for points and scales.
|
// Grade to pass: ensure that the grade to pass is valid for points and scales.
|
||||||
// If we are working with a scale, convert into a positive number for validation.
|
// If we are working with a scale, convert into a positive number for validation.
|
||||||
|
if ($gradepassvalid && isset($data['gradepass']) && (!empty($data['grade']) || !empty($data['scale']))) {
|
||||||
if (isset($data['gradepass']) && (!empty($data['grade']) || !empty($data['scale']))) {
|
|
||||||
$scale = !empty($data['grade']) ? $data['grade'] : $data['scale'];
|
$scale = !empty($data['grade']) ? $data['grade'] : $data['scale'];
|
||||||
if ($scale < 0) {
|
if ($scale < 0) {
|
||||||
$scalevalues = $DB->get_record('scale', array('id' => -$scale));
|
$scalevalues = $DB->get_record('scale', array('id' => -$scale));
|
||||||
|
@ -672,8 +681,7 @@ abstract class moodleform_mod extends moodleform {
|
||||||
$mform->addElement('text', 'gradepass', get_string('gradepass', 'grades'));
|
$mform->addElement('text', 'gradepass', get_string('gradepass', 'grades'));
|
||||||
$mform->addHelpButton('gradepass', 'gradepass', 'grades');
|
$mform->addHelpButton('gradepass', 'gradepass', 'grades');
|
||||||
$mform->setDefault('gradepass', '');
|
$mform->setDefault('gradepass', '');
|
||||||
$mform->setType('gradepass', PARAM_FLOAT);
|
$mform->setType('gradepass', PARAM_RAW);
|
||||||
$mform->addRule('gradepass', null, 'numeric', null, 'client');
|
|
||||||
if (!$this->_features->rating) {
|
if (!$this->_features->rating) {
|
||||||
$mform->disabledIf('gradepass', 'grade[modgrade_type]', 'eq', 'none');
|
$mform->disabledIf('gradepass', 'grade[modgrade_type]', 'eq', 'none');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue