Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
question_engine Class Reference

This static class provides access to the other question engine classes. More...

Static Public Member Functions

static can_questions_finish_during_the_attempt ($behaviour)
 With this behaviour, is it possible that a question might finish as the student interacts with it, without a call to the question_attempt::finish() method?
 
static delete_questions_usage_by_activities (qubaid_condition $qubaids)
 Delete from the database.
 
static delete_questions_usage_by_activity ($qubaid)
 Delete a question_usage_by_activity from the database, based on its id.
 
static get_all_response_file_areas ()
 
static get_archetypal_behaviours ()
 Return an array where the keys are the internal names of the archetypal behaviours, and the values are a human-readable name.
 
static get_behaviour_name ($behaviour)
 Get the translated name of a behaviour, for display in the UI.
 
static get_behaviour_options ($currentbehaviour)
 Return an array where the keys are the internal names of the behaviours in preferred order and the values are a human-readable name.
 
static get_behaviour_type ($behaviour)
 Create a behaviour for a particular type.
 
static get_behaviour_unused_display_options ($behaviour)
 
static get_dp_options ()
 Returns the valid choices for the number of decimal places for showing question marks.
 
static initialise_js ()
 Initialise the JavaScript required on pages where questions will be displayed.
 
static is_behaviour_archetypal ($behaviour)
 
static is_manual_grade_in_range ($qubaid, $slot)
 Validate that the manual grade submitted for a particular question is in range.
 
static load_behaviour_class ($behaviour)
 Load the behaviour class(es) belonging to a particular model.
 
static load_questions_usage_by_activity ($qubaid, moodle_database $db=null)
 Load a question_usage_by_activity from the database, based on its id.
 
static load_used_variants (array $questionids, qubaid_condition $qubaids)
 Get the number of times each variant has been used for each question in a list in a set of usages.
 
static make_archetypal_behaviour ($preferredbehaviour, question_attempt $qa)
 Create an archetypal behaviour for a particular question attempt.
 
static make_behaviour ($behaviour, question_attempt $qa, $preferredbehaviour)
 Create a behaviour for a particular type.
 
static make_questions_usage_by_activity ($component, $context)
 Create a new question_usage_by_activity.
 
static questions_in_use (array $questionids, qubaid_condition $qubaids=null)
 
static save_questions_usage_by_activity (question_usage_by_activity $quba, moodle_database $db=null)
 Save a question_usage_by_activity to the database.
 
static set_max_mark_in_attempts (qubaid_condition $qubaids, $slot, $newmaxmark)
 Change the maxmark for the question_attempt with number in usage $slot for all the specified question_attempts.
 
static sort_behaviours ($archetypes, $orderlist, $disabledlist, $current=null)
 Return an array where the keys are the internal names of the behaviours in preferred order and the values are a human-readable name.
 

Static Protected Member Functions

static load_behaviour_type_class ($behaviour)
 Load the behaviour type class for a particular behaviour.
 

Detailed Description

This static class provides access to the other question engine classes.

It provides functions for managing question behaviours), and for creating, loading, saving and deleting , which is the main class that is used by other code that wants to use questions. 2009 The Open University License http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Member Function Documentation

◆ can_questions_finish_during_the_attempt()

static question_engine::can_questions_finish_during_the_attempt ( $behaviour)
static

With this behaviour, is it possible that a question might finish as the student interacts with it, without a call to the question_attempt::finish() method?

Parameters
string$behaviourthe name of a behaviour. E.g. 'deferredfeedback'.
Return values
boolwhether with this behaviour, questions may finish naturally.

◆ delete_questions_usage_by_activities()

static question_engine::delete_questions_usage_by_activities ( qubaid_condition $qubaids)
static

Delete from the database.

Parameters
qubaid_condition$qubaidsidentifies which questions usages to delete.

◆ delete_questions_usage_by_activity()

static question_engine::delete_questions_usage_by_activity ( $qubaid)
static

Delete a question_usage_by_activity from the database, based on its id.

Parameters
int$qubaidthe id of the usage to delete.

◆ get_all_response_file_areas()

static question_engine::get_all_response_file_areas ( )
static
Return values
arrayall the file area names that may contain response files.

◆ get_archetypal_behaviours()

static question_engine::get_archetypal_behaviours ( )
static

Return an array where the keys are the internal names of the archetypal behaviours, and the values are a human-readable name.

An archetypal behaviour is one that is suitable to pass the name of to question_usage_by_activity::set_preferred_behaviour().

Return values
arraymodel name => lang string for this behaviour name.

◆ get_behaviour_name()

static question_engine::get_behaviour_name ( $behaviour)
static

Get the translated name of a behaviour, for display in the UI.

Parameters
string$behaviourthe internal name of the model.
Return values
stringname from the current language pack.

◆ get_behaviour_options()

static question_engine::get_behaviour_options ( $currentbehaviour)
static

Return an array where the keys are the internal names of the behaviours in preferred order and the values are a human-readable name.

Parameters
string$currentbehaviour
Return values
arraymodel name => lang string for this behaviour name.

◆ get_behaviour_type()

static question_engine::get_behaviour_type ( $behaviour)
static

Create a behaviour for a particular type.

If that type cannot be found, return an instance of qbehaviour_missing.

Normally you should use make_archetypal_behaviour(), or call the constructor of a particular model class directly. This method is only intended for use by question_attempt::load_from_records().

Parameters
string$behaviourthe type of model to create.
question_attempt$qathe question attempt the model will process.
string$preferredbehaviourthe preferred behaviour for the containing usage.
Return values
question_behaviour_typean instance of appropriate behaviour class.

◆ get_behaviour_unused_display_options()

static question_engine::get_behaviour_unused_display_options ( $behaviour)
static
Parameters
string$behaviourthe name of a behaviour.
Return values
arrayof question_display_options field names, that are not relevant to this behaviour before a 'finish' action.

◆ get_dp_options()

static question_engine::get_dp_options ( )
static

Returns the valid choices for the number of decimal places for showing question marks.

For use in the user interface.

Return values
arraysuitable for passing to html_writer::select() or similar.

◆ initialise_js()

static question_engine::initialise_js ( )
static

Initialise the JavaScript required on pages where questions will be displayed.

Return values
string

◆ is_behaviour_archetypal()

static question_engine::is_behaviour_archetypal ( $behaviour)
static
Parameters
string$behaviourthe name of a behaviour. E.g. 'deferredfeedback'.
Return values
boolwhether this is an archetypal behaviour.

◆ is_manual_grade_in_range()

static question_engine::is_manual_grade_in_range ( $qubaid,
$slot )
static

Validate that the manual grade submitted for a particular question is in range.

Parameters
int$qubaidthe question_usage id.
int$slotthe slot number within the usage.
Return values
boolwhether the submitted data is in range.

◆ load_behaviour_class()

static question_engine::load_behaviour_class ( $behaviour)
static

Load the behaviour class(es) belonging to a particular model.

That is, include_once('/question/behaviour/' . $behaviour . '/behaviour.php'), with a bit of checking.

Parameters
string$qtypenamethe question type name. For example 'multichoice' or 'shortanswer'.

◆ load_behaviour_type_class()

static question_engine::load_behaviour_type_class ( $behaviour)
staticprotected

Load the behaviour type class for a particular behaviour.

That is, include_once('/question/behaviour/' . $behaviour . '/behaviourtype.php').

Parameters
string$behaviourthe behaviour name. For example 'interactive' or 'deferredfeedback'.

◆ load_questions_usage_by_activity()

static question_engine::load_questions_usage_by_activity ( $qubaid,
moodle_database $db = null )
static

Load a question_usage_by_activity from the database, based on its id.

Parameters
int$qubaidthe id of the usage to load.
moodle_database$dba database connectoin. Defaults to global $DB.
Return values
question_usage_by_activityloaded from the database.

◆ load_used_variants()

static question_engine::load_used_variants ( array $questionids,
qubaid_condition $qubaids )
static

Get the number of times each variant has been used for each question in a list in a set of usages.

Parameters
array$questionidsof question ids.
qubaid_condition$qubaidsids of the usages to consider.
Return values
arrayquestionid => variant number => num uses.

◆ make_archetypal_behaviour()

static question_engine::make_archetypal_behaviour ( $preferredbehaviour,
question_attempt $qa )
static

Create an archetypal behaviour for a particular question attempt.

Used by question_definition::make_behaviour().

Parameters
string$preferredbehaviourthe type of model required.
question_attempt$qathe question attempt the model will process.
Return values
question_behaviouran instance of appropriate behaviour class.

◆ make_behaviour()

static question_engine::make_behaviour ( $behaviour,
question_attempt $qa,
$preferredbehaviour )
static

Create a behaviour for a particular type.

If that type cannot be found, return an instance of qbehaviour_missing.

Normally you should use make_archetypal_behaviour(), or call the constructor of a particular model class directly. This method is only intended for use by question_attempt::load_from_records().

Parameters
string$behaviourthe type of model to create.
question_attempt$qathe question attempt the model will process.
string$preferredbehaviourthe preferred behaviour for the containing usage.
Return values
question_behaviouran instance of appropriate behaviour class.

◆ make_questions_usage_by_activity()

static question_engine::make_questions_usage_by_activity ( $component,
$context )
static

Create a new question_usage_by_activity.

The usage is created in memory. If you want it to persist, you will need to call save_questions_usage_by_activity().

Parameters
string$componentthe plugin creating this attempt. For example mod_quiz.
context$contextthe context this usage belongs to.
Return values
question_usage_by_activitythe newly created object.

◆ questions_in_use()

static question_engine::questions_in_use ( array $questionids,
qubaid_condition $qubaids = null )
static
Parameters
array$questionidsof question ids.
qubaid_condition$qubaidsids of the usages to consider.
Return values
booleanwhether any of these questions are being used by any of those usages.

◆ save_questions_usage_by_activity()

static question_engine::save_questions_usage_by_activity ( question_usage_by_activity $quba,
moodle_database $db = null )
static

Save a question_usage_by_activity to the database.

This works either if the usage was newly created by make_questions_usage_by_activity() or loaded from the database using load_questions_usage_by_activity()

Parameters
question_usage_by_activitythe usage to save.
moodle_database$dba database connectoin. Defaults to global $DB.

◆ set_max_mark_in_attempts()

static question_engine::set_max_mark_in_attempts ( qubaid_condition $qubaids,
$slot,
$newmaxmark )
static

Change the maxmark for the question_attempt with number in usage $slot for all the specified question_attempts.

Parameters
qubaid_condition$qubaidsSelects which usages are updated.
int$slotthe number is usage to affect.
number$newmaxmarkthe new max mark to set.

◆ sort_behaviours()

static question_engine::sort_behaviours ( $archetypes,
$orderlist,
$disabledlist,
$current = null )
static

Return an array where the keys are the internal names of the behaviours in preferred order and the values are a human-readable name.

Parameters
array$archetypes,arrayof behaviours
string$orderlist,acomma separated list of behaviour names
string$disabledlist,acomma separated list of behaviour names
string$current,currentbehaviour name
Return values
arraymodel name => lang string for this behaviour name.

The documentation for this class was generated from the following file: