True/False question type
Database tables
Each true/false question creates two records in the quiz_answers table, one for the 'true' option, one for the 'false' option. The ids of these answers are stored in the 'trueanswer' and 'falseanswer' field of the quiz_truefalse table.
- id
- int(10) unsigned NOT NULL auto_increment,
- question
- int(10) unsigned NOT NULL default '0',
- trueanswer
- int(10) unsigned NOT NULL default '0',
- id of the answer 'True' (not necessarily the correct answer).
- falseanswer
- int(10) unsigned NOT NULL default '0',
- id of the answer 'False' (not necessarily the wrong answer).
It is important to distinguish between the answer 'True' and the correct answer. When setting up a true/false question the teacher decides whether the answer 'True' or the answer 'False' is the correct answer. So 'true' and 'false' here refer to the statement in the question text, not to the correctness of the answer.
The way Moodle stores which of the answers is the correct answer is via the 'fraction' field in the quiz_answers table. The correct answer has 'fraction' = 1, the wrong one has 'fraction' = 0.
Response storage
The response from the student in $state->responses[''] is the id of the answer chosen by the student. This then also gets stored in the 'answer' field in the quiz_states table.
Question->options
$question->options object holds the data from the quiz_truefalse table and the ->answers property is an array of answers, indexed by the answer id. In the case of the true/false question $question->options->answers should of course be an array of only two answers.
State->options
True/false questions do not use the $state->options property.