original_string: public static function save_grade($assignmentid,
                                        $userid,
                                        $grade,
                                        $attemptnumber,
                                        $addattempt,
                                        $workflowstate,
                                        $applytoall,
                                        $plugindata = array(),
                                        $advancedgradingdata = array()) {
          global $CFG, $USER;
  
          $params = self::validate_parameters(self::save_grade_parameters(),
                                              array('assignmentid' => $assignmentid,
                                                    'userid' => $userid,
                                                    'grade' => $grade,
                                                    'attemptnumber' => $attemptnumber,
                                                    'workflowstate' => $workflowstate,
                                                    'addattempt' => $addattempt,
                                                    'applytoall' => $applytoall,
                                                    'plugindata' => $plugindata,
                                                    'advancedgradingdata' => $advancedgradingdata));
  
          list($assignment, $course, $cm, $context) = self::validate_assign($params['assignmentid']);
  
          $gradedata = (object)$params['plugindata'];
  
          $gradedata->addattempt = $params['addattempt'];
          $gradedata->attemptnumber = $params['attemptnumber'];
          $gradedata->workflowstate = $params['workflowstate'];
          $gradedata->applytoall = $params['applytoall'];
          $gradedata->grade = $params['grade'];
  
          if (!empty($params['advancedgradingdata'])) {
              $advancedgrading = array();
              $criteria = reset($params['advancedgradingdata']);
              foreach ($criteria as $key => $criterion) {
                  $details = array();
                  foreach ($criterion as $value) {
                      foreach ($value['fillings'] as $filling) {
                          $details[$value['criterionid']] = $filling;
                      }
                  }
                  $advancedgrading[$key] = $details;
              }
              $gradedata->advancedgrading = $advancedgrading;
          }
  
          $assignment->save_grade($params['userid'], $gradedata);
  
          return null;
      }
code: public static function save_grade($assignmentid,
                                        $userid,
                                        $grade,
                                        $attemptnumber,
                                        $addattempt,
                                        $workflowstate,
                                        $applytoall,
                                        $plugindata = array(),
                                        $advancedgradingdata = array()) {
          global $CFG, $USER;
  
          $params = self::validate_parameters(self::save_grade_parameters(),
                                              array('assignmentid' => $assignmentid,
                                                    'userid' => $userid,
                                                    'grade' => $grade,
                                                    'attemptnumber' => $attemptnumber,
                                                    'workflowstate' => $workflowstate,
                                                    'addattempt' => $addattempt,
                                                    'applytoall' => $applytoall,
                                                    'plugindata' => $plugindata,
                                                    'advancedgradingdata' => $advancedgradingdata));
  
          list($assignment, $course, $cm, $context) = self::validate_assign($params['assignmentid']);
  
          $gradedata = (object)$params['plugindata'];
  
          $gradedata->addattempt = $params['addattempt'];
          $gradedata->attemptnumber = $params['attemptnumber'];
          $gradedata->workflowstate = $params['workflowstate'];
          $gradedata->applytoall = $params['applytoall'];
          $gradedata->grade = $params['grade'];
  
          if (!empty($params['advancedgradingdata'])) {
              $advancedgrading = array();
              $criteria = reset($params['advancedgradingdata']);
              foreach ($criteria as $key => $criterion) {
                  $details = array();
                  foreach ($criterion as $value) {
                      foreach ($value['fillings'] as $filling) {
                          $details[$value['criterionid']] = $filling;
                      }
                  }
                  $advancedgrading[$key] = $details;
              }
              $gradedata->advancedgrading = $advancedgrading;
          }
  
          $assignment->save_grade($params['userid'], $gradedata);
  
          return null;
      }
code_tokens: public static function save_grade ( $ assignmentid , $ userid , $ grade , $ attemptnumber , $ addattempt , $ workflowstate , $ applytoall , $ plugindata = array ( ) , $ advancedgradingdata = array ( ) ) { global $ CFG , $ USER ; $ params = self :: validate_parameters ( self :: save_grade_parameters ( ) , array ( 'assignmentid' => $ assignmentid , 'userid' => $ userid , 'grade' => $ grade , 'attemptnumber' => $ attemptnumber , 'workflowstate' => $ workflowstate , 'addattempt' => $ addattempt , 'applytoall' => $ applytoall , 'plugindata' => $ plugindata , 'advancedgradingdata' => $ advancedgradingdata ) ) ; list ( $ assignment , $ course , $ cm , $ context ) = self :: validate_assign ( $ params [ 'assignmentid' ] ) ; $ gradedata = ( object ) $ params [ 'plugindata' ] ; $ gradedata -> addattempt = $ params [ 'addattempt' ] ; $ gradedata -> attemptnumber = $ params [ 'attemptnumber' ] ; $ gradedata -> workflowstate = $ params [ 'workflowstate' ] ; $ gradedata -> applytoall = $ params [ 'applytoall' ] ; $ gradedata -> grade = $ params [ 'grade' ] ; if ( ! empty ( $ params [ 'advancedgradingdata' ] ) ) { $ advancedgrading = array ( ) ; $ criteria = reset ( $ params [ 'advancedgradingdata' ] ) ; foreach ( $ criteria as $ key => $ criterion ) { $ details = array ( ) ; foreach ( $ criterion as $ value ) { foreach ( $ value [ 'fillings' ] as $ filling ) { $ details [ $ value [ 'criterionid' ] ] = $ filling ; } } $ advancedgrading [ $ key ] = $ details ; } $ gradedata -> advancedgrading = $ advancedgrading ; } $ assignment -> save_grade ( $ params [ 'userid' ] , $ gradedata ) ; return null ; }
docstring: Save a student grade for a single assignment.
  
  @param int $assignmentid The id of the assignment
  @param int $userid The id of the user
  @param float $grade The grade (ignored if the assignment uses advanced grading)
  @param int $attemptnumber The attempt number
  @param bool $addattempt Allow another attempt
  @param string $workflowstate New workflow state
  @param bool $applytoall Apply the grade to all members of the group
  @param array $plugindata Custom data used by plugins
  @param array $advancedgradingdata Advanced grading data
  @return null
  @since Moodle 2.6
docstring_tokens: Save a student grade for a single assignment .