Skip to content

Commit

Permalink
MDL-14008 various SUM aggregation bugfixes; merged from MOODLE_19_STABLE
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Mar 22, 2008
1 parent 85db09f commit 94e7961
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 17 deletions.
2 changes: 1 addition & 1 deletion grade/edit/tree/category_form.php
Expand Up @@ -65,7 +65,6 @@ function definition() {
} 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');
}
Expand Down Expand Up @@ -235,6 +234,7 @@ function definition_after_data() {
$mform->setHelpButton('aggregationcoef', array('aggregationcoef', get_string('aggregationcoef', 'grades'), 'grade'), true);
}
}

}

if ($grade_item->is_calculated()) {
Expand Down
5 changes: 4 additions & 1 deletion grade/edit/tree/item.php
Expand Up @@ -58,6 +58,7 @@
$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();
Expand Down Expand Up @@ -90,7 +91,9 @@
$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);
Expand Down
5 changes: 3 additions & 2 deletions grade/edit/tree/item_form.php
Expand Up @@ -153,7 +153,7 @@ function definition() {
$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';
Expand Down Expand Up @@ -271,6 +271,7 @@ function definition_after_data() {
$aggcoef = '';
if ($parent_category->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
$aggcoef = 'aggregationcoefweight';

} else if ($parent_category->aggregation == GRADE_AGGREGATE_EXTRACREDIT_MEAN) {
$aggcoef = 'aggregationcoefextra';

Expand All @@ -280,7 +281,7 @@ function definition_after_data() {

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);
}
}
}
Expand Down
26 changes: 15 additions & 11 deletions grade/edit/tree/outcomeitem.php
Expand Up @@ -58,16 +58,8 @@
}
$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);
Expand Down Expand Up @@ -96,12 +88,24 @@
$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);
}
Expand Down
17 changes: 15 additions & 2 deletions grade/edit/tree/outcomeitem_form.php
Expand Up @@ -103,6 +103,9 @@ function definition() {
} 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';
}
Expand All @@ -117,8 +120,13 @@ function definition() {
}

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
Expand Down Expand Up @@ -190,9 +198,14 @@ function definition_after_data() {
$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'));
Expand Down

0 comments on commit 94e7961

Please sign in to comment.