Multiple Choice question type
quiz_multichoice table
The quiz_multichoice table is an extension of the quiz_questions table.
- id
- int(10) unsigned NOT NULL auto_increment,
- Primary key
- question
- int(10) unsigned NOT NULL default '0',
- Foreign key to the id field of the quiz_questions table
- layout
- tinyint(4) NOT NULL default '0',
- does not seem to be used
- answers
- 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
- single
- tinyint(4) NOT NULL default '0',
- A flag signaling, whether only one option or multiple options can be chosen.
- shuffleanswers
- tinyint(4) NOT NULL default '1',
- a flag that determines whether the answers should be shuffled, provided the quiz settings allows this.
Response storage
Runtime
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).
Database
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 (primary keys from 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 Gustav Delius: 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.