Difference between revisions of "Multiple Choice question type"

Jump to: navigation, search
m (added template and categories)
Line 1: Line 1:
{{Questiontype developer docs}}
==quiz_multichoice table==
==quiz_multichoice table==
Line 38: Line 39:
$state->options has a single property '''order''' that is set to an array of answerids.
$state->options has a single property '''order''' that is set to an array of answerids.

Revision as of 20:58, 5 February 2006

quiz_multichoice table

The quiz_multichoice table is an extension of the quiz_questions table.

int(10) unsigned NOT NULL auto_increment,
Primary key
int(10) unsigned NOT NULL default '0',
Foreign key to the id field of the quiz_questions table
tinyint(4) NOT NULL default '0',
does not seem to be used
varchar(255) NOT NULL default ,
stores the order of the answers. This should be superseded by the seq_number field in the quiz_answers table
tinyint(4) NOT NULL default '0',
A flag signaling, whether only one option or multiple options can be chosen.

Response storage

What is stored in $state->responses depends on whether only a single answer is allowed or whether multiple answers are allowed. For single answers the answer id is saved in $state->responses[], whereas for the multiple answers case the $state->responses array is indexed by the answer ids and the values are also the answer ids (i.e. key = value).

The multichoice questiontype stores both the order of the choices and the selected choices in the answer field of the quiz_states table. Storing the order is optional (mainly to provide backward compatibility with previous versions of this questiontype). The order is stored as a comma separated list of answer ids (i.e. form the quiz_answers table). It is separated with a colon (':') from the selected responses, which are also stored as a comma separated list of answer ids. For example 1,3,2,4:2,4 means that the answers were shown in the order 1, 3, 2 and then 4 and the answers 2 and 4 were checked. Note that the list of selected responses is usually shorter (and often contains only one id) than the list that provides the order.

Comment by User:Gustav: It is logically not very nice that the quiz_states table is used to store the order of answers in the multiple choice question. This is information that does not change in between states. It is really associated with the attempt and the question, not the state. Unfortunately we don't have a natural table to store such information.

Question options object

$question->options is set to the object from the appropriate record in the quiz_multichoice table but with the 'answers' field replaced by an array of answer objects from the quiz_answers table.

State options object

$state->options has a single property order that is set to an array of answerids.