Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit cc3b8c75de3917c947a57a8b4830b2769a99dbed 1 parent cbb8979
moodler authored
6 lang/en/quiz.php
@@ -47,6 +47,12 @@
47 47 $string['feedback'] = "Feedback";
48 48 $string['filloutoneanswer'] = "You must fill out at least one possible answer. Answers left blank will not be used.";
49 49 $string['fillouttwochoices'] = "You must fill out at least two choices. Choices left blank will not be used.";
  50 +$string['fractionsaddwrong'] = "The positive grades you have chosen do not add up to 100%%
  51 +<BR>Instead, they add up to \$a%%
  52 +<BR>Do you want to go back and fix this question?";
  53 +$string['fractionsnomax'] = "One of the answers should be 100%%, so that it is
  54 +<BR>possible to get a full grade for this question.
  55 +<BR>Do you want to go back and fix this question?";
50 56 $string['gradeaverage'] = "Average grade";
51 57 $string['gradehighest'] = "Highest grade";
52 58 $string['grademethod'] = "Grading method";
5 mod/forum/lib.php
@@ -569,7 +569,7 @@ function forum_print_post(&$post, $courseid, $ownpost=false, $reply=false, $link
569 569 echo "</DIV>";
570 570 }
571 571
572   - if ($link && (strlen($post->message) > $FORUM_LONG_POST)) {
  572 + if ($link && (strlen(strip_tags($post->message)) > $FORUM_LONG_POST)) {
573 573 // Print shortened version
574 574 echo format_text(forum_shorten_post($post->message), $post->format);
575 575 $numwords = count_words($post->message);
@@ -687,8 +687,9 @@ function forum_print_post_header(&$post, $courseid, $ownpost=false, $reply=false
687 687 function forum_shorten_post($message) {
688 688 global $FORUM_LONG_POST, $FORUM_SHORT_POST;
689 689
690   - if (strlen($message) > $FORUM_LONG_POST) {
  690 + if (strlen(strip_tags($message)) > $FORUM_LONG_POST) {
691 691 // Look for the first return between $FORUM_SHORT_POST and $FORUM_LONG_POST
  692 + // XXXX
692 693 $shortmessage = substr($message, $FORUM_SHORT_POST, $FORUM_LONG_POST);
693 694 if ($pos = strpos($shortmessage, "\n")) {
694 695 return substr($message, 0, $FORUM_SHORT_POST + $pos);
13 mod/quiz/lib.php
@@ -222,20 +222,25 @@ function quiz_print_correctanswer($text) {
222 222
223 223 function quiz_print_question_icon($question) {
224 224 // Prints a question icon
  225 +
  226 + global $QUIZ_QUESTION_TYPE;
  227 +
  228 + echo "<A HREF=\"question.php?id=$question->id\" TITLE=\"".$QUIZ_QUESTION_TYPE[$question->type]."\">";
225 229 switch ($question->type) {
226 230 case SHORTANSWER:
227   - echo "<IMG HEIGHT=16 WIDTH=16 SRC=\"pix/sa.gif\">";
  231 + echo "<IMG BORDER=0 HEIGHT=16 WIDTH=16 SRC=\"pix/sa.gif\">";
228 232 break;
229 233 case TRUEFALSE:
230   - echo "<IMG HEIGHT=16 WIDTH=16 SRC=\"pix/tf.gif\">";
  234 + echo "<IMG BORDER=0 HEIGHT=16 WIDTH=16 SRC=\"pix/tf.gif\">";
231 235 break;
232 236 case MULTICHOICE:
233   - echo "<IMG HEIGHT=16 WIDTH=16 SRC=\"pix/mc.gif\">";
  237 + echo "<IMG BORDER=0 HEIGHT=16 WIDTH=16 SRC=\"pix/mc.gif\">";
234 238 break;
235 239 case RANDOM:
236   - echo "<IMG HEIGHT=16 WIDTH=16 SRC=\"pix/rs.gif\">";
  240 + echo "<IMG BORDER=0 HEIGHT=16 WIDTH=16 SRC=\"pix/rs.gif\">";
237 241 break;
238 242 }
  243 + echo "</A>\n";
239 244 }
240 245
241 246 function quiz_print_question($number, $questionid, $grade, $courseid,
39 mod/quiz/question.php
@@ -123,6 +123,7 @@
123 123 delete_records("quiz_shortanswer", "question", $question->id);
124 124
125 125 $answers = array();
  126 + $maxfraction = -1;
126 127
127 128 // Insert all the new answers
128 129 foreach ($form->answer as $key => $formanswer) {
@@ -136,6 +137,9 @@
136 137 error("Could not insert quiz answer!");
137 138 }
138 139 $answers[] = $answer->id;
  140 + if ($fraction[$key] > $maxfraction) {
  141 + $maxfraction = $fraction[$key];
  142 + }
139 143 }
140 144 }
141 145
@@ -146,6 +150,14 @@
146 150 if (!insert_record("quiz_shortanswer", $options)) {
147 151 error("Could not insert quiz shortanswer options!");
148 152 }
  153 +
  154 + /// Perform sanity checks on fractional grades
  155 + if ($maxfraction != 1) {
  156 + $maxfraction = $maxfraction * 100;
  157 + notice_yesno(get_string("fractionsnomax", "quiz", $maxfraction), "question.php?id=$question->id", "edit.php");
  158 + print_footer($course);
  159 + exit;
  160 + }
149 161 break;
150 162 case TRUEFALSE:
151 163 delete_records("quiz_answers", "question", $question->id);
@@ -179,6 +191,9 @@
179 191 delete_records("quiz_answers", "question", $question->id);
180 192 delete_records("quiz_multichoice", "question", $question->id);
181 193
  194 + $totalfraction = 0;
  195 + $maxfraction = -1;
  196 +
182 197 $answers = array();
183 198
184 199 // Insert all the new answers
@@ -193,6 +208,13 @@
193 208 error("Could not insert quiz answer!");
194 209 }
195 210 $answers[] = $answer->id;
  211 +
  212 + if ($fraction[$key] > 0) { // Sanity checks
  213 + $totalfraction += $fraction[$key];
  214 + }
  215 + if ($fraction[$key] > $maxfraction) {
  216 + $maxfraction = $fraction[$key];
  217 + }
196 218 }
197 219 }
198 220
@@ -203,6 +225,23 @@
203 225 if (!insert_record("quiz_multichoice", $options)) {
204 226 error("Could not insert quiz multichoice options!");
205 227 }
  228 +
  229 + /// Perform sanity checks on fractional grades
  230 + if ($options->single) {
  231 + if ($maxfraction != 1) {
  232 + $maxfraction = $maxfraction * 100;
  233 + notice_yesno(get_string("fractionsnomax", "quiz", $maxfraction), "question.php?id=$question->id", "edit.php");
  234 + print_footer($course);
  235 + exit;
  236 + }
  237 + } else {
  238 + if ($totalfraction != 1) {
  239 + $totalfraction = $totalfraction * 100;
  240 + notice_yesno(get_string("fractionsaddwrong", "quiz", $totalfraction), "question.php?id=$question->id", "edit.php");
  241 + print_footer($course);
  242 + exit;
  243 + }
  244 + }
206 245 break;
207 246 case RANDOM:
208 247 echo "<P>Not supported yet</P>";

0 comments on commit cc3b8c7

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