See Release Notes
Long Term Support Release
Differences Between: [Versions 401 and 403]
A class for efficiently finds questions at random from the question bank.
Copyright: | 2015 The Open University |
License: | http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
File Size: | 328 lines (15 kb) |
Included or required: | 0 times |
Referenced: | 0 times |
Includes or requires: | 0 files |
random_question_loader:: (9 methods):
__construct()
get_next_question_id()
get_category_key()
ensure_questions_for_category_loaded()
use_question()
get_question_ids()
is_question_available()
get_questions()
count_questions()
Class: random_question_loader - X-Ref
This class efficiently finds questions at random from the question bank.__construct(\qubaid_condition $qubaids, array $usedquestions = []) X-Ref |
Constructor. param: \qubaid_condition $qubaids the usages to consider when counting previous uses of each question. param: array $usedquestions questionid => number of times used count. If we should allow for |
get_next_question_id($categoryid, $includesubcategories, $tagids = []) X-Ref |
Pick a question at random from the given category, from among those with the fewest uses. If an array of tag ids are specified, then only the questions that are tagged with ALL those tags will be selected. It is up the the caller to verify that the cateogry exists. An unknown category behaves like an empty one. param: int $categoryid the id of a category in the question bank. param: bool $includesubcategories wether to pick a question from exactly param: array $tagids An array of tag ids. A question has to be tagged with all the provided tagids (if any) return: int|null the id of the question picked, or null if there aren't any. |
get_category_key($categoryid, $includesubcategories, $tagids = []) X-Ref |
Get the key into {@see $availablequestionscache} for this combination of options. param: int $categoryid the id of a category in the question bank. param: bool $includesubcategories wether to pick a question from exactly param: array $tagids an array of tag ids. return: string the cache key. |
ensure_questions_for_category_loaded($categoryid, $includesubcategories, $tagids = []) X-Ref |
Populate {@see $availablequestionscache} for this combination of options. param: int $categoryid The id of a category in the question bank. param: bool $includesubcategories Whether to pick a question from exactly param: array $tagids An array of tag ids. If an array is provided, then |
use_question($questionid) X-Ref |
Update the internal data structures to indicate that a given question has been used one more time. param: int $questionid the question that is being used. |
get_question_ids($categoryid, $includesubcategories, $tagids = []) X-Ref |
Get the list of available question ids for the given criteria. param: int $categoryid The id of a category in the question bank. param: bool $includesubcategories Whether to pick a question from exactly param: array $tagids An array of tag ids. If an array is provided, then return: int[] The list of question ids |
is_question_available($categoryid, $includesubcategories, $questionid, $tagids = []) X-Ref |
Check whether a given question is available in a given category. If so, mark it used. If an optional list of tag ids are provided, then the question must be tagged with ALL of the provided tags to be considered as available. param: int $categoryid the id of a category in the question bank. param: bool $includesubcategories wether to pick a question from exactly param: int $questionid the question that is being used. param: array $tagids An array of tag ids. Only the questions that are tagged with all the provided tagids can be available. return: bool whether the question is available in the requested category. |
get_questions($categoryid, $includesubcategories, $tagids = [], $limit = 100, $offset = 0, $fields = []) X-Ref |
Get the list of available questions for the given criteria. param: int $categoryid The id of a category in the question bank. param: bool $includesubcategories Whether to pick a question from exactly param: array $tagids An array of tag ids. If an array is provided, then param: int $limit Maximum number of results to return. param: int $offset Number of items to skip from the begging of the result set. param: string[] $fields The fields to return for each question. return: \stdClass[] The list of question records |
count_questions($categoryid, $includesubcategories, $tagids = []) X-Ref |
Count the number of available questions for the given criteria. param: int $categoryid The id of a category in the question bank. param: bool $includesubcategories Whether to pick a question from exactly param: array $tagids An array of tag ids. If an array is provided, then return: int The number of questions matching the criteria. |