From cc3b8c75de3917c947a57a8b4830b2769a99dbed Mon Sep 17 00:00:00 2001 From: moodler Date: Wed, 23 Oct 2002 12:10:38 +0000 Subject: [PATCH] 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. --- lang/en/quiz.php | 6 ++++++ mod/forum/lib.php | 5 +++-- mod/quiz/lib.php | 13 +++++++++---- mod/quiz/question.php | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 6 deletions(-) diff --git a/lang/en/quiz.php b/lang/en/quiz.php index 453a363adb..1407f01358 100644 --- a/lang/en/quiz.php +++ b/lang/en/quiz.php @@ -47,6 +47,12 @@ $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['fractionsaddwrong'] = "The positive grades you have chosen do not add up to 100%% +
Instead, they add up to \$a%% +
Do you want to go back and fix this question?"; +$string['fractionsnomax'] = "One of the answers should be 100%%, so that it is +
possible to get a full grade for this question. +
Do you want to go back and fix this question?"; $string['gradeaverage'] = "Average grade"; $string['gradehighest'] = "Highest grade"; $string['grademethod'] = "Grading method"; diff --git a/mod/forum/lib.php b/mod/forum/lib.php index cda277c48c..f75f142702 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -569,7 +569,7 @@ function forum_print_post(&$post, $courseid, $ownpost=false, $reply=false, $link echo ""; } - 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); diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index dd61b9adb3..e788b2029f 100644 --- a/mod/quiz/lib.php +++ b/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 "id\" TITLE=\"".$QUIZ_QUESTION_TYPE[$question->type]."\">"; switch ($question->type) { case SHORTANSWER: - echo ""; + echo ""; break; case TRUEFALSE: - echo ""; + echo ""; break; case MULTICHOICE: - echo ""; + echo ""; break; case RANDOM: - echo ""; + echo ""; break; } + echo "\n"; } function quiz_print_question($number, $questionid, $grade, $courseid, diff --git a/mod/quiz/question.php b/mod/quiz/question.php index 1533c84cf2..14b594e56b 100644 --- a/mod/quiz/question.php +++ b/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 "

Not supported yet

"; -- 2.39.5