Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
mod_quiz\question\bank\qbank_helper Class Reference

Static Public Member Functions

static choose_question_for_redo (int $quizid, context_module $quizcontext, int $slotid, qubaid_condition $qubaids)
 Choose question for redo in a particular slot.
 
static describe_random_question (stdClass $slotdata)
 Given a slot from the array returned by get_question_structure, describe the random question it represents.
 
static get_question_structure (int $quizid, context_module $quizcontext, int $slotid=null)
 Get the information about which questions should be used to create a quiz attempt.
 
static get_tag_ids_for_slot (stdClass $slotdata)
 Get this list of random selection tag ids from one of the slots returned by get_question_structure.
 
static get_version_information_for_questions_in_attempt (stdClass $attempt, context_module $quizcontext,)
 Check all the questions in an attempt and return information about their versions.
 
static get_version_options (int $questionid)
 Get the available versions of a question where one of the version has the given question id.
 

Detailed Description

Author
Safat Shahin safat.nosp@m.shah.nosp@m.in@ca.nosp@m.taly.nosp@m.st-au.nosp@m..net
License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Member Function Documentation

◆ choose_question_for_redo()

static mod_quiz\question\bank\qbank_helper::choose_question_for_redo ( int $quizid,
context_module $quizcontext,
int $slotid,
qubaid_condition $qubaids )
static

Choose question for redo in a particular slot.

Parameters
int$quizidthe id of the quiz to load the data for.
context_module$quizcontextthe context of this quiz.
int$slotidoptional, if passed only load the data for this one slot (if it is in this quiz).
qubaid_condition$qubaidsattempts to consider when avoiding picking repeats of random questions.
Return values
intthe id of the question to use.

◆ describe_random_question()

static mod_quiz\question\bank\qbank_helper::describe_random_question ( stdClass $slotdata)
static

Given a slot from the array returned by get_question_structure, describe the random question it represents.

Parameters
stdClass$slotdataone of the array elements returned by get_question_structure.
Return values
stringthat can be used to display the random slot.

◆ get_question_structure()

static mod_quiz\question\bank\qbank_helper::get_question_structure ( int $quizid,
context_module $quizcontext,
int $slotid = null )
static

Get the information about which questions should be used to create a quiz attempt.

Each element in the returned array is indexed by slot.slot (slot number) an each object hass:

  • All the field of the slot table.
  • contextid for where the question(s) come from.
  • category id for where the questions come from.
  • For non-random questions, All the fields of the question table (but id is in questionid). Also question version and question bankentryid.
  • For random questions, filtercondition, which is also unpacked into category, randomrecurse, randomtags, and note that these also have a ->name set and ->qtype set to 'random'.
Parameters
int$quizidthe id of the quiz to load the data for.
context_module$quizcontextthe context of this quiz.
int | null$slotidoptional, if passed only load the data for this one slot (if it is in this quiz).
Return values
arrayindexed by slot, with information about the content of each slot.

◆ get_tag_ids_for_slot()

static mod_quiz\question\bank\qbank_helper::get_tag_ids_for_slot ( stdClass $slotdata)
static

Get this list of random selection tag ids from one of the slots returned by get_question_structure.

Parameters
stdClass$slotdataone of the array elements returned by get_question_structure.
Return values
arraylist of tag ids.

◆ get_version_information_for_questions_in_attempt()

static mod_quiz\question\bank\qbank_helper::get_version_information_for_questions_in_attempt ( stdClass $attempt,
context_module $quizcontext )
static

Check all the questions in an attempt and return information about their versions.

Once a quiz attempt has been started, it continues to use the version of each question it was started with. This checks the version used for each question, against the quiz settings for that slot, and returns which version would be used if the quiz attempt was being started now.

There are several cases for each slot:

  • If this slot is currently set to use version 'Always latest' (which includes random slots) and if there is now a newer version than the one in the attempt, use that.
  • If the slot is currently set to use a fixed version of the question, and that is different from the version currently in the attempt, use that.
  • Otherwise, use the same version.

This is used in places like the re-grade code.

The returned data probably contains a bit more information than is strictly needed, (see the SQL for details) but returning a few extra ints is fast, and this could prove invaluable when debugging. The key information is probably:

  • questionattemptslot <– array key
  • questionattemptid
  • currentversion
  • currentquestionid
  • newversion
  • newquestionid
Parameters
stdClass$attempta quiz_attempt database row.
context_module$quizcontextthe quiz context for the quiz the attempt belongs to.
Return values
arrayfor each question_attempt in the quiz attempt, information about whether it is using the latest version of the question. Array indexed by questionattemptslot.

◆ get_version_options()

static mod_quiz\question\bank\qbank_helper::get_version_options ( int $questionid)
static

Get the available versions of a question where one of the version has the given question id.

Parameters
int$questionidid of a question.
Return values
stdClass[]other versions of this question. Each object has fields versionid, version and questionid. Array is returned most recent version first.

The documentation for this class was generated from the following file: