Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 310 and 400] [Versions 311 and 400] [Versions 39 and 400]

Question type class for the random question type.

Copyright: 1999 onwards Martin Dougiamas {@link http://moodle.com}
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 321 lines (13 kb)
Included or required:0 times
Referenced: 1 time
Includes or requires: 0 files

Defines 1 class


Class: qtype_random  - X-Ref

The random question type.

This question type does not have a question definition class, nor any
renderers. When you load a question of this type, it actually loads a
question chosen randomly from a particular category in the question bank.

menu_name()   X-Ref
Cache of availabe question ids from a particular category.


is_manual_graded()   X-Ref
No description

is_usable_by_random()   X-Ref
No description

is_question_manual_graded($question, $otherquestionsinuse)   X-Ref
No description

init_qtype_lists()   X-Ref
This method needs to be called before the ->excludedqtypes and
->manualqtypes fields can be used.


get_question_options($question)   X-Ref
No description

question_name($category, $includesubcategories, $tagnames = [])   X-Ref
Random questions always get a question name that is Random (cateogryname).
This function is a centralised place to calculate that, given the category.

return: string the name this question should have.
param: stdClass $category the category this question picks from. (->parent, ->name & ->contextid are used.)
param: bool $includesubcategories whether this question also picks from subcategories.
param: string[] $tagnames Name of tags this question picks from.

set_selected_question_name($question, $randomname)   X-Ref
No description

save_question($question, $form)   X-Ref
No description

save_question_options($question)   X-Ref
No description

clear_caches_before_testing()   X-Ref
During unit tests we need to be able to reset all caches so that each new test starts in a known state.
Intended for use only for testing. This is a stop gap until we start using the MUC caching api here.
You need to call this before every test that loads one or more random questions.


get_available_questions_from_category($categoryid, $subcategories)   X-Ref
Get all the usable questions from a particular question category.

return: array of question records.
param: int $categoryid the id of a question category.
param: bool whether to include questions from subcategories.
param: string $questionsinuse comma-separated list of question ids to

make_question($questiondata)   X-Ref
No description

choose_other_question($questiondata, $excludedquestions, $allowshuffle = true, $forcequestionid = null)   X-Ref
Load the definition of another question picked randomly by this question.

return: question_definition|null the definition of the question that was
param: object       $questiondata the data defining a random question.
param: array        $excludedquestions of question ids. We will no pick any question whose id is in this list.
param: bool         $allowshuffle      if false, then any shuffle option on the selected quetsion is disabled.
param: null|integer $forcequestionid   if not null then force the picking of question with id $forcequestionid.

get_random_guess_score($questiondata)   X-Ref
No description