Skip to content

Commit

Permalink
MDL-43293 Events: Added comments event in modules supporting comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Rajesh Taneja committed Dec 23, 2013
1 parent edd9bb4 commit a55eaf0
Show file tree
Hide file tree
Showing 18 changed files with 550 additions and 9 deletions.
37 changes: 37 additions & 0 deletions blocks/comments/classes/event/comment_created.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?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/>.

/**
* block_comments comment created event.
*
* @package block_comments
* @copyright 2013 Rajesh Taneja <[email protected]>
* @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 <[email protected]>
* @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.
}
37 changes: 37 additions & 0 deletions blocks/comments/classes/event/comment_deleted.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?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/>.

/**
* block_comments comment deleted event.
*
* @package block_comments
* @copyright 2013 Rajesh Taneja <[email protected]>
* @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 <[email protected]>
* @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.
}
12 changes: 10 additions & 2 deletions comment/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,11 @@ public function add($content, $format = FORMAT_MOODLE) {
$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(
Expand Down Expand Up @@ -724,7 +728,11 @@ public function delete($commentid) {
}
$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(
Expand Down
10 changes: 10 additions & 0 deletions lib/classes/component.php
Original file line number Diff line number Diff line change
Expand Up @@ -1013,4 +1013,14 @@ public static function invalidate_opcode_php_cache($file) {
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]);
}
}
53 changes: 53 additions & 0 deletions lib/classes/event/blog_comment_created.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?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/>.

/**
* blog comment created event.
*
* @package core
* @copyright 2013 Rajesh Taneja <[email protected]>
* @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 <[email protected]>
* @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'];
}
}
53 changes: 53 additions & 0 deletions lib/classes/event/blog_comment_deleted.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?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/>.

/**
* blog comment deleted event.
*
* @package core
* @copyright 2013 Rajesh Taneja <[email protected]>
* @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 <[email protected]>
* @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'];
}
}
11 changes: 10 additions & 1 deletion lib/classes/event/comment_created.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,19 @@ public static function get_name() {
* @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.
*
Expand Down
11 changes: 10 additions & 1 deletion lib/classes/event/comment_deleted.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,19 @@ public static function get_name() {
* @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.
*
Expand Down
9 changes: 9 additions & 0 deletions lib/classes/event/comments_viewed.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,13 @@ public function get_description() {
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();
}
}
53 changes: 53 additions & 0 deletions mod/assign/submission/comments/classes/event/comment_created.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?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/>.

/**
* assignsubmission_comments comment created event.
*
* @package assignsubmission_comments
* @copyright 2013 Rajesh Taneja <[email protected]>
* @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 <[email protected]>
* @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'];
}
}
53 changes: 53 additions & 0 deletions mod/assign/submission/comments/classes/event/comment_deleted.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?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/>.

/**
* assignsubmission_comments comment deleted event.
*
* @package assignsubmission_comments
* @copyright 2013 Rajesh Taneja <[email protected]>
* @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 <[email protected]>
* @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'];
}
}
Loading

0 comments on commit a55eaf0

Please sign in to comment.