Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]

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: 314 lines (13 kb)
Included or required:0 times
Referenced: 0 times
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. (Only ->name is 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