Commit 86b0e3b3 authored by Rajesh Taneja's avatar Rajesh Taneja Committed by Marina Glancy
Browse files

MDL-40058 Events: Replaced add_to_log for page comments to event

parent 8b43cf22
......@@ -651,6 +651,20 @@ class comment {
}
$newcmt->time = userdate($newcmt->timecreated, $newcmt->strftimeformat);
// Trigger comment created event.
$eventclassname = '\\' . $this->component . '\\event\comment_created';
if (class_exists($eventclassname)) {
$event = $eventclassname::create(
array(
'context' => $this->context,
'objectid' => $newcmt->id,
'other' => array(
'itemid' => $this->itemid
)
));
$event->trigger();
}
return $newcmt;
} else {
throw new comment_exception('dbupdatefailed');
......@@ -709,6 +723,20 @@ class comment {
throw new comment_exception('nopermissiontocomment');
}
$DB->delete_records('comments', array('id'=>$commentid));
// Trigger comment delete event.
$eventclassname = '\\' . $this->component . '\\event\comment_deleted';
if (class_exists($eventclassname)) {
$event = $eventclassname::create(
array(
'context' => $this->context,
'objectid' => $commentid,
'other' => array(
'itemid' => $this->itemid
)
));
$event->add_record_snapshot('comments', $comment);
$event->trigger();
}
return true;
}
......
......@@ -710,6 +710,9 @@ $string['errorcreatingactivity'] = 'Unable to create an instance of activity \'{
$string['errorfiletoobig'] = 'The file was bigger than the limit of {$a} bytes';
$string['errornouploadrepo'] = 'There is no upload repository enabled for this site';
$string['errorwhenconfirming'] = 'You are not confirmed yet because an error occurred. If you clicked on a link in an email to get here, make sure that the line in your email wasn\'t broken or wrapped. You may have to use cut and paste to reconstruct the link properly.';
$string['eventcommentcreated'] = 'Comment created';
$string['eventcommentdeleted'] = 'Comment deleted';
$string['eventcommentsviewed'] = 'Comments viewed';
$string['eventcoursecategorydeleted'] = 'Category deleted';
$string['eventcoursecontentdeleted'] = 'Course content deleted';
$string['eventcoursecreated'] = 'Course created';
......
<?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/>.
/**
* Abstract comment created event.
*
* @package core
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\event;
defined('MOODLE_INTERNAL') || die();
/**
* Abstract comment created event class.
*
* This class has to be extended by any event which is triggred while creating new comment.
*
* @package core
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class comment_created extends \core\event\base {
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'c';
$this->data['level'] = self::LEVEL_PARTICIPATING;
$this->data['objecttable'] = 'comments';
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventcommentcreated', 'moodle');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return 'User with id '. $this->userid . ' added comment for ' . $this->component . ' with instance id ' .
$this->contextinstanceid;
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
if (!isset($this->other['itemid'])) {
throw new \coding_exception('The itemid needs to be set in $other');
}
}
}
<?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/>.
/**
* Abstract comment deleted event.
*
* @package core
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\event;
defined('MOODLE_INTERNAL') || die();
/**
* Abstract comment deleted event class.
*
* This class has to be extended by any event which is triggred while deleting comment.
*
* @package core
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class comment_deleted extends \core\event\base {
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'd';
$this->data['level'] = self::LEVEL_PARTICIPATING;
$this->data['objecttable'] = 'comments';
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventcommentdeleted', 'moodle');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return 'User with id '. $this->userid . ' deleted comment for ' . $this->component . ' with instance id ' .
$this->contextinstanceid;
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
if (!isset($this->other['itemid'])) {
throw new \coding_exception('The itemid needs to be set in $other');
}
}
}
<?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/>.
/**
* Abstract comments viewed event.
*
* @package core
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\event;
defined('MOODLE_INTERNAL') || die();
/**
* Abstract comments viewed event class.
*
* This class has to be extended by any event which is triggred while viewing comment.
*
* @package core
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class comments_viewed extends \core\event\base {
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['level'] = self::LEVEL_PARTICIPATING;
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventcommentsviewed', 'moodle');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return 'User with id '. $this->userid . ' viewed comments for ' . $this->component . ' with instance id ' .
$this->objectid;
}
}
<?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/>.
/**
* mod_wiki comment created event.
*
* @package mod_wiki
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_wiki\event;
defined('MOODLE_INTERNAL') || die();
/**
* mod_wiki comment created event.
*
* @package mod_wiki
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class comment_created extends \core\event\comment_created {
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/wiki/comments.php', array('pageid' => $this->other['itemid']));
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return 'User with id '. $this->userid . ' added comment for ' . $this->component . ' with page id ' .
$this->other['itemid'];
}
}
<?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/>.
/**
* mod_wiki comment deleted event.
*
* @package mod_wiki
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_wiki\event;
defined('MOODLE_INTERNAL') || die();
/**
* mod_wiki comment deleted event.
*
* @package mod_wiki
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class comment_deleted extends \core\event\comment_deleted {
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/wiki/comments.php', array('pageid' => $this->other['itemid']));
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return 'User with id '. $this->userid . ' deleted comment for ' . $this->component . ' with page id ' .
$this->other['itemid'];
}
}
<?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/>.
/**
* mod_wiki comments viewed event.
*
* @package mod_wiki
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_wiki\event;
defined('MOODLE_INTERNAL') || die();
/**
* mod_wiki comments viewed event.
*
* @package mod_wiki
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class comments_viewed extends \core\event\comments_viewed {
/**
* Init method.
*
* @return void
*/
protected function init() {
parent::init();
$this->data['objecttable'] = 'wiki_pages';
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return 'User with id '. $this->userid . ' viewed comments for wiki page id ' .
$this->objectid;
}
/**
* Return the legacy event log data.
*
* @return array
*/
protected function get_legacy_logdata() {
return(array($this->courseid, 'wiki', 'comments',
'comments.php?pageid=' . $this->objectid, $this->objectid, $this->context->instanceid));
}
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/wiki/comments.php', array('pageid' => $this->objectid));
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected function validate_data() {
if (empty($this->objectid) || empty($this->objecttable)) {
throw new \coding_exception('The objectid and objecttable need to be set in $other');
}
}
}
......@@ -59,7 +59,16 @@ $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST)
require_login($course, true, $cm);
add_to_log($course->id, 'wiki', 'comments', "comments.php?pageid=".$pageid, $pageid, $cm->id);
// Trigger comment viewed event.
$event = \mod_wiki\event\comments_viewed::create(
array(
'context' => context_module::instance($cm->id),
'objectid' => $pageid
));
$event->add_record_snapshot('wiki_pages', $page);
$event->add_record_snapshot('wiki', $wiki);
$event->add_record_snapshot('wiki_subwikis', $subwiki);
$event->trigger();
/// Print the page header
$wikipage = new page_wiki_comments($wiki, $subwiki, $cm);
......
......@@ -99,7 +99,6 @@ if ($action == 'delete') {
$comm->set_action($action, 0, $content);
}
}
add_to_log($course->id, 'wiki', 'comment', "comments.php?pageid=".$pageid, $pageid, $cm->id);
$comm->print_header();
$comm->print_content();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment