Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

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

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.

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.
return: string the name this question should have.

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.

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
return: array of question records.

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.

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.
return: question_definition|null the definition of the question that was

get_random_guess_score($questiondata)   X-Ref
No description