]> git.mjollnir.org Git - moodle.git/commitdiff
Changed three fields to avoid SQL problems with PostgreSQL etc:
authormoodler <moodler>
Fri, 3 Jan 2003 16:01:48 +0000 (16:01 +0000)
committermoodler <moodler>
Fri, 3 Jan 2003 16:01:48 +0000 (16:01 +0000)
quiz_truefalse:  true->trueanswer  and false->falseanswer
quiz_questions:  type->qtype

mod/quiz/db/mysql.php
mod/quiz/db/mysql.sql
mod/quiz/db/postgres7.php
mod/quiz/db/postgres7.sql
mod/quiz/lib.php
mod/quiz/multichoice.html
mod/quiz/question.php
mod/quiz/shortanswer.html
mod/quiz/truefalse.html
mod/quiz/version.php

index 754eef177db35fe42781251147f9ae053cdea588..11c787380a1efcbd2ffc08ab338b6414eaaf33e3 100644 (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;
 }
 
index 4c844a757a56f70c897284450d72c32d9bd8238e..c601b5d90668182f1237c177fba23d5e3b8f9e8b 100644 (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';
index 87cd5dff4507f4d6d57c8d34c435fa879d9f0a14..bc7010d2c6fa3ddb585b9ca1c2b5338a38986138 100644 (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;
 }
 
index c42b7b02b0712d91e678467916e0ce5a6430fb9e..459e22a345485a605a808e3a0628a01f6dee9a96 100644 (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);
 
index 58cc00a3982758aeaf1ff98e3490141b468d140e..bfb61ef192f7411f791df08ef5e690b9ea14283a 100644 (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);
index 942da9df3499e211ec759b195b3ad5d543e3d5d4..9a1bc4b4557c5d1d3518e19eb2081b3e94cb91c6 100644 (file)
 </TABLE>\r
 \r
 <INPUT type="hidden" name=id value="<? p($question->id) ?>">\r
-<INPUT type="hidden" name=type value="<? p($question->type) ?>">\r
+<INPUT type="hidden" name=qtype value="<? p($question->qtype) ?>">\r
 <INPUT type="submit" value="<? print_string("savechanges") ?>">\r
 \r
 </CENTER>\r
index 2fa064c39461f91b87f27e6b189eee548e67e3c7..2f765cbf3d4965b8e073853367ec0ef83934c5c5 100644 (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");
     
             // 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);
                     }
     
                     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!");
                     }
     }
 
 
-    switch ($type) {
+    switch ($qtype) {
         case SHORTANSWER:
             if (!empty($question->id)) {
                 $options = get_record("quiz_shortanswer", "question", $question->id);
             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 = "";
index 0f1f92da0944c8c5dade8e51debf70ddae083cc8..063b883cfebc55eb580da4904f1334bc8536f00e 100644 (file)
 </TABLE>\r
 \r
 <INPUT type="hidden" name=id value="<? p($question->id) ?>">\r
-<INPUT type="hidden" name=type value="<? p($question->type) ?>">\r
+<INPUT type="hidden" name=qtype value="<? p($question->qtype) ?>">\r
 <INPUT type="submit" value="<? print_string("savechanges") ?>">\r
 \r
 </CENTER>\r
index 308f66b246c531f0f212d5860d6b0701ebcc6b71..bc43738288e499fc3ec6a54db87d966f795e8f9b 100644 (file)
@@ -62,7 +62,7 @@
 </TABLE>\r
 \r
 <INPUT type="hidden" name=id value="<? p($question->id) ?>">\r
-<INPUT type="hidden" name=type value="<? p($question->type) ?>">\r
+<INPUT type="hidden" name=qtype value="<? p($question->qtype) ?>">\r
 <INPUT type="submit" value="<? print_string("savechanges") ?>">\r
 \r
 </CENTER>\r
index ebd409fa8bf2b78876bda97bc38fe5c601ddeb9e..55847316e2de448cb688628397b178d62e70bd16 100644 (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)?
 
 ?>