original_string: protected function get_grading_instance($userid, $grade, $gradingdisabled) {
          global $CFG, $USER;
  
          $grademenu = make_grades_menu($this->get_instance()->grade);
          $allowgradedecimals = $this->get_instance()->grade > 0;
  
          $advancedgradingwarning = false;
          $gradingmanager = get_grading_manager($this->context, 'mod_assign', 'submissions');
          $gradinginstance = null;
          if ($gradingmethod = $gradingmanager->get_active_method()) {
              $controller = $gradingmanager->get_controller($gradingmethod);
              if ($controller->is_form_available()) {
                  $itemid = null;
                  if ($grade) {
                      $itemid = $grade->id;
                  }
                  if ($gradingdisabled && $itemid) {
                      $gradinginstance = $controller->get_current_instance($USER->id, $itemid);
                  } else if (!$gradingdisabled) {
                      $instanceid = optional_param('advancedgradinginstanceid', 0, PARAM_INT);
                      $gradinginstance = $controller->get_or_create_instance($instanceid,
                                                                             $USER->id,
                                                                             $itemid);
                  }
              } else {
                  $advancedgradingwarning = $controller->form_unavailable_notification();
              }
          }
          if ($gradinginstance) {
              $gradinginstance->get_controller()->set_grade_range($grademenu, $allowgradedecimals);
          }
          return $gradinginstance;
      }
code: protected function get_grading_instance($userid, $grade, $gradingdisabled) {
          global $CFG, $USER;
  
          $grademenu = make_grades_menu($this->get_instance()->grade);
          $allowgradedecimals = $this->get_instance()->grade > 0;
  
          $advancedgradingwarning = false;
          $gradingmanager = get_grading_manager($this->context, 'mod_assign', 'submissions');
          $gradinginstance = null;
          if ($gradingmethod = $gradingmanager->get_active_method()) {
              $controller = $gradingmanager->get_controller($gradingmethod);
              if ($controller->is_form_available()) {
                  $itemid = null;
                  if ($grade) {
                      $itemid = $grade->id;
                  }
                  if ($gradingdisabled && $itemid) {
                      $gradinginstance = $controller->get_current_instance($USER->id, $itemid);
                  } else if (!$gradingdisabled) {
                      $instanceid = optional_param('advancedgradinginstanceid', 0, PARAM_INT);
                      $gradinginstance = $controller->get_or_create_instance($instanceid,
                                                                             $USER->id,
                                                                             $itemid);
                  }
              } else {
                  $advancedgradingwarning = $controller->form_unavailable_notification();
              }
          }
          if ($gradinginstance) {
              $gradinginstance->get_controller()->set_grade_range($grademenu, $allowgradedecimals);
          }
          return $gradinginstance;
      }
code_tokens: protected function get_grading_instance ( $ userid , $ grade , $ gradingdisabled ) { global $ CFG , $ USER ; $ grademenu = make_grades_menu ( $ this -> get_instance ( ) -> grade ) ; $ allowgradedecimals = $ this -> get_instance ( ) -> grade > 0 ; $ advancedgradingwarning = false ; $ gradingmanager = get_grading_manager ( $ this -> context , 'mod_assign' , 'submissions' ) ; $ gradinginstance = null ; if ( $ gradingmethod = $ gradingmanager -> get_active_method ( ) ) { $ controller = $ gradingmanager -> get_controller ( $ gradingmethod ) ; if ( $ controller -> is_form_available ( ) ) { $ itemid = null ; if ( $ grade ) { $ itemid = $ grade -> id ; } if ( $ gradingdisabled && $ itemid ) { $ gradinginstance = $ controller -> get_current_instance ( $ USER -> id , $ itemid ) ; } else if ( ! $ gradingdisabled ) { $ instanceid = optional_param ( 'advancedgradinginstanceid' , 0 , PARAM_INT ) ; $ gradinginstance = $ controller -> get_or_create_instance ( $ instanceid , $ USER -> id , $ itemid ) ; } } else { $ advancedgradingwarning = $ controller -> form_unavailable_notification ( ) ; } } if ( $ gradinginstance ) { $ gradinginstance -> get_controller ( ) -> set_grade_range ( $ grademenu , $ allowgradedecimals ) ; } return $ gradinginstance ; }
docstring: Get an instance of a grading form if advanced grading is enabled.
  This is specific to the assignment, marker and student.
  
  @param int $userid - The student userid
  @param stdClass|false $grade - The grade record
  @param bool $gradingdisabled
  @return mixed gradingform_instance|null $gradinginstance
docstring_tokens: Get an instance of a grading form if advanced grading is enabled . This is specific to the assignment marker and student .