original_string: 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;
      }
code: 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;
      }
code_tokens: 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 ; }
docstring: Update the aggregation fields when the aggregation changed.
  
  This method should always be called when the aggregation has changed, but also when
  the item was moved to another category, even it if uses the same aggregation method.
  
  Some values such as the weight only make sense within a category, once moved the
  values should be reset to let the user adapt them accordingly.
  
  Note that this method does not save the grade item.
  {@link grade_item::update()} has to be called manually after using this method.
  
  @param  int $from Aggregation method constant value.
  @param  int $to   Aggregation method constant value.
  @return boolean   True when at least one field was changed, false otherwise
docstring_tokens: Update the aggregation fields when the aggregation changed .