MDL-11296 fixed incorrect detection of duplicate scales in course

This commit is contained in:
skodak 2007-09-15 21:17:11 +00:00
parent 43c137ac23
commit 8fafbc0ea3
2 changed files with 33 additions and 10 deletions

View File

@ -33,7 +33,7 @@ if ($id) {
}
$scale_rec->standard = 1;
$scale_rec->courseid = $courseid;
require_login();
require_login($courseid);
require_capability('moodle/course:managescales', $systemcontext);
}

View File

@ -84,21 +84,44 @@ class edit_scale_form extends moodleform {
/// perform extra validation before submission
function validation($data){
global $CFG, $COURSE;
global $CFG;
$errors= array();
$errors = array();
// we can not allow 2 scales with the same exact scale as this creates
// problems for backup/restore
$courseid = empty($data['courseid'])?0:$data['courseid'];
if (count_records('scale', 'courseid', $courseid, 'scale', $data['scale'])) {
$errors['scale'] = get_string('duplicatescale', 'grades');
$old = grade_scale::fetch(array('id'=>$data['id']));
if (array_key_exists('standard', $data)) {
if (empty($data['standard'])) {
$courseid = $COURSE->id;
} else {
$courseid = 0;
}
} else {
$courseid = $old->courseid;
}
$options = explode(',', $data['scale']);
if (count($options) < 2) {
$errors['scale'] = get_string('error');
if (array_key_exists('scale', $data)) {
$count = count_records('scale', 'courseid', $courseid, 'scale', $data['scale']);
if (empty($old->id) or $old->courseid != $courseid) {
if ($count) {
$errors['scale'] = get_string('duplicatescale', 'grades');
}
} else if ($old->scale != $data['scale']) {
if ($count) {
$errors['scale'] = get_string('duplicatescale', 'grades');
}
}
$options = explode(',', $data['scale']);
if (count($options) < 2) {
$errors['scale'] = get_string('error');
}
}
if (0 == count($errors)){