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/>.
20 * Event for when a new blog entry is added..
23 * @copyright 2013 Ankit Agarwal
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 * Class blog_entry_created
30 * Class for event to be triggered when a blog entry is created.
33 * @copyright 2013 Ankit Agarwal
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 class blog_entry_created extends \core\event\base {
38 /** @var \blog_entry A reference to the active blog_entry object. */
39 protected $customobject;
42 * Set basic properties for the event.
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;
52 * Set custom data of the event.
54 * @param \blog_entry $data A reference to the active blog_entry object.
56 public function set_custom_data($data) {
57 $this->customobject = $data;
61 * Returns localised general event name.
65 public static function get_name() {
66 return get_string("evententryadded", "core_blog");
70 * Returns non-localised event description with id's for admin use only.
74 public function get_description() {
75 return 'Blog entry "'. $this->other['subject']. '" was created by user with id '. $this->userid;
79 * Returns relevant URL.
82 public function get_url() {
83 return new \moodle_url('/blog/index.php', array('entryid' => $this->objectid, 'userid' => $this->userid));
87 * Does this event replace legacy event?
89 * @return string legacy event name
91 public static function get_legacy_eventname() {
92 return 'blog_entry_added';
96 * Legacy event data if get_legacy_eventname() is not empty.
100 protected function get_legacy_eventdata() {
101 return $this->customobject;
105 * replace add_to_log() statement.
107 * @return array of parameters to be passed to legacy add_to_log() function.
109 protected function get_legacy_logdata() {
110 return array (SITEID, 'blog', 'add', 'index.php?userid=' . $this->relateduserid . '&entryid=' . $this->objectid,
111 $this->customobject->subject);