MDL-48634 core: prevent change of grade values when necessary

Three additional checks have been added.

Once grades have been recorded for the activity/grade item -

1) Do not allow the grade type to be changed.
2) Do not allow the scale to be changed.
3) If we are using ratings do not allow the 'Maximum points'
value to be changed.

Also reordered form elements, removed form elements that
were not necessary, added and changed existing language
strings to improve the overall UI.
This commit is contained in:
Mark Nelson
2016-02-09 17:46:42 +08:00
parent 3c4cf9f02b
commit 664d8be7ea
4 changed files with 277 additions and 72 deletions
+29 -5
View File
@@ -405,7 +405,9 @@ abstract class moodleform_mod extends moodleform {
$permission=CAP_ALLOW;
$rolenamestring = null;
$isupdate = false;
if (!empty($this->_cm)) {
$isupdate = true;
$context = context_module::instance($this->_cm->id);
$rolenames = get_role_names_with_caps_in_context($context, array('moodle/rating:rate', 'mod/'.$this->_cm->modname.':rate'));
@@ -420,7 +422,25 @@ abstract class moodleform_mod extends moodleform {
$mform->setDefault('assessed', 0);
$mform->addHelpButton('assessed', 'aggregatetype', 'rating');
$mform->addElement('modgrade', 'scale', get_string('scale'), false);
$gradeoptions = array('isupdate' => $isupdate,
'currentgrade' => false,
'hasgrades' => false,
'canrescale' => $this->_features->canrescale,
'useratings' => $this->_features->rating);
if ($isupdate) {
$gradeitem = grade_item::fetch(array('itemtype' => 'mod',
'itemmodule' => $this->_cm->modname,
'iteminstance' => $this->_cm->instance,
'itemnumber' => 0,
'courseid' => $COURSE->id));
if ($gradeitem) {
$gradeoptions['currentgrade'] = $gradeitem->grademax;
$gradeoptions['currentgradetype'] = $gradeitem->gradetype;
$gradeoptions['currentscaleid'] = $gradeitem->scaleid;
$gradeoptions['hasgrades'] = $gradeitem->has_grades();
}
}
$mform->addElement('modgrade', 'scale', get_string('scale'), $gradeoptions);
$mform->disabledIf('scale', 'assessed', 'eq', 0);
$mform->addHelpButton('scale', 'modgrade', 'grades');
$mform->setDefault('scale', $CFG->gradepointdefault);
@@ -645,7 +665,8 @@ abstract class moodleform_mod extends moodleform {
$gradeoptions = array('isupdate' => $isupdate,
'currentgrade' => false,
'hasgrades' => false,
'canrescale' => $this->_features->canrescale);
'canrescale' => $this->_features->canrescale,
'useratings' => $this->_features->rating);
if ($this->_features->hasgrades) {
@@ -662,9 +683,12 @@ abstract class moodleform_mod extends moodleform {
'iteminstance' => $this->_cm->instance,
'itemnumber' => 0,
'courseid' => $COURSE->id));
$gradeoptions['currentgrade'] = $gradeitem->grademax;
$gradeoptions['hasgrades'] = $gradeitem->has_grades();
if ($gradeitem) {
$gradeoptions['currentgrade'] = $gradeitem->grademax;
$gradeoptions['currentgradetype'] = $gradeitem->gradetype;
$gradeoptions['currentscaleid'] = $gradeitem->scaleid;
$gradeoptions['hasgrades'] = $gradeitem->has_grades();
}
}
$mform->addElement('modgrade', 'grade', get_string('grade'), $gradeoptions);
$mform->addHelpButton('grade', 'modgrade', 'grades');
+77 -12
View File
@@ -51,6 +51,23 @@ class edit_item_form extends moodleform {
$mform->addHelpButton('idnumber', 'idnumbermod');
$mform->setType('idnumber', PARAM_RAW);
if (!empty($item->id)) {
$gradeitem = new grade_item(array('id' => $item->id, 'courseid' => $item->courseid));
// If grades exist set a message so the user knows why they can not alter the grade type or scale.
// We could never change the grade type for external items, so only need to show this for manual grade items.
if ($gradeitem->has_grades() && !$gradeitem->is_external_item()) {
// Set a message so the user knows why they can not alter the grade type or scale.
if ($gradeitem->gradetype == GRADE_TYPE_SCALE) {
$gradesexistmsg = get_string('modgradecantchangegradetyporscalemsg', 'grades');
} else {
$gradesexistmsg = get_string('modgradecantchangegradetypemsg', 'grades');
}
$gradesexisthtml = '<div class=\'alert\'>' . $gradesexistmsg . '</div>';
$mform->addElement('static', 'gradesexistmsg', '', $gradesexisthtml);
}
}
// Manual grade items cannot have grade type GRADE_TYPE_NONE.
$options = array(GRADE_TYPE_VALUE => get_string('typevalue', 'grades'),
GRADE_TYPE_SCALE => get_string('typescale', 'grades'),
@@ -85,6 +102,14 @@ class edit_item_form extends moodleform {
$mform->addHelpButton('scaleid', 'typescale', 'grades');
$mform->disabledIf('scaleid', 'gradetype', 'noteq', GRADE_TYPE_SCALE);
$choices = array();
$choices[''] = get_string('choose');
$choices['no'] = get_string('no');
$choices['yes'] = get_string('yes');
$mform->addElement('select', 'rescalegrades', get_string('modgraderescalegrades', 'grades'), $choices);
$mform->addHelpButton('rescalegrades', 'modgraderescalegrades', 'grades');
$mform->disabledIf('rescalegrades', 'gradetype', 'noteq', GRADE_TYPE_VALUE);
$mform->addElement('text', 'grademax', get_string('grademax', 'grades'));
$mform->addHelpButton('grademax', 'grademax', 'grades');
$mform->disabledIf('grademax', 'gradetype', 'noteq', GRADE_TYPE_VALUE);
@@ -97,14 +122,6 @@ class edit_item_form extends moodleform {
$mform->setType('grademin', PARAM_RAW);
}
$choices = array();
$choices[''] = get_string('choose');
$choices['no'] = get_string('no');
$choices['yes'] = get_string('yes');
$mform->addElement('select', 'rescalegrades', get_string('modgraderescalegrades', 'grades'), $choices);
$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);
@@ -277,8 +294,39 @@ class edit_item_form extends moodleform {
// the idnumber of grade itemnumber 0 is synced with course_modules
$mform->hardFreeze('idnumber');
}
// For external items we can not change the grade type, even if no grades exist, so if it is set to
// scale, then remove the grademax and grademin fields from the form - no point displaying them.
if ($grade_item->gradetype == GRADE_TYPE_SCALE) {
$mform->removeElement('grademax');
if ($mform->elementExists('grademin')) {
$mform->removeElement('grademin');
}
} else { // Not using scale, so remove it.
$mform->removeElement('scaleid');
}
// Always remove the rescale grades element if it's an external item.
$mform->removeElement('rescalegrades');
} else if ($grade_item->has_grades()) {
// Can't change the grade type or the scale if there are grades.
$mform->hardFreeze('gradetype, scaleid');
// If we are using scales then remove the unnecessary rescale and grade fields.
if ($grade_item->gradetype == GRADE_TYPE_SCALE) {
$mform->removeElement('rescalegrades');
$mform->removeElement('grademax');
if ($mform->elementExists('grademin')) {
$mform->removeElement('grademin');
}
} else { // Remove the scale field.
$mform->removeElement('scaleid');
// Set the maximum grade to disabled unless a grade is chosen.
$mform->disabledIf('grademax', 'rescalegrades', 'eq', '');
}
} else {
// Remove the rescale element if there are no grades.
$mform->removeElement('rescalegrades');
//$mform->removeElement('calculation');
}
}
@@ -398,11 +446,28 @@ class edit_item_form extends moodleform {
$errors['grademax'] = get_string('incorrectminmax', 'grades');
}
}
// We do not want the user to be able to change the grade type or scale for this item if grades exist.
if ($grade_item && $grade_item->has_grades()) {
// Check that grade type is set - should never not be set unless form has been modified.
if (!isset($data['gradetype'])) {
$errors['gradetype'] = get_string('modgradecantchangegradetype', 'grades');
} else if ($data['gradetype'] !== $grade_item->gradetype) { // Check if we are changing the grade type.
$errors['gradetype'] = get_string('modgradecantchangegradetype', 'grades');
} else if ($data['gradetype'] == GRADE_TYPE_SCALE) {
// Check if we are changing the scale - can't do this when grades exist.
if (isset($data['scaleid']) && ($data['scaleid'] !== $grade_item->scaleid)) {
$errors['scaleid'] = get_string('modgradecantchangescale', 'grades');
}
}
}
if ($grade_item) {
if (grade_floats_different($data['grademin'], $grade_item->grademin) ||
if ($grade_item->gradetype == GRADE_TYPE_VALUE) {
if (grade_floats_different($data['grademin'], $grade_item->grademin) ||
grade_floats_different($data['grademax'], $grade_item->grademax)) {
if ($grade_item->has_grades() && empty($data['rescalegrades'])) {
$errors['rescalegrades'] = get_string('mustchooserescaleyesorno', 'grades');
if ($grade_item->has_grades() && empty($data['rescalegrades'])) {
$errors['rescalegrades'] = get_string('mustchooserescaleyesorno', 'grades');
}
}
}
}
+10 -8
View File
@@ -474,19 +474,21 @@ $string['missingscale'] = 'Scale must be selected';
$string['mode'] = 'Mode';
$string['modgrade'] = 'Grade';
$string['modgrade_help'] = 'Select the type of grading used for this activity. If "scale" is chosen, you can then choose the scale from the "scale" dropdown. If using "point" grading, you can then enter the maximum grade available for this activity.';
$string['modgradecantchangegradetype'] = 'You cannot change the type, as grades already exist for this item.';
$string['modgradecantchangegradetypemsg'] = 'Some grades have already been awarded, so the grade type cannot be changed. If you wish to change the maximum grade, you must first choose whether or not to rescale existing grades.';
$string['modgradecantchangegradetyporscalemsg'] = 'Some grades have already been awarded, so the grade type and scale cannot be changed.';
$string['modgradecantchangescale'] = 'You cannot change the scale, as grades already exist for this item.';
$string['modgradecantchangeratingmaxgrade'] = 'You cannot change the maximum grade when grades already exist for an activity with ratings.';
$string['modgradedonotmodify'] = 'Do not modify existing grades';
$string['modgradeerrorbadpoint'] = 'Invalid Grade Value. This must be an integer between 0 and {$a}';
$string['modgradeerrorbadpoint'] = 'Invalid grade value. This must be an integer between 1 and {$a}';
$string['modgradeerrorbadscale'] = 'Invalid scale selected. Please make sure you select a scale from the selections below.';
$string['modgrademaxgrade'] = 'Maximum points';
$string['modgrademaxgrade'] = 'Maximum grade';
$string['modgraderescalegrades'] = 'Rescale existing grades';
$string['modgraderescalegrades_help'] = 'Changing the maximum points value for an activity has an effect on the percentage of any existing grades for that activity. If this "Rescale existing grades" option is enabled, all existing grades will be scaled so that the same percentage grade is maintained.
$string['modgraderescalegrades_help'] = 'When changing the maximum grades on a gradebook item you need to specify whether or not this will cause existing percentage grades to change as well.
Example (with "Rescale existing grades" set to "Yes"):
If this is set to \'Yes\', any existing grades will be rescaled so that the percentage grade remains the same.
A student grade of "6 / 10 ( 60 % )" would change to "12 / 20 ( 60 % )" when the maximum points is changed to 20.
';
$string['modgraderescalegrades_link'] = 'Scaling_Activity_Grades';
For example, if this option is set to \'Yes\', changing the maximum grade on an item from 10 to 20 would cause a grade of 6/10 (60%) to be rescaled to 12/20 (60%). With this option set to \'No\', the grade would change from 6/10 (60%) to 6/20 (30%), requiring manual adjustment of the grade items to ensure correct scores.';
$string['modgradetype'] = 'Type';
$string['modgradetypenone'] = 'None';
$string['modgradetypepoint'] = 'Point';
+161 -47
View File
@@ -57,6 +57,24 @@ class MoodleQuickForm_modgrade extends MoodleQuickForm_group {
/** @var boolean $canrescale Does this activity support rescaling grades? */
public $canrescale = false;
/** @var int $currentscaleid The current scale id */
public $currentscaleid = null;
/** @var string $currentgradetype The current gradetype - can either be 'none', 'scale', or 'point' */
public $currentgradetype = 'none';
/** @var boolean $useratings Set to true if the activity is using ratings, false otherwise */
public $useratings = false;
/** @var MoodleQuickForm_select $gradetypeformelement */
private $gradetypeformelement;
/** @var MoodleQuickForm_select $scaleformelement */
private $scaleformelement;
/** @var MoodleQuickForm_text $maxgradeformelement */
private $maxgradeformelement;
/**
* Constructor
*
@@ -76,12 +94,29 @@ class MoodleQuickForm_modgrade extends MoodleQuickForm_group {
$this->_appendName = true;
$this->_type = 'modgrade';
$this->isupdate = !empty($options['isupdate']);
$this->currentgrade = false;
if (isset($options['currentgrade'])) {
$this->currentgrade = $options['currentgrade'];
}
if (isset($options['currentgradetype'])) {
$gradetype = $options['currentgradetype'];
switch ($gradetype) {
case GRADE_TYPE_NONE :
$this->currentgradetype = 'none';
break;
case GRADE_TYPE_SCALE :
$this->currentgradetype = 'scale';
break;
case GRADE_TYPE_VALUE :
$this->currentgradetype = 'point';
break;
}
}
if (isset($options['currentscaleid'])) {
$this->currentscaleid = $options['currentscaleid'];
}
$this->hasgrades = !empty($options['hasgrades']);
$this->canrescale = !empty($options['canrescale']);
$this->useratings = !empty($options['useratings']);
}
/**
@@ -112,17 +147,18 @@ class MoodleQuickForm_modgrade extends MoodleQuickForm_group {
// Grade scale select box.
$scales = get_scales_menu($COURSE->id);
$langscale = get_string('modgradetypescale', 'grades');
$scaleselect = @MoodleQuickForm::createElement('select', 'modgrade_scale', $langscale, $scales, $attributes);
$scaleselect->setHiddenLabel = false;
$scaleselectid = $this->generate_modgrade_subelement_id('modgrade_scale');
$scaleselect->updateAttributes(array('id' => $scaleselectid));
$this->scaleformelement = @MoodleQuickForm::createElement('select', 'modgrade_scale', $langscale,
$scales, $attributes);
$this->scaleformelement->setHiddenLabel = false;
$scaleformelementid = $this->generate_modgrade_subelement_id('modgrade_scale');
$this->scaleformelement->updateAttributes(array('id' => $scaleformelementid));
// Maximum grade textbox.
$langmaxgrade = get_string('modgrademaxgrade', 'grades');
$maxgrade = @MoodleQuickForm::createElement('text', 'modgrade_point', $langmaxgrade, array());
$maxgrade->setHiddenLabel = false;
$maxgradeid = $this->generate_modgrade_subelement_id('modgrade_point');
$maxgrade->updateAttributes(array('id' => $maxgradeid));
$this->maxgradeformelement = @MoodleQuickForm::createElement('text', 'modgrade_point', $langmaxgrade, array());
$this->maxgradeformelement->setHiddenLabel = false;
$maxgradeformelementid = $this->generate_modgrade_subelement_id('modgrade_point');
$this->maxgradeformelement->updateAttributes(array('id' => $maxgradeformelementid));
// Grade type select box.
$gradetype = array(
@@ -131,54 +167,80 @@ class MoodleQuickForm_modgrade extends MoodleQuickForm_group {
'point' => get_string('modgradetypepoint', 'grades'),
);
$langtype = get_string('modgradetype', 'grades');
$typeselect = @MoodleQuickForm::createElement('select', 'modgrade_type', $langtype, $gradetype, $attributes, true);
$typeselect->setHiddenLabel = false;
$typeselectid = $this->generate_modgrade_subelement_id('modgrade_type');
$typeselect->updateAttributes(array('id' => $typeselectid));
$this->gradetypeformelement = @MoodleQuickForm::createElement('select', 'modgrade_type', $langtype, $gradetype,
$attributes, true);
$this->gradetypeformelement->setHiddenLabel = false;
$gradetypeformelementid = $this->generate_modgrade_subelement_id('modgrade_type');
$this->gradetypeformelement->updateAttributes(array('id' => $gradetypeformelementid));
// Check box for options for processing existing grades.
if ($this->isupdate && $this->hasgrades && $this->canrescale) {
$langrescalegrades = get_string('modgraderescalegrades', 'grades');
$choices = array();
$choices[''] = get_string('choose');
$choices['no'] = get_string('no');
$choices['yes'] = get_string('yes');
$rescalegradesselect = @MoodleQuickForm::createElement('select',
'modgrade_rescalegrades',
$langrescalegrades,
$choices);
$rescalegradesselect->_generateId();
$rescalegradesid = $rescalegradesselect->getAttribute('id');
if ($this->isupdate && $this->hasgrades) {
$this->gradetypeformelement->updateAttributes(array('disabled' => 'disabled'));
$this->scaleformelement->updateAttributes(array('disabled' => 'disabled'));
// Check box for options for processing existing grades.
if ($this->canrescale) {
$langrescalegrades = get_string('modgraderescalegrades', 'grades');
$choices = array();
$choices[''] = get_string('choose');
$choices['no'] = get_string('no');
$choices['yes'] = get_string('yes');
$rescalegradesselect = @MoodleQuickForm::createElement('select',
'modgrade_rescalegrades',
$langrescalegrades,
$choices);
$rescalegradesselect->setHiddenLabel = false;
$rescalegradesselectid = $this->generate_modgrade_subelement_id('modgrade_rescalegrades');
$rescalegradesselect->updateAttributes(array('id' => $rescalegradesselectid));
}
}
// Add elements.
if ($this->isupdate && $this->hasgrades) {
// Set a message so the user knows why they can not alter the grade type or scale.
if ($this->currentgradetype == 'scale') {
$gradesexistmsg = get_string('modgradecantchangegradetyporscalemsg', 'grades');
} else {
$gradesexistmsg = get_string('modgradecantchangegradetypemsg', 'grades');
}
$gradesexisthtml = '<div class=\'alert\'>' . $gradesexistmsg . '</div>';
$this->_elements[] = @MoodleQuickForm::createElement('static', 'gradesexistmsg', '', $gradesexisthtml);
}
// Grade type select box.
$label = html_writer::tag('label', $typeselect->getLabel(), array('for' => $typeselect->getAttribute('id')));
$label = html_writer::tag('label', $this->gradetypeformelement->getLabel(),
array('for' => $this->gradetypeformelement->getAttribute('id')));
$this->_elements[] = @MoodleQuickForm::createElement('static', 'gradetypelabel', '', '&nbsp;'.$label);
$this->_elements[] = $typeselect;
$this->_elements[] = $this->gradetypeformelement;
$this->_elements[] = @MoodleQuickForm::createElement('static', 'gradetypespacer', '', '<br />');
// Grade scale select box.
$label = html_writer::tag('label', $scaleselect->getLabel(), array('for' => $scaleselectid));
$this->_elements[] = @MoodleQuickForm::createElement('static', 'scalelabel', '', $label);
$this->_elements[] = $scaleselect;
$this->_elements[] = @MoodleQuickForm::createElement('static', 'scalespacer', '', '<br />');
// Only show the grade scale select box when applicable.
if (!$this->isupdate || !$this->hasgrades || $this->currentgradetype == 'scale') {
$label = html_writer::tag('label', $this->scaleformelement->getLabel(),
array('for' => $this->scaleformelement->getAttribute('id')));
$this->_elements[] = @MoodleQuickForm::createElement('static', 'scalelabel', '', $label);
$this->_elements[] = $this->scaleformelement;
$this->_elements[] = @MoodleQuickForm::createElement('static', 'scalespacer', '', '<br />');
}
// Maximum grade textbox.
$label = html_writer::tag('label', $maxgrade->getLabel(), array('for' => $maxgradeid));
$this->_elements[] = @MoodleQuickForm::createElement('static', 'pointlabel', '', $label);
$this->_elements[] = $maxgrade;
$this->_elements[] = @MoodleQuickForm::createElement('static', 'pointspacer', '', '<br />');
if ($this->isupdate && $this->hasgrades && $this->canrescale) {
if ($this->isupdate && $this->hasgrades && $this->canrescale && $this->currentgradetype == 'point') {
// We need to know how to apply any changes to maxgrade - ie to either update, or don't touch exising grades.
$label = html_writer::tag('label', $rescalegradesselect->getLabel(), array('for' => $rescalegradesid));
$label = html_writer::tag('label', $rescalegradesselect->getLabel(),
array('for' => $rescalegradesselect->getAttribute('id')));
$labelhelp = new help_icon('modgraderescalegrades', 'grades');
$this->_elements[] = @MoodleQuickForm::createElement('static', 'scalelabel', '', $label . $OUTPUT->render($labelhelp));
$this->_elements[] = $rescalegradesselect;
$this->_elements[] = @MoodleQuickForm::createElement('static', 'scalespacer', '', '<br />');
}
// Only show the max points form element when applicable.
if (!$this->isupdate || !$this->hasgrades || $this->currentgradetype == 'point') {
$label = html_writer::tag('label', $this->maxgradeformelement->getLabel(),
array('for' => $this->maxgradeformelement->getAttribute('id')));
$this->_elements[] = @MoodleQuickForm::createElement('static', 'pointlabel', '', $label);
$this->_elements[] = $this->maxgradeformelement;
$this->_elements[] = @MoodleQuickForm::createElement('static', 'pointspacer', '', '<br />');
}
}
/**
@@ -285,6 +347,48 @@ class MoodleQuickForm_modgrade extends MoodleQuickForm_group {
// A handy note: the parent scope of a closure is the function in which the closure was declared.
// Because of this using $this is safe despite the closures being called statically.
// A nasty magic hack!
$checkgradetypechange = function($val) {
// Nothing is affected by changes to the grade type if there are no grades yet.
if (!$this->hasgrades) {
return true;
}
// Check if we are changing the grade type when grades are present.
if (isset($val['modgrade_type']) && $val['modgrade_type'] !== $this->currentgradetype) {
return false;
}
return true;
};
$checkscalechange = function($val) {
// Nothing is affected by changes to the scale if there are no grades yet.
if (!$this->hasgrades) {
return true;
}
// Check if we are changing the scale type when grades are present.
if (isset($val['modgrade_type']) && $val['modgrade_type'] === 'scale') {
if (isset($val['modgrade_scale']) && ($val['modgrade_scale'] !== $this->currentscaleid)) {
return false;
}
}
return true;
};
$checkmaxgradechange = function($val) {
// Nothing is affected by changes to the max grade if there are no grades yet.
if (!$this->hasgrades) {
return true;
}
// If we are not using ratings we can change the max grade.
if (!$this->useratings) {
return true;
}
// Check if we are changing the max grade if we are using ratings and there is a grade.
if (isset($val['modgrade_type']) && $val['modgrade_type'] === 'point') {
if (isset($val['modgrade_point']) &&
grade_floats_different($this->currentgrade, $val['modgrade_point'])) {
return false;
}
}
return true;
};
$checkmaxgrade = function($val) {
// Closure to validate a max points value. See the note above about scope if this confuses you.
if (isset($val['modgrade_type']) && $val['modgrade_type'] === 'point') {
@@ -324,14 +428,20 @@ class MoodleQuickForm_modgrade extends MoodleQuickForm_group {
return true;
};
$cantchangegradetype = get_string('modgradecantchangegradetype', 'grades');
$cantchangemaxgrade = get_string('modgradecantchangeratingmaxgrade', 'grades');
$maxgradeexceeded = get_string('modgradeerrorbadpoint', 'grades', get_config('core', 'gradepointmax'));
$invalidscale = get_string('modgradeerrorbadscale', 'grades');
$cantchangescale = get_string('modgradecantchangescale', 'grades');
$mustchooserescale = get_string('mustchooserescaleyesorno', 'grades');
// When creating the rules the sixth arg is $force, we set it to true because otherwise the form
// will attempt to validate the existence of the element, we don't want this because the element
// is being created right now and doesn't actually exist as a registered element yet.
$caller->addRule($name, $cantchangegradetype, 'callback', $checkgradetypechange, 'server', false, true);
$caller->addRule($name, $cantchangemaxgrade, 'callback', $checkmaxgradechange, 'server', false, true);
$caller->addRule($name, $maxgradeexceeded, 'callback', $checkmaxgrade, 'server', false, true);
$caller->addRule($name, $invalidscale, 'callback', $checkvalidscale, 'server', false, true);
$caller->addRule($name, $cantchangescale, 'callback', $checkscalechange, 'server', false, true);
$caller->addRule($name, $mustchooserescale, 'callback', $checkrescale, 'server', false, true);
break;
@@ -342,6 +452,10 @@ class MoodleQuickForm_modgrade extends MoodleQuickForm_group {
// In this case we expect an int that is going to translate to a scale if negative, or to max points
// if positive.
// Set the maximum points field to disabled if the rescale option has not been chosen and there are grades.
$caller->disabledIf($this->getName() . '[modgrade_point]', $this->getName() .
'[modgrade_rescalegrades]', 'eq', '');
// A constant value should be given as an int.
// The default value should be an int and should really be $CFG->gradepointdefault.
$value = $this->_findValue($caller->_constantValues);
@@ -367,15 +481,15 @@ class MoodleQuickForm_modgrade extends MoodleQuickForm_group {
if (!empty($this->_elements)) {
if (!empty($value)) {
if ($value < 0) {
$this->_elements[1]->setValue('scale');
$this->_elements[4]->setValue(($value * -1));
$this->gradetypeformelement->setValue('scale');
$this->scaleformelement->setValue(($value * -1));
} else if ($value > 0) {
$this->_elements[1]->setValue('point');
$this->_elements[7]->setValue($value);
$this->gradetypeformelement->setValue('point');
$this->maxgradeformelement->setValue($value);
}
} else {
$this->_elements[1]->setValue('none');
$this->_elements[7]->setValue('');
$this->gradetypeformelement->setValue('none');
$this->maxgradeformelement->setValue('');
}
}
break;