$item->gradepass = format_float($item->gradepass, $decimalpoints);
$item->multfactor = format_float($item->multfactor, 4);
$item->plusfactor = format_float($item->plusfactor, 4);
-$item->aggregationcoef = format_float($item->aggregationcoef, 4);
+
+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;
+ }
+
$hidden = empty($data->hidden) ? 0: $data->hidden;
$hiddenuntil = empty($data->hiddenuntil) ? 0: $data->hiddenuntil;
unset($data->hidden);
}
/// hiding
- /// advcheckbox is not compatible with disabledIf !!
+ // advcheckbox is not compatible with disabledIf!
$mform->addElement('checkbox', 'hidden', get_string('hidden', 'grades'));
$mform->setHelpButton('hidden', array('hidden', get_string('hidden', 'grades'), 'grade'));
$mform->addElement('date_time_selector', 'hiddenuntil', get_string('hiddenuntil', 'grades'), array('optional'=>true));
} 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'));
+ 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(false, get_string($coefstring, 'grades'),
false, true, false, get_string($coefstring.'help', 'grades')));
}
$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(false, get_string($aggcoef, 'grades'),
$parent_category->apply_forced_settings();
- if (!$parent_category->is_aggregationcoef_used()) {
+ if (!$parent_category->is_aggregationcoef_used() or $parent_category->aggregation == GRADE_AGGREGATE_SUM) {
if ($mform->elementExists('aggregationcoef')) {
$mform->removeElement('aggregationcoef');
}
$string['aggregationcoef'] = 'Aggregation coefficient';
$string['aggregationcoefextra'] = 'Extra credit';
$string['aggregationcoefextrahelp'] = 'Extra credit for this grade item during aggregation.';
+$string['aggregationcoefextrasum'] = 'Extra credit';
+$string['aggregationcoefextrasumhelp'] = 'Extra credit for this grade item during aggregation.';
$string['aggregationcoefweight'] = 'Item weight';
$string['aggregationcoefweighthelp'] = 'Weight applied to all grades in this grade item during aggregation with other grade items.';
$string['aggregationhelp'] = 'Strategy used to aggregate grades across all students in a course.';
//find max grade
foreach ($items as $item) {
if ($item->gradetype != GRADE_TYPE_VALUE) {
- continue; // sum only items with value grades, no scales and outcomes!
+ // sum only items with value grades, no scales and outcomes!
+ unset($grade_values[$item->id]);
+ continue;
+ }
+ if ($item->aggregationcoef > 0) {
+ // extra credit from this activity - does not affect total
+ continue;
}
$max += $item->grademax;
}
*/
function is_aggregationcoef_used() {
return ($this->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN
- or $this->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN);
+ or $this->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN
+ or $this->aggregation == GRADE_AGGREGATE_SUM);
}
return null;
}
+ if ($source_max == $source_min or $target_min == $target_max) {
+ // prevent division by 0
+ return $target_max;
+ }
+
$factor = ($rawgrade - $source_min) / ($source_max - $source_min);
$diff = $target_max - $target_min;
$standardised_value = $factor * $diff + $target_min;