MDL-41599 events: Set relateduserid instead of userid in blog events
[moodle.git] / lib / classes / event / blog_entry_created.php
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
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.
8 //
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.
13 //
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/>.
17 namespace core\event;
19 /**
20  * Event for when a new blog entry is added..
21  *
22  * @package    core_blog
23  * @copyright  2013 Ankit Agarwal
24  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25  */
27 /**
28  * Class blog_entry_created
29  *
30  * Class for event to be triggered when a blog entry is created.
31  *
32  * @package    core_blog
33  * @copyright  2013 Ankit Agarwal
34  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35  */
36 class blog_entry_created extends \core\event\base {
38     /** @var  \blog_entry A reference to the active blog_entry object. */
39     protected $customobject;
41     /**
42      * Set basic properties for the event.
43      */
44     protected function init() {
45         $this->context = \context_system::instance();
46         $this->data['objecttable'] = 'post';
47         $this->data['crud'] = 'c';
48         $this->data['level'] = self::LEVEL_PARTICIPATING;
49     }
51     /**
52      * Set custom data of the event.
53      *
54      * @param \blog_entry $data A reference to the active blog_entry object.
55      */
56     public function set_custom_data($data) {
57         $this->customobject = $data;
58     }
60     /**
61      * Returns localised general event name.
62      *
63      * @return string
64      */
65     public static function get_name() {
66         return get_string("evententryadded", "core_blog");
67     }
69     /**
70      * Returns non-localised event description with id's for admin use only.
71      *
72      * @return string
73      */
74     public function get_description() {
75         return 'Blog entry "'. $this->other['subject']. '" was created by user with id '. $this->userid;
76     }
78     /**
79      * Returns relevant URL.
80      * @return \moodle_url
81      */
82     public function get_url() {
83         return new \moodle_url('/blog/index.php', array('entryid' => $this->objectid, 'userid' => $this->userid));
84     }
86     /**
87      * Does this event replace legacy event?
88      *
89      * @return string legacy event name
90      */
91     public static function get_legacy_eventname() {
92         return 'blog_entry_added';
93     }
95     /**
96      * Legacy event data if get_legacy_eventname() is not empty.
97      *
98      * @return \blog_entry
99      */
100     protected function get_legacy_eventdata() {
101         return $this->customobject;
102     }
104     /**
105      * replace add_to_log() statement.
106      *
107      * @return array of parameters to be passed to legacy add_to_log() function.
108      */
109     protected function get_legacy_logdata() {
110         return array (SITEID, 'blog', 'add', 'index.php?userid=' . $this->relateduserid . '&entryid=' . $this->objectid,
111                 $this->customobject->subject);
112     }