shuffleanswers option can now also be set at the question level, see http://moodle.org/mod/forum/discuss.php?d=39371
This commit is contained in:
@@ -394,6 +394,7 @@
|
||||
fwrite ($bf,full_tag("LAYOUT",$level+1,false,$multichoice->layout));
|
||||
fwrite ($bf,full_tag("ANSWERS",$level+1,false,$multichoice->answers));
|
||||
fwrite ($bf,full_tag("SINGLE",$level+1,false,$multichoice->single));
|
||||
fwrite ($bf,full_tag("SHUFFLEANSWERS",$level+1,false,$randomsamatch->shuffleanswers));
|
||||
$status =fwrite ($bf,end_tag("MULTICHOICE",$level,true));
|
||||
}
|
||||
//Now print quiz_answers
|
||||
@@ -420,6 +421,7 @@
|
||||
$status =fwrite ($bf,start_tag("RANDOMSAMATCH",6,true));
|
||||
//Print randomsamatch contents
|
||||
fwrite ($bf,full_tag("CHOOSE",7,false,$randomsamatch->choose));
|
||||
fwrite ($bf,full_tag("SHUFFLEANSWERS",7,false,$randomsamatch->shuffleanswers));
|
||||
$status =fwrite ($bf,end_tag("RANDOMSAMATCH",6,true));
|
||||
}
|
||||
}
|
||||
@@ -445,6 +447,7 @@
|
||||
fwrite ($bf,full_tag("ID",8,false,$match->id));
|
||||
fwrite ($bf,full_tag("QUESTIONTEXT",8,false,$match->questiontext));
|
||||
fwrite ($bf,full_tag("ANSWERTEXT",8,false,$match->answertext));
|
||||
fwrite ($bf,full_tag("SHUFFLEANSWERS",8,false,$randomsamatch->shuffleanswers));
|
||||
$status =fwrite ($bf,end_tag("MATCH",7,true));
|
||||
}
|
||||
$status =fwrite ($bf,end_tag("MATCHS",6,true));
|
||||
|
||||
@@ -883,6 +883,13 @@ function quiz_upgrade($oldversion) {
|
||||
execute_sql("UPDATE {$CFG->prefix}quiz_questions SET defaultgrade = '0' WHERE qtype = '".DESCRIPTION."'", false);
|
||||
}
|
||||
|
||||
if ($oldversion < 2006021103) {
|
||||
// add new field to store the question-level shuffleanswers option
|
||||
table_column('quiz_match', '', 'shuffleanswers', 'tinyint', '4', 'unsigned', '1', 'not null', 'subquestions');
|
||||
table_column('quiz_multichoice', '', 'shuffleanswers', 'tinyint', '4', 'unsigned', '1', 'not null', 'single');
|
||||
table_column('quiz_randomsamatch', '', 'shuffleanswers', 'tinyint', '4', 'unsigned', '1', 'not null', 'choose');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -228,6 +228,7 @@ CREATE TABLE prefix_quiz_match (
|
||||
id int(10) unsigned NOT NULL auto_increment,
|
||||
question int(10) unsigned NOT NULL default '0',
|
||||
subquestions varchar(255) NOT NULL default '',
|
||||
shuffleanswers tinyint(4) NOT NULL default '1',
|
||||
PRIMARY KEY (id),
|
||||
KEY question (question)
|
||||
) TYPE=MyISAM COMMENT='Defines fixed matching questions';
|
||||
@@ -273,6 +274,7 @@ CREATE TABLE prefix_quiz_multichoice (
|
||||
layout tinyint(4) NOT NULL default '0',
|
||||
answers varchar(255) NOT NULL default '',
|
||||
single tinyint(4) NOT NULL default '0',
|
||||
shuffleanswers tinyint(4) NOT NULL default '1',
|
||||
PRIMARY KEY (id),
|
||||
KEY question (question)
|
||||
) TYPE=MyISAM COMMENT='Options for multiple choice questions';
|
||||
@@ -406,6 +408,7 @@ CREATE TABLE prefix_quiz_randomsamatch (
|
||||
id int(10) unsigned NOT NULL auto_increment,
|
||||
question int(10) unsigned NOT NULL default '0',
|
||||
choose int(10) unsigned NOT NULL default '4',
|
||||
shuffleanswers tinyint(4) NOT NULL default '1',
|
||||
PRIMARY KEY (id),
|
||||
KEY question (question)
|
||||
) TYPE=MyISAM COMMENT='Info about a random short-answer matching question';
|
||||
|
||||
@@ -979,6 +979,13 @@ function quiz_upgrade($oldversion) {
|
||||
execute_sql("UPDATE {$CFG->prefix}quiz_questions SET defaultgrade = '0' WHERE qtype = '".DESCRIPTION."'", false);
|
||||
}
|
||||
|
||||
if ($oldversion < 2006021103) {
|
||||
// add new field to store the question-level shuffleanswers option
|
||||
table_column('quiz_match', '', 'shuffleanswers', 'tinyint', '4', 'unsigned', '1', 'not null', 'subquestions');
|
||||
table_column('quiz_multichoice', '', 'shuffleanswers', 'tinyint', '4', 'unsigned', '1', 'not null', 'single');
|
||||
table_column('quiz_randomsamatch', '', 'shuffleanswers', 'tinyint', '4', 'unsigned', '1', 'not null', 'choose');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -194,7 +194,8 @@ CREATE INDEX prefix_quiz_grades_userid_idx ON prefix_quiz_grades (userid);
|
||||
CREATE TABLE prefix_quiz_match (
|
||||
id SERIAL PRIMARY KEY,
|
||||
question integer NOT NULL default '0',
|
||||
subquestions varchar(255) NOT NULL default ''
|
||||
subquestions varchar(255) NOT NULL default '',
|
||||
shuffleanswers integer NOT NULL default '1'
|
||||
);
|
||||
|
||||
CREATE INDEX prefix_quiz_match_question_idx ON prefix_quiz_match (question);
|
||||
@@ -238,7 +239,8 @@ CREATE TABLE prefix_quiz_multichoice (
|
||||
question integer NOT NULL default '0',
|
||||
layout integer NOT NULL default '0',
|
||||
answers varchar(255) NOT NULL default '',
|
||||
single integer NOT NULL default '0'
|
||||
single integer NOT NULL default '0',
|
||||
shuffleanswers integer NOT NULL default '1'
|
||||
);
|
||||
|
||||
CREATE INDEX prefix_quiz_multichoice_question_idx ON prefix_quiz_multichoice (question);
|
||||
@@ -370,7 +372,8 @@ CREATE INDEX prefix_quiz_questions_category_idx ON prefix_quiz_questions (catego
|
||||
CREATE TABLE prefix_quiz_randomsamatch (
|
||||
id SERIAL PRIMARY KEY,
|
||||
question integer NOT NULL default '0',
|
||||
choose integer NOT NULL default '4'
|
||||
choose integer NOT NULL default '4',
|
||||
shuffleanswers integer NOT NULL default '1'
|
||||
);
|
||||
|
||||
CREATE INDEX prefix_quiz_randomsamatch_question_idx ON prefix_quiz_randomsamatch (question);
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
if (!empty($options->subquestions)) {
|
||||
$oldsubquestions = get_records_list("quiz_match_sub", "id", $options->subquestions);
|
||||
}
|
||||
} else {
|
||||
$options->shuffleanswers = 0;
|
||||
}
|
||||
|
||||
$subquestions = array();
|
||||
@@ -25,6 +27,10 @@
|
||||
$subanswers[] = ""; // Make answer slots, default as blank
|
||||
}
|
||||
|
||||
$yesnooptions = array();
|
||||
$yesnooptions[0] = get_string("no");
|
||||
$yesnooptions[1] = get_string("yes");
|
||||
|
||||
print_heading_with_help(get_string("editingmatch", "quiz"), "match", "quiz");
|
||||
require("$CFG->dirroot/mod/quiz/questiontypes/match/match.html");
|
||||
|
||||
|
||||
@@ -83,6 +83,15 @@
|
||||
<td align="left"><?php print_string("filloutthreequestions", "quiz") ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td align="right"><b><?php print_string("shuffleanswers", "quiz") ?>:</b></td>
|
||||
<td align="left">
|
||||
<?php
|
||||
choose_from_menu($yesnooptions, "shuffleanswers", "$options->shuffleanswers", "");
|
||||
helpbutton("shuffleanswers", get_string("shuffleanswers","quiz"), "quiz");
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
for ($i=1; $i <= count($subquestions); $i++) {
|
||||
?>
|
||||
|
||||
@@ -12,8 +12,8 @@ class quiz_match_qtype extends quiz_default_questiontype {
|
||||
}
|
||||
|
||||
function get_question_options(&$question) {
|
||||
$subquestions = get_records("quiz_match_sub", "question", $question->id, "id ASC" );
|
||||
$question->options->subquestions = $subquestions;
|
||||
$question->options = get_record('quiz_match', 'question', $question->id);
|
||||
$question->options->subquestions = get_records("quiz_match_sub", "question", $question->id, "id ASC" );
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -78,6 +78,7 @@ class quiz_match_qtype extends quiz_default_questiontype {
|
||||
|
||||
if ($options = get_record("quiz_match", "question", $question->id)) {
|
||||
$options->subquestions = implode(",",$subquestions);
|
||||
$options->shuffleanswers = $question->shuffleanswers;
|
||||
if (!update_record("quiz_match", $options)) {
|
||||
$result->error = "Could not update quiz match options! (id=$options->id)";
|
||||
return $result;
|
||||
@@ -86,6 +87,7 @@ class quiz_match_qtype extends quiz_default_questiontype {
|
||||
unset($options);
|
||||
$options->question = $question->id;
|
||||
$options->subquestions = implode(",",$subquestions);
|
||||
$options->shuffleanswers = $question->shuffleanswers;
|
||||
if (!insert_record("quiz_match", $options)) {
|
||||
$result->error = "Could not insert quiz match options!";
|
||||
return $result;
|
||||
@@ -129,7 +131,7 @@ class quiz_match_qtype extends quiz_default_questiontype {
|
||||
}
|
||||
|
||||
// Shuffle the answers if required
|
||||
if ($cmoptions->shuffleanswers) {
|
||||
if ($cmoptions->shuffleanswers and $question->options->shuffleanswers) {
|
||||
$state->options->subquestions = swapshuffle_assoc($state->options->subquestions);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
$options = get_record("quiz_multichoice", "question", $question->id);
|
||||
} else {
|
||||
$options->single = 1;
|
||||
$options->shuffleanswers = 0;
|
||||
}
|
||||
if (!empty($options->answers)) {
|
||||
$answersraw = get_records_list("quiz_answers", "id", $options->answers);
|
||||
@@ -23,6 +24,11 @@
|
||||
for (; $i < $limit; $i++) {
|
||||
$answers[] = ""; // Make answer slots, default as blank
|
||||
}
|
||||
|
||||
$yesnooptions = array();
|
||||
$yesnooptions[0] = get_string("no");
|
||||
$yesnooptions[1] = get_string("yes");
|
||||
|
||||
print_heading_with_help(get_string("editingmultichoice", "quiz"), "multichoice", "quiz");
|
||||
require("$CFG->dirroot/mod/quiz/questiontypes/multichoice/multichoice.html");
|
||||
|
||||
|
||||
@@ -1,8 +1,3 @@
|
||||
<?php
|
||||
if (!isset($options->single)) {
|
||||
$options->single = 1;
|
||||
}
|
||||
?>
|
||||
<form name="theform" method="post" action="question.php">
|
||||
<center>
|
||||
<table cellpadding="5">
|
||||
@@ -97,7 +92,15 @@
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr valign="top">
|
||||
<td align="right"><b><?php print_string("shuffleanswers", "quiz") ?>:</b></td>
|
||||
<td align="left">
|
||||
<?php
|
||||
choose_from_menu($yesnooptions, "shuffleanswers", "$options->shuffleanswers", "");
|
||||
helpbutton("shuffleanswers", get_string("shuffleanswers","quiz"), "quiz");
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td align="right"><b><?php print_string("choices", "quiz") ?></b>:</td>
|
||||
<td align="left"><?php print_string("fillouttwochoices", "quiz") ?></td>
|
||||
|
||||
@@ -54,8 +54,6 @@ class quiz_multichoice_qtype extends quiz_default_questiontype {
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Insert all the new answers
|
||||
|
||||
$totalfraction = 0;
|
||||
@@ -98,6 +96,7 @@ class quiz_multichoice_qtype extends quiz_default_questiontype {
|
||||
if ($options = get_record("quiz_multichoice", "question", $question->id)) {
|
||||
$options->answers = implode(",",$answers);
|
||||
$options->single = $question->single;
|
||||
$options->shuffleanswers = $question->shuffleanswers;
|
||||
if (!update_record("quiz_multichoice", $options)) {
|
||||
$result->error = "Could not update quiz multichoice options! (id=$options->id)";
|
||||
return $result;
|
||||
@@ -107,6 +106,7 @@ class quiz_multichoice_qtype extends quiz_default_questiontype {
|
||||
$options->question = $question->id;
|
||||
$options->answers = implode(",",$answers);
|
||||
$options->single = $question->single;
|
||||
$options->shuffleanswers = $question->shuffleanswers;
|
||||
if (!insert_record("quiz_multichoice", $options)) {
|
||||
$result->error = "Could not insert quiz multichoice options!";
|
||||
return $result;
|
||||
@@ -154,7 +154,7 @@ class quiz_multichoice_qtype extends quiz_default_questiontype {
|
||||
$answerids = array_values(array_map(create_function('$val',
|
||||
'return $val->id;'), $question->options->answers));
|
||||
// Shuffle the answers if required
|
||||
if ($cmoptions->shuffleanswers) {
|
||||
if ($cmoptions->shuffleanswers and $question->options->shuffleanswers) {
|
||||
$answerids = swapshuffle($answerids);
|
||||
}
|
||||
$state->options->order = $answerids;
|
||||
|
||||
@@ -3,10 +3,16 @@
|
||||
$options = get_record("quiz_randomsamatch", "question", $question->id);
|
||||
} else {
|
||||
$options->choose = "";
|
||||
$options->shuffleanswers = 0;
|
||||
}
|
||||
$saquestions = $QUIZ_QTYPES[RANDOMSAMATCH]->get_sa_candidates($category->id);
|
||||
$numberavailable = count($saquestions);
|
||||
unset($saquestions);
|
||||
|
||||
$yesnooptions = array();
|
||||
$yesnooptions[0] = get_string("no");
|
||||
$yesnooptions[1] = get_string("yes");
|
||||
|
||||
print_heading_with_help(get_string("editingrandomsamatch", "quiz"), "randomsamatch", "quiz");
|
||||
require("$CFG->dirroot/mod/quiz/questiontypes/randomsamatch/randomsamatch.html");
|
||||
|
||||
|
||||
@@ -16,8 +16,7 @@ class quiz_randomsamatch_qtype extends quiz_match_qtype {
|
||||
}
|
||||
|
||||
function get_question_options(&$question) {
|
||||
if (!$question->options->choose = get_field('quiz_randomsamatch',
|
||||
'choose', 'question', $question->id)) {
|
||||
if (!$question->options = get_record('quiz_randomsamatch', 'question', $question->id)) {
|
||||
notify('Error: Missing question options!');
|
||||
return false;
|
||||
}
|
||||
@@ -33,6 +32,7 @@ class quiz_randomsamatch_qtype extends quiz_match_qtype {
|
||||
function save_question_options($question) {
|
||||
$options->question = $question->id;
|
||||
$options->choose = $question->choose;
|
||||
$options->shuffleanswers = $question->shuffleanswers;
|
||||
|
||||
if (2 > $question->choose) {
|
||||
$result->error = "At least two shortanswer questions need to be chosen!";
|
||||
@@ -153,7 +153,7 @@ class quiz_randomsamatch_qtype extends quiz_match_qtype {
|
||||
// Shuffle the answers if required
|
||||
$subquestionids = array_values(array_map(create_function('$val',
|
||||
'return $val->id;'), $state->options->subquestions));
|
||||
if ($cmoptions->shuffleanswers) {
|
||||
if ($cmoptions->shuffleanswers and $question->options->shuffleanswers) {
|
||||
$subquestionids = swapshuffle($subquestionids);
|
||||
}
|
||||
|
||||
|
||||
@@ -94,6 +94,15 @@
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td align="right"><b><?php print_string("shuffleanswers", "quiz") ?>:</b></td>
|
||||
<td align="left">
|
||||
<?php
|
||||
choose_from_menu($yesnooptions, "shuffleanswers", "$options->shuffleanswers", "");
|
||||
helpbutton("shuffleanswers", get_string("shuffleanswers","quiz"), "quiz");
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
$QUIZ_QTYPES[$question->qtype]->print_replacement_options($question, $course, $contextquiz);
|
||||
$QUIZ_QTYPES[$question->qtype]->print_question_form_end($question);
|
||||
|
||||
@@ -588,6 +588,7 @@
|
||||
$multichoice->layout = backup_todb($mul_info['#']['LAYOUT']['0']['#']);
|
||||
$multichoice->answers = backup_todb($mul_info['#']['ANSWERS']['0']['#']);
|
||||
$multichoice->single = backup_todb($mul_info['#']['SINGLE']['0']['#']);
|
||||
$multichoice->shuffleanswers = backup_todb($mul_info['#']['SHUFFLEANSWERS']['0']['#']);
|
||||
|
||||
//We have to recode the answers field (a list of answers id)
|
||||
//Extracts answer id from sequence
|
||||
@@ -842,6 +843,7 @@
|
||||
//Now, build the QUIZ_RANDOMSAMATCH record structure
|
||||
$randomsamatch->question = $new_question_id;
|
||||
$randomsamatch->choose = backup_todb($ran_info['#']['CHOOSE']['0']['#']);
|
||||
$randomsamatch->shuffleanswers = backup_todb($ran_info['#']['SHUFFLEANSWERS']['0']['#']);
|
||||
|
||||
//The structure is equal to the db, so insert the quiz_randomsamatch
|
||||
$newid = insert_record ("quiz_randomsamatch",$randomsamatch);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
// This fragment is called by moodle_needs_upgrading() and /admin/index.php
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$module->version = 2006021102; // The (date) version of this module
|
||||
$module->version = 2006021103; // The (date) version of this module
|
||||
$module->requires = 2005021600; // Requires this Moodle version
|
||||
$module->cron = 0; // How often should cron check this module (seconds)?
|
||||
|
||||
|
||||
Reference in New Issue
Block a user