MDL-41599 events: Set relateduserid instead of userid in blog events
[moodle.git] / lib / classes / event / blog_entry_created.php
CommitLineData
3049780a
AA
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/>.
16
17namespace core\event;
18
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 */
26
c1ff221e
AA
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 */
3049780a
AA
36class blog_entry_created extends \core\event\base {
37
38 /** @var \blog_entry A reference to the active blog_entry object. */
39 protected $customobject;
40
c1ff221e
AA
41 /**
42 * Set basic properties for the event.
43 */
3049780a
AA
44 protected function init() {
45 $this->context = \context_system::instance();
46 $this->data['objecttable'] = 'post';
47 $this->data['crud'] = 'c';
38d6fbfa 48 $this->data['level'] = self::LEVEL_PARTICIPATING;
3049780a
AA
49 }
50
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 }
59
60 /**
61 * Returns localised general event name.
62 *
2cf88d54 63 * @return string
3049780a
AA
64 */
65 public static function get_name() {
2cf88d54 66 return get_string("evententryadded", "core_blog");
3049780a
AA
67 }
68
69 /**
2cf88d54 70 * Returns non-localised event description with id's for admin use only.
3049780a 71 *
2cf88d54 72 * @return string
3049780a
AA
73 */
74 public function get_description() {
2cf88d54 75 return 'Blog entry "'. $this->other['subject']. '" was created by user with id '. $this->userid;
3049780a
AA
76 }
77
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 }
85
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 }
94
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 }
103
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() {
77037e27
AA
110 return array (SITEID, 'blog', 'add', 'index.php?userid=' . $this->relateduserid . '&entryid=' . $this->objectid,
111 $this->customobject->subject);
3049780a
AA
112 }
113}