This class contains all the logic for computing the grade of a quiz.  
 More...
|  | 
| float const | ALMOST_ZERO = 0.000005 | 
|  | a number that is effectively zero. 
 | 
|  | 
|  | 
| quiz_settings | $quizobj | 
|  | the quiz for which this instance computes grades. 
 | 
|  | 
This class contains all the logic for computing the grade of a quiz. 
There are two sorts of calculation which need to be done. For a single attempt, we need to compute the total attempt score from score for each question. And for a quiz user, we need to compute the final grade from all the separate attempt grades.
- Copyright
- 2023 The Open University 
- License
- http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 
◆ __construct()
Constructor. 
Recommended way to get an instance is $quizobj->get_grade_calculator();
- Parameters
- 
  
  
 
 
◆ compute_final_grade_from_attempts()
  
  | 
        
          | mod_quiz\grade_calculator::compute_final_grade_from_attempts | ( | array | $attempts | ) |  |  | protected | 
 
Calculate the overall grade for a quiz given a number of attempts by a particular user. 
- Parameters
- 
  
    | array | $attempts | an array of all the user's attempts at this quiz in order. |  
 
- Return values
- 
  
    | float|null | the overall grade, or null if the user does not have a grade. |  
 
 
 
◆ create()
  
  | 
        
          | static mod_quiz\grade_calculator::create | ( | quiz_settings | $quizobj | ) |  |  | static | 
 
Factory. 
The recommended way to get an instance is $quizobj->get_grade_calculator();
- Parameters
- 
  
    | quiz_settings | $quizobj | settings of a quiz. |  
 
- Return values
- 
  
    | grade_calculator | instance of this class for the given quiz. |  
 
 
 
◆ recompute_all_final_grades()
      
        
          | mod_quiz\grade_calculator::recompute_all_final_grades | ( |  | ) |  | 
      
 
Update the final grade at this quiz for all students. 
This function is equivalent to calling {
- See also
- recompute_final_grade()} for all users who have attempted the quiz, but is much more efficient. 
 
 
◆ recompute_final_grade()
      
        
          | mod_quiz\grade_calculator::recompute_final_grade | ( | ?int | $userid = null, | 
        
          |  |  | array | $attempts = [] ) | 
      
 
Update the final grade at this quiz for a particular student. 
That is, given the quiz settings, and all the attempts this user has made, compute their final grade for the quiz, as shown in the gradebook.
The $attempts parameter is for efficiency. If you already have the data for all this user's attempts loaded (for example from {
- See also
- quiz_get_user_attempts()} or because you are looping through a large recordset fetched in one efficient query, then you can pass that data here to save DB queries.
- Parameters
- 
  
    | int | null | $userid | The userid to calculate the grade for. Defaults to the current user. |  | array | $attempts | if you already have this user's attempt records loaded, pass them here to save queries. |  
 
 
 
◆ recompute_quiz_sumgrades()
      
        
          | mod_quiz\grade_calculator::recompute_quiz_sumgrades | ( |  | ) |  | 
      
 
Update the sumgrades field of the quiz. 
This needs to be called whenever the grading structure of the quiz is changed. For example if a question is added or removed, or a question weight is changed.
You should call {
- See also
- quiz_delete_previews()} before you call this function. 
 
 
◆ update_quiz_maximum_grade()
      
        
          | mod_quiz\grade_calculator::update_quiz_maximum_grade | ( | float | $newgrade | ) |  | 
      
 
Update the quiz setting for the grade the quiz is out of. 
This function will update the data in quiz_grades and quiz_feedback, and pass the new grades on to the gradebook.
- Parameters
- 
  
    | float | $newgrade | the new maximum grade for the quiz. |  
 
 
 
◆ ALMOST_ZERO
      
        
          | float const mod_quiz\grade_calculator::ALMOST_ZERO = 0.000005 | 
      
 
a number that is effectively zero. 
Used to avoid division-by-zero or underflow problems. 
 
 
The documentation for this class was generated from the following file: