From 8d94f5a08e00d23f63364de46fdecb0f85ad66ab Mon Sep 17 00:00:00 2001 From: moodler Date: Tue, 15 Oct 2002 12:54:11 +0000 Subject: [PATCH] OK, it seems reliable enough now for alpha testing. If you have existing quizzes, delete them all, then drop all the quiz tables and delete the quiz line from the modules table. Things to do still: - add/edit/remove categories - display question feedback on submissions ... - record the time they started the quiz, as well as the completion. - place time limits between attempts - add full specification of quiz open time and quiz close time --- lang/en/moodle.php | 1 + lang/en/quiz.php | 5 ++- mod/quiz/attempt.php | 6 ++- mod/quiz/db/mysql.sql | 17 ++++----- mod/quiz/edit.php | 3 +- mod/quiz/index.php | 12 ++++-- mod/quiz/lib.php | 80 +++++++++++++++++++++++++++------------ mod/quiz/multichoice.html | 12 +++--- mod/quiz/report.php | 7 +--- mod/quiz/shortanswer.html | 10 ++--- mod/quiz/view.php | 39 ++++++++++++------- 11 files changed, 120 insertions(+), 72 deletions(-) diff --git a/lang/en/moodle.php b/lang/en/moodle.php index 08d210a03e..d705b48136 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -192,6 +192,7 @@ GNU General Public License for more details: http://www.gnu.org/copyleft/gpl.html"; $string['grade'] = "Grade"; +$string['grades'] = "Grades"; $string['guestskey'] = "Allow guests who have the key"; $string['guestsno'] = "Do not allow guests in"; $string['guestsnotallowed'] = "Sorry, '\$a' does not allow guests to enter."; diff --git a/lang/en/quiz.php b/lang/en/quiz.php index f04866a19a..8bf38ff845 100644 --- a/lang/en/quiz.php +++ b/lang/en/quiz.php @@ -40,11 +40,10 @@ $string['false'] = "False"; $string['feedback'] = "Feedback"; $string['filloutoneanswer'] = "You must fill out at least one possible answer. Answers left blank will not be used."; $string['fillouttwochoices'] = "You must fill out at least two choices. Choices left blank will not be used."; -$string['grade'] = "Grade"; $string['gradeaverage'] = "Average grade"; $string['gradehighest'] = "Highest grade"; $string['grademethod'] = "Grading method"; -$string['imageaddress'] = "Image URL address"; +$string['imagedisplay'] = "Image to display"; $string['introduction'] = "Introduction"; $string['marks'] = "Marks"; $string['multichoice'] = "Multiple Choice"; @@ -59,12 +58,14 @@ $string['save'] = "Save"; $string['savegrades'] = "Save grades"; $string['savemyanswers'] = "Save my answers"; $string['savequiz'] = "Save this whole quiz"; +$string['score'] = "Raw score"; $string['select'] = "Select"; $string['selectcategoryabove'] = "Select a category above"; $string['shortanswer'] = "Short Answer"; $string['show'] = "Show"; $string['showfeedback'] = "After answering, show feedback?"; $string['showcorrectanswer'] = "After answering, show correct answers?"; +$string['time'] = "Time"; $string['true'] = "True"; $string['truefalse'] = "True/False"; $string['viewallanswers'] = "View \$a completed quizzes"; diff --git a/mod/quiz/attempt.php b/mod/quiz/attempt.php index 5c4b438ef2..dac9679cb5 100644 --- a/mod/quiz/attempt.php +++ b/mod/quiz/attempt.php @@ -117,7 +117,11 @@ error("Sorry! Could not calculate your best grade!"); } - print_heading(get_string("grade", "quiz").": $result->grade/$quiz->grade ($result->sumgrades / $quiz->sumgrades = $result->percentage %)"); + $strgrade = get_string("grade"); + $strscore = get_string("score", "quiz"); + + print_heading("$strscore: $result->sumgrades/$quiz->sumgrades ($result->percentage %)"); + print_heading("$strgrade: $result->grade/$quiz->grade"); print_continue("view.php?id=$cm->id"); diff --git a/mod/quiz/db/mysql.sql b/mod/quiz/db/mysql.sql index e1e192e153..e76a618dad 100644 --- a/mod/quiz/db/mysql.sql +++ b/mod/quiz/db/mysql.sql @@ -3,7 +3,7 @@ # http://www.phpmyadmin.net/ (download page) # # Host: localhost -# Generation Time: Oct 13, 2002 at 03:11 PM +# Generation Time: Oct 15, 2002 at 08:22 PM # Server version: 3.23.49 # PHP Version: 4.2.3 # Database : `moodle` @@ -40,10 +40,9 @@ 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 '', - `fraction` float NOT NULL default '0', + `fraction` varchar(10) NOT NULL default '0.0', `feedback` varchar(255) NOT NULL default '', PRIMARY KEY (`id`) - ) TYPE=MyISAM COMMENT='Answers, with a fractional grade (0-1) and feedback'; # -------------------------------------------------------- @@ -56,7 +55,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', - `sumgrades` float NOT NULL default '0', + `sumgrades` int(10) NOT NULL default '0', `timemodified` int(10) unsigned NOT NULL default '0', PRIMARY KEY (`id`) ) TYPE=MyISAM COMMENT='Stores various attempts on a quiz'; @@ -84,7 +83,7 @@ CREATE TABLE `quiz_grades` ( `id` int(10) unsigned NOT NULL auto_increment, `quiz` int(10) unsigned NOT NULL default '0', `user` int(10) unsigned NOT NULL default '0', - `grade` float NOT NULL default '0', + `grade` int(10) NOT NULL default '0', `timemodified` int(10) unsigned NOT NULL default '0', PRIMARY KEY (`id`) ) TYPE=MyISAM COMMENT='Final quiz grade (may be best of several attempts)'; @@ -126,7 +125,7 @@ CREATE TABLE `quiz_questions` ( `id` int(10) NOT NULL auto_increment, `category` int(10) NOT NULL default '0', `name` varchar(255) NOT NULL default '', - `question` text NOT NULL, + `questiontext` text NOT NULL, `image` varchar(255) NOT NULL default '', `type` smallint(6) NOT NULL default '0', PRIMARY KEY (`id`) @@ -142,7 +141,7 @@ CREATE TABLE `quiz_responses` ( `attempt` int(10) unsigned NOT NULL default '0', `question` int(10) unsigned NOT NULL default '0', `answer` varchar(255) NOT NULL default '', - `grade` float NOT NULL default '0', + `grade` int(10) NOT NULL default '0', PRIMARY KEY (`id`) ) TYPE=MyISAM COMMENT='Stores user responses to a quiz, and percentage grades'; # -------------------------------------------------------- @@ -154,8 +153,8 @@ CREATE TABLE `quiz_responses` ( CREATE TABLE `quiz_shortanswer` ( `id` int(10) unsigned NOT NULL auto_increment, `question` int(10) unsigned NOT NULL default '0', - `answer` int(10) NOT NULL default '0', - `case` tinyint(4) NOT NULL default '0', + `answers` varchar(255) NOT NULL default '', + `usecase` tinyint(2) NOT NULL default '0', PRIMARY KEY (`id`), KEY `question` (`question`) ) TYPE=MyISAM COMMENT='Options for short answer questions'; diff --git a/mod/quiz/edit.php b/mod/quiz/edit.php index 9ccfa50ad6..09963d828e 100644 --- a/mod/quiz/edit.php +++ b/mod/quiz/edit.php @@ -108,8 +108,9 @@ $modform->questions = implode(",", $questions); } - if ($grade) { /// The grades have been updated, so update our internal list + if ($setgrades) { /// The grades have been updated, so update our internal list $rawgrades = $HTTP_POST_VARS; + unset($modform->grades); foreach ($rawgrades as $key => $value) { // Parse input for question -> grades if (substr($key, 0, 1) == "q") { $key = substr($key,1); diff --git a/mod/quiz/index.php b/mod/quiz/index.php index e7e4a36ed5..febce54f59 100644 --- a/mod/quiz/index.php +++ b/mod/quiz/index.php @@ -40,16 +40,20 @@ $strname = get_string("name"); $strweek = get_string("week"); $strtopic = get_string("topic"); + $strgrades = get_string("grades"); if ($course->format == "weeks") { - $table->head = array ($strweek, $strname); + $table->head = array ($strweek, $strname, $strgrades); $table->align = array ("CENTER", "LEFT"); + $table->width = array (10, "*", 10); } else if ($course->format == "topics") { - $table->head = array ($strtopic, $strname); + $table->head = array ($strtopic, $strname, $strgrades); $table->align = array ("CENTER", "LEFT", "LEFT", "LEFT"); + $table->width = array (10, "*", 10); } else { - $table->head = array ($strname); - $table->align = array ("LEFT", "LEFT", "LEFT"); + $table->head = array ($strname, $strgrades); + $table->align = array ("LEFT", "LEFT"); + $table->width = array ("*", 10); } foreach ($quizzes as $quiz) { diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index 09c304bdb1..3489c5bd1e 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -16,9 +16,9 @@ $QUIZ_GRADE_METHOD = array ( GRADEHIGHEST => get_string("gradehighest", "quiz"), define("SHORTANSWER", "1"); define("TRUEFALSE", "2"); define("MULTICHOICE", "3"); -$QUIZ_QUESTION_TYPE = array ( SHORTANSWER => get_string("shortanswer", "quiz"), +$QUIZ_QUESTION_TYPE = array ( MULTICHOICE => get_string("multichoice", "quiz"), TRUEFALSE => get_string("truefalse", "quiz"), - MULTICHOICE => get_string("multichoice", "quiz")); + SHORTANSWER => get_string("shortanswer", "quiz") ); @@ -39,11 +39,14 @@ function quiz_add_instance($quiz) { // The grades for every question in this quiz are stored in an array if ($quiz->grades) { foreach ($quiz->grades as $question => $grade) { - $questiongrade->quiz = $quiz->id; - $questiongrade->question = $question; - $questiongrade->grade = $grade; - if (!insert_record("quiz_question_grades", $questiongrade)) { - return false; + if ($question and $grade) { + unset($questiongrade); + $questiongrade->quiz = $quiz->id; + $questiongrade->question = $question; + $questiongrade->grade = $grade; + if (!insert_record("quiz_question_grades", $questiongrade)) { + return false; + } } } } @@ -72,20 +75,23 @@ function quiz_update_instance($quiz) { if ($quiz->grades) { foreach ($quiz->grades as $question => $grade) { - $questiongrade->quiz = $quiz->id; - $questiongrade->question = $question; - $questiongrade->grade = $grade; - if (isset($existing[$question])) { - if ($existing[$question]->grade != $grade) { - $questiongrade->id = $existing[$question]->id; - if (!update_record("quiz_question_grades", $questiongrade)) { + if ($question and $grade) { + unset($questiongrade); + $questiongrade->quiz = $quiz->id; + $questiongrade->question = $question; + $questiongrade->grade = $grade; + if (isset($existing[$question])) { + if ($existing[$question]->grade != $grade) { + $questiongrade->id = $existing[$question]->id; + if (!update_record("quiz_question_grades", $questiongrade)) { + return false; + } + } + } else { + if (!insert_record("quiz_question_grades", $questiongrade)) { return false; } } - } else { - if (!insert_record("quiz_question_grades", $questiongrade)) { - return false; - } } } } @@ -328,6 +334,13 @@ function quiz_print_category_form($course, $current) { } $categories[$category->id] = $category->name; } + foreach ($categories as $key => $category) { + if ($category->publish) { + if ($course = get_record_sql("course", "id", $category->course)) { + $categories[$key]->name .= " ($course->shortname)"; + } + } + } $strcategory = get_string("category", "quiz"); $strshow = get_string("show", "quiz"); $stredit = get_string("edit"); @@ -423,7 +436,7 @@ function quiz_print_question_list($questionlist, $grades) { echo ""; echo "".$questions[$qnum]->name.""; echo ""; - choose_from_menu($gradesmenu, "q$qnum", $grades[$qnum], ""); + choose_from_menu($gradesmenu, "q$qnum", (string)$grades[$qnum], ""); echo ""; echo " "; @@ -435,7 +448,7 @@ function quiz_print_question_list($questionlist, $grades) { } echo ""; echo ""; - echo ""; + echo ""; echo "cellcontent\">"; echo "$sumgrade"; echo ""; @@ -473,6 +486,7 @@ function quiz_print_cat_question_list($categoryid) { return; } echo "

$strcategory: $category->name

\n"; + echo "
"; echo text_to_html($category->info); echo "
"; @@ -481,6 +495,7 @@ function quiz_print_cat_question_list($categoryid) { echo "id\">"; echo ""; echo "
"; + echo "
"; if (!$questions = get_records("quiz_questions", "category", $category->id)) { echo "

"; @@ -528,6 +543,23 @@ function quiz_get_user_attempts($quizid, $userid) { return get_records_sql("SELECT * FROM quiz_attempts WHERE quiz = '$quizid' and user = '$userid' ORDER by attempt ASC"); } + +function quiz_get_user_attempts_string($quiz, $attempts, $bestgrade) { +/// Returns a simple little comma-separated list of all attempts, +/// with the best grade bolded + + $bestgrade = format_float($bestgrade); + foreach ($attempts as $attempt) { + $attemptgrade = format_float(($attempt->sumgrades / $quiz->sumgrades) * $quiz->grade); + if ($attemptgrade == $bestgrade) { + $userattempts[] = "$attemptgrade"; + } else { + $userattempts[] = "$attemptgrade"; + } + } + return implode(",", $userattempts); +} + function quiz_get_best_grade($quizid, $userid) { /// Get the best current grade for a particular user in a quiz if (!$grade = get_record_sql("SELECT * FROM quiz_grades WHERE quiz = '$quizid' and user = '$userid'")) { @@ -702,9 +734,6 @@ function quiz_grade_attempt_results($quiz, $questions) { $result->sumgrades = 0; - global $db; - $db->debug=true; - foreach ($questions as $question) { if (!$answers = quiz_get_answers($question)) { error("No answers defined for question id $question->id!"); @@ -777,8 +806,9 @@ function quiz_grade_attempt_results($quiz, $questions) { $result->feedback[$question->id] = $feedback; } - $result->percentage = ($result->sumgrades / $quiz->sumgrades); - $result->grade = $result->percentage * $quiz->grade; + $fraction = (float)($result->sumgrades / $quiz->sumgrades); + $result->percentage = format_float($fraction * 100.0); + $result->grade = format_float($fraction * $quiz->grade); return $result; } diff --git a/mod/quiz/multichoice.html b/mod/quiz/multichoice.html index f0ff1885fa..e727ff0bcb 100644 --- a/mod/quiz/multichoice.html +++ b/mod/quiz/multichoice.html @@ -49,7 +49,7 @@

1:

   - fraction, ""); ?>
@@ -70,7 +70,7 @@

2:

   - fraction, ""); ?>
@@ -91,7 +91,7 @@

3:

   - fraction, ""); ?>
@@ -112,7 +112,7 @@

4:

   - fraction, ""); ?>
@@ -133,7 +133,7 @@

5:

   - fraction, ""); ?>
@@ -154,7 +154,7 @@

6:

   - fraction, ""); ?>
diff --git a/mod/quiz/report.php b/mod/quiz/report.php index bd9b878f4b..e7116106eb 100644 --- a/mod/quiz/report.php +++ b/mod/quiz/report.php @@ -52,7 +52,7 @@ $strreport = get_string("report", "quiz"); $strname = get_string("name"); $strattempts = get_string("attempts", "quiz"); - $strgrade = get_string("grade", "quiz"); + $strgrade = get_string("grade"); print_header("$course->shortname: $quiz->name", "$course->fullname", "$navigation id>$strquizzes @@ -74,10 +74,7 @@ $picture = print_user_picture($grade->user, $course->id, $grade->picture, false, true); if ($attempts = quiz_get_user_attempts($quiz->id, $grade->user)) { - foreach ($attempts as $attempt) { - $userattempts[] = ($attempt->sumgrades / $quiz->sumgrades) * $quiz->grade; - } - $userattempts = implode(",", $userattempts); + $userattempts = quiz_get_user_attempts_string($quiz, $attempts, $grade->grade); } $table->data[] = array ($picture, diff --git a/mod/quiz/shortanswer.html b/mod/quiz/shortanswer.html index 8b93a20a38..703921ccc2 100644 --- a/mod/quiz/shortanswer.html +++ b/mod/quiz/shortanswer.html @@ -48,7 +48,7 @@

1:

   - fraction,""); ?>
@@ -69,7 +69,7 @@

2:

   - fraction,""); ?>
@@ -90,7 +90,7 @@

3:

   - fraction,""); ?>
@@ -111,7 +111,7 @@

4:

   - fraction,""); ?>
@@ -132,7 +132,7 @@

5:

   - fraction,""); ?>
diff --git a/mod/quiz/view.php b/mod/quiz/view.php index c7e0c2b0f3..dfdb4d95ce 100644 --- a/mod/quiz/view.php +++ b/mod/quiz/view.php @@ -92,34 +92,45 @@ if ($quiz->attempts > 1) { echo "

".get_string("attemptsallowed", "quiz").": $quiz->attempts

"; echo "

".get_string("grademethod", "quiz").": ".$QUIZ_GRADE_METHOD[$quiz->grademethod]."

"; + } else { + echo "
"; } + + $strattempt = get_string("attempt", "quiz"); + $strtime = get_string("time", "quiz"); + $strgrade = get_string("grade"); + if ($numattempts) { - $table->head = array("Attempt", "Time", "Grade"); + $table->head = array($strattempt, $strtime, "$strgrade / $quiz->grade"); $table->align = array("CENTER", "LEFT", "RIGHT"); foreach ($attempts as $attempt) { $table->data[] = array( $attempt->attempt, userdate($attempt->timemodified), - ($attempt->sumgrades/$quiz->sumgrades)*$quiz->grade ); + format_float(($attempt->sumgrades/$quiz->sumgrades)*$quiz->grade) ); } print_table($table); } $mygrade = quiz_get_best_grade($quiz->id, $USER->id); - if ($numattempts < $quiz->attempts or !$quiz->attempts) { - if ($available) { - $options["id"] = $cm->id; - if ($numattempts) { - print_heading("Your best grade so far is $mygrade / $quiz->grade."); + if (!$quiz->questions) { + print_heading(get_string("noquestions", "quiz")); + } else { + if ($numattempts < $quiz->attempts or !$quiz->attempts) { + if ($available) { + $options["id"] = $cm->id; + if ($numattempts) { + print_heading("Your best grade so far is $mygrade / $quiz->grade."); + } + echo "
"; + echo "
"; + print_single_button("attempt.php", $options, $label="Attempt quiz now"); + echo "

"; } - echo "
"; - echo "
"; - print_single_button("attempt.php", $options, $label="Attempt quiz now"); - echo "

"; + } else { + print_heading(get_string("nomoreattempts", "quiz")); + print_heading(get_string("yourfinalgradeis", "quiz", "$mygrade / $quiz->grade")); } - } else { - print_heading(get_string("nomoreattempts", "quiz")); - print_heading(get_string("yourfinalgradeis", "quiz", "$mygrade / $quiz->grade")); } -- 2.39.5