MDL-14008 various SUM aggregation bugfixes
This commit is contained in:
@@ -65,7 +65,6 @@ class edit_category_form extends moodleform {
|
||||
} else {
|
||||
$mform->addElement('checkbox', 'aggregateoutcomes', get_string('aggregateoutcomes', 'grades'));
|
||||
$mform->setHelpButton('aggregateoutcomes', array('aggregateoutcomes', get_string('aggregateoutcomes', 'grades'), 'grade'), true);
|
||||
$mform->disabledIf('aggregateoutcomes', 'aggregation', 'eq', GRADE_AGGREGATE_SUM);
|
||||
if ((int)$CFG->grade_aggregateoutcomes_flag & 2) {
|
||||
$mform->setAdvanced('aggregateoutcomes');
|
||||
}
|
||||
|
||||
@@ -58,6 +58,7 @@ if ($grade_item = grade_item::fetch(array('id'=>$id, 'courseid'=>$courseid))) {
|
||||
$item = $grade_item->get_record_data();
|
||||
|
||||
if ($grade_item->is_course_item()) {
|
||||
$parent_category = null;
|
||||
$item->parentcategory = 0;
|
||||
} else if ($grade_item->is_category_item()) {
|
||||
$parent_category = $grade_item->get_parent_category();
|
||||
@@ -90,7 +91,9 @@ $item->gradepass = format_float($item->gradepass, $decimalpoints);
|
||||
$item->multfactor = format_float($item->multfactor, 4);
|
||||
$item->plusfactor = format_float($item->plusfactor, 4);
|
||||
|
||||
if ($parent_category->aggregation == GRADE_AGGREGATE_SUM) {
|
||||
if (empty($parent_category)) {
|
||||
$item->aggregationcoef = 0;
|
||||
} else if ($parent_category->aggregation == GRADE_AGGREGATE_SUM) {
|
||||
$item->aggregationcoef = $item->aggregationcoef > 0 ? 1 : 0;
|
||||
} else {
|
||||
$item->aggregationcoef = format_float($item->aggregationcoef, 4);
|
||||
|
||||
@@ -271,6 +271,7 @@ class edit_item_form extends moodleform {
|
||||
$aggcoef = '';
|
||||
if ($parent_category->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
|
||||
$aggcoef = 'aggregationcoefweight';
|
||||
|
||||
} else if ($parent_category->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN) {
|
||||
$aggcoef = 'aggregationcoefextra';
|
||||
|
||||
|
||||
@@ -58,16 +58,8 @@ if ($grade_item = grade_item::fetch(array('id'=>$id, 'courseid'=>$courseid))) {
|
||||
}
|
||||
$item = $grade_item->get_record_data();
|
||||
|
||||
if ($grade_item->is_course_item()) {
|
||||
$item->parentcategory = 0;
|
||||
} else if ($grade_item->is_category_item()) {
|
||||
$parent_category = $grade_item->get_parent_category();
|
||||
$parent_category = $parent_category->get_parent_category();
|
||||
$item->parentcategory = $parent_category->id;
|
||||
} else {
|
||||
$parent_category = $grade_item->get_parent_category();
|
||||
$item->parentcategory = $parent_category->id;
|
||||
}
|
||||
$parent_category = $grade_item->get_parent_category();
|
||||
$item->parentcategory = $parent_category->id;
|
||||
|
||||
if ($item->itemtype == 'mod') {
|
||||
$cm = get_coursemodule_from_instance($item->itemmodule, $item->iteminstance, $item->courseid);
|
||||
@@ -96,12 +88,24 @@ if ($item->hidden > 1) {
|
||||
$item->locked = !empty($item->locked);
|
||||
|
||||
$item->gradepass = format_float($item->gradepass, $decimalpoints);
|
||||
$item->aggregationcoef = format_float($item->aggregationcoef, 4);
|
||||
|
||||
if (empty($parent_category)) {
|
||||
$item->aggregationcoef = 0;
|
||||
} else if ($parent_category->aggregation == GRADE_AGGREGATE_SUM) {
|
||||
$item->aggregationcoef = $item->aggregationcoef > 0 ? 1 : 0;
|
||||
} else {
|
||||
$item->aggregationcoef = format_float($item->aggregationcoef, 4);
|
||||
}
|
||||
|
||||
$mform->set_data($item);
|
||||
|
||||
|
||||
if ($data = $mform->get_data(false)) {
|
||||
|
||||
if (!isset($data->aggregationcoef)) {
|
||||
$data->aggregationcoef = 0;
|
||||
}
|
||||
|
||||
if (array_key_exists('calculation', $data)) {
|
||||
$data->calculation = grade_item::normalize_formula($data->calculation, $course->id);
|
||||
}
|
||||
|
||||
@@ -103,6 +103,9 @@ class edit_outcomeitem_form extends moodleform {
|
||||
} else if ($cat->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN) {
|
||||
$coefstring = ($coefstring=='' or $coefstring=='aggregationcoefextra') ? 'aggregationcoefextra' : 'aggregationcoef';
|
||||
|
||||
} else if ($cat->aggregation == GRADE_AGGREGATE_SUM) {
|
||||
$coefstring = ($coefstring=='' or $coefstring=='aggregationcoefextrasump') ? 'aggregationcoefextrasum' : 'aggregationcoef';
|
||||
|
||||
} else {
|
||||
$coefstring = 'aggregationcoef';
|
||||
}
|
||||
@@ -117,8 +120,13 @@ class edit_outcomeitem_form extends moodleform {
|
||||
}
|
||||
|
||||
if ($coefstring !== '') {
|
||||
$mform->addElement('text', 'aggregationcoef', get_string($coefstring, 'grades'));
|
||||
$mform->setHelpButton('aggregationcoef', array('aggregationcoef', get_string('aggregationcoef', 'grades'), 'grade'));
|
||||
if ($coefstring == 'aggregationcoefextrasum') {
|
||||
// advcheckbox is not compatible with disabledIf!
|
||||
$mform->addElement('checkbox', 'aggregationcoef', get_string($coefstring, 'grades'));
|
||||
} else {
|
||||
$mform->addElement('text', 'aggregationcoef', get_string($coefstring, 'grades'));
|
||||
}
|
||||
$mform->setHelpButton('aggregationcoef', array('aggregationcoef', get_string('aggregationcoef', 'grades'), 'grade'), true);
|
||||
}
|
||||
|
||||
/// hidden params
|
||||
@@ -190,9 +198,14 @@ class edit_outcomeitem_form extends moodleform {
|
||||
$aggcoef = '';
|
||||
if ($parent_category->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
|
||||
$aggcoef = 'aggregationcoefweight';
|
||||
|
||||
} else if ($parent_category->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN) {
|
||||
$aggcoef = 'aggregationcoefextra';
|
||||
|
||||
} else if ($parent_category->aggregation == GRADE_AGGREGATE_SUM) {
|
||||
$aggcoef = 'aggregationcoefextrasum';
|
||||
}
|
||||
|
||||
if ($aggcoef !== '') {
|
||||
$agg_el->setLabel(get_string($aggcoef, 'grades'));
|
||||
$mform->setHelpButton('aggregationcoef', array('aggregationcoef', get_string('aggregationcoef', 'grades'), 'grade'));
|
||||
|
||||
Reference in New Issue
Block a user