Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed bug reported at http://moodle.org/mod/forum/discuss.php?d=23526

  • Loading branch information...
commit c4aff6543c575ff38931652ff64bd14341184bf7 1 parent 30e99c8
authored May 10, 2005
12  mod/quiz/editlib.php
@@ -486,6 +486,14 @@ function quiz_print_cat_question_list($course, $categoryid, $quizselected=true,
486 486
 
487 487
     // hide-feature
488 488
     $showhidden = $showhidden ? '' : " AND hidden = '0'";
  489
+
  490
+    if (!$totalnumber = count_records_select('quiz_questions', "category IN ($categorylist) AND parent = '0' $showhidden")) {
  491
+        echo "<p align=\"center\">";
  492
+        print_string("noquestions", "quiz");
  493
+        echo "</p>";
  494
+        return;
  495
+    }
  496
+
489 497
     if (!$questions = get_records_select('quiz_questions', "category IN ($categorylist) AND parent = '0' $showhidden", 'qtype, name ASC', '*', $page*$perpage, $perpage)) {
490 498
         echo "<p align=\"center\">";
491 499
         print_string("noquestions", "quiz");
@@ -557,9 +565,7 @@ function quiz_print_cat_question_list($course, $categoryid, $quizselected=true,
557 565
     quiz_category_select_menu($course->id, false, true, $category->id);
558 566
     echo "</td></tr></table>";
559 567
 
560  
-    $numquestions = count($questions);
561  
-
562  
-    print_paging_bar($numquestions, $page, $perpage,
  568
+    print_paging_bar($totalnumber, $page, $perpage,
563 569
                 "edit.php?perpage=$perpage&amp;");
564 570
 
565 571
     if ($quizselected) {
6  mod/quiz/locallib.php
@@ -1420,8 +1420,12 @@ function quiz_extract_responses($questions, $responses, $defaultevent) {
1420 1420
 */
1421 1421
 function quiz_regrade_question_in_quizzes($question, $quizlist) {
1422 1422
 
  1423
+	if (empty($quizlist)) {
  1424
+		return;
  1425
+	}
  1426
+
1423 1427
     $quizlist = implode(',', $quizlist);
1424  
-    if (empty($quizlist)) { // assume that all quizzes are affected
  1428
+    if ($quizlist == 'all') { // assume that all quizzes are affected
1425 1429
         if (! $instances = get_records('quiz_question_instances',
1426 1430
          'question', $question->id)) {
1427 1431
             // No instances were found, so it successfully regraded all of them
68  mod/quiz/question.php
@@ -207,48 +207,48 @@
207 207
                 }
208 208
 
209 209
                 /// now update the question references in the quizzes
210  
-                if (empty($replaceinquiz) || !$quizzes = get_records_list("quiz", "id", implode(',', $replaceinquiz))) {
211  
-                    $quizzes = array();
212  
-                }
213  
-
214  
-                foreach($quizzes as $quiz) {
215  
-                    $questionlist = ",$quiz->questions,"; // a little hack with the commas here. not nice but effective
216  
-                    $questionlist = str_replace(",$oldquestionid,", ",$question->id,", $questionlist);
217  
-                    $questionlist = substr($questionlist, 1, -1); // and get rid of the surrounding commas again
218  
-                    if (!set_field("quiz", 'questions', $questionlist, 'id', $quiz->id)) {
219  
-                        error("Could not update questionlist in quiz $quiz->id!");
220  
-                    }
221  
-
222  
-                    // the quiz_question_instances table needs to be updated too (aah, the joys of duplication :)
223  
-                    if (!set_field('quiz_question_instances', 'question', $question->id, 'quiz', $quiz->id, 'question', $oldquestionid)) {
224  
-                        error("Could not update question instance!");
225  
-                    }
226  
-                    if (isset($SESSION->modform) && (int)$SESSION->modform->instance === (int)$quiz->id) {
227  
-                        $SESSION->modform->questions = $questionlist;
228  
-                        $SESSION->modform->grades[$question->id] = $SESSION->modform->grades[$oldquestionid];
229  
-                        unset($SESSION->modform->grades[$oldquestionid]);
230  
-                    }
231  
-                }
232  
-
233  
-                // set originalquestion in states
234  
-                if ($attempts = get_records_list('quiz_attempts', 'quiz', implode(',', $replaceinquiz))) {
235  
-                    foreach ($attempts as $attempt) {
236  
-                        set_field('quiz_states', 'originalquestion', $oldquestionid, 'attempt', $attempt->id, 'question', $question->id, 'originalquestion', '0');
237  
-                    }
238  
-                }
  210
+                if (!empty($replaceinquiz) and $quizzes = get_records_list("quiz", "id", implode(',', $replaceinquiz))) {
  211
+
  212
+					foreach($quizzes as $quiz) {
  213
+						$questionlist = ",$quiz->questions,"; // a little hack with the commas here. not nice but effective
  214
+						$questionlist = str_replace(",$oldquestionid,", ",$question->id,", $questionlist);
  215
+						$questionlist = substr($questionlist, 1, -1); // and get rid of the surrounding commas again
  216
+						if (!set_field("quiz", 'questions', $questionlist, 'id', $quiz->id)) {
  217
+						error("Could not update questionlist in quiz $quiz->id!");
  218
+						}
  219
+			
  220
+						// the quiz_question_instances table needs to be updated too (aah, the joys of duplication :)
  221
+						if (!set_field('quiz_question_instances', 'question', $question->id, 'quiz', $quiz->id, 'question', $oldquestionid)) {
  222
+						error("Could not update question instance!");
  223
+						}
  224
+						if (isset($SESSION->modform) && (int)$SESSION->modform->instance === (int)$quiz->id) {
  225
+						$SESSION->modform->questions = $questionlist;
  226
+						$SESSION->modform->grades[$question->id] = $SESSION->modform->grades[$oldquestionid];
  227
+						unset($SESSION->modform->grades[$oldquestionid]);
  228
+						}
  229
+					}
  230
+			
  231
+					// set originalquestion in states
  232
+					if ($attempts = get_records_list('quiz_attempts', 'quiz', implode(',', $replaceinquiz))) {
  233
+						foreach ($attempts as $attempt) {
  234
+						set_field('quiz_states', 'originalquestion', $oldquestionid, 'attempt', $attempt->id, 'question', $question->id, 'originalquestion', '0');
  235
+						}
  236
+					}
  237
+				}
239 238
             }
240 239
         } else {
241 240
             // use the old code which simply overwrites old versions
242 241
             // it is also used for creating new questions
243 242
             $question = $QUIZ_QTYPES[$qtype]->save_question($question, $form, $course);
244  
-            $quizlist = array();
  243
+			$replaceinquiz = 'all';
245 244
         }
246 245
 
247  
-        if (empty($question->errors) &&
248  
-         $QUIZ_QTYPES[$qtype]->finished_edit_wizard($form)) {
249  
-            $QUIZ_QTYPES[$question->qtype]->get_question_options($question);
  246
+        if (empty($question->errors) && $QUIZ_QTYPES[$qtype]->finished_edit_wizard($form)) {
250 247
             // Automagically regrade all attempts (and states) in the affected quizzes
251  
-            quiz_regrade_question_in_quizzes($question, $quizlist);
  248
+			if (!empty($replaceinquiz)) {
  249
+                $QUIZ_QTYPES[$question->qtype]->get_question_options($question);
  250
+                quiz_regrade_question_in_quizzes($question, $replaceinquiz);
  251
+			}
252 252
             redirect("edit.php");
253 253
         }
254 254
     }

0 notes on commit c4aff65

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