function validation($data, $files) { global $COURSE, $DB, $CFG; $errors = parent::validation($data, $files); $mform =& $this->_form; $errors = array(); if ($mform->elementExists('name')) { $name = trim($data['name']); if ($name == '') { $errors['name'] = get_string('required'); } } $grade_item = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => $data['modulename'], 'iteminstance' => $data['instance'], 'itemnumber' => 0, 'courseid' => $COURSE->id)); if ($data['coursemodule']) { $cm = $DB->get_record('course_modules', array('id' => $data['coursemodule'])); } else { $cm = null; } if ($mform->elementExists('cmidnumber')) { // verify the idnumber if (!grade_verify_idnumber($data['cmidnumber'], $COURSE->id, $grade_item, $cm)) { $errors['cmidnumber'] = get_string('idnumbertaken'); } } // Ratings: Don't let them select an aggregate type without selecting a scale. // If the user has selected to use ratings but has not chosen a scale or set max points then the form is // invalid. If ratings have been selected then the user must select either a scale or max points. // This matches (horrible) logic in data_preprocessing. if (isset($data['assessed']) && $data['assessed'] > 0 && empty($data['scale'])) { $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 ($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)); $grade = count(explode(',', $scalevalues->scale)); } else { $grade = $scale; } if ($data['gradepass'] > $grade) { $errors['gradepass'] = get_string('gradepassgreaterthangrade', 'grades', $grade); } } // Completion: Don't let them choose automatic completion without turning // on some conditions. Ignore this check when completion settings are // locked, as the options are then disabled. if (array_key_exists('completion', $data) && $data['completion'] == COMPLETION_TRACKING_AUTOMATIC && !empty($data['completionunlocked'])) { if (empty($data['completionview']) && empty($data['completionusegrade']) && !$this->completion_rule_enabled($data)) { $errors['completion'] = get_string('badautocompletion', 'completion'); } } // Availability: Check availability field does not have errors. if (!empty($CFG->enableavailability)) { \core_availability\frontend::report_validation_errors($data, $errors); } return $errors; }
public function validation($data, $files) { global $CFG; $errors = array(); // Availability: Check availability field does not have errors. if (!empty($CFG->enableavailability)) { \core_availability\frontend::report_validation_errors($data, $errors); } // Validate section name if 'Use default section name' is unchecked. if (empty($data['usedefaultname'])) { // Make sure the trimmed value of section name is not empty. $trimmedname = trim($data['name']); if (empty($trimmedname)) { $errors['name_group'] = get_string('required'); } } return $errors; }
public function validation($data, $files) { global $CFG; $errors = array(); // Availability: Check availability field does not have errors. if (!empty($CFG->enableavailability)) { \core_availability\frontend::report_validation_errors($data, $errors); } return $errors; }
function validation($data, $files) { global $COURSE, $DB, $CFG; $errors = parent::validation($data, $files); $mform =& $this->_form; $errors = array(); if ($mform->elementExists('name')) { $name = trim($data['name']); if ($name == '') { $errors['name'] = get_string('required'); } } $grade_item = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => $data['modulename'], 'iteminstance' => $data['instance'], 'itemnumber' => 0, 'courseid' => $COURSE->id)); if ($data['coursemodule']) { $cm = $DB->get_record('course_modules', array('id' => $data['coursemodule'])); } else { $cm = null; } if ($mform->elementExists('cmidnumber')) { // verify the idnumber if (!grade_verify_idnumber($data['cmidnumber'], $COURSE->id, $grade_item, $cm)) { $errors['cmidnumber'] = get_string('idnumbertaken'); } } // Completion: Don't let them choose automatic completion without turning // on some conditions. Ignore this check when completion settings are // locked, as the options are then disabled. if (array_key_exists('completion', $data) && $data['completion'] == COMPLETION_TRACKING_AUTOMATIC && !empty($data['completionunlocked'])) { if (empty($data['completionview']) && empty($data['completionusegrade']) && !$this->completion_rule_enabled($data)) { $errors['completion'] = get_string('badautocompletion', 'completion'); } } // Availability: Check availability field does not have errors. if (!empty($CFG->enableavailability)) { \core_availability\frontend::report_validation_errors($data, $errors); } return $errors; }