Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Further work done. It currently can print the quiz form (including im…

…ages!)

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 ...
  • Loading branch information...
commit 14d8c0b4099b0d331bf6e766eac046e2259e173a 1 parent 55c0c75
moodler authored
13 mod/quiz/attempt.php
@@ -85,23 +85,28 @@
85 85 /// Print all the questions
86 86
87 87 echo "<BR>";
88   - print_simple_box_start("CENTER");
89 88
90 89 if (!$quiz->questions) {
91   - error("No questions have bee defined!", "view.php?id=$cm->id");
  90 + error("No questions have been defined!", "view.php?id=$cm->id");
92 91 }
93 92
94 93 $questions = explode(",", $quiz->questions);
95 94
  95 + if (!$grades = get_records_sql("SELECT question, grade FROM quiz_question_grades WHERE question in ($quiz->questions)")) {
  96 + error("No grades were found for these questions!");
  97 + }
  98 +
96 99 echo "<FORM METHOD=POST ACTION=attempt.php>";
97 100 echo "<INPUT TYPE=hidden NAME=q VALUE=\"$quiz->id\">";
98 101 foreach ($questions as $key => $questionid) {
99   - quiz_print_question($key+1, $questionid);
  102 + print_simple_box_start("CENTER", "90%");
  103 + quiz_print_question($key+1, $questionid, $grades[$questionid]->grade, $course->id);
  104 + print_simple_box_end();
  105 + echo "<BR>";
100 106 }
101 107 echo "<CENTER><INPUT TYPE=submit VALUE=\"".get_string("savemyanswers", "quiz")."\"></CENTER>";
102 108 echo "</FORM>";
103 109
104   - print_simple_box_end();
105 110
106 111 // Finish the page
107 112 print_footer($course);
4 mod/quiz/db/mysql.php
@@ -6,7 +6,9 @@ function quiz_upgrade($oldversion) {
6 6
7 7 global $CFG;
8 8
9   - if ($oldversion < 2002100300) {
  9 + if ($oldversion < 2002110100) {
  10 +
  11 + 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.";
10 12
11 13 }
12 14
19 mod/quiz/db/mysql.sql
@@ -3,7 +3,7 @@
3 3 # http://www.phpmyadmin.net/ (download page)
4 4 #
5 5 # Host: localhost
6   -# Generation Time: Oct 03, 2002 at 11:15 PM
  6 +# Generation Time: Oct 07, 2002 at 12:23 AM
7 7 # Server version: 3.23.49
8 8 # PHP Version: 4.2.3
9 9 # Database : `moodle`
@@ -39,7 +39,7 @@ CREATE TABLE `quiz` (
39 39 CREATE TABLE `quiz_answers` (
40 40 `id` int(10) unsigned NOT NULL auto_increment,
41 41 `question` int(10) unsigned NOT NULL default '0',
42   - `answer` int(10) unsigned NOT NULL default '0',
  42 + `answer` varchar(255) NOT NULL default '',
43 43 `grade` float NOT NULL default '0',
44 44 `feedback` varchar(255) NOT NULL default '',
45 45 PRIMARY KEY (`id`)
@@ -99,7 +99,8 @@ CREATE TABLE `quiz_multichoice` (
99 99 `layout` tinyint(4) NOT NULL default '0',
100 100 `answers` varchar(255) NOT NULL default '',
101 101 `single` tinyint(4) NOT NULL default '0',
102   - PRIMARY KEY (`id`)
  102 + PRIMARY KEY (`id`),
  103 + KEY `question` (`question`)
103 104 ) TYPE=MyISAM COMMENT='Options for multiple choice questions';
104 105 # --------------------------------------------------------
105 106
@@ -122,12 +123,11 @@ CREATE TABLE `quiz_question_grades` (
122 123
123 124 CREATE TABLE `quiz_questions` (
124 125 `id` int(10) NOT NULL auto_increment,
125   - `course` int(10) NOT NULL default '0',
  126 + `category` int(10) NOT NULL default '0',
126 127 `name` varchar(255) NOT NULL default '',
127 128 `question` text NOT NULL,
  129 + `image` varchar(255) NOT NULL default '',
128 130 `type` smallint(6) NOT NULL default '0',
129   - `options` int(10) NOT NULL default '0',
130   - `category` int(10) NOT NULL default '0',
131 131 PRIMARY KEY (`id`)
132 132 ) TYPE=MyISAM COMMENT='The quiz questions themselves';
133 133 # --------------------------------------------------------
@@ -155,7 +155,8 @@ CREATE TABLE `quiz_shortanswer` (
155 155 `question` int(10) unsigned NOT NULL default '0',
156 156 `answer` int(10) NOT NULL default '0',
157 157 `case` tinyint(4) NOT NULL default '0',
158   - PRIMARY KEY (`id`)
  158 + PRIMARY KEY (`id`),
  159 + KEY `question` (`question`)
159 160 ) TYPE=MyISAM COMMENT='Options for short answer questions';
160 161 # --------------------------------------------------------
161 162
@@ -168,6 +169,8 @@ CREATE TABLE `quiz_truefalse` (
168 169 `question` int(10) unsigned NOT NULL default '0',
169 170 `true` int(10) unsigned NOT NULL default '0',
170 171 `false` int(10) unsigned NOT NULL default '0',
171   - PRIMARY KEY (`id`)
  172 + PRIMARY KEY (`id`),
  173 + KEY `question` (`question`)
172 174 ) TYPE=MyISAM COMMENT='Options for True-False questions';
173 175
  176 +
98 mod/quiz/lib.php
@@ -100,12 +100,98 @@ function quiz_cron () {
100 100 // Any other quiz functions go here. Each of them must have a name that
101 101 // starts with quiz_
102 102
103   -function quiz_print_question($number, $questionid) {
104   - echo "<P><B>$number</B></P>";
105   - echo "<UL>";
106   - echo "<P>XXXXXX</P>";
107   - echo "</UL>";
108   - echo "<HR>";
  103 +function quiz_print_question($number, $questionid, $grade, $courseid) {
  104 +
  105 + if (!$question = get_record("quiz_questions", "id", $questionid)) {
  106 + notify("Error: Question not found!");
  107 + }
  108 +
  109 + $stranswer = get_string("answer", "quiz");
  110 + $strmarks = get_string("marks", "quiz");
  111 +
  112 + echo "<TABLE WIDTH=100% CELLSPACING=10><TR><TD NOWRAP WIDTH=100 VALIGN=top>";
  113 + echo "<P ALIGN=CENTER><B>$number</B><BR><FONT SIZE=1>$grade $strmarks</FONT></P>";
  114 + print_spacer(1,100);
  115 + echo "</TD><TD VALIGN=TOP>";
  116 +
  117 + switch ($question->type) {
  118 + case 1: // shortanswer
  119 + if (!$options = get_record("quiz_shortanswer", "question", $question->id)) {
  120 + notify("Error: Missing question options!");
  121 + }
  122 + if (!$answer = get_record("quiz_answers", "id", $options->answer)) {
  123 + notify("Error: Missing question answers!");
  124 + }
  125 + echo "<P>$question->question</P>";
  126 + if ($question->image) {
  127 + print_file_picture($question->image, $courseid, 200);
  128 + }
  129 + echo "<P ALIGN=RIGHT>$stranswer: <INPUT TYPE=TEXT NAME=q$question->id SIZE=20></P>";
  130 + break;
  131 +
  132 + case 2: // true-false
  133 + if (!$options = get_record("quiz_truefalse", "question", $question->id)) {
  134 + notify("Error: Missing question options!");
  135 + }
  136 + if (!$true = get_record("quiz_answers", "id", $options->true)) {
  137 + notify("Error: Missing question answers!");
  138 + }
  139 + if (!$false = get_record("quiz_answers", "id", $options->false)) {
  140 + notify("Error: Missing question answers!");
  141 + }
  142 + if (!$true->answer) {
  143 + $true->answer = get_string("true", "quiz");
  144 + }
  145 + if (!$false->answer) {
  146 + $false->answer = get_string("false", "quiz");
  147 + }
  148 + echo "<P>$question->question</P>";
  149 + if ($question->image) {
  150 + print_file_picture($question->image, $courseid, 200);
  151 + }
  152 + echo "<P ALIGN=RIGHT>$stranswer:&nbsp;&nbsp;";
  153 + echo "<INPUT TYPE=RADIO NAME=\"q$question->id\" VALUE=\"$true->id\">$true->answer";
  154 + echo "&nbsp;&nbsp;&nbsp;";
  155 + echo "<INPUT TYPE=RADIO NAME=\"q$question->id\" VALUE=\"$false->id\">$false->answer</P>";
  156 + break;
  157 +
  158 + case 3: // multiple-choice
  159 + if (!$options = get_record("quiz_multichoice", "question", $question->id)) {
  160 + notify("Error: Missing question options!");
  161 + }
  162 + if (!$answers = get_records_sql("SELECT * from quiz_answers WHERE id in ($options->answers)")) {
  163 + notify("Error: Missing question answers!");
  164 + }
  165 + echo "<P>$question->question</P>";
  166 + if ($question->image) {
  167 + print_file_picture($question->image, $courseid, 200);
  168 + }
  169 + echo "<TABLE ALIGN=right>";
  170 + echo "<TR><TD valign=top>$stranswer:&nbsp;&nbsp;</TD><TD>";
  171 + echo "<TABLE ALIGN=right>";
  172 + $answerids = explode(",", $options->answers);
  173 + foreach ($answerids as $key => $answerid) {
  174 + $answer = $answers[$answerid];
  175 + $qnum = $key + 1;
  176 + echo "<TR><TD valign=top>";
  177 + if (!$options->single) {
  178 + echo "<INPUT TYPE=RADIO NAME=q$question->id VALUE=\"$answer->id\">";
  179 + } else {
  180 + echo "<INPUT TYPE=CHECKBOX NAME=q$question->id VALUE=\"$answer->id\">";
  181 + }
  182 + echo "</TD>";
  183 + echo "<TD valign=top>$qnum. $answer->answer</TD>";
  184 + echo "</TR>";
  185 + }
  186 + echo "</TABLE>";
  187 + echo "</TABLE>";
  188 + break;
  189 +
  190 + default:
  191 + notify("Error: Unknown question type!");
  192 + }
  193 +
  194 + echo "</TD></TR></TABLE>";
109 195 }
110 196
111 197
2  mod/quiz/version.php
@@ -5,7 +5,7 @@
5 5 // This fragment is called by moodle_needs_upgrading() and /admin/index.php
6 6 ////////////////////////////////////////////////////////////////////////////////
7 7
8   -$module->version = 2002100300; // The (date) version of this module
  8 +$module->version = 2002100600; // The (date) version of this module
9 9 $module->cron = 0; // How often should cron check this module (seconds)?
10 10
11 11 ?>

0 comments on commit 14d8c0b

Please sign in to comment.
Something went wrong with that request. Please try again.