Merge branch 'MDL-40682-master' of git://github.com/ankitagarwal/moodle
[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';
48 // TODO: MDL-37658 set level.
49 $this->data['level'] = 50;
50 }
51
52 /**
53 * Set custom data of the event.
54 *
55 * @param \blog_entry $data A reference to the active blog_entry object.
56 */
57 public function set_custom_data($data) {
58 $this->customobject = $data;
59 }
60
61 /**
62 * Returns localised general event name.
63 *
64 * @return \lang_string
65 */
66 public static function get_name() {
67 return new \lang_string("evententryadded", "core_blog");
68 }
69
70 /**
71 * Returns localised description of what happened.
72 *
73 * @return \lang_string
74 */
75 public function get_description() {
76 $a = new \stdClass();
77 $a->subject = $this->other['subject'];
78 $a->userid = $this->userid;
79 return new \lang_string("evententryaddeddesc", "core_blog", $a);
80 }
81
82 /**
83 * Returns relevant URL.
84 * @return \moodle_url
85 */
86 public function get_url() {
87 return new \moodle_url('/blog/index.php', array('entryid' => $this->objectid, 'userid' => $this->userid));
88 }
89
90 /**
91 * Does this event replace legacy event?
92 *
93 * @return string legacy event name
94 */
95 public static function get_legacy_eventname() {
96 return 'blog_entry_added';
97 }
98
99 /**
100 * Legacy event data if get_legacy_eventname() is not empty.
101 *
102 * @return \blog_entry
103 */
104 protected function get_legacy_eventdata() {
105 return $this->customobject;
106 }
107
108 /**
109 * replace add_to_log() statement.
110 *
111 * @return array of parameters to be passed to legacy add_to_log() function.
112 */
113 protected function get_legacy_logdata() {
114 return array (SITEID, 'blog', 'add', 'index.php?userid='.$this->userid.'&entryid='.$this->objectid, $this->customobject->subject);
115 }
116}