diff --git a/blocks/comments/classes/event/comment_created.php b/blocks/comments/classes/event/comment_created.php new file mode 100644 index 00000000000..db96870a8ec --- /dev/null +++ b/blocks/comments/classes/event/comment_created.php @@ -0,0 +1,37 @@ +. + +/** + * block_comments comment created event. + * + * @package block_comments + * @copyright 2013 Rajesh Taneja + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace block_comments\event; +defined('MOODLE_INTERNAL') || die(); + +/** + * block_comments comment created event. + * + * @package block_comments + * @copyright 2013 Rajesh Taneja + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class comment_created extends \core\event\comment_created { + // No need to override any method. +} diff --git a/blocks/comments/classes/event/comment_deleted.php b/blocks/comments/classes/event/comment_deleted.php new file mode 100644 index 00000000000..a347c0bb00c --- /dev/null +++ b/blocks/comments/classes/event/comment_deleted.php @@ -0,0 +1,37 @@ +. + +/** + * block_comments comment deleted event. + * + * @package block_comments + * @copyright 2013 Rajesh Taneja + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace block_comments\event; +defined('MOODLE_INTERNAL') || die(); + +/** + * block_comments comment deleted event. + * + * @package block_comments + * @copyright 2013 Rajesh Taneja + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class comment_deleted extends \core\event\comment_deleted { + // No need to override any method. +} diff --git a/comment/lib.php b/comment/lib.php index 8033ac0eaf7..443382fa557 100644 --- a/comment/lib.php +++ b/comment/lib.php @@ -652,7 +652,11 @@ class comment { $newcmt->time = userdate($newcmt->timecreated, $newcmt->strftimeformat); // Trigger comment created event. - $eventclassname = '\\' . $this->component . '\\event\comment_created'; + if (core_component::is_core_subsystem($this->component)) { + $eventclassname = '\\core\\event\\' . $this->component . '_comment_created'; + } else { + $eventclassname = '\\' . $this->component . '\\event\comment_created'; + } if (class_exists($eventclassname)) { $event = $eventclassname::create( array( @@ -724,7 +728,11 @@ class comment { } $DB->delete_records('comments', array('id'=>$commentid)); // Trigger comment delete event. - $eventclassname = '\\' . $this->component . '\\event\comment_deleted'; + if (core_component::is_core_subsystem($this->component)) { + $eventclassname = '\\core\\event\\' . $this->component . '_comment_deleted'; + } else { + $eventclassname = '\\' . $this->component . '\\event\comment_deleted'; + } if (class_exists($eventclassname)) { $event = $eventclassname::create( array( diff --git a/lib/classes/component.php b/lib/classes/component.php index e6ea562c37e..ce70ef0f5c8 100644 --- a/lib/classes/component.php +++ b/lib/classes/component.php @@ -1013,4 +1013,14 @@ $cache = '.var_export($cache, true).'; opcache_invalidate($file, true); } } + + /** + * Return true if subsystemname is core subsystem. + * + * @param string $subsystemname name of the subsystem. + * @return bool true if core subsystem. + */ + public static function is_core_subsystem($subsystemname) { + return isset(self::$subsystems[$subsystemname]); + } } diff --git a/lib/classes/event/blog_comment_created.php b/lib/classes/event/blog_comment_created.php new file mode 100644 index 00000000000..1ac2850d602 --- /dev/null +++ b/lib/classes/event/blog_comment_created.php @@ -0,0 +1,53 @@ +. + +/** + * blog comment created event. + * + * @package core + * @copyright 2013 Rajesh Taneja + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace core\event; +defined('MOODLE_INTERNAL') || die(); + +/** + * blog comment created event. + * + * @package core + * @copyright 2013 Rajesh Taneja + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class blog_comment_created extends \core\event\comment_created { + /** + * Get URL related to the action. + * + * @return \moodle_url + */ + public function get_url() { + return new \moodle_url('/blog/index.php', array('entryid' => $this->other['itemid'])); + } + + /** + * Returns description of what happened. + * + * @return string + */ + public function get_description() { + return 'User with id ' . $this->userid . ' added comment for blog with id ' . $this->other['itemid']; + } +} diff --git a/lib/classes/event/blog_comment_deleted.php b/lib/classes/event/blog_comment_deleted.php new file mode 100644 index 00000000000..cf8e7da2c84 --- /dev/null +++ b/lib/classes/event/blog_comment_deleted.php @@ -0,0 +1,53 @@ +. + +/** + * blog comment deleted event. + * + * @package core + * @copyright 2013 Rajesh Taneja + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace core\event; +defined('MOODLE_INTERNAL') || die(); + +/** + * blog comment deleted event. + * + * @package core + * @copyright 2013 Rajesh Taneja + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class blog_comment_deleted extends \core\event\comment_deleted { + /** + * Get URL related to the action. + * + * @return \moodle_url + */ + public function get_url() { + return new \moodle_url('/blog/index.php', array('entryid' => $this->other['itemid'])); + } + + /** + * Returns description of what happened. + * + * @return string + */ + public function get_description() { + return 'User with id ' . $this->userid . ' deleted comment for blog with id ' . $this->other['itemid']; + } +} diff --git a/lib/classes/event/comment_created.php b/lib/classes/event/comment_created.php index abee52e0e93..25cb0e67c52 100644 --- a/lib/classes/event/comment_created.php +++ b/lib/classes/event/comment_created.php @@ -63,10 +63,19 @@ abstract class comment_created extends \core\event\base { * @return string */ public function get_description() { - return 'User with id '. $this->userid . ' added comment for ' . $this->component . ' with instance id ' . + return 'User with id ' . $this->userid . ' added comment for ' . $this->component . ' with instance id ' . $this->contextinstanceid; } + /** + * Get URL related to the action. + * + * @return \moodle_url + */ + public function get_url() { + return $this->context->get_url(); + } + /** * Custom validation. * diff --git a/lib/classes/event/comment_deleted.php b/lib/classes/event/comment_deleted.php index f6a20040c39..84f6a6dc5d2 100644 --- a/lib/classes/event/comment_deleted.php +++ b/lib/classes/event/comment_deleted.php @@ -63,10 +63,19 @@ abstract class comment_deleted extends \core\event\base { * @return string */ public function get_description() { - return 'User with id '. $this->userid . ' deleted comment for ' . $this->component . ' with instance id ' . + return 'User with id ' . $this->userid . ' deleted comment for ' . $this->component . ' with instance id ' . $this->contextinstanceid; } + /** + * Get URL related to the action. + * + * @return \moodle_url + */ + public function get_url() { + return $this->context->get_url(); + } + /** * Custom validation. * diff --git a/lib/classes/event/comments_viewed.php b/lib/classes/event/comments_viewed.php index 1f6aaded8d1..05618f08c7d 100644 --- a/lib/classes/event/comments_viewed.php +++ b/lib/classes/event/comments_viewed.php @@ -65,4 +65,13 @@ abstract class comments_viewed extends \core\event\base { return 'User with id '. $this->userid . ' viewed comments for ' . $this->component . ' with instance id ' . $this->objectid; } + + /** + * Get URL related to the action. + * + * @return \moodle_url + */ + public function get_url() { + return $this->context->get_url(); + } } diff --git a/mod/assign/submission/comments/classes/event/comment_created.php b/mod/assign/submission/comments/classes/event/comment_created.php new file mode 100644 index 00000000000..0339217ddac --- /dev/null +++ b/mod/assign/submission/comments/classes/event/comment_created.php @@ -0,0 +1,53 @@ +. + +/** + * assignsubmission_comments comment created event. + * + * @package assignsubmission_comments + * @copyright 2013 Rajesh Taneja + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace assignsubmission_comments\event; +defined('MOODLE_INTERNAL') || die(); + +/** + * assignsubmission_comments comment created event. + * + * @package assignsubmission_comments + * @copyright 2013 Rajesh Taneja + * @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/assign/view.php', array('id' => $this->contextinstanceid)); + } + + /** + * Returns description of what happened. + * + * @return string + */ + public function get_description() { + return 'User with id ' . $this->userid . ' added comment for assignment submission with id ' . $this->other['itemid']; + } +} diff --git a/mod/assign/submission/comments/classes/event/comment_deleted.php b/mod/assign/submission/comments/classes/event/comment_deleted.php new file mode 100644 index 00000000000..2b11fa38738 --- /dev/null +++ b/mod/assign/submission/comments/classes/event/comment_deleted.php @@ -0,0 +1,53 @@ +. + +/** + * assignsubmission_comments comment deleted event. + * + * @package assignsubmission_comments + * @copyright 2013 Rajesh Taneja + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace assignsubmission_comments\event; +defined('MOODLE_INTERNAL') || die(); + +/** + * assignsubmission_comments comment deleted event. + * + * @package assignsubmission_comments + * @copyright 2013 Rajesh Taneja + * @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/assign/view.php', array('id' => $this->contextinstanceid)); + } + + /** + * Returns description of what happened. + * + * @return string + */ + public function get_description() { + return 'User with id ' . $this->userid . ' deleted comment for assignment submission with id ' . $this->other['itemid']; + } +} diff --git a/mod/data/classes/event/comment_created.php b/mod/data/classes/event/comment_created.php new file mode 100644 index 00000000000..9bf3c63af8e --- /dev/null +++ b/mod/data/classes/event/comment_created.php @@ -0,0 +1,53 @@ +. + +/** + * mod_data comment created event. + * + * @package mod_data + * @copyright 2013 Rajesh Taneja + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace mod_data\event; +defined('MOODLE_INTERNAL') || die(); + +/** + * mod_data comment created event. + * + * @package mod_data + * @copyright 2013 Rajesh Taneja + * @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/data/view.php', array('id' => $this->other['itemid'])); + } + + /** + * Returns description of what happened. + * + * @return string + */ + public function get_description() { + return 'User with id ' . $this->userid . ' added comment for database activity with id ' . $this->other['itemid']; + } +} diff --git a/mod/data/classes/event/comment_deleted.php b/mod/data/classes/event/comment_deleted.php new file mode 100644 index 00000000000..b73d6a07bc0 --- /dev/null +++ b/mod/data/classes/event/comment_deleted.php @@ -0,0 +1,53 @@ +. + +/** + * mod_data comment deleted event. + * + * @package mod_data + * @copyright 2013 Rajesh Taneja + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace mod_data\event; +defined('MOODLE_INTERNAL') || die(); + +/** + * mod_data comment deleted event. + * + * @package mod_data + * @copyright 2013 Rajesh Taneja + * @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/data/view.php', array('id' => $this->other['itemid'])); + } + + /** + * Returns description of what happened. + * + * @return string + */ + public function get_description() { + return 'User with id ' . $this->userid . ' deleted comment for database activity with id ' . $this->other['itemid']; + } +} diff --git a/mod/glossary/classes/event/comment_created.php b/mod/glossary/classes/event/comment_created.php new file mode 100644 index 00000000000..bdae5489bd0 --- /dev/null +++ b/mod/glossary/classes/event/comment_created.php @@ -0,0 +1,53 @@ +. + +/** + * mod_glossary comment created event. + * + * @package mod_glossary + * @copyright 2013 Rajesh Taneja + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace mod_glossary\event; +defined('MOODLE_INTERNAL') || die(); + +/** + * mod_glossary comment created event. + * + * @package mod_glossary + * @copyright 2013 Rajesh Taneja + * @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/glossary/view.php', array('id' => $this->other['itemid'])); + } + + /** + * Returns description of what happened. + * + * @return string + */ + public function get_description() { + return 'User with id ' . $this->userid . ' added comment for glossary activity with id ' . $this->other['itemid']; + } +} diff --git a/mod/glossary/classes/event/comment_deleted.php b/mod/glossary/classes/event/comment_deleted.php new file mode 100644 index 00000000000..a864bfebe6f --- /dev/null +++ b/mod/glossary/classes/event/comment_deleted.php @@ -0,0 +1,53 @@ +. + +/** + * mod_glossary comment deleted event. + * + * @package mod_glossary + * @copyright 2013 Rajesh Taneja + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace mod_glossary\event; +defined('MOODLE_INTERNAL') || die(); + +/** + * mod_glossary comment deleted event. + * + * @package mod_glossary + * @copyright 2013 Rajesh Taneja + * @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/glossary/view.php', array('id' => $this->other['itemid'])); + } + + /** + * Returns description of what happened. + * + * @return string + */ + public function get_description() { + return 'User with id ' . $this->userid . ' deleted comment for glossary activity with id ' . $this->other['itemid']; + } +} diff --git a/mod/wiki/classes/event/comment_created.php b/mod/wiki/classes/event/comment_created.php index bbc4a583d28..b0828a77b91 100644 --- a/mod/wiki/classes/event/comment_created.php +++ b/mod/wiki/classes/event/comment_created.php @@ -49,7 +49,6 @@ class comment_created extends \core\event\comment_created { * @return string */ public function get_description() { - return 'User with id '. $this->userid . ' added comment for ' . $this->component . ' with page id ' . - $this->other['itemid']; + return 'User with id ' . $this->userid . ' added comment for wiki with page id ' . $this->other['itemid']; } } diff --git a/mod/wiki/classes/event/comment_deleted.php b/mod/wiki/classes/event/comment_deleted.php index 1e3c757e2eb..279e790efaf 100644 --- a/mod/wiki/classes/event/comment_deleted.php +++ b/mod/wiki/classes/event/comment_deleted.php @@ -49,7 +49,6 @@ class comment_deleted extends \core\event\comment_deleted { * @return string */ public function get_description() { - return 'User with id '. $this->userid . ' deleted comment for ' . $this->component . ' with page id ' . - $this->other['itemid']; + return 'User with id ' . $this->userid . ' deleted comment for wiki with page id ' . $this->other['itemid']; } } diff --git a/mod/wiki/classes/event/comments_viewed.php b/mod/wiki/classes/event/comments_viewed.php index 2e7274da417..bd4cb708aa6 100644 --- a/mod/wiki/classes/event/comments_viewed.php +++ b/mod/wiki/classes/event/comments_viewed.php @@ -50,7 +50,7 @@ class comments_viewed extends \core\event\comments_viewed { * @return string */ public function get_description() { - return 'User with id '. $this->userid . ' viewed comments for wiki page id ' . + return 'User with id ' . $this->userid . ' viewed comments for wiki page id ' . $this->objectid; }