Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

True/False question type: Difference between revisions

From MoodleDocs
 
(5 intermediate revisions by 2 users not shown)
Line 19: Line 19:


==Response storage==
==Response storage==
Each true/false question defines two answer records, 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.


The response from the student in <nowiki>$state->responses['']</nowiki> is the id of the answer chosen by the student. This then also gets stored in the 'answer' field in the quiz_states table.
The response from the student in <nowiki>$state->responses['']</nowiki> is the id of the answer chosen by the student. This then also gets stored in the 'answer' field in the quiz_states table.
Line 26: Line 24:
==Question->options==
==Question->options==


$question->options object holds the data from the quiz_truefalse table and the ->answers property which is an array with indices 'true' and 'false' and the values are the corresponding answer objects.
$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==
==State->options==
 
True/false questions do not use the $state->options property.


[[Category:Quiz]]
[[Category:Quiz]]

Latest revision as of 07:36, 10 June 2011

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.