|
float const | ALMOST_ZERO = 0.000005 |
| a number that is effectively zero.
|
|
|
stdClass[] null array | $gradeitems = null |
| quiz_grade_items for this quiz indexed by id, sorted by sortorder, with a maxmark field added.
|
|
quiz_settings | $quizobj |
| the quiz for which this instance computes grades.
|
|
stdClass[] null array | $slots = null |
| quiz_slot for this quiz.
|
|
◆ __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. |
◆ compute_grade_item_totals()
Compute the grade and maximum for each item, for an attempt where the question_usage_by_activity is available.
- Parameters
-
- Return values
-
grade_out_of[] | the grade for each item where the total grade is not zero. ->name will be set to the grade item name. Must be output through { |
- See also
- format_string()}.
◆ compute_grade_item_totals_for_attempts()
mod_quiz\grade_calculator::compute_grade_item_totals_for_attempts |
( |
array | $qubaids | ) |
|
Compute the grade and maximum for each item, for some attempts where we only have the usage ids.
- Parameters
-
int[] | $qubaids | array of usage ids. |
- Return values
-
grade_out_of[][] | question_usage.id => array of grade_out_of. ->name will be set to the grade item name. Must be output through { |
- See also
- format_string()}..
◆ 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. |
◆ ensure_grade_items_loaded()
mod_quiz\grade_calculator::ensure_grade_items_loaded |
( |
| ) |
|
|
protected |
Ensure the {.
- See also
- grade_calculator\$gradeitems} field is ready to use.
◆ ensure_slots_loaded()
mod_quiz\grade_calculator::ensure_slots_loaded |
( |
| ) |
|
|
protected |
Ensure the {.
- See also
- $gradeitems} field is ready to use.
◆ get_grade_items()
mod_quiz\grade_calculator::get_grade_items |
( |
| ) |
|
Get the extra grade items for this quiz.
Returned objects have fields ->id, ->quizid, ->sortorder, ->name and maxmark.
- Return values
-
stdClass[] | the grade items for this quiz. |
◆ load_grade_item_totals()
Query the database return the total mark for each grade item for a set of attempts.
- Parameters
-
- Return values
-
float[][] | Array question_usage.id => quiz_grade_item.id => mark. |
◆ 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.
◆ set_slots()
mod_quiz\grade_calculator::set_slots |
( |
array | $slots | ) |
|
Lets other code pass in the slot information, so it does note have to be re-loaded from the DB.
- Parameters
-
stdClass[] | $slots | the data from quiz_slots. The only required fields are ->slot and ->quizgradeitemid. |
◆ 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. |
◆ $gradeitems
stdClass [] null array mod_quiz\grade_calculator::$gradeitems = null |
|
protected |
quiz_grade_items for this quiz indexed by id, sorted by sortorder, with a maxmark field added.
Lazy-loaded when needed. See {
- See also
- ensure_grade_items_loaded()}.
◆ $slots
stdClass [] null array mod_quiz\grade_calculator::$slots = null |
|
protected |
quiz_slot for this quiz.
Only ->slot and ->quizgradeitemid fields are used.
This is either set by another class that already has the data, using {
- See also
- set_slots()} or it is lazy-loaded when needed. See {
-
ensure_slots_loaded()}.
◆ 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:
- mod/quiz/classes/grade_calculator.php