/** * Used to notify the completion system (if necessary) that a user's grade * has changed, and clear up a possible score cache. * * @param bool $deleted True if grade was actually deleted */ protected function notify_changed($deleted) { global $CFG; // Condition code may cache the grades for conditional availability of // modules or sections. (This code should use a hook for communication // with plugin, but hooks are not implemented at time of writing.) if (!empty($CFG->enableavailability) && class_exists('\\availability_grade\\callbacks')) { \availability_grade\callbacks::grade_changed($this->userid); } require_once $CFG->libdir . '/completionlib.php'; // Bail out immediately if completion is not enabled for site (saves loading // grade item & requiring the restore stuff). if (!completion_info::is_enabled_for_site()) { return; } // Ignore during restore, as completion data will be updated anyway and // doing it now will result in incorrect dates (it will say they got the // grade completion now, instead of the correct time). if (class_exists('restore_controller', false) && restore_controller::is_executing()) { return; } // Load information about grade item $this->load_grade_item(); // Only course-modules have completion data if ($this->grade_item->itemtype != 'mod') { return; } // Use $COURSE if available otherwise get it via item fields $course = get_course($this->grade_item->courseid, false); // Bail out if completion is not enabled for course $completion = new completion_info($course); if (!$completion->is_enabled()) { return; } // Get course-module $cm = get_coursemodule_from_instance($this->grade_item->itemmodule, $this->grade_item->iteminstance, $this->grade_item->courseid); // If the course-module doesn't exist, display a warning... if (!$cm) { // ...unless the grade is being deleted in which case it's likely // that the course-module was just deleted too, so that's okay. if (!$deleted) { debugging("Couldn't find course-module for module '" . $this->grade_item->itemmodule . "', instance '" . $this->grade_item->iteminstance . "', course '" . $this->grade_item->courseid . "'"); } return; } // Pass information on to completion system $completion->inform_grade_changed($cm, $this->grade_item, $this, $deleted); }
/** * Used to notify the completion system (if necessary) that a user's grade * has changed, and clear up a possible score cache. * * @param bool $deleted True if grade was actually deleted */ protected function notify_changed($deleted) { global $CFG; // Condition code may cache the grades for conditional availability of // modules or sections. (This code should use a hook for communication // with plugin, but hooks are not implemented at time of writing.) if (!empty($CFG->enableavailability) && class_exists('\\availability_grade\\callbacks')) { \availability_grade\callbacks::grade_item_changed($this->courseid); } }