Changed three fields to avoid SQL problems with PostgreSQL etc:

quiz_truefalse:  true->trueanswer  and false->falseanswer
quiz_questions:  type->qtype
This commit is contained in:
moodler
2003-01-03 16:01:48 +00:00
parent a3fb1c450a
commit a2fe7cc0dc
10 changed files with 62 additions and 36 deletions
+7 -1
View File
@@ -29,12 +29,18 @@ function quiz_upgrade($oldversion) {
execute_sql("ALTER TABLE `quiz_attempts` CHANGE `user` `userid` INT(10) UNSIGNED DEFAULT '0' NOT NULL ");
}
// prefixes required from here on
// prefixes required from here on, or use table_column()
if ($oldversion < 2003010100) {
execute_sql(" ALTER TABLE {$CFG->prefix}quiz ADD review TINYINT(4) UNSIGNED DEFAULT '0' NOT NULL AFTER `grademethod` ");
}
if ($oldversion < 2003010301) {
table_column("quiz_truefalse", "true", "trueanswer", "INTEGER", "UNSIGNED", "0", "NOT NULL", "");
table_column("quiz_truefalse", "false", "falseanswer", "INTEGER", "UNSIGNED", "0", "NOT NULL", "");
table_column("quiz_questions", "type", "qtype", "INTEGER", "UNSIGNED", "0", "NOT NULL", "");
}
return true;
}
+3 -3
View File
@@ -132,7 +132,7 @@ CREATE TABLE `prefix_quiz_questions` (
`name` varchar(255) NOT NULL default '',
`questiontext` text NOT NULL,
`image` varchar(255) NOT NULL default '',
`type` smallint(6) NOT NULL default '0',
`qtype` smallint(6) NOT NULL default '0',
PRIMARY KEY (`id`)
) TYPE=MyISAM COMMENT='The quiz questions themselves';
# --------------------------------------------------------
@@ -172,8 +172,8 @@ CREATE TABLE `prefix_quiz_shortanswer` (
CREATE TABLE `prefix_quiz_truefalse` (
`id` int(10) unsigned NOT NULL auto_increment,
`question` int(10) unsigned NOT NULL default '0',
`true` int(10) unsigned NOT NULL default '0',
`false` int(10) unsigned NOT NULL default '0',
`trueanswer` int(10) unsigned NOT NULL default '0',
`falseanswer` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`id`),
KEY `question` (`question`)
) TYPE=MyISAM COMMENT='Options for True-False questions';
+6
View File
@@ -10,6 +10,12 @@ function quiz_upgrade($oldversion) {
execute_sql(" ALTER TABLE {$CFG->prefix}quiz ADD review integer DEFAULT '0' NOT NULL AFTER `grademethod` ");
}
if ($oldversion < 2003010301) {
table_column("quiz_truefalse", "true", "trueanswer", "INTEGER", "UNSIGNED", "0", "NOT NULL", "");
table_column("quiz_truefalse", "false", "falseanswer", "INTEGER", "UNSIGNED", "0", "NOT NULL", "");
table_column("quiz_questions", "type", "qtype", "INTEGER", "UNSIGNED", "0", "NOT NULL", "");
}
return true;
}
+3 -3
View File
@@ -124,7 +124,7 @@ CREATE TABLE prefix_quiz_questions (
name varchar(255) NOT NULL default '',
questiontext text NOT NULL default '',
image varchar(255) NOT NULL default '',
type integer NOT NULL default '0'
qtype integer NOT NULL default '0'
);
# --------------------------------------------------------
@@ -161,8 +161,8 @@ CREATE INDEX question_prefix_quiz_shortanswer_idx ON prefix_quiz_shortanswer (qu
CREATE TABLE prefix_quiz_truefalse (
id SERIAL PRIMARY KEY,
question integer NOT NULL default '0',
"true" integer NOT NULL default '0',
"false" integer NOT NULL default '0'
trueanswer integer NOT NULL default '0',
falseanswer integer NOT NULL default '0'
);
CREATE INDEX question_prefix_quiz_truefalse_idx ON prefix_quiz_truefalse (question);
+27 -13
View File
@@ -240,7 +240,7 @@ function quiz_get_grade_records($quiz) {
function quiz_get_answers($question) {
// Given a question, returns the correct answers and grades
global $CFG;
switch ($question->type) {
switch ($question->qtype) {
case SHORTANSWER; // Could be multiple answers
return get_records_sql("SELECT a.*, sa.usecase, g.grade
FROM {$CFG->prefix}quiz_shortanswer sa,
@@ -285,7 +285,7 @@ function quiz_get_attempt_responses($attempt) {
// for regrading using quiz_grade_attempt_results()
global $CFG;
if (!$responses = get_records_sql("SELECT q.id, q.type, r.answer
if (!$responses = get_records_sql("SELECT q.id, q.qtype, r.answer
FROM {$CFG->prefix}quiz_responses r,
{$CFG->prefix}quiz_questions q
WHERE r.attempt = '$attempt->id'
@@ -324,8 +324,8 @@ function quiz_print_question_icon($question) {
global $QUIZ_QUESTION_TYPE;
echo "<A HREF=\"question.php?id=$question->id\" TITLE=\"".$QUIZ_QUESTION_TYPE[$question->type]."\">";
switch ($question->type) {
echo "<A HREF=\"question.php?id=$question->id\" TITLE=\"".$QUIZ_QUESTION_TYPE[$question->qtype]."\">";
switch ($question->qtype) {
case SHORTANSWER:
echo "<IMG BORDER=0 HEIGHT=16 WIDTH=16 SRC=\"pix/sa.gif\">";
break;
@@ -350,6 +350,10 @@ function quiz_print_question($number, $questionid, $grade, $courseid,
notify("Error: Question not found!");
}
if (empty($actualgrade)) {
$actualgrade = 0;
}
$stranswer = get_string("answer", "quiz");
$strmarks = get_string("marks", "quiz");
@@ -363,7 +367,7 @@ function quiz_print_question($number, $questionid, $grade, $courseid,
print_spacer(1,100);
echo "</TD><TD VALIGN=TOP>";
switch ($question->type) {
switch ($question->qtype) {
case SHORTANSWER:
if (!$options = get_record("quiz_shortanswer", "question", $question->id)) {
notify("Error: Missing question options!");
@@ -374,6 +378,8 @@ function quiz_print_question($number, $questionid, $grade, $courseid,
}
if ($response) {
$value = "VALUE=\"$response[0]\"";
} else {
$value = "";
}
echo "<P ALIGN=RIGHT>$stranswer: <INPUT TYPE=TEXT NAME=q$question->id SIZE=20 $value></P>";
if ($feedback) {
@@ -389,10 +395,10 @@ function quiz_print_question($number, $questionid, $grade, $courseid,
if (!$options = get_record("quiz_truefalse", "question", $question->id)) {
notify("Error: Missing question options!");
}
if (!$true = get_record("quiz_answers", "id", $options->true)) {
if (!$true = get_record("quiz_answers", "id", $options->trueanswer)) {
notify("Error: Missing question answers!");
}
if (!$false = get_record("quiz_answers", "id", $options->false)) {
if (!$false = get_record("quiz_answers", "id", $options->falseanswer)) {
notify("Error: Missing question answers!");
}
if (!$true->answer) {
@@ -406,18 +412,24 @@ function quiz_print_question($number, $questionid, $grade, $courseid,
print_file_picture($question->image, $courseid, 200);
}
if ($response[$true->id]) {
$truechecked = "";
$falsechecked = "";
if (!empty($response[$true->id])) {
$truechecked = "CHECKED";
$feedbackid = $true->id;
} else if ($response[$false->id]) {
} else if (!empty($response[$false->id])) {
$falsechecked = "CHECKED";
$feedbackid = $false->id;
}
$truecorrect = "";
$falsecorrect = "";
if ($correct) {
if ($correct[$true->id]) {
if (!empty($correct[$true->id])) {
$truecorrect = "CLASS=highlight";
}
if ($correct[$false->id]) {
if (!empty($correct[$false->id])) {
$falsecorrect = "CLASS=highlight";
}
}
@@ -751,7 +763,7 @@ function quiz_print_cat_question_list($categoryid) {
echo "<FORM METHOD=GET ACTION=question.php>";
echo "<B>$strquestion:</B>&nbsp;";
choose_from_menu($QUIZ_QUESTION_TYPE, "type", "", "");
choose_from_menu($QUIZ_QUESTION_TYPE, "qtype", "", "");
echo "<INPUT TYPE=hidden NAME=category VALUE=\"$category->id\">";
echo "<INPUT TYPE=submit NAME=new VALUE=\"$strcreatenewquestion\">";
helpbutton("questiontypes", $strcreatenewquestion, "quiz");
@@ -1001,7 +1013,7 @@ function quiz_grade_attempt_results($quiz, $questions) {
$feedback = array();
$response = array();
switch ($question->type) {
switch ($question->qtype) {
case SHORTANSWER:
if ($question->answer) {
$question->answer = trim($question->answer[0]);
@@ -1009,9 +1021,11 @@ function quiz_grade_attempt_results($quiz, $questions) {
$question->answer = "";
}
$response[0] = $question->answer;
$bestshortanswer = 0;
foreach($answers as $answer) { // There might be multiple right answers
if ($answer->fraction > $bestshortanswer) {
$correct[$answer->id] = $answer->answer;
$bestshortanswer = $answer->fraction;
}
if (!$answer->usecase) { // Don't compare case
$answer->answer = strtolower($answer->answer);
+1 -1
View File
@@ -180,7 +180,7 @@
</TABLE>
<INPUT type="hidden" name=id value="<? p($question->id) ?>">
<INPUT type="hidden" name=type value="<? p($question->type) ?>">
<INPUT type="hidden" name=qtype value="<? p($question->qtype) ?>">
<INPUT type="submit" value="<? print_string("savechanges") ?>">
</CENTER>
+12 -12
View File
@@ -7,7 +7,7 @@
optional_variable($id);
optional_variable($type);
optional_variable($qtype);
optional_variable($category);
if ($id) {
@@ -22,7 +22,7 @@
error("This question category doesn't belong to a valid course!");
}
$type = $question->type;
$qtype = $question->qtype;
} else if ($category) {
@@ -34,7 +34,7 @@
}
$question->category = $category->id;
$question->type = $type;
$question->qtype = $qtype;
} else {
error("Must specify question id or category");
@@ -116,7 +116,7 @@
// Now to save all the answers and type-specific options
switch ($question->type) {
switch ($question->qtype) {
case SHORTANSWER:
// Delete all the old answers
delete_records("quiz_answers", "question", $question->id);
@@ -180,9 +180,9 @@
}
unset($options);
$options->question = $question->id;
$options->true = $true->id;
$options->false = $false->id;
$options->question = $question->id;
$options->trueanswer = $true->id;
$options->falseanswer = $false->id;
if (!insert_record("quiz_truefalse", $options)) {
error("Could not insert quiz truefalse options!");
}
@@ -298,7 +298,7 @@
}
switch ($type) {
switch ($qtype) {
case SHORTANSWER:
if (!empty($question->id)) {
$options = get_record("quiz_shortanswer", "question", $question->id);
@@ -326,14 +326,14 @@
if (!empty($question->id)) {
$options = get_record("quiz_truefalse", "question", "$question->id");
}
if (!empty($options->true)) {
$true = get_record("quiz_answers", "id", "$options->true");
if (!empty($options->trueanswer)) {
$true = get_record("quiz_answers", "id", $options->trueanswer);
} else {
$true->fraction = 1;
$true->feedback = "";
}
if (!empty($options->false)) {
$false = get_record("quiz_answers", "id", "$options->false");
if (!empty($options->falseanswer)) {
$false = get_record("quiz_answers", "id", "$options->falseanswer");
} else {
$false->fraction = 0;
$false->feedback = "";
+1 -1
View File
@@ -159,7 +159,7 @@
</TABLE>
<INPUT type="hidden" name=id value="<? p($question->id) ?>">
<INPUT type="hidden" name=type value="<? p($question->type) ?>">
<INPUT type="hidden" name=qtype value="<? p($question->qtype) ?>">
<INPUT type="submit" value="<? print_string("savechanges") ?>">
</CENTER>
+1 -1
View File
@@ -62,7 +62,7 @@
</TABLE>
<INPUT type="hidden" name=id value="<? p($question->id) ?>">
<INPUT type="hidden" name=type value="<? p($question->type) ?>">
<INPUT type="hidden" name=qtype value="<? p($question->qtype) ?>">
<INPUT type="submit" value="<? print_string("savechanges") ?>">
</CENTER>
+1 -1
View File
@@ -5,7 +5,7 @@
// This fragment is called by moodle_needs_upgrading() and /admin/index.php
////////////////////////////////////////////////////////////////////////////////
$module->version = 2003010100; // The (date) version of this module
$module->version = 2003010301; // The (date) version of this module
$module->cron = 0; // How often should cron check this module (seconds)?
?>