original_string: public function rescale_grades_keep_percentage($oldgrademin, $oldgrademax, $newgrademin, $newgrademax, $source = null) {
          global $DB;
  
          if (empty($this->id)) {
              return false;
          }
  
          if ($oldgrademax <= $oldgrademin) {
              // Grades cannot be scaled.
              return false;
          }
          $scale = ($newgrademax - $newgrademin) / ($oldgrademax - $oldgrademin);
          if (($newgrademax - $newgrademin) <= 1) {
              // We would lose too much precision, lets bail.
              return false;
          }
  
          $rs = $DB->get_recordset('grade_grades', array('itemid' => $this->id));
  
          foreach ($rs as $graderecord) {
              // For each record, create an object to work on.
              $grade = new grade_grade($graderecord, false);
              // Set this object in the item so it doesn't re-fetch it.
              $grade->grade_item = $this;
  
              if (!$this->is_category_item() || ($this->is_category_item() && $grade->is_overridden())) {
                  // Updating the raw grade automatically updates the min/max.
                  if ($this->is_raw_used()) {
                      $rawgrade = (($grade->rawgrade - $oldgrademin) * $scale) + $newgrademin;
                      $this->update_raw_grade(false, $rawgrade, $source, false, FORMAT_MOODLE, null, null, null, $grade);
                  } else {
                      $finalgrade = (($grade->finalgrade - $oldgrademin) * $scale) + $newgrademin;
                      $this->update_final_grade($grade->userid, $finalgrade, $source);
                  }
              }
          }
          $rs->close();
  
          // Mark this item for regrading.
          $this->force_regrading();
  
          return true;
      }
code: public function rescale_grades_keep_percentage($oldgrademin, $oldgrademax, $newgrademin, $newgrademax, $source = null) {
          global $DB;
  
          if (empty($this->id)) {
              return false;
          }
  
          if ($oldgrademax <= $oldgrademin) {
              // Grades cannot be scaled.
              return false;
          }
          $scale = ($newgrademax - $newgrademin) / ($oldgrademax - $oldgrademin);
          if (($newgrademax - $newgrademin) <= 1) {
              // We would lose too much precision, lets bail.
              return false;
          }
  
          $rs = $DB->get_recordset('grade_grades', array('itemid' => $this->id));
  
          foreach ($rs as $graderecord) {
              // For each record, create an object to work on.
              $grade = new grade_grade($graderecord, false);
              // Set this object in the item so it doesn't re-fetch it.
              $grade->grade_item = $this;
  
              if (!$this->is_category_item() || ($this->is_category_item() && $grade->is_overridden())) {
                  // Updating the raw grade automatically updates the min/max.
                  if ($this->is_raw_used()) {
                      $rawgrade = (($grade->rawgrade - $oldgrademin) * $scale) + $newgrademin;
                      $this->update_raw_grade(false, $rawgrade, $source, false, FORMAT_MOODLE, null, null, null, $grade);
                  } else {
                      $finalgrade = (($grade->finalgrade - $oldgrademin) * $scale) + $newgrademin;
                      $this->update_final_grade($grade->userid, $finalgrade, $source);
                  }
              }
          }
          $rs->close();
  
          // Mark this item for regrading.
          $this->force_regrading();
  
          return true;
      }
code_tokens: public function rescale_grades_keep_percentage ( $ oldgrademin , $ oldgrademax , $ newgrademin , $ newgrademax , $ source = null ) { global $ DB ; if ( empty ( $ this -> id ) ) { return false ; } if ( $ oldgrademax <= $ oldgrademin ) { // Grades cannot be scaled. return false ; } $ scale = ( $ newgrademax - $ newgrademin ) / ( $ oldgrademax - $ oldgrademin ) ; if ( ( $ newgrademax - $ newgrademin ) <= 1 ) { // We would lose too much precision, lets bail. return false ; } $ rs = $ DB -> get_recordset ( 'grade_grades' , array ( 'itemid' => $ this -> id ) ) ; foreach ( $ rs as $ graderecord ) { // For each record, create an object to work on. $ grade = new grade_grade ( $ graderecord , false ) ; // Set this object in the item so it doesn't re-fetch it. $ grade -> grade_item = $ this ; if ( ! $ this -> is_category_item ( ) || ( $ this -> is_category_item ( ) && $ grade -> is_overridden ( ) ) ) { // Updating the raw grade automatically updates the min/max. if ( $ this -> is_raw_used ( ) ) { $ rawgrade = ( ( $ grade -> rawgrade - $ oldgrademin ) * $ scale ) + $ newgrademin ; $ this -> update_raw_grade ( false , $ rawgrade , $ source , false , FORMAT_MOODLE , null , null , null , $ grade ) ; } else { $ finalgrade = ( ( $ grade -> finalgrade - $ oldgrademin ) * $ scale ) + $ newgrademin ; $ this -> update_final_grade ( $ grade -> userid , $ finalgrade , $ source ) ; } } } $ rs -> close ( ) ; // Mark this item for regrading. $ this -> force_regrading ( ) ; return true ; }
docstring: Update the rawgrademax and rawgrademin for all grade_grades records for this item.
  Scale every rawgrade to maintain the percentage. This function should be called
  after the gradeitem has been updated to the new min and max values.
  
  @param float $oldgrademin The previous grade min value
  @param float $oldgrademax The previous grade max value
  @param float $newgrademin The new grade min value
  @param float $newgrademax The new grade max value
  @param string $source from where was the object inserted (mod/forum, manual, etc.)
  @return bool True on success
docstring_tokens: Update the rawgrademax and rawgrademin for all grade_grades records for this item . Scale every rawgrade to maintain the percentage . This function should be called after the gradeitem has been updated to the new min and max values .