Moodle PHP Documentation 4.2
Moodle 4.2.8 (Build: 20240610) (2d41ac46f45)
mod_quiz\grade_calculator Class Reference

Public Member Functions

 recompute_all_attempt_sumgrades ()
 Update the sumgrades field of attempts at this quiz.
 
 recompute_all_final_grades ()
 Update the final grade at this quiz for all students.
 
 recompute_final_grade (?int $userid=null, array $attempts=[])
 Update the final grade at this quiz for a particular student.
 
 recompute_quiz_sumgrades ()
 Update the sumgrades field of the quiz.
 
 update_quiz_maximum_grade (float $newgrade)
 Update the quiz setting for the grade the quiz is out of.
 

Static Public Member Functions

static create (quiz_settings $quizobj)
 Factory.
 

Public Attributes

float const ALMOST_ZERO = 0.000005
 a number that is effectively zero.
 

Protected Member Functions

 __construct (quiz_settings $quizobj)
 Constructor.
 
 compute_final_grade_from_attempts (array $attempts)
 Calculate the overall grade for a quiz given a number of attempts by a particular user.
 

Protected Attributes

quiz_settings $quizobj
 the quiz for which this instance computes grades.
 

Constructor & Destructor Documentation

◆ __construct()

mod_quiz\grade_calculator::__construct ( quiz_settings $quizobj)
protected

Constructor.

Recommended way to get an instance is $quizobj->get_grade_calculator();

Parameters
quiz_settings$quizobj

Member Function Documentation

◆ 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$attemptsan array of all the user's attempts at this quiz in order.
Return values
float|nullthe 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$quizobjsettings of a quiz.
Return values
grade_calculatorinstance 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$useridThe userid to calculate the grade for. Defaults to the current user.
array$attemptsif 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$newgradethe new maximum grade for the quiz.

Member Data Documentation

◆ 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: