Moodle APIs  3.8
Moodle 3.8.6 (Build: 20201109)
Static Public Member Functions | Public Attributes | Static Protected Member Functions | List of all members
question_bank Class Reference

This static class provides access to the other question bank. More...

Static Public Member Functions

static end_unit_test ()
 Only to be called from unit tests. More...
 
static fraction_options ()
 
static fraction_options_full ()
 
static get_all_qtypes ()
 
static get_all_question_types_in_categories ($categories)
 Return a list of the different question types present in the given categories. More...
 
static get_config ()
 Load the question configuration data from config_plugins. More...
 
static get_creatable_qtypes ()
 
static get_finder ()
 
static get_qtype ($qtypename, $mustexist=true)
 Get the question type class for a particular question type. More...
 
static get_qtype_name ($qtypename)
 
static is_qtype_installed ($qtypename)
 
static load_question ($questionid, $allowshuffle=true)
 Load a question definition from the database. More...
 
static load_question_data ($questionid)
 Load a question definition data from the database. More...
 
static load_question_definition_classes ($qtypename)
 Load the question definition class(es) belonging to a question type. More...
 
static load_test_question_data (question_definition $question)
 To be used for unit testing only. More...
 
static make_question ($questiondata)
 Convert the question information loaded with get_question_options() to a question_definintion object. More...
 
static notify_question_edited ($questionid)
 This method needs to be called whenever a question is edited.
 
static qtype_enabled ($qtypename)
 
static qtype_exists ($qtypename)
 
static sort_qtype_array ($qtypes, $config=null)
 Sort an array of question types according to the order the admin set up, and then alphabetically for the rest. More...
 
static start_unit_test ()
 Only to be called from unit tests. More...
 

Public Attributes

const MAX_SUMMARY_LENGTH = 32000
 

Static Protected Member Functions

static ensure_fraction_options_initialised ()
 

Detailed Description

This static class provides access to the other question bank.

It provides functions for managing question types and question definitions.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Member Function Documentation

◆ end_unit_test()

static question_bank::end_unit_test ( )
static

Only to be called from unit tests.

Allows load_test_data() to be used.

◆ fraction_options()

static question_bank::fraction_options ( )
static
Return values
arraystring => string The standard set of grade options (fractions) to use when editing questions, in the range 0 to 1 inclusive. Array keys are string becuase: a) we want grades to exactly 7 d.p., and b. you can't have float array keys in PHP. Initialised by ensure_grade_options_initialised().

◆ fraction_options_full()

static question_bank::fraction_options_full ( )
static
Return values
arraystring => string The full standard set of (fractions) -1 to 1 inclusive.

◆ get_all_qtypes()

static question_bank::get_all_qtypes ( )
static
Return values
arrayall the installed question types.

◆ get_all_question_types_in_categories()

static question_bank::get_all_question_types_in_categories (   $categories)
static

Return a list of the different question types present in the given categories.

Parameters
array$categoriesa list of category ids
Return values
arraythe list of question types in the categories
Since
Moodle 3.1

◆ get_config()

static question_bank::get_config ( )
static

Load the question configuration data from config_plugins.

Return values
objectget_config('question') with caching.

◆ get_creatable_qtypes()

static question_bank::get_creatable_qtypes ( )
static
Return values
arrayall the question types that users are allowed to create, sorted into the preferred order set on the admin screen.

◆ get_finder()

static question_bank::get_finder ( )
static
Return values
question_findera question finder.

◆ get_qtype()

static question_bank::get_qtype (   $qtypename,
  $mustexist = true 
)
static

Get the question type class for a particular question type.

Parameters
string$qtypenamethe question type name. For example 'multichoice' or 'shortanswer'.
bool$mustexistif false, the missing question type is returned when the requested question type is not installed.
Return values
question_typethe corresponding question type class.

◆ get_qtype_name()

static question_bank::get_qtype_name (   $qtypename)
static
Parameters
$qtypenamethe internal name of a question type, for example multichoice.
Return values
stringthe human_readable name of this question type, from the language pack.

◆ is_qtype_installed()

static question_bank::is_qtype_installed (   $qtypename)
static
Parameters
string$qtypenamea question type name, e.g. 'multichoice'.
Return values
boolwhether that question type is installed in this Moodle.

◆ load_question()

static question_bank::load_question (   $questionid,
  $allowshuffle = true 
)
static

Load a question definition from the database.

The object returned will actually be of an appropriate question_definition subclass.

Parameters
int$questionidthe id of the question to load.
bool$allowshuffleif false, then any shuffle option on the selected quetsion is disabled.
Return values
question_definitionloaded from the database.

◆ load_question_data()

static question_bank::load_question_data (   $questionid)
static

Load a question definition data from the database.

The data will be returned as a plain stdClass object.

Parameters
int$questionidthe id of the question to load.
Return values
objectquestion definition loaded from the database.

◆ load_question_definition_classes()

static question_bank::load_question_definition_classes (   $qtypename)
static

Load the question definition class(es) belonging to a question type.

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

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

◆ load_test_question_data()

static question_bank::load_test_question_data ( question_definition  $question)
static

To be used for unit testing only.

Will throw an exception if start_unit_test() has not been called first.

Parameters
object$questiondataa question data object to put in the test data store.

◆ make_question()

static question_bank::make_question (   $questiondata)
static

Convert the question information loaded with get_question_options() to a question_definintion object.

Parameters
object$questiondataraw data loaded from the database.
Return values
question_definitionloaded from the database.

◆ qtype_enabled()

static question_bank::qtype_enabled (   $qtypename)
static
Parameters
string$qtypenamethe internal name of a question type. For example multichoice.
Return values
boolwhether users are allowed to create questions of this type.

◆ qtype_exists()

static question_bank::qtype_exists (   $qtypename)
static
Parameters
string$qtypenamethe internal name of a question type. For example multichoice.
Return values
boolwhether this question type exists.

◆ sort_qtype_array()

static question_bank::sort_qtype_array (   $qtypes,
  $config = null 
)
static

Sort an array of question types according to the order the admin set up, and then alphabetically for the rest.

Parameters
arrayqtype->name() => qtype->local_name().
Return values
arraysorted array.

◆ start_unit_test()

static question_bank::start_unit_test ( )
static

Only to be called from unit tests.

Allows load_test_data() to be used.


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