Skip to content

Commit

Permalink
Extra credit gradebook fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rrusso committed Sep 29, 2023
1 parent fafa32b commit a98afc5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
29 changes: 19 additions & 10 deletions grade/edit/tree/category_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ function definition() {
/// parent category related settings
$mform->addElement('header', 'headerparent', get_string('parentcategory', 'grades'));

$mform->addElement('advcheckbox', 'grade_item_weightoverride', get_string('adjustedweight', 'grades'));
$mform->addElement('checkbox', 'grade_item_weightoverride', get_string('adjustedweight', 'grades'));
$mform->addHelpButton('grade_item_weightoverride', 'weightoverride', 'grades');

$mform->addElement('float', 'grade_item_aggregationcoef2', get_string('weight', 'grades'));
Expand Down Expand Up @@ -520,9 +520,10 @@ function definition_after_data() {
$coefstring = $grade_item->get_coefstring();

// BEGIN LSU Weighted Mean extra credit.
if ($coefstring == 'aggregationcoefextrasum' || ($coefstring == 'aggregationcoefweight' && $grade_item->aggregationcoef < 0) || $coefstring == 'aggregationcoefextraweightsum' ) {
// END LSU Weighted Mean extra credit.
// advcheckbox is not compatible with disabledIf!
if ($coefstring == 'aggregationcoefextrasum'
|| ($coefstring == 'aggregationcoefweight' && $grade_item->aggregationcoef < 0)
|| $coefstring == 'aggregationcoefextraweightsum' ) {
// END LSU Weighted Mean extra credit.
// BEGIN LSU Gradebook Enhancement.
if ($coefstring == 'aggregationcoefextraweightsum') {
$element =& $mform->createElement('checkbox', 'grade_item_aggregationcoef', get_string('aggregationcoefextrasum', 'grades'));
Expand All @@ -531,13 +532,14 @@ function definition_after_data() {
}
// END LSU Gradebook Enhancement.
// BEGIN LSU Disable Extra Credit unless weight adjusted.
$mform->disabledIf('grade_item_aggregationcoef', 'grade_item_weightoverride');
$mform->hideIf('grade_item_aggregationcoef', 'grade_item_weightoverride', 'notchecked');
// END LSU Disable Extra Credit unless weight adjusted.
} else {
$element =& $mform->createElement('text', 'grade_item_aggregationcoef', get_string($coefstring, 'grades'));
// BEGIN LSU Disable Extra Credit unless weight adjusted.
$mform->disabledIf('grade_item_aggregationcoef', 'grade_item_weightoverride');
// END LSU Disable Extra Credit unless weight adjusted.
// BEGIN LSU Gradebook Enhancement.
$mform->hideIf('grade_item_aggregationcoef', 'grade_item_weightoverride', 'notchecked');
$mform->hideIf('grade_item_weightoverride', 'grade_item_extracred', 'checked');
// END LSU Gradebook Enhancement.
}
$mform->insertElementBefore($element, 'parentcategory');
// BEGIN LSU Gradebook Enhancement.
Expand All @@ -559,6 +561,7 @@ function definition_after_data() {
$mform->removeElement('grade_item_aggregationcoef2');
}
$element =& $mform->createElement('checkbox', 'grade_item_extracred', get_string('aggregationcoefextrasum', 'grades'));
$mform->hideIf('grade_item_extracred', 'grade_item_weightoverride', 'checked');

if ($mform->elementExists('parentcategory')) {
$mform->insertElementBefore($element, 'parentcategory');
Expand All @@ -575,9 +578,15 @@ function definition_after_data() {
if ($mform->elementExists('grade_item_aggregationcoef')) {
$mform->removeElement('grade_item_aggregationcoef');
}
$mform->addElement('checkbox', 'grade_item_extracred', get_string('aggregationcoefextrasum', 'grades'));
$element =& $mform->createElement('checkbox', 'grade_item_extracred', get_string('aggregationcoefextrasum', 'grades'));

if ($mform->elementExists('parentcategory')) {
$mform->insertElementBefore($element, 'parentcategory');
} else {
$mform->insertElementBefore($element, 'id');
}
if ($grade_item->aggregationcoef < 0) {
$mform->setDefault('grade_item_extracred','1');
$mform->setDefault('grade_item_extracred','1');
}
} else {
if ($mform->elementExists('grade_item_weightoverride')) {
Expand Down
17 changes: 17 additions & 0 deletions grade/edit/tree/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -604,9 +604,15 @@ public static function update_gradecategory(grade_category $gradecategory, stdCl
if (empty($gradecategory->id)) {
$gradecategory->insert();

// BEGIN LSU Weighted Mean Extra Credit.
} else {
$ectest = isset($data->grade_item_extracred);
if ($ectest == 1) {
$data->grade_item_aggregationcoef = -1;
}
$gradecategory->update();
}
// END LSU Weighted Mean Extra Credit.

// GRADE ITEM.
// Grade item data saved with prefix "grade_item_".
Expand Down Expand Up @@ -712,6 +718,17 @@ public static function update_gradecategory(grade_category $gradecategory, stdCl
$gradeitem->set_locktime($locktime); // Locktime first - it might be removed when unlocking.
$gradeitem->set_locked($locked, false, true);

// BEGIN LSU Weighted Mean Extra Credit.
$ectest = isset($data->grade_item_extracred);
$parentcategory = $gradeitem->get_parent_category();

if ($gradeitem->itemtype == 'category' && $parentcategory->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN && $ectest == 1) {
$gradeitem->aggregationcoef = $gradeitem->aggregationcoef <> 0 ? abs($gradeitem->aggregationcoef) * -1 : -1;
$gradeitem->weightoverride = 0;
$gradeitem->aggregationcoef2 = 0;
}
// END LSU Weighted Mean Extra Credit.

$gradeitem->update(); // We don't need to insert it, it's already created when the category is created.

// Set parent if needed.
Expand Down

0 comments on commit a98afc5

Please sign in to comment.