]> git.mjollnir.org Git - moodle.git/commitdiff
Further work done. It currently can print the quiz form (including images!)
authormoodler <moodler>
Sun, 6 Oct 2002 17:06:54 +0000 (17:06 +0000)
committermoodler <moodler>
Sun, 6 Oct 2002 17:06:54 +0000 (17:06 +0000)
but can't mark them yet.  I've been constructing quizzes manually in the
database and it's helping to refine the database structure.  Don't count
on anything stable in the quiz module for a few days yet ...

mod/quiz/attempt.php
mod/quiz/db/mysql.php
mod/quiz/db/mysql.sql
mod/quiz/lib.php
mod/quiz/version.php

index cb3ab1b4fff0d595da08dd8bdf1a19cfd208ef01..b5ee176bce946631fe82ac310264f174b9c5ef22 100644 (file)
 /// Print all the questions
 
     echo "<BR>";
-    print_simple_box_start("CENTER");
 
     if (!$quiz->questions) {
-        error("No questions have bee defined!", "view.php?id=$cm->id");
+        error("No questions have been defined!", "view.php?id=$cm->id");
     }
 
     $questions = explode(",", $quiz->questions);
 
+    if (!$grades = get_records_sql("SELECT question, grade FROM quiz_question_grades WHERE question in ($quiz->questions)")) {
+        error("No grades were found for these questions!");
+    }
+
     echo "<FORM METHOD=POST ACTION=attempt.php>";
     echo "<INPUT TYPE=hidden NAME=q VALUE=\"$quiz->id\">";
     foreach ($questions as $key => $questionid) {
-        quiz_print_question($key+1, $questionid);
+        print_simple_box_start("CENTER", "90%");
+        quiz_print_question($key+1, $questionid, $grades[$questionid]->grade, $course->id);
+        print_simple_box_end();
+        echo "<BR>";
     }
     echo "<CENTER><INPUT TYPE=submit VALUE=\"".get_string("savemyanswers", "quiz")."\"></CENTER>";
     echo "</FORM>";
 
-    print_simple_box_end();
 
 // Finish the page
     print_footer($course);
index d24d36560e6a329a54ddc78d4a721fe1e7e3f75d..18a5176af35f98ceb0521e1705fcf43a9d30643e 100644 (file)
@@ -6,7 +6,9 @@ function quiz_upgrade($oldversion) {
 
     global $CFG;
 
-    if ($oldversion < 2002100300) {
+    if ($oldversion < 2002110100) {
+
+        echo "The quiz module is under heavy development ... at this stage you should delete all existing quiz tables, as well as the quiz entry in the 'modules' table, then come back here to rebuild them.";
 
     }
 
index 4b884541c97d48cf7b896c68af5a3569f0438c65..ddb835fb1cc821a97ddf489f4c37942f8d607159 100644 (file)
@@ -3,7 +3,7 @@
 # http://www.phpmyadmin.net/ (download page)
 #
 # Host: localhost
-# Generation Time: Oct 03, 2002 at 11:15 PM
+# Generation Time: Oct 07, 2002 at 12:23 AM
 # Server version: 3.23.49
 # PHP Version: 4.2.3
 # Database : `moodle`
@@ -39,7 +39,7 @@ CREATE TABLE `quiz` (
 CREATE TABLE `quiz_answers` (
   `id` int(10) unsigned NOT NULL auto_increment,
   `question` int(10) unsigned NOT NULL default '0',
-  `answer` int(10) unsigned NOT NULL default '0',
+  `answer` varchar(255) NOT NULL default '',
   `grade` float NOT NULL default '0',
   `feedback` varchar(255) NOT NULL default '',
   PRIMARY KEY  (`id`)
@@ -99,7 +99,8 @@ CREATE TABLE `quiz_multichoice` (
   `layout` tinyint(4) NOT NULL default '0',
   `answers` varchar(255) NOT NULL default '',
   `single` tinyint(4) NOT NULL default '0',
-  PRIMARY KEY  (`id`)
+  PRIMARY KEY  (`id`),
+  KEY `question` (`question`)
 ) TYPE=MyISAM COMMENT='Options for multiple choice questions';
 # --------------------------------------------------------
 
@@ -122,12 +123,11 @@ CREATE TABLE `quiz_question_grades` (
 
 CREATE TABLE `quiz_questions` (
   `id` int(10) NOT NULL auto_increment,
-  `course` int(10) NOT NULL default '0',
+  `category` int(10) NOT NULL default '0',
   `name` varchar(255) NOT NULL default '',
   `question` text NOT NULL,
+  `image` varchar(255) NOT NULL default '',
   `type` smallint(6) NOT NULL default '0',
-  `options` int(10) NOT NULL default '0',
-  `category` int(10) NOT NULL default '0',
   PRIMARY KEY  (`id`)
 ) TYPE=MyISAM COMMENT='The quiz questions themselves';
 # --------------------------------------------------------
@@ -155,7 +155,8 @@ CREATE TABLE `quiz_shortanswer` (
   `question` int(10) unsigned NOT NULL default '0',
   `answer` int(10) NOT NULL default '0',
   `case` tinyint(4) NOT NULL default '0',
-  PRIMARY KEY  (`id`)
+  PRIMARY KEY  (`id`),
+  KEY `question` (`question`)
 ) TYPE=MyISAM COMMENT='Options for short answer questions';
 # --------------------------------------------------------
 
@@ -168,6 +169,8 @@ CREATE TABLE `quiz_truefalse` (
   `question` int(10) unsigned NOT NULL default '0',
   `true` int(10) unsigned NOT NULL default '0',
   `false` int(10) unsigned NOT NULL default '0',
-  PRIMARY KEY  (`id`)
+  PRIMARY KEY  (`id`),
+  KEY `question` (`question`)
 ) TYPE=MyISAM COMMENT='Options for True-False questions';
 
+
index 94d0f5aefddb1c0ad6224272a319caf77b366a18..de777a0a57a3c0208f72a309d36c042fdd77a2b0 100644 (file)
@@ -100,12 +100,98 @@ function quiz_cron () {
 // Any other quiz functions go here.  Each of them must have a name that 
 // starts with quiz_
 
-function  quiz_print_question($number, $questionid) {
-    echo "<P><B>$number</B></P>";
-    echo "<UL>";
-    echo "<P>XXXXXX</P>";
-    echo "</UL>";
-    echo "<HR>";
+function  quiz_print_question($number, $questionid, $grade, $courseid) {
+    
+    if (!$question = get_record("quiz_questions", "id", $questionid)) {
+        notify("Error: Question not found!");
+    }
+
+    $stranswer = get_string("answer", "quiz");
+    $strmarks  = get_string("marks", "quiz");
+
+    echo "<TABLE WIDTH=100% CELLSPACING=10><TR><TD NOWRAP WIDTH=100 VALIGN=top>";
+    echo "<P ALIGN=CENTER><B>$number</B><BR><FONT SIZE=1>$grade $strmarks</FONT></P>";
+    print_spacer(1,100);
+    echo "</TD><TD VALIGN=TOP>";
+
+    switch ($question->type) {
+       case 1: // shortanswer
+           if (!$options = get_record("quiz_shortanswer", "question", $question->id)) {
+               notify("Error: Missing question options!");
+           }
+           if (!$answer = get_record("quiz_answers", "id", $options->answer)) {
+               notify("Error: Missing question answers!");
+           }
+           echo "<P>$question->question</P>";
+           if ($question->image) {
+               print_file_picture($question->image, $courseid, 200);
+           }
+           echo "<P ALIGN=RIGHT>$stranswer: <INPUT TYPE=TEXT NAME=q$question->id SIZE=20></P>";
+           break;
+
+       case 2: // true-false
+           if (!$options = get_record("quiz_truefalse", "question", $question->id)) {
+               notify("Error: Missing question options!");
+           }
+           if (!$true = get_record("quiz_answers", "id", $options->true)) {
+               notify("Error: Missing question answers!");
+           }
+           if (!$false = get_record("quiz_answers", "id", $options->false)) {
+               notify("Error: Missing question answers!");
+           }
+           if (!$true->answer) {
+               $true->answer = get_string("true", "quiz");
+           }
+           if (!$false->answer) {
+               $false->answer = get_string("false", "quiz");
+           }
+           echo "<P>$question->question</P>";
+           if ($question->image) {
+               print_file_picture($question->image, $courseid, 200);
+           }
+           echo "<P ALIGN=RIGHT>$stranswer:&nbsp;&nbsp;";
+           echo "<INPUT TYPE=RADIO NAME=\"q$question->id\" VALUE=\"$true->id\">$true->answer";
+           echo "&nbsp;&nbsp;&nbsp;";
+           echo "<INPUT TYPE=RADIO NAME=\"q$question->id\" VALUE=\"$false->id\">$false->answer</P>";
+           break;
+
+       case 3: // multiple-choice
+           if (!$options = get_record("quiz_multichoice", "question", $question->id)) {
+               notify("Error: Missing question options!");
+           }
+           if (!$answers = get_records_sql("SELECT * from quiz_answers WHERE id in ($options->answers)")) {
+               notify("Error: Missing question answers!");
+           }
+           echo "<P>$question->question</P>";
+           if ($question->image) {
+               print_file_picture($question->image, $courseid, 200);
+           }
+           echo "<TABLE ALIGN=right>";
+           echo "<TR><TD valign=top>$stranswer:&nbsp;&nbsp;</TD><TD>";
+           echo "<TABLE ALIGN=right>";
+           $answerids = explode(",", $options->answers);
+           foreach ($answerids as $key => $answerid) {
+               $answer = $answers[$answerid];
+               $qnum = $key + 1;
+               echo "<TR><TD valign=top>";
+               if (!$options->single) {
+                   echo "<INPUT TYPE=RADIO NAME=q$question->id VALUE=\"$answer->id\">";
+               } else {
+                   echo "<INPUT TYPE=CHECKBOX NAME=q$question->id VALUE=\"$answer->id\">";
+               }
+               echo "</TD>";
+               echo "<TD valign=top>$qnum. $answer->answer</TD>";
+               echo "</TR>";
+           }
+           echo "</TABLE>";
+           echo "</TABLE>";
+           break;
+
+       default: 
+           notify("Error: Unknown question type!");
+    }
+
+    echo "</TD></TR></TABLE>";
 }
 
 
index 203408afa21a0491d98f380321c8da0f3f541831..d11556c041f4c37f674c594e8ee246b712c19595 100644 (file)
@@ -5,7 +5,7 @@
 //  This fragment is called by moodle_needs_upgrading() and /admin/index.php
 ////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2002100300;   // The (date) version of this module
+$module->version  = 2002100600;   // The (date) version of this module
 $module->cron     = 0;            // How often should cron check this module (seconds)?
 
 ?>