diff --git a/lib/conditionlib.php b/lib/conditionlib.php index f253c4366a8..3fc62e73f46 100644 --- a/lib/conditionlib.php +++ b/lib/conditionlib.php @@ -1228,6 +1228,24 @@ abstract class condition_info_base { } } + /** + * Called by grade code to inform the completion system when a grade has + * been changed. Grades can be used to determine condition for + * the course-module or section. + * + * Note that this function may be called twice for one changed grade object. + * + * @param grade_grade $grade + * @param bool $deleted + */ + public static function inform_grade_changed($grade, $deleted) { + global $USER, $SESSION; + // In case of self-grading we can purge cache immediately. + if ($USER->id == $grade->userid) { + unset($SESSION->gradescorecache[$grade->itemid]); + } + } + /** * Returns true if a field meets the required conditions, false otherwise. * diff --git a/lib/grade/grade_grade.php b/lib/grade/grade_grade.php index a51586be56b..79ed71cbbfd 100644 --- a/lib/grade/grade_grade.php +++ b/lib/grade/grade_grade.php @@ -772,12 +772,7 @@ class grade_grade extends grade_object { * @param bool $deleted True if grade was actually deleted */ function notify_changed($deleted) { - global $USER, $SESSION, $CFG,$COURSE, $DB; - - // Grades may be cached in user session - if ($USER->id == $this->userid) { - unset($SESSION->gradescorecache[$this->itemid]); - } + global $CFG,$COURSE, $DB; // Ignore during restore // TODO There should be a proper way to determine when we are in restore @@ -787,6 +782,12 @@ class grade_grade extends grade_object { return; } + // Inform conditionlib since it may cache the grades for conditional availability of modules or sections. + if (!empty($CFG->enableavailability)) { + require_once($CFG->libdir.'/conditionlib.php'); + condition_info_base::inform_grade_changed($this, $deleted); + } + require_once($CFG->libdir.'/completionlib.php'); // Bail out immediately if completion is not enabled for site (saves loading