Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-12933

Bug in mod/quiz/lib.php break MyMoodle

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 1.9
    • 1.9
    • Quiz
    • None
    • php 4.x, pgsql 8.1
    • MOODLE_19_STABLE
    • MOODLE_19_STABLE

    Description

      These are the things that I have had to do to reproduce the bug:
      Have a quiz that has a date range and is currently open.
      At least one student has to have made an attempt.
      Login as course instructor and view /my/

      You will get a 'Incorrect course id in cm' error.

      What is happening:
      In quiz_print_overview (mod/quiz/lib.php), it iterates through each quiz. If you have the 'mod/quiz:viewreports' capability, then it attempts to print the number of attempts by calling quiz_num_attempt_summary($quiz, $cm, $returnzero = false, $currentgroup = 0) (also in mod/quiz/lib.php).

      In the comments just above this call it notes that 'The $quiz objects returned by get_all_instances_in_course have the necessary $cm fields set to make the following call work.', which appears to be true. But, it passes ($quiz, true). quiz_num_attempt_summary does not check for $cm being 'true' (or 1), it assumes it is going to be a coursemodule object and passes it to groups_get_activity_groupmode, which also assumes it is going to be a cm object, and then throws the error because it is not an object.

      My proposed fix is to change line 1065 in mod/quiz/lib.php from:

      $str .= '<div class="info">' . quiz_num_attempt_summary($quiz, true) . '</div>';

      to:

      $str .= '<div class="info">' . quiz_num_attempt_summary($quiz, $quiz) . '</div>';

      The other option is to add something like this to quiz_num_attempt_summary():
      if ($cm == 1) {
      $cm = $quiz;
      }

      -eric

      Attachments

        Activity

          People

            timhunt Tim Hunt
            emerrill Eric Merrill
            Tim Hunt, Andrew Lyons, Huong Nguyen, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              3/Mar/08