Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Attributes | List of all members
question_finder Class Reference

Class for loading questions according to various criteria. More...

Inheritance diagram for question_finder:
cache_data_source

Public Member Functions

 get_questions_from_categories ($categoryids, $extraconditions, $extraparams=array())
 Get the ids of all the questions in a list of categories. More...
 
 get_questions_from_categories_and_tags_with_usage_counts ($categoryids, qubaid_condition $qubaids, $extraconditions='', $extraparams=array(), $tagids=array())
 Get the ids of all the questions in a list of categories that have ALL the provided tags, with the number of times they have already been used in a given set of usages. More...
 
 get_questions_from_categories_with_usage_counts ($categoryids, qubaid_condition $qubaids, $extraconditions='', $extraparams=array())
 Get the ids of all the questions in a list of categories, with the number of times they have already been used in a given set of usages. More...
 
 load_for_cache ($questionid)
 Loads the data for the key provided ready formatted for caching. More...
 
 load_many_for_cache (array $questionids)
 Loads several keys for the cache. More...
 
 load_question_data ($questionid)
 Load a question definition data from the database. More...
 
 uncache_question ($questionid)
 This method needs to be called whenever a question is edited.
 

Static Public Member Functions

static get_instance ()
 
static get_instance_for_cache (cache_definition $definition)
 Returns an instance of the data source class that the cache can use for loading data using the other methods specified by this interface. More...
 

Protected Member Functions

 get_data_cache ()
 

Static Protected Attributes

static question_finder $questionfinder = null
 the singleton instance of this class.
 

Detailed Description

Class for loading questions according to various criteria.

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

Member Function Documentation

◆ get_data_cache()

question_finder::get_data_cache ( )
protected
Return values
getthe question definition cache we are using.

◆ get_instance()

static question_finder::get_instance ( )
static
Return values
question_findera question finder.

◆ get_instance_for_cache()

static question_finder::get_instance_for_cache ( cache_definition  $definition)
static

Returns an instance of the data source class that the cache can use for loading data using the other methods specified by this interface.

Parameters
cache_definition$definition
Return values
object

Implements cache_data_source.

◆ get_questions_from_categories()

question_finder::get_questions_from_categories (   $categoryids,
  $extraconditions,
  $extraparams = array() 
)

Get the ids of all the questions in a list of categories.

Parameters
array$categoryidseither a categoryid, or a comma-separated list category ids, or an array of them.
string$extraconditionsextra conditions to AND with the rest of the where clause. Must use named parameters.
array$extraparamsany parameters used by $extraconditions.
Return values
arrayquestionid => questionid.

◆ get_questions_from_categories_and_tags_with_usage_counts()

question_finder::get_questions_from_categories_and_tags_with_usage_counts (   $categoryids,
qubaid_condition  $qubaids,
  $extraconditions = '',
  $extraparams = array(),
  $tagids = array() 
)

Get the ids of all the questions in a list of categories that have ALL the provided tags, with the number of times they have already been used in a given set of usages.

The result array is returned in order of increasing (count previous uses).

Parameters
array$categoryidsan array of question_category ids.
qubaid_condition$qubaidswhich question_usages to count previous uses from.
string$extraconditionsextra conditions to AND with the rest of the where clause. Must use named parameters.
array$extraparamsany parameters used by $extraconditions.
array$tagidsan array of tag ids
Return values
arrayquestionid => count of number of previous uses.

◆ get_questions_from_categories_with_usage_counts()

question_finder::get_questions_from_categories_with_usage_counts (   $categoryids,
qubaid_condition  $qubaids,
  $extraconditions = '',
  $extraparams = array() 
)

Get the ids of all the questions in a list of categories, with the number of times they have already been used in a given set of usages.

The result array is returned in order of increasing (count previous uses).

Parameters
array$categoryidsan array question_category ids.
qubaid_condition$qubaidswhich question_usages to count previous uses from.
string$extraconditionsextra conditions to AND with the rest of the where clause. Must use named parameters.
array$extraparamsany parameters used by $extraconditions.
Return values
arrayquestionid => count of number of previous uses.

◆ load_for_cache()

question_finder::load_for_cache (   $key)

Loads the data for the key provided ready formatted for caching.

Parameters
string | int$keyThe key to load.
Return values
mixedWhat ever data should be returned, or false if it can't be loaded.

Implements cache_data_source.

◆ load_many_for_cache()

question_finder::load_many_for_cache ( array  $keys)

Loads several keys for the cache.

Parameters
array$keysAn array of keys each of which will be string|int.
Return values
arrayAn array of matching data items.

Implements cache_data_source.

◆ load_question_data()

question_finder::load_question_data (   $questionid)

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.

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