original_string: public function set($value) {
          global $DB;
  
          $userid = $this->grade->userid;
          $gradeitem = $this->grade->grade_item;
  
          $feedback = false;
          $feedbackformat = false;
          if ($gradeitem->gradetype == GRADE_TYPE_SCALE) {
              if ($value == -1) {
                  $finalgrade = null;
              } else {
                  $finalgrade = $value;
              }
          } else {
              $finalgrade = unformat_float($value);
          }
  
          $errorstr = '';
          if ($finalgrade) {
              $bounded = $gradeitem->bounded_grade($finalgrade);
              if ($bounded > $finalgrade) {
                  $errorstr = 'lessthanmin';
              } else if ($bounded < $finalgrade) {
                  $errorstr = 'morethanmax';
              }
          }
  
          if ($errorstr) {
              $user = $DB->get_record('user', array('id' => $userid), 'id, firstname, alternatename, lastname');
              $gradestr = new stdClass;
              if (!empty($user->alternatename)) {
                  $gradestr->username = $user->alternatename . ' (' . $user->firstname . ') ' . $user->lastname;
              } else {
                  $gradestr->username = $user->firstname . ' ' . $user->lastname;
              }
              $gradestr->itemname = $this->grade->grade_item->get_name();
              $errorstr = get_string($errorstr, 'grades', $gradestr);
              return $errorstr;
          }
  
          // Only update grades if there are no errors.
          $gradeitem->update_final_grade($userid, $finalgrade, 'singleview', $feedback, FORMAT_MOODLE);
          return '';
      }
code: public function set($value) {
          global $DB;
  
          $userid = $this->grade->userid;
          $gradeitem = $this->grade->grade_item;
  
          $feedback = false;
          $feedbackformat = false;
          if ($gradeitem->gradetype == GRADE_TYPE_SCALE) {
              if ($value == -1) {
                  $finalgrade = null;
              } else {
                  $finalgrade = $value;
              }
          } else {
              $finalgrade = unformat_float($value);
          }
  
          $errorstr = '';
          if ($finalgrade) {
              $bounded = $gradeitem->bounded_grade($finalgrade);
              if ($bounded > $finalgrade) {
                  $errorstr = 'lessthanmin';
              } else if ($bounded < $finalgrade) {
                  $errorstr = 'morethanmax';
              }
          }
  
          if ($errorstr) {
              $user = $DB->get_record('user', array('id' => $userid), 'id, firstname, alternatename, lastname');
              $gradestr = new stdClass;
              if (!empty($user->alternatename)) {
                  $gradestr->username = $user->alternatename . ' (' . $user->firstname . ') ' . $user->lastname;
              } else {
                  $gradestr->username = $user->firstname . ' ' . $user->lastname;
              }
              $gradestr->itemname = $this->grade->grade_item->get_name();
              $errorstr = get_string($errorstr, 'grades', $gradestr);
              return $errorstr;
          }
  
          // Only update grades if there are no errors.
          $gradeitem->update_final_grade($userid, $finalgrade, 'singleview', $feedback, FORMAT_MOODLE);
          return '';
      }
code_tokens: public function set ( $ value ) { global $ DB ; $ userid = $ this -> grade -> userid ; $ gradeitem = $ this -> grade -> grade_item ; $ feedback = false ; $ feedbackformat = false ; if ( $ gradeitem -> gradetype == GRADE_TYPE_SCALE ) { if ( $ value == - 1 ) { $ finalgrade = null ; } else { $ finalgrade = $ value ; } } else { $ finalgrade = unformat_float ( $ value ) ; } $ errorstr = '' ; if ( $ finalgrade ) { $ bounded = $ gradeitem -> bounded_grade ( $ finalgrade ) ; if ( $ bounded > $ finalgrade ) { $ errorstr = 'lessthanmin' ; } else if ( $ bounded < $ finalgrade ) { $ errorstr = 'morethanmax' ; } } if ( $ errorstr ) { $ user = $ DB -> get_record ( 'user' , array ( 'id' => $ userid ) , 'id, firstname, alternatename, lastname' ) ; $ gradestr = new stdClass ; if ( ! empty ( $ user -> alternatename ) ) { $ gradestr -> username = $ user -> alternatename . ' (' . $ user -> firstname . ') ' . $ user -> lastname ; } else { $ gradestr -> username = $ user -> firstname . ' ' . $ user -> lastname ; } $ gradestr -> itemname = $ this -> grade -> grade_item -> get_name ( ) ; $ errorstr = get_string ( $ errorstr , 'grades' , $ gradestr ) ; return $ errorstr ; } // Only update grades if there are no errors. $ gradeitem -> update_final_grade ( $ userid , $ finalgrade , 'singleview' , $ feedback , FORMAT_MOODLE ) ; return '' ; }
docstring: Save the altered value for this field.
  
  @param string $value The new value.
  @return string Any error string
docstring_tokens: Save the altered value for this field .