MDL-40682 events: Add a event for when a blog entry is created
[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
27class blog_entry_created extends \core\event\base {
28
29 /** @var \blog_entry A reference to the active blog_entry object. */
30 protected $customobject;
31
32 protected function init() {
33 $this->context = \context_system::instance();
34 $this->data['objecttable'] = 'post';
35 $this->data['crud'] = 'c';
36 // TODO: MDL-37658 set level.
37 $this->data['level'] = 50;
38 }
39
40 /**
41 * Set custom data of the event.
42 *
43 * @param \blog_entry $data A reference to the active blog_entry object.
44 */
45 public function set_custom_data($data) {
46 $this->customobject = $data;
47 }
48
49 /**
50 * Returns localised general event name.
51 *
52 * @return \lang_string
53 */
54 public static function get_name() {
55 return new \lang_string("evententryadded", "core_blog");
56 }
57
58 /**
59 * Returns localised description of what happened.
60 *
61 * @return \lang_string
62 */
63 public function get_description() {
64 $a = new \stdClass();
65 $a->subject = $this->other['subject'];
66 $a->userid = $this->userid;
67 return new \lang_string("evententryaddeddesc", "core_blog", $a);
68 }
69
70 /**
71 * Returns relevant URL.
72 * @return \moodle_url
73 */
74 public function get_url() {
75 return new \moodle_url('/blog/index.php', array('entryid' => $this->objectid, 'userid' => $this->userid));
76 }
77
78 /**
79 * Does this event replace legacy event?
80 *
81 * @return string legacy event name
82 */
83 public static function get_legacy_eventname() {
84 return 'blog_entry_added';
85 }
86
87 /**
88 * Legacy event data if get_legacy_eventname() is not empty.
89 *
90 * @return \blog_entry
91 */
92 protected function get_legacy_eventdata() {
93 return $this->customobject;
94 }
95
96 /**
97 * replace add_to_log() statement.
98 *
99 * @return array of parameters to be passed to legacy add_to_log() function.
100 */
101 protected function get_legacy_logdata() {
102 return array (SITEID, 'blog', 'add', 'index.php?userid='.$this->userid.'&entryid='.$this->objectid, $this->customobject->subject);
103 }
104}