MDL-41123 report_completion: Add context validations to the events

This commit is contained in:
Ankit Agarwal 2014-04-08 16:07:35 +08:00
parent df13233697
commit e5f4487194
2 changed files with 26 additions and 0 deletions

View File

@ -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.');
}
}
}

View File

@ -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.');
}
}
}