[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/question/classes/bank/ -> random_question_loader.php (summary)

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: 223 lines (9 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

random_question_loader:: (6 methods):
  __construct()
  get_next_question_id()
  get_category_key()
  ensure_questions_for_category_loaded()
  use_question()
  is_question_available()


Class: random_question_loader  - X-Ref

This class efficiently finds questions at random from the question bank.

You can ask for questions at random one at a time. Each time you ask, you
pass a category id, and whether to pick from that category and all subcategories
or just that category.

The number of teams each question has been used is tracked, and we will always
return a question from among those elegible that has been used the fewest times.
So, if there are questions that have not been used yet in the category asked for,
one of those will be returned. However, within one instantiation of this class,
we will never return a given question more than once, and we will never return
questions passed into the constructor as $usedquestions.

__construct(\qubaid_condition $qubaids, array $usedquestions = array()   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)   X-Ref
Pick a question at random from the given category, from among those with the fewest uses.

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
return: int|null the id of the question picked, or null if there aren't any.

get_category_key($categoryid, $includesubcategories)   X-Ref
Get the key into {@link $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
return: string the cache key.

ensure_questions_for_category_loaded($categoryid, $includesubcategories)   X-Ref
Populate {@link $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

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.

is_question_available($categoryid, $includesubcategories, $questionid)   X-Ref
Check whether a given question is available in a given category. If so, mark it used.

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.
return: bool whether the question is available in the requested category.



Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1