Permalink
Browse files

Just to show that something is happening!

At this stage this module:

  - prints quizzes,
  - accepts answers (for multiple attempts) and grades them,
  - stores the grades.

Really, it's usable as long as you don't mind using the database manually. :)

Next up is quiz reports, then I'll tackle quiz creation.
  • Loading branch information...
1 parent 5a84640 commit a5e1f35c66f65d2f21648a1678f3c038b39db6e6 moodler committed Oct 13, 2002
Showing with 388 additions and 106 deletions.
  1. +80 −37 mod/quiz/attempt.php
  2. +5 −5 mod/quiz/db/mysql.sql
  3. +296 −60 mod/quiz/lib.php
  4. +1 −1 mod/quiz/version.php
  5. +6 −3 mod/quiz/view.php
View
@@ -35,16 +35,7 @@
require_login($course->id);
- add_to_log($course->id, "quiz", "attempt", "attempt.php?id=$cm->id", "$quiz->id");
- if ($course->format == "weeks" and $quiz->days) {
- $timenow = time();
- $timestart = $course->startdate + (($cw->section - 1) * 608400);
- $timefinish = $timestart + (3600 * 24 * $quiz->days);
- $available = ($timestart < $timenow and $timenow < $timefinish);
- } else {
- $available = true;
- }
// Print the page header
@@ -57,15 +48,9 @@
print_header("$course->shortname: $quiz->name", "$course->fullname",
"$navigation <A HREF=index.php?id=$course->id>$strquizzes</A> -> $quiz->name",
- "", "", true, update_module_icon($cm->id, $course->id));
+ "", "", true);
-/// Print the headings and so on
-
- print_heading($quiz->name);
-
- if (!$available) {
- error("Sorry, this quiz is not available", "view.php?id=$cm->id");
- }
+/// Check some quiz parameters
if ($attempts = quiz_get_user_attempts($quiz->id, $USER->id)) {
$numattempts = count($attempts) + 1;
@@ -77,38 +62,96 @@
error("Sorry, you've had $quiz->attempts attempts already.", "view.php?id=$cm->id");
}
- print_heading("Attempt $numattempts out of $quiz->attempts");
+ if ($course->format == "weeks" and $quiz->days) {
+ $timenow = time();
+ $timestart = $course->startdate + (($cw->section - 1) * 608400);
+ $timefinish = $timestart + (3600 * 24 * $quiz->days);
+ $available = ($timestart < $timenow and $timenow < $timefinish);
+ } else {
+ $available = true;
+ }
- print_simple_box($quiz->intro, "CENTER");
+/// Check to see if they are submitting answers
+ if (match_referer() && isset($HTTP_POST_VARS)) {
+ add_to_log($course->id, "quiz", "submit", "attempt.php?id=$cm->id", "$quiz->id");
+ $rawanswers = $HTTP_POST_VARS;
+ unset($rawanswers["q"]); // quiz id
+ if (! count($rawanswers)) {
+ print_heading(get_string("noanswers", "quiz"));
+ print_continue("attempt.php?q=$quiz->id");
+ exit;
+ }
-/// Print all the questions
+ if (!$questions = get_records_list("quiz_questions", "id", $quiz->questions)) {
+ error("No questions found!");
+ }
- echo "<BR>";
+ foreach ($rawanswers as $key => $value) { // Parse input for question -> answers
+ if (substr($key, 0, 1) == "q") {
+ $key = substr($key,1);
+ if (!isset($questions[$key])) {
+ if (substr_count($key, "a")) { // checkbox style multiple answers
+ $check = explode("a", $key);
+ $key = $check[0];
+ $value = $check[1];
+ } else {
+ error("Answer received for non-existent question ($key)!");
+ }
+ }
+ $questions[$key]->answer[] = $value; // Store answers in array
+ }
+ }
- if (!$quiz->questions) {
- error("No questions have been defined!", "view.php?id=$cm->id");
- }
+ if (!$result = quiz_grade_attempt_results($quiz, $questions)) {
+ error("Could not grade your quiz attempt!");
+ }
+
+ if (! $attempt = quiz_save_attempt($quiz, $questions, $result, $numattempts)) {
+ error("Sorry! Could not save your attempt!");
+ }
+
+ if (! quiz_save_best_grade($quiz, $USER)) {
+ error("Sorry! Could not calculate your best grade!");
+ }
- $questions = explode(",", $quiz->questions);
+ print_heading(get_string("grade", "quiz").": $result->grade/$quiz->grade ($result->sumgrades / $quiz->sumgrades = $percent %)");
- 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!");
+ print_continue("view.php?id=$cm->id");
+
+ if ($quiz->correctanswers) {
+ quiz_print_quiz_questions($quiz, $result);
+ print_continue("view.php?id=$cm->id");
+ }
+
+ exit;
}
- echo "<FORM METHOD=POST ACTION=attempt.php>";
- echo "<INPUT TYPE=hidden NAME=q VALUE=\"$quiz->id\">";
- foreach ($questions as $key => $questionid) {
- print_simple_box_start("CENTER", "90%");
- quiz_print_question($key+1, $questionid, $grades[$questionid]->grade, $course->id);
- print_simple_box_end();
- echo "<BR>";
+ add_to_log($course->id, "quiz", "attempt", "attempt.php?id=$cm->id", "$quiz->id");
+
+/// Print the quiz page
+
+/// First print the headings and so on
+
+ print_heading($quiz->name);
+
+ if (!$available) {
+ error("Sorry, this quiz is not available", "view.php?id=$cm->id");
}
- echo "<CENTER><INPUT TYPE=submit VALUE=\"".get_string("savemyanswers", "quiz")."\"></CENTER>";
- echo "</FORM>";
+
+ print_heading("Attempt $numattempts out of $quiz->attempts");
+
+ print_simple_box($quiz->intro, "CENTER");
+
+
+/// Print all the questions
+
+ echo "<BR>";
+
+ quiz_print_quiz_questions($quiz);
-// Finish the page
+/// Finish the page
print_footer($course);
?>
View
@@ -3,7 +3,7 @@
# http://www.phpmyadmin.net/ (download page)
#
# Host: localhost
-# Generation Time: Oct 07, 2002 at 12:23 AM
+# Generation Time: Oct 13, 2002 at 03:11 PM
# Server version: 3.23.49
# PHP Version: 4.2.3
# Database : `moodle`
@@ -40,10 +40,11 @@ CREATE TABLE `quiz_answers` (
`id` int(10) unsigned NOT NULL auto_increment,
`question` int(10) unsigned NOT NULL default '0',
`answer` varchar(255) NOT NULL default '',
- `grade` float NOT NULL default '0',
+ `fraction` float NOT NULL default '0',
`feedback` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`)
-) TYPE=MyISAM COMMENT='Answers, with a percentage grade and feedback';
+
+) TYPE=MyISAM COMMENT='Answers, with a fractional grade (0-1) and feedback';
# --------------------------------------------------------
#
@@ -55,7 +56,7 @@ CREATE TABLE `quiz_attempts` (
`quiz` int(10) unsigned NOT NULL default '0',
`user` int(10) unsigned NOT NULL default '0',
`attempt` smallint(6) NOT NULL default '0',
- `grade` float NOT NULL default '0',
+ `sumgrades` float NOT NULL default '0',
`timemodified` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`id`)
) TYPE=MyISAM COMMENT='Stores various attempts on a quiz';
@@ -173,4 +174,3 @@ CREATE TABLE `quiz_truefalse` (
KEY `question` (`question`)
) TYPE=MyISAM COMMENT='Options for True-False questions';
-
Oops, something went wrong.

0 comments on commit a5e1f35

Please sign in to comment.