MDL-50394 core_course: fixed form validation of 'gradepass'

This commit is contained in:
Mark Nelson 2015-06-01 00:22:33 -07:00
parent 0c6faf4b51
commit 9758da6ed5
2 changed files with 18 additions and 4 deletions

View file

@ -262,6 +262,12 @@ if ($mform->is_cancelled()) {
redirect(course_get_url($course, $cw->section, array('sr' => $sectionreturn)));
}
} 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)) {
list($cm, $fromform) = update_moduleinfo($cm, $fromform, $course, $mform);

View file

@ -299,10 +299,19 @@ abstract class moodleform_mod extends moodleform {
$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.
// If we are working with a scale, convert into a positive number for validation.
if (isset($data['gradepass']) && (!empty($data['grade']) || !empty($data['scale']))) {
if ($gradepassvalid && isset($data['gradepass']) && (!empty($data['grade']) || !empty($data['scale']))) {
$scale = !empty($data['grade']) ? $data['grade'] : $data['scale'];
if ($scale < 0) {
$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->addHelpButton('gradepass', 'gradepass', 'grades');
$mform->setDefault('gradepass', '');
$mform->setType('gradepass', PARAM_FLOAT);
$mform->addRule('gradepass', null, 'numeric', null, 'client');
$mform->setType('gradepass', PARAM_RAW);
if (!$this->_features->rating) {
$mform->disabledIf('gradepass', 'grade[modgrade_type]', 'eq', 'none');
}