MDL-12942 extra credit implemented in sum aggregation type; fixed sum aggregation; fixed division by zero in item grade min==max; merged from MOODLE_19_STABLE
This commit is contained in:
@@ -89,12 +89,21 @@ $item->grademin = format_float($item->grademin, $decimalpoints);
|
||||
$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);
|
||||
|
||||
@@ -129,7 +129,7 @@ class edit_item_form extends moodleform {
|
||||
}
|
||||
|
||||
/// 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));
|
||||
@@ -164,6 +164,9 @@ class edit_item_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';
|
||||
}
|
||||
@@ -177,7 +180,12 @@ class edit_item_form extends moodleform {
|
||||
}
|
||||
|
||||
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')));
|
||||
}
|
||||
@@ -278,7 +286,11 @@ class edit_item_form extends moodleform {
|
||||
$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'),
|
||||
|
||||
@@ -185,7 +185,7 @@ class edit_outcomeitem_form extends moodleform {
|
||||
|
||||
$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');
|
||||
}
|
||||
|
||||
@@ -31,6 +31,8 @@ $string['aggregation'] = 'Aggregation';
|
||||
$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.';
|
||||
|
||||
@@ -689,7 +689,13 @@ class grade_category extends grade_object {
|
||||
//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;
|
||||
}
|
||||
@@ -740,7 +746,8 @@ class grade_category extends grade_object {
|
||||
*/
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -535,6 +535,11 @@ class grade_grade extends grade_object {
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user