MDL-47243 core_grades: Add weight settings to outcome edit page

This commit is contained in:
John Okely 2014-09-23 17:06:40 +08:00
parent cfa91962d1
commit c53708d9c0
2 changed files with 24 additions and 2 deletions

View file

@ -104,6 +104,7 @@ if (empty($parent_category)) {
$item->aggregationcoef = 0;
} else if ($parent_category->aggregation == GRADE_AGGREGATE_SUM) {
$item->aggregationcoef = $item->aggregationcoef > 0 ? 1 : 0;
$item->aggregationcoef2 = format_float($item->aggregationcoef2 * 100.0);
} else {
$item->aggregationcoef = format_float($item->aggregationcoef, 4);
}
@ -131,12 +132,15 @@ if ($data = $mform->get_data()) {
unset($data->locked);
unset($data->locktime);
$convert = array('gradepass', 'aggregationcoef');
$convert = array('gradepass', 'aggregationcoef', 'aggregationcoef2');
foreach ($convert as $param) {
if (property_exists($data, $param)) {
$data->$param = unformat_float($data->$param);
}
}
if (isset($data->aggregationcoef2) && $parent_category->aggregation == GRADE_AGGREGATE_SUM) {
$data->aggregationcoef2 = $data->aggregationcoef2 / 100.0;
}
$grade_item = new grade_item(array('id'=>$id, 'courseid'=>$courseid));
grade_item::set_properties($grade_item, $data);

View file

@ -73,6 +73,14 @@ class edit_outcomeitem_form extends moodleform {
$mform->addHelpButton('cmid', 'linkedactivity', 'grades');
$mform->setDefault('cmid', 0);
$mform->addElement('advcheckbox', 'weightoverride', get_string('adjustedweight', 'grades'));
$mform->addHelpButton('weightoverride', 'weightoverride', 'grades');
$mform->addElement('text', 'aggregationcoef2', get_string('weight', 'grades'));
$mform->addHelpButton('aggregationcoef2', 'weight', 'grades');
$mform->setType('aggregationcoef2', PARAM_RAW);
$mform->disabledIf('aggregationcoef2', 'weightoverride');
/// hiding
/// advcheckbox is not compatible with disabledIf !!
$mform->addElement('checkbox', 'hidden', get_string('hidden', 'grades'));
@ -125,8 +133,9 @@ class edit_outcomeitem_form extends moodleform {
}
if ($coefstring !== '') {
if ($coefstring == 'aggregationcoefextrasum') {
if ($coefstring == 'aggregationcoefextrasum' || $coefstring == 'aggregationcoefextraweightsum') {
// advcheckbox is not compatible with disabledIf!
$coefstring = 'aggregationcoefextrasum';
$mform->addElement('checkbox', 'aggregationcoef', get_string($coefstring, 'grades'));
} else {
$mform->addElement('text', 'aggregationcoef', get_string($coefstring, 'grades'));
@ -219,6 +228,15 @@ class edit_outcomeitem_form extends moodleform {
$mform->addHelpButton('aggregationcoef', $aggcoef, 'grades');
}
}
// Remove fields used by natural weighting if the parent category is not using natural weighting.
if ($parent_category->aggregation != GRADE_AGGREGATE_SUM) {
if ($mform->elementExists('weightoverride')) {
$mform->removeElement('weightoverride');
}
if ($mform->elementExists('aggregationcoef2')) {
$mform->removeElement('aggregationcoef2');
}
}
}
}