Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401] [Versions 401 and 403]

A collection of all the question statistics calculated for an activity instance ie. the stats calculated for slots and sub-questions and variants of those questions.

Author: James Pratt me@jamiep.org
Copyright: 2014 The Open University
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 493 lines (21 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: all_calculated_for_qubaid_condition  - X-Ref

A collection of all the question statistics calculated for an activity instance.

initialise_for_subq($step, $variant = null)   X-Ref
Set up a calculated_for_subquestion instance ready to store a randomly selected question's stats.

param: object     $step
param: int|null   $variant Is this to keep track of a variant's stats? If so what is the variant, if not null.

initialise_for_slot($slot, $question, $variant = null)   X-Ref
Set up a calculated instance ready to store a slot question's stats.

param: int      $slot
param: object   $question
param: int|null $variant Is this to keep track of a variant's stats? If so what is the variant, if not null.

has_subq($questionid, $variant = null)   X-Ref
Do we have stats for a particular quesitonid (and optionally variant)?

param: int  $questionid The id of the sub question.
param: int|null $variant if not null then we want the object to store a variant of a sub-question's stats.
return: bool whether those stats exist (yet).

for_subq($questionid, $variant = null)   X-Ref
Reference for a item stats instance for a questionid and optional variant no.

param: int  $questionid The id of the sub question.
param: int|null $variant if not null then we want the object to store a variant of a sub-question's stats.
return: calculated|calculated_for_subquestion stats instance for a questionid and optional variant no.

get_all_subq_ids()   X-Ref
ids of all randomly selected question for all slots.

return: int[] An array of all sub-question ids.

get_all_slots()   X-Ref
All slots nos that stats have been calculated for.

return: int[] An array of all slot nos.

has_slot($slot, $variant = null)   X-Ref
Do we have stats for a particular slot (and optionally variant)?

param: int  $slot The slot no.
param: int|null $variant if provided then we want the object which stores a variant of a position's stats.
return: bool whether those stats exist (yet).

for_slot($slot, $variant = null)   X-Ref
Get position stats instance for a slot and optional variant no.

param: int  $slot The slot no.
param: int|null $variant if provided then we want the object which stores a variant of a position's stats.
return: calculated|calculated_for_subquestion An instance of the class storing the calculated position stats.

get_cached($qubaids)   X-Ref
Load cached statistics from the database.

param: \qubaid_condition $qubaids Which question usages to load stats for?

get_last_calculated_time($qubaids)   X-Ref
Find time of non-expired statistics in the database.

param: \qubaid_condition $qubaids Which question usages to look for stats for?
return: int|bool Time of cached record that matches this qubaid_condition or false if non found.

cache($qubaids)   X-Ref
Save stats to db, first cleaning up any old ones.

param: \qubaid_condition $qubaids Which question usages are we caching the stats of?

get_sub_questions()   X-Ref
Return all sub-questions used.

return: \object[] array of questions.

structure_analysis_for_one_slot($slot, $limitvariants = false)   X-Ref
Return all stats for one slot, stats for the slot itself, and either :
- variants of question
- variants of randomly selected questions
- randomly selected questions

param: int      $slot          the slot no
param: bool|int $limitvariants limit number of variants and sub-questions displayed?
return: calculated|calculated_for_subquestion[] stats to display

any_error_messages()   X-Ref
Call after calculations to output any error messages.

return: string[] Array of strings describing error messages found during stats calculation.

all_variant_stats_for_one_slot($slot)   X-Ref
Return all stats for variants of question in slot $slot.

param: int $slot The slot no.
return: calculated[] The instances storing the calculated stats.

all_subq_variants_for_one_slot($slot)   X-Ref
Return all stats for variants of randomly selected questions for one slot $slot.

param: int $slot The slot no.
return: calculated[] The instances storing the calculated stats.

all_subqs_for_one_slot($slot)   X-Ref
Return all stats for randomly selected questions for one slot $slot.

param: int $slot The slot no.
return: calculated[] The instances storing the calculated stats.

all_subq_and_variant_stats_for_slot($slot, $limited)   X-Ref
Return all variant or 'sub-question' stats one slot, either :
- variants of question
- variants of randomly selected questions
- randomly selected questions

param: int $slot the slot no
param: bool $limited limit number of variants and sub-questions displayed?
return: calculated|calculated_for_subquestion|calculated_question_summary[] stats to display

make_new_subq_stat_for($displaynumber, $slot, $subqid, $variant = null)   X-Ref
We need a new object for display. Sub-question stats can appear more than once in different slots.
So we create a clone of the object and then we can set properties on the object that are per slot.

param: int  $displaynumber                   The display number for this sub question.
param: int  $slot                            The slot number.
param: int  $subqid                          The sub question id.
param: null|int $variant                     The variant no.
return: calculated_for_subquestion           The object for display.

make_new_calculated_question_summary_stat($randomquestioncalculated, $subquestionstats)   X-Ref
Create a summary calculated object for a calculated question. This is used as a placeholder
to indicate that a calculated question has sub questions or variations to show rather than listing each
subquestion or variation directly.

param: calculated $randomquestioncalculated The calculated instance for the random question slot.
param: calculated[] $subquestionstats The instances of the calculated stats of the questions that are being summarised.
return: calculated_question_summary