} 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');
}
$mform->setHelpButton('aggregationcoef', array('aggregationcoef', get_string('aggregationcoef', 'grades'), 'grade'), true);
}
}
+
}
if ($grade_item->is_calculated()) {
$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();
$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);
$coefstring = ($coefstring=='' or $coefstring=='aggregationcoefextra') ? 'aggregationcoefextra' : 'aggregationcoef';
} else if ($cat->aggregation == GRADE_AGGREGATE_SUM) {
- $coefstring = ($coefstring=='' or $coefstring=='aggregationcoefextrasum') ? 'aggregationcoefextrasum' : 'aggregationcoef';
+ $coefstring = ($coefstring=='' or $coefstring=='aggregationcoefextrasump') ? 'aggregationcoefextrasum' : 'aggregationcoef';
} else {
$coefstring = 'aggregationcoef';
$aggcoef = '';
if ($parent_category->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
$aggcoef = 'aggregationcoefweight';
+
} else if ($parent_category->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN) {
$aggcoef = 'aggregationcoefextra';
if ($aggcoef !== '') {
$agg_el->setLabel(get_string($aggcoef, 'grades'));
- $mform->setHelpButton('aggregationcoef', array($aggcoef, get_string($aggcoef, 'grades'), 'grade'), true);
+ $mform->setHelpButton('aggregationcoef', array('aggregationcoef', get_string('aggregationcoef', 'grades'), 'grade'), true);
}
}
}
}
$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);
$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);
}
} 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';
}
}
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
$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'));