MDL-48634 grades: Add an option to rescale when changing the maxgrade

This commit is contained in:
Damyon Wiese 2015-04-15 07:57:28 -04:00 committed by Mark Nelson
parent 9d5d9c64ff
commit d629c601c5
12 changed files with 422 additions and 11 deletions

View file

@ -156,6 +156,8 @@ if ($mform->is_cancelled()) {
}
$grade_item = new grade_item(array('id'=>$id, 'courseid'=>$courseid));
$oldmin = $grade_item->grademin;
$oldmax = $grade_item->grademax;
grade_item::set_properties($grade_item, $data);
$grade_item->outcomeid = null;
@ -175,6 +177,12 @@ if ($mform->is_cancelled()) {
} else {
$grade_item->update();
if (!empty($data->rescalegrades)) {
$newmin = $grade_item->grademin;
$newmax = $grade_item->grademax;
$grade_item->rescale_grades_keep_percentage($oldmin, $oldmax, $newmin, $newmax, 'gradebook');
}
}
// update hiding flag

View file

@ -97,6 +97,10 @@ class edit_item_form extends moodleform {
$mform->setType('grademin', PARAM_RAW);
}
$mform->addElement('selectyesno', 'rescalegrades', get_string('modgraderescalegrades', 'grades'));
$mform->addHelpButton('rescalegrades', 'modgraderescalegrades', 'grades');
$mform->disabledIf('rescalegrades', 'gradetype', 'noteq', GRADE_TYPE_VALUE);
$mform->addElement('text', 'gradepass', get_string('gradepass', 'grades'));
$mform->addHelpButton('gradepass', 'gradepass', 'grades');
$mform->disabledIf('gradepass', 'gradetype', 'eq', GRADE_TYPE_NONE);
@ -269,6 +273,7 @@ class edit_item_form extends moodleform {
// the idnumber of grade itemnumber 0 is synced with course_modules
$mform->hardFreeze('idnumber');
}
$mform->removeElement('rescalegrades');
//$mform->removeElement('calculation');
}
}
@ -342,6 +347,7 @@ class edit_item_form extends moodleform {
// all new items are manual, children of course category
$mform->removeElement('plusfactor');
$mform->removeElement('multfactor');
$mform->removeElement('rescalegrades');
}
// no parent header for course category
@ -353,12 +359,15 @@ class edit_item_form extends moodleform {
/// perform extra validation before submission
function validation($data, $files) {
global $COURSE;
$grade_item = false;
if ($data['id']) {
$grade_item = new grade_item(array('id' => $data['id'], 'courseid' => $data['courseid']));
}
$errors = parent::validation($data, $files);
if (array_key_exists('idnumber', $data)) {
if ($data['id']) {
$grade_item = new grade_item(array('id'=>$data['id'], 'courseid'=>$data['courseid']));
if ($grade_item) {
if ($grade_item->itemtype == 'mod') {
$cm = get_coursemodule_from_instance($grade_item->itemmodule, $grade_item->iteminstance, $grade_item->courseid);
} else {