MDL-28463 grades: inform conditionlib that grades changed

This commit is contained in:
Marina Glancy
2013-10-29 11:33:21 +11:00
parent 68291f2d57
commit b85b9b7c29
2 changed files with 25 additions and 6 deletions
+18
View File
@@ -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.
*
+7 -6
View File
@@ -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