Moodle
  1. Moodle
  2. MDL-23577

grade_update_outcomes() never returns a value (+ fix)

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.9.9
    • Fix Version/s: 1.9.10
    • Component/s: Gradebook
    • Labels:
      None
    • Affected Branches:
      MOODLE_19_STABLE
    • Fixed Branches:
      MOODLE_19_STABLE

      Description

      This makes it very difficult to develop extensions that save outcomes to the gradebook as it is impossible to know if the save has occurred properly.

      here's a working version:

      function grade_update_outcomes($source, $courseid, $itemtype, $itemmodule, $iteminstance, $userid, $data) {
          if ($items = grade_item::fetch_all(array('itemtype'=>$itemtype, 'itemmodule'=>$itemmodule, 'iteminstance'=>$iteminstance, 'courseid'=>$courseid))) {
              $errors = false;
              foreach ($items as $item) {
                  if (!array_key_exists($item->itemnumber, $data)) {
                      continue;
                  }
                  $grade = $data[$item->itemnumber] < 1 ? null : $data[$item->itemnumber];
                  $errors = ($item->update_final_grade($userid, $grade, $source)) ? $errors : true;
              }
              return $errors;
          }
          return false;
      }

        Gliffy Diagrams

          Activity

          Hide
          Matt Gibson added a comment -

          line 320 of gradelib.php

          Show
          Matt Gibson added a comment - line 320 of gradelib.php
          Hide
          Matt Gibson added a comment -

          Oops, just got the logic backwards!

          Here's the fixed one:

          function grade_update_outcomes($source, $courseid, $itemtype, $itemmodule, $iteminstance, $userid, $data) {
              if ($items = grade_item::fetch_all(array('itemtype'=>$itemtype, 'itemmodule'=>$itemmodule, 'iteminstance'=>$iteminstance, 'courseid'=>$courseid))) {
                  $allok = true;
                  foreach ($items as $item) {
                      if (!array_key_exists($item->itemnumber, $data)) {
                          continue;
                      }
                      $grade = $data[$item->itemnumber] < 1 ? null : $data[$item->itemnumber];
                      $allok = ($item->update_final_grade($userid, $grade, $source)) ? $allok : false;
                  }
                  return $allok;
              }
              return false;
          }
          

          Show
          Matt Gibson added a comment - Oops, just got the logic backwards! Here's the fixed one: function grade_update_outcomes($source, $courseid, $itemtype, $itemmodule, $iteminstance, $userid, $data) { if ($items = grade_item::fetch_all(array('itemtype'=>$itemtype, 'itemmodule'=>$itemmodule, 'iteminstance'=>$iteminstance, 'courseid'=>$courseid))) { $allok = true; foreach ($items as $item) { if (!array_key_exists($item->itemnumber, $data)) { continue; } $grade = $data[$item->itemnumber] < 1 ? null : $data[$item->itemnumber]; $allok = ($item->update_final_grade($userid, $grade, $source)) ? $allok : false; } return $allok; } return false; }
          Hide
          Andrew Davis added a comment -

          I've committed a modified version of this to both the 1.9 and 2.0 branches. Thanks for the suggestion

          Show
          Andrew Davis added a comment - I've committed a modified version of this to both the 1.9 and 2.0 branches. Thanks for the suggestion
          Hide
          Matt Gibson added a comment -

          Cool, thanks!

          Show
          Matt Gibson added a comment - Cool, thanks!

            People

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

              Dates

              • Created:
                Updated:
                Resolved: