From e5f44871943f11043db9570b7ea7aac8f854871d Mon Sep 17 00:00:00 2001 From: Ankit Agarwal Date: Tue, 8 Apr 2014 16:07:35 +0800 Subject: [PATCH] MDL-41123 report_completion: Add context validations to the events --- report/completion/classes/event/report_viewed.php | 13 +++++++++++++ .../completion/classes/event/user_report_viewed.php | 13 +++++++++++++ 2 files changed, 26 insertions(+) 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.'); + } + } }