diff --git a/grade/edit/tree/item.php b/grade/edit/tree/item.php index 7acf2ebe17d..b3399ddc815 100644 --- a/grade/edit/tree/item.php +++ b/grade/edit/tree/item.php @@ -132,7 +132,7 @@ if ($mform->is_cancelled()) { unset($data->locked); unset($data->locktime); - $convert = array('grademax', 'grademin', 'gradepass', 'multfactor', 'plusfactor', 'aggregationcoef'); + $convert = array('grademax', 'grademin', 'gradepass', 'multfactor', 'plusfactor', 'aggregationcoef', 'aggregationcoef2'); foreach ($convert as $param) { if (property_exists($data, $param)) { $data->$param = unformat_float($data->$param); @@ -148,6 +148,16 @@ if ($mform->is_cancelled()) { $grade_item->decimals = null; } + // Change weightoverride flag. + if (!isset($data->weightoverride)) { + $data->weightoverride = 0; // Checkbox unticked. + } + // If we are using natural weight and the weight has been un-overriden, force parent category to recalculate weights. + if ($grade_item->weightoverride != $data->weightoverride && $parent_category->aggregation == GRADE_AGGREGATE_SUM) { + $parent_category->force_regrading(); + } + $grade_item->weightoverride = $data->weightoverride; + if (empty($grade_item->id)) { $grade_item->itemtype = 'manual'; // all new items to be manual only $grade_item->insert(); diff --git a/grade/edit/tree/item_form.php b/grade/edit/tree/item_form.php index 13ad68703c9..5ec14799594 100644 --- a/grade/edit/tree/item_form.php +++ b/grade/edit/tree/item_form.php @@ -97,6 +97,14 @@ class edit_item_form extends moodleform { $mform->setType('grademin', PARAM_RAW); } + $mform->addElement('checkbox', 'weightoverride', get_string('adjustedweight', 'grades')); + $mform->addHelpButton('weightoverride', 'weightoverride', 'grades'); + + $mform->addElement('text', 'aggregationcoef2', get_string('weight', 'grades')); + $mform->addHelpButton('aggregationcoef2', 'weight', 'grades'); + $mform->setType('aggregationcoef2', PARAM_RAW); + $mform->hardFreeze('aggregationcoef2'); + $mform->addElement('text', 'gradepass', get_string('gradepass', 'grades')); $mform->addHelpButton('gradepass', 'gradepass', 'grades'); $mform->disabledIf('gradepass', 'gradetype', 'eq', GRADE_TYPE_NONE); @@ -295,6 +303,17 @@ class edit_item_form extends moodleform { $mform->disabledIf('aggregationcoef', 'parentcategory', 'eq', $parent_category->id); } + // Remove fields used by natural weighting if the parent category is not using natural weighting. + if ($parent_category->aggregation != GRADE_AGGREGATE_SUM) { + print_object('removing'); + if ($mform->elementExists('weightoverride')) { + $mform->removeElement('weightoverride'); + } + if ($mform->elementExists('aggregationcoef2')) { + $mform->removeElement('aggregationcoef2'); + } + } + if ($category = $grade_item->get_item_category()) { if ($category->aggregation == GRADE_AGGREGATE_SUM) { if ($mform->elementExists('gradetype')) { diff --git a/lang/en/grades.php b/lang/en/grades.php index 3b43a88bc7e..a8ab8781137 100644 --- a/lang/en/grades.php +++ b/lang/en/grades.php @@ -35,6 +35,7 @@ $string['addoutcome'] = 'Add an outcome'; $string['addoutcomeitem'] = 'Add outcome item'; $string['addscale'] = 'Add a scale'; $string['adjusted'] = 'Adjusted'; +$string['adjustedweight'] = 'Weight adjusted'; $string['aggregateextracreditmean'] = 'Mean of grades (with extra credits)'; $string['aggregatemax'] = 'Highest grade'; $string['aggregatemean'] = 'Mean of grades'; @@ -711,9 +712,12 @@ $string['viewbygroup'] = 'Group'; $string['viewgrades'] = 'View grades'; $string['warningexcludedsum'] = 'Warning: excluding of grades is not compatible with sum aggregation.'; $string['weight'] = 'weight'; +$string['weight_help'] = 'A value used to determine the relative value of multiple grade items in a category or course.'; $string['weightcourse'] = 'Use weighted grades for course'; $string['weightedascending'] = 'Sort by weighted percent ascending'; $string['weighteddescending'] = 'Sort by weighted percent descending'; +$string['weightoverride'] = 'weight adjustment'; +$string['weightoverride_help'] = 'Uncheck this to reset a grade item weight to its automatically calculated value. Checking this will prevent the weight being automatically adjusted.'; $string['weightedpct'] = 'weighted %'; $string['weightedpctcontribution'] = 'weighted % contribution'; $string['weightorextracredit'] = 'Weight or extra credit'; diff --git a/lib/grade/grade_category.php b/lib/grade/grade_category.php index 9ec498eace1..9fc10681b30 100644 --- a/lib/grade/grade_category.php +++ b/lib/grade/grade_category.php @@ -1031,7 +1031,6 @@ class grade_category extends grade_object { /** * Recalculate the weights of the grade items in this category. - * THIS DOES NOT TAKE INTO ACCOUNT HIDDEN ACTIVITIES, GROUPS. */ private function auto_update_weights() { if ($this->aggregation != GRADE_AGGREGATE_SUM) {