Permalink
Browse files

After saving new question, sanity checks are made to make sure the

fractional grades are correct.

Icons now have tooltips and are also a shortcut to editing page.
  • Loading branch information...
1 parent cbb8979 commit cc3b8c75de3917c947a57a8b4830b2769a99dbed moodler committed Oct 23, 2002
Showing with 57 additions and 6 deletions.
  1. +6 −0 lang/en/quiz.php
  2. +3 −2 mod/forum/lib.php
  3. +9 −4 mod/quiz/lib.php
  4. +39 −0 mod/quiz/question.php
View
6 lang/en/quiz.php
@@ -47,6 +47,12 @@
$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['fractionsaddwrong'] = "The positive grades you have chosen do not add up to 100%%
+<BR>Instead, they add up to \$a%%
+<BR>Do you want to go back and fix this question?";
+$string['fractionsnomax'] = "One of the answers should be 100%%, so that it is
+<BR>possible to get a full grade for this question.
+<BR>Do you want to go back and fix this question?";
$string['gradeaverage'] = "Average grade";
$string['gradehighest'] = "Highest grade";
$string['grademethod'] = "Grading method";
View
5 mod/forum/lib.php
@@ -569,7 +569,7 @@ function forum_print_post(&$post, $courseid, $ownpost=false, $reply=false, $link
echo "</DIV>";
}
- if ($link && (strlen($post->message) > $FORUM_LONG_POST)) {
+ if ($link && (strlen(strip_tags($post->message)) > $FORUM_LONG_POST)) {
// Print shortened version
echo format_text(forum_shorten_post($post->message), $post->format);
$numwords = count_words($post->message);
@@ -687,8 +687,9 @@ function forum_print_post_header(&$post, $courseid, $ownpost=false, $reply=false
function forum_shorten_post($message) {
global $FORUM_LONG_POST, $FORUM_SHORT_POST;
- if (strlen($message) > $FORUM_LONG_POST) {
+ if (strlen(strip_tags($message)) > $FORUM_LONG_POST) {
// Look for the first return between $FORUM_SHORT_POST and $FORUM_LONG_POST
+ // XXXX
$shortmessage = substr($message, $FORUM_SHORT_POST, $FORUM_LONG_POST);
if ($pos = strpos($shortmessage, "\n")) {
return substr($message, 0, $FORUM_SHORT_POST + $pos);
View
13 mod/quiz/lib.php
@@ -222,20 +222,25 @@ function quiz_print_correctanswer($text) {
function quiz_print_question_icon($question) {
// Prints a question icon
+
+ global $QUIZ_QUESTION_TYPE;
+
+ echo "<A HREF=\"question.php?id=$question->id\" TITLE=\"".$QUIZ_QUESTION_TYPE[$question->type]."\">";
switch ($question->type) {
case SHORTANSWER:
- echo "<IMG HEIGHT=16 WIDTH=16 SRC=\"pix/sa.gif\">";
+ echo "<IMG BORDER=0 HEIGHT=16 WIDTH=16 SRC=\"pix/sa.gif\">";
break;
case TRUEFALSE:
- echo "<IMG HEIGHT=16 WIDTH=16 SRC=\"pix/tf.gif\">";
+ echo "<IMG BORDER=0 HEIGHT=16 WIDTH=16 SRC=\"pix/tf.gif\">";
break;
case MULTICHOICE:
- echo "<IMG HEIGHT=16 WIDTH=16 SRC=\"pix/mc.gif\">";
+ echo "<IMG BORDER=0 HEIGHT=16 WIDTH=16 SRC=\"pix/mc.gif\">";
break;
case RANDOM:
- echo "<IMG HEIGHT=16 WIDTH=16 SRC=\"pix/rs.gif\">";
+ echo "<IMG BORDER=0 HEIGHT=16 WIDTH=16 SRC=\"pix/rs.gif\">";
break;
}
+ echo "</A>\n";
}
function quiz_print_question($number, $questionid, $grade, $courseid,
View
39 mod/quiz/question.php
@@ -123,6 +123,7 @@
delete_records("quiz_shortanswer", "question", $question->id);
$answers = array();
+ $maxfraction = -1;
// Insert all the new answers
foreach ($form->answer as $key => $formanswer) {
@@ -136,6 +137,9 @@
error("Could not insert quiz answer!");
}
$answers[] = $answer->id;
+ if ($fraction[$key] > $maxfraction) {
+ $maxfraction = $fraction[$key];
+ }
}
}
@@ -146,6 +150,14 @@
if (!insert_record("quiz_shortanswer", $options)) {
error("Could not insert quiz shortanswer options!");
}
+
+ /// Perform sanity checks on fractional grades
+ if ($maxfraction != 1) {
+ $maxfraction = $maxfraction * 100;
+ notice_yesno(get_string("fractionsnomax", "quiz", $maxfraction), "question.php?id=$question->id", "edit.php");
+ print_footer($course);
+ exit;
+ }
break;
case TRUEFALSE:
delete_records("quiz_answers", "question", $question->id);
@@ -179,6 +191,9 @@
delete_records("quiz_answers", "question", $question->id);
delete_records("quiz_multichoice", "question", $question->id);
+ $totalfraction = 0;
+ $maxfraction = -1;
+
$answers = array();
// Insert all the new answers
@@ -193,6 +208,13 @@
error("Could not insert quiz answer!");
}
$answers[] = $answer->id;
+
+ if ($fraction[$key] > 0) { // Sanity checks
+ $totalfraction += $fraction[$key];
+ }
+ if ($fraction[$key] > $maxfraction) {
+ $maxfraction = $fraction[$key];
+ }
}
}
@@ -203,6 +225,23 @@
if (!insert_record("quiz_multichoice", $options)) {
error("Could not insert quiz multichoice options!");
}
+
+ /// Perform sanity checks on fractional grades
+ if ($options->single) {
+ if ($maxfraction != 1) {
+ $maxfraction = $maxfraction * 100;
+ notice_yesno(get_string("fractionsnomax", "quiz", $maxfraction), "question.php?id=$question->id", "edit.php");
+ print_footer($course);
+ exit;
+ }
+ } else {
+ if ($totalfraction != 1) {
+ $totalfraction = $totalfraction * 100;
+ notice_yesno(get_string("fractionsaddwrong", "quiz", $totalfraction), "question.php?id=$question->id", "edit.php");
+ print_footer($course);
+ exit;
+ }
+ }
break;
case RANDOM:
echo "<P>Not supported yet</P>";

0 comments on commit cc3b8c7

Please sign in to comment.