diff --git a/report/completion/classes/event/report_viewed.php b/report/completion/classes/event/report_viewed.php index f8be4c08dd5..ccb8440dad8 100644 --- a/report/completion/classes/event/report_viewed.php +++ b/report/completion/classes/event/report_viewed.php @@ -71,5 +71,18 @@ class report_viewed extends \core\event\base { public function get_url() { return new \moodle_url('/report/completion/index.php', array('course' => $this->courseid)); } + + /** + * custom validations. + * + * @throws \coding_exception when validation fails. + * @return void + */ + protected function validate_data() { + parent::validate_data(); + if ($this->contextlevel != CONTEXT_COURSE) { + throw new \coding_exception('Context passed must be course context.'); + } + } } diff --git a/report/completion/classes/event/user_report_viewed.php b/report/completion/classes/event/user_report_viewed.php index dfa1174a2ce..bb52db04889 100644 --- a/report/completion/classes/event/user_report_viewed.php +++ b/report/completion/classes/event/user_report_viewed.php @@ -81,5 +81,18 @@ class user_report_viewed extends \core\event\base { public function get_url() { return new \moodle_url('/report/completion/user.php', array('course' => $this->courseid, 'id' => $this->relateduserid)); } + + /** + * custom validations. + * + * @throws \coding_exception when validation fails. + * @return void + */ + protected function validate_data() { + parent::validate_data(); + if ($this->contextlevel != CONTEXT_COURSE) { + throw new \coding_exception('Context passed must be course context.'); + } + } }