2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * The mod_forum discussion viewed event.
21 * @copyright 2014 Dan Poltawski <dan@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 namespace mod_forum\event;
27 defined('MOODLE_INTERNAL') || die();
30 * The mod_forum discussion viewed event.
33 * @copyright 2014 Dan Poltawski <dan@moodle.com>
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 class discussion_viewed extends \core\event\base {
43 protected function init() {
44 $this->data['crud'] = 'r';
45 $this->data['edulevel'] = self::LEVEL_PARTICIPATING;
46 $this->data['objecttable'] = 'forum_discussions';
50 * Returns description of what happened.
54 public function get_description() {
55 return "The user {$this->userid} has viewed the forum discussion {$this->objectid}";
59 * Return localised event name.
63 public static function get_name() {
64 return get_string('eventdiscussionviewed', 'mod_forum');
68 * Get URL related to the action
72 public function get_url() {
73 return new \moodle_url('/mod/forum/discuss.php', array('d' => $this->objectid));
77 * Return the legacy event log data.
81 protected function get_legacy_logdata() {
82 return array($this->courseid, 'forum', 'view discussion', 'discuss.php?d=' . $this->objectid,
83 $this->objectid, $this->contextinstanceid);
89 * @throws \coding_exception
92 protected function validate_data() {
93 parent::validate_data();
95 if ($this->contextlevel != CONTEXT_MODULE) {
96 throw new \coding_exception('Context passed must be module context.');
99 if (!isset($this->objectid)) {
100 throw new \coding_exception('objectid must be set to the discussionid.');