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

Lesson module does not calculate grade correctly when retakes not allowed

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.5.4
    • Fix Version/s: 1.7.1
    • Component/s: Lesson
    • Labels:
      None
    • Affected Branches:
      MOODLE_15_STABLE
    • Fixed Branches:
      MOODLE_17_STABLE

      Description

      When a lesson is set to not allow retakes it should calculate grades from the first attempt and not as the max or mean.

        Gliffy Diagrams

          Activity

          Hide
          jgraham Jeff Graham added a comment -

          Diff snippet from 1.5.4 to a heavily hacked version of mod/lesson/lib.php
          <pre>
          @@ -381,16 +420,28 @@
          if (!$lesson = get_record("lesson", "id", $lessonid))

          { return NULL; }
          • if ($lesson->usemaxgrade) {
          • $grades = get_records_sql_menu("SELECT userid,MAX(grade) FROM {$CFG->prefix}lesson_grades WHERE
            +
            + if ($lesson->retake) {
            + if ($lesson->usemaxgrade) {
            + $grades = get_records_sql_menu("SELECT userid,MAX(grade) FROM {$CFG->prefix}lesson_grades WHERE
            + lessonid = $lessonid GROUP BY userid");
            + } else {
            + $grades = get_records_sql_menu("SELECT userid,AVG(grade) FROM {$CFG->prefix}lesson_grades WHERE
            lessonid = $lessonid GROUP BY userid");
          • } else {
          • $grades = get_records_sql_menu("SELECT userid,AVG(grade) FROM {$CFG->prefix}lesson_grades WHERE
          • lessonid = $lessonid GROUP BY userid");
            + }
            + }
            + else {
            + $first_grades = get_records_sql("SELECT userid, MIN(completed), grade FROM {$CFG->prefix}lesson_grades WHERE lessonid = $lessonid GROUP BY userid");
            + $grades = array();
            + if (!empty($first_grades))
            Unknown macro: {+ foreach($first_grades as $userid => $info) { + $grades[$userid] = $info->grade; + }+ }

            }

          // convert grades from percentages and tidy the numbers

          • if (!$lesson->practice) { // dont display practice lessons CDC-FLAG
            + if (!$lesson->practice) { // dont display practice lessons
            if ($grades) {
            foreach ($grades as $userid => $grade) {
            $return->grades[$userid] = number_format($grade * $lesson->grade / 100.0, 1);
            @@ -422,4 +473,13 @@

          </pre>

          Show
          jgraham Jeff Graham added a comment - Diff snippet from 1.5.4 to a heavily hacked version of mod/lesson/lib.php <pre> @@ -381,16 +420,28 @@ if (!$lesson = get_record("lesson", "id", $lessonid)) { return NULL; } if ($lesson->usemaxgrade) { $grades = get_records_sql_menu("SELECT userid,MAX(grade) FROM {$CFG->prefix}lesson_grades WHERE + + if ($lesson->retake) { + if ($lesson->usemaxgrade) { + $grades = get_records_sql_menu("SELECT userid,MAX(grade) FROM {$CFG->prefix}lesson_grades WHERE + lessonid = $lessonid GROUP BY userid"); + } else { + $grades = get_records_sql_menu("SELECT userid,AVG(grade) FROM {$CFG->prefix}lesson_grades WHERE lessonid = $lessonid GROUP BY userid"); } else { $grades = get_records_sql_menu("SELECT userid,AVG(grade) FROM {$CFG->prefix}lesson_grades WHERE lessonid = $lessonid GROUP BY userid"); + } + } + else { + $first_grades = get_records_sql("SELECT userid, MIN(completed), grade FROM {$CFG->prefix}lesson_grades WHERE lessonid = $lessonid GROUP BY userid"); + $grades = array(); + if (!empty($first_grades)) Unknown macro: {+ foreach($first_grades as $userid => $info) { + $grades[$userid] = $info->grade; + }+ } } // convert grades from percentages and tidy the numbers if (!$lesson->practice) { // dont display practice lessons CDC-FLAG + if (!$lesson->practice) { // dont display practice lessons if ($grades) { foreach ($grades as $userid => $grade) { $return->grades [$userid] = number_format($grade * $lesson->grade / 100.0, 1); @@ -422,4 +473,13 @@ </pre>
          Hide
          bushido Mark Nielsen added a comment -

          Fixed also in index.php so the grade matches the grade book for students. Fixed in MOODLE_17_STABLE and HEAD.

          Show
          bushido Mark Nielsen added a comment - Fixed also in index.php so the grade matches the grade book for students. Fixed in MOODLE_17_STABLE and HEAD.

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Fix Release Date:
                17/Jan/07