mirror of
https://github.com/moodle/moodle.git
synced 2025-03-03 15:29:08 +01:00
MDL-40062 mod_forum: post events
* post_created * post_updated * post_deleted Prune post (split discussion) has been converted to multiple events as splitting a post actually means new discussion created.
This commit is contained in:
parent
e70ebc55f8
commit
2d3f692bfe
131
mod/forum/classes/event/post_created.php
Normal file
131
mod/forum/classes/event/post_created.php
Normal file
@ -0,0 +1,131 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* The mod_forum post created event.
|
||||
*
|
||||
* @package mod_forum
|
||||
* @copyright 2014 Dan Poltawski <dan@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_forum\event;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* The mod_forum post created event.
|
||||
* @property-read array $other Extra information about the event.
|
||||
* - int discussionid: The discussion id the post is part of.
|
||||
* - int forumid: The forum id the post is part of.
|
||||
* - string forumtype: The type of forum the post is part of.
|
||||
*
|
||||
* @package mod_forum
|
||||
* @copyright 2014 Dan Poltawski <dan@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class post_created extends \core\event\base {
|
||||
/**
|
||||
* Init method.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'c';
|
||||
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
|
||||
$this->data['objecttable'] = 'forum_posts';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return "The user {$this->userid} has created a post in the discussion {$this->other['discussionid']} ".
|
||||
" in forum {$this->other['forumid']}.";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return localised event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return get_string('eventpostcreated', 'mod_forum');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL related to the action
|
||||
*
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
if ($this->other['forumtype'] == 'single') {
|
||||
// Single discussion forums are an exception. We show
|
||||
// the forum itself since it only has one discussion
|
||||
// thread.
|
||||
$url = new \moodle_url('/mod/forum/view.php', array('id' => $this->other['forumid']));
|
||||
} else {
|
||||
$url = new \moodle_url('/mod/forum/discuss.php', array('d' => $this->other['discussionid']));
|
||||
}
|
||||
$url->set_anchor('p'.$this->objectid);
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the legacy event log data.
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
protected function get_legacy_logdata() {
|
||||
|
||||
// The legacy log table expects a relative path to /mod/forum/.
|
||||
$logurl = substr($this->get_url()->out_as_local_url(), strlen('/mod/forum/'));
|
||||
|
||||
return array($this->courseid, 'forum', 'add post', $logurl, $this->other['forumid'], $this->contextinstanceid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom validation.
|
||||
*
|
||||
* @throws \coding_exception
|
||||
* @return void
|
||||
*/
|
||||
protected function validate_data() {
|
||||
parent::validate_data();
|
||||
|
||||
if (!isset($this->objectid)) {
|
||||
throw new \coding_exception('objectid must be set to the postid.');
|
||||
}
|
||||
|
||||
if (!isset($this->other['discussionid'])) {
|
||||
throw new \coding_exception('discussionid must be set in other.');
|
||||
}
|
||||
|
||||
if (!isset($this->other['forumid'])) {
|
||||
throw new \coding_exception('forumid must be set in other.');
|
||||
}
|
||||
|
||||
if (!isset($this->other['forumtype'])) {
|
||||
throw new \coding_exception('forumtype must be set in other.');
|
||||
}
|
||||
|
||||
if ($this->contextlevel != CONTEXT_MODULE) {
|
||||
throw new \coding_exception('Context passed must be module context.');
|
||||
}
|
||||
}
|
||||
}
|
130
mod/forum/classes/event/post_deleted.php
Normal file
130
mod/forum/classes/event/post_deleted.php
Normal file
@ -0,0 +1,130 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* The mod_forum post deleted event.
|
||||
*
|
||||
* @package mod_forum
|
||||
* @copyright 2014 Dan Poltawski <dan@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_forum\event;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* The mod_forum post deleted event.
|
||||
*
|
||||
* @property-read array $other Extra information about the event.
|
||||
* - int discussionid: The discussion id the post is part of.
|
||||
* - int forumid: The forum id the post is part of.
|
||||
* - string forumtype: The type of forum the post is part of.
|
||||
*
|
||||
* @package mod_forum
|
||||
* @copyright 2014 Dan Poltawski <dan@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class post_deleted extends \core\event\base {
|
||||
/**
|
||||
* Init method.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'd';
|
||||
$this->data['edulevel'] = self::LEVEL_OTHER;
|
||||
$this->data['objecttable'] = 'forum_posts';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return "The user {$this->userid} has deleted the post {$this->objectid} ".
|
||||
" in discussion {$this->other['discussionid']}.";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return localised event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return get_string('eventpostdeleted', 'mod_forum');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL related to the action
|
||||
*
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
if ($this->other['forumtype'] == 'single') {
|
||||
// Single discussion forums are an exception. We show
|
||||
// the forum itself since it only has one discussion
|
||||
// thread.
|
||||
$url = new \moodle_url('/mod/forum/view.php', array('id' => $this->other['forumid']));
|
||||
} else {
|
||||
$url = new \moodle_url('/mod/forum/discuss.php', array('d' => $this->other['discussionid']));
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the legacy event log data.
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
protected function get_legacy_logdata() {
|
||||
// The legacy log table expects a relative path to /mod/forum/.
|
||||
$logurl = substr($this->get_url()->out_as_local_url(), strlen('/mod/forum/'));
|
||||
|
||||
return array($this->courseid, 'forum', 'delete post', $logurl, $this->objectid, $this->contextinstanceid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom validation.
|
||||
*
|
||||
* @throws \coding_exception
|
||||
* @return void
|
||||
*/
|
||||
protected function validate_data() {
|
||||
parent::validate_data();
|
||||
|
||||
if (!isset($this->objectid)) {
|
||||
throw new \coding_exception('objectid must be set to the postid.');
|
||||
}
|
||||
|
||||
if (!isset($this->other['discussionid'])) {
|
||||
throw new \coding_exception('discussionid must be set in other.');
|
||||
}
|
||||
|
||||
if (!isset($this->other['forumid'])) {
|
||||
throw new \coding_exception('forumid must be set in other.');
|
||||
}
|
||||
|
||||
if (!isset($this->other['forumtype'])) {
|
||||
throw new \coding_exception('forumtype must be set in other.');
|
||||
}
|
||||
|
||||
if ($this->contextlevel != CONTEXT_MODULE) {
|
||||
throw new \coding_exception('Context passed must be module context.');
|
||||
}
|
||||
}
|
||||
}
|
131
mod/forum/classes/event/post_updated.php
Normal file
131
mod/forum/classes/event/post_updated.php
Normal file
@ -0,0 +1,131 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* The mod_forum post updated event.
|
||||
*
|
||||
* @package mod_forum
|
||||
* @copyright 2014 Dan Poltawski <dan@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_forum\event;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* The mod_forum post updated event.
|
||||
*
|
||||
* @property-read array $other Extra information about the event.
|
||||
* - int discussionid: The discussion id the post is part of.
|
||||
* - int forumid: The forum id the post is part of.
|
||||
* - string forumtype: The type of forum the post is part of.
|
||||
*
|
||||
* @package mod_forum
|
||||
* @copyright 2014 Dan Poltawski <dan@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class post_updated extends \core\event\base {
|
||||
/**
|
||||
* Init method.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'u';
|
||||
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
|
||||
$this->data['objecttable'] = 'forum_posts';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return "The user {$this->userid} has created updated the post {$this->objectid} ".
|
||||
" in discussion {$this->other['discussionid']}.";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return localised event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return get_string('eventpostupdated', 'mod_forum');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL related to the action
|
||||
*
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
if ($this->other['forumtype'] == 'single') {
|
||||
// Single discussion forums are an exception. We show
|
||||
// the forum itself since it only has one discussion
|
||||
// thread.
|
||||
$url = new \moodle_url('/mod/forum/view.php', array('id' => $this->other['forumid']));
|
||||
} else {
|
||||
$url = new \moodle_url('/mod/forum/discuss.php', array('d' => $this->other['discussionid']));
|
||||
}
|
||||
$url->set_anchor('p'.$this->objectid);
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the legacy event log data.
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
protected function get_legacy_logdata() {
|
||||
// The legacy log table expects a relative path to /mod/forum/.
|
||||
$logurl = substr($this->get_url()->out_as_local_url(), strlen('/mod/forum/'));
|
||||
|
||||
return array($this->courseid, 'forum', 'update post', $logurl, $this->objectid, $this->contextinstanceid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom validation.
|
||||
*
|
||||
* @throws \coding_exception
|
||||
* @return void
|
||||
*/
|
||||
protected function validate_data() {
|
||||
parent::validate_data();
|
||||
|
||||
if (!isset($this->objectid)) {
|
||||
throw new \coding_exception('objectid must be set to the postid.');
|
||||
}
|
||||
|
||||
if (!isset($this->other['discussionid'])) {
|
||||
throw new \coding_exception('discussionid must be set in other.');
|
||||
}
|
||||
|
||||
if (!isset($this->other['forumid'])) {
|
||||
throw new \coding_exception('forumid must be set in other.');
|
||||
}
|
||||
|
||||
if (!isset($this->other['forumtype'])) {
|
||||
throw new \coding_exception('forumtype must be set in other.');
|
||||
}
|
||||
|
||||
if ($this->contextlevel != CONTEXT_MODULE) {
|
||||
throw new \coding_exception('Context passed must be module context.');
|
||||
}
|
||||
}
|
||||
}
|
@ -151,9 +151,12 @@ $string['eventdiscussionmoved'] = 'Discussion moved';
|
||||
$string['eventdiscussionviewed'] = 'Discussion viewed';
|
||||
$string['eventforumviewed'] = 'Forum viewed';
|
||||
$string['eventuserreportviewed'] = 'User report viewed';
|
||||
$string['eventsubscribersviewed'] = 'Subscribers viewed';
|
||||
$string['eventpostcreated'] = 'Post created';
|
||||
$string['eventpostdeleted'] = 'Post deleted';
|
||||
$string['eventpostupdated'] = 'Post updated';
|
||||
$string['eventreadtrackingdisabled'] = 'Read tracking disabled';
|
||||
$string['eventreadtrackingenabled'] = 'Read tracking enabled';
|
||||
$string['eventsubscribersviewed'] = 'Subscribers viewed';
|
||||
$string['eventsubscriptioncreated'] = 'Subscription created';
|
||||
$string['eventsubscriptiondeleted'] = 'Subscription deleted';
|
||||
$string['emaildigestcompleteshort'] = 'Complete posts';
|
||||
|
@ -361,7 +361,23 @@ if (!empty($forum)) { // User is starting a new discussion in a forum
|
||||
$discussionurl = "discuss.php?d=$post->discussion";
|
||||
}
|
||||
|
||||
add_to_log($discussion->course, "forum", "delete post", $discussionurl, "$post->id", $cm->id);
|
||||
$params = array(
|
||||
'context' => $modcontext,
|
||||
'objectid' => $post->id,
|
||||
'other' => array(
|
||||
'discussionid' => $discussion->id,
|
||||
'forumid' => $forum->id,
|
||||
'forumtype' => $forum->type,
|
||||
)
|
||||
);
|
||||
|
||||
if ($post->userid !== $USER->id) {
|
||||
$params['relateduserid'] = $post->userid;
|
||||
}
|
||||
$event = \mod_forum\event\post_deleted::create($params);
|
||||
$event->add_record_snapshot('forum_posts', $post);
|
||||
$event->add_record_snapshot('forum_discussions', $discussion);
|
||||
$event->trigger();
|
||||
|
||||
redirect(forum_go_back_to($discussionurl));
|
||||
} else {
|
||||
@ -464,8 +480,29 @@ if (!empty($forum)) { // User is starting a new discussion in a forum
|
||||
forum_discussion_update_last_post($discussion->id);
|
||||
forum_discussion_update_last_post($newid);
|
||||
|
||||
add_to_log($discussion->course, "forum", "prune post",
|
||||
"discuss.php?d=$newid", "$post->id", $cm->id);
|
||||
// Fire events to reflect the split..
|
||||
$params = array(
|
||||
'context' => $modcontext,
|
||||
'objectid' => $newid,
|
||||
'other' => array(
|
||||
'forumid' => $forum->id,
|
||||
)
|
||||
);
|
||||
$event = \mod_forum\event\discussion_created::create($params);
|
||||
$event->trigger();
|
||||
|
||||
$params = array(
|
||||
'context' => $modcontext,
|
||||
'objectid' => $post->id,
|
||||
'other' => array(
|
||||
'discussionid' => $newid,
|
||||
'forumid' => $forum->id,
|
||||
'forumtype' => $forum->type,
|
||||
)
|
||||
);
|
||||
$event = \mod_forum\event\post_updated::create($params);
|
||||
$event->add_record_snapshot('forum_discussions', $discussion);
|
||||
$event->trigger();
|
||||
|
||||
redirect(forum_go_back_to("discuss.php?d=$newid"));
|
||||
|
||||
@ -692,8 +729,25 @@ if ($fromform = $mform_post->get_data()) {
|
||||
} else {
|
||||
$discussionurl = "discuss.php?d=$discussion->id#p$fromform->id";
|
||||
}
|
||||
add_to_log($course->id, "forum", "update post",
|
||||
"$discussionurl&parent=$fromform->id", "$fromform->id", $cm->id);
|
||||
|
||||
$params = array(
|
||||
'context' => $modcontext,
|
||||
'objectid' => $fromform->id,
|
||||
'other' => array(
|
||||
'discussionid' => $discussion->id,
|
||||
'forumid' => $forum->id,
|
||||
'forumtype' => $forum->type,
|
||||
)
|
||||
);
|
||||
|
||||
if ($realpost->userid !== $USER->id) {
|
||||
$params['relateduserid'] = $realpost->userid;
|
||||
}
|
||||
|
||||
$event = \mod_forum\event\post_updated::create($params);
|
||||
$event->add_record_snapshot('forum_posts', $fromform);
|
||||
$event->add_record_snapshot('forum_discussions', $discussion);
|
||||
$event->trigger();
|
||||
|
||||
redirect(forum_go_back_to("$discussionurl"), $message.$subscribemessage, $timemessage);
|
||||
|
||||
@ -735,8 +789,20 @@ if ($fromform = $mform_post->get_data()) {
|
||||
} else {
|
||||
$discussionurl = "discuss.php?d=$discussion->id";
|
||||
}
|
||||
add_to_log($course->id, "forum", "add post",
|
||||
"$discussionurl&parent=$fromform->id", "$fromform->id", $cm->id);
|
||||
|
||||
$params = array(
|
||||
'context' => $modcontext,
|
||||
'objectid' => $fromform->id,
|
||||
'other' => array(
|
||||
'discussionid' => $discussion->id,
|
||||
'forumid' => $forum->id,
|
||||
'forumtype' => $forum->type,
|
||||
)
|
||||
);
|
||||
$event = \mod_forum\event\post_created::create($params);
|
||||
$event->add_record_snapshot('forum_posts', $fromform);
|
||||
$event->add_record_snapshot('forum_discussions', $discussion);
|
||||
$event->trigger();
|
||||
|
||||
// Update completion state
|
||||
$completion=new completion_info($course);
|
||||
|
Loading…
x
Reference in New Issue
Block a user