public function set_aggregation_fields_for_aggregation($from, $to) {
        $defaults = grade_category::get_default_aggregation_coefficient_values($to);

        $origaggregationcoef = $this->aggregationcoef;
        $origaggregationcoef2 = $this->aggregationcoef2;
        $origweighoverride = $this->weightoverride;

        if ($from == GRADE_AGGREGATE_SUM && $to == GRADE_AGGREGATE_SUM && $this->weightoverride) {
            // Do nothing. We are switching from SUM to SUM and the weight is overriden,
            // a teacher would not expect any change in this situation.

        } else if ($from == GRADE_AGGREGATE_WEIGHTED_MEAN && $to == GRADE_AGGREGATE_WEIGHTED_MEAN) {
            // Do nothing. The weights can be kept in this case.

        } else if (in_array($from, array(GRADE_AGGREGATE_SUM,  GRADE_AGGREGATE_EXTRACREDIT_MEAN, GRADE_AGGREGATE_WEIGHTED_MEAN2))
                && in_array($to, array(GRADE_AGGREGATE_SUM,  GRADE_AGGREGATE_EXTRACREDIT_MEAN, GRADE_AGGREGATE_WEIGHTED_MEAN2))) {

            // Reset all but the the extra credit field.
            $this->aggregationcoef2 = $defaults['aggregationcoef2'];
            $this->weightoverride = $defaults['weightoverride'];

            if ($to != GRADE_AGGREGATE_EXTRACREDIT_MEAN) {
                // Normalise extra credit, except for 'Mean with extra credit' which supports higher values than 1.
                $this->aggregationcoef = min(1, $this->aggregationcoef);
            }
        } else {
            // Reset all.
            $this->aggregationcoef = $defaults['aggregationcoef'];
            $this->aggregationcoef2 = $defaults['aggregationcoef2'];
            $this->weightoverride = $defaults['weightoverride'];
        }

        $acoefdiff       = grade_floats_different($origaggregationcoef, $this->aggregationcoef);
        $acoefdiff2      = grade_floats_different($origaggregationcoef2, $this->aggregationcoef2);
        $weightoverride  = grade_floats_different($origweighoverride, $this->weightoverride);

        return $acoefdiff || $acoefdiff2 || $weightoverride;
    }