MDL-43293 Events: Added comments event in modules supporting comments

This commit is contained in:
Rajesh Taneja 2013-12-16 14:23:06 +08:00
parent edd9bb451c
commit a55eaf0351
18 changed files with 550 additions and 9 deletions

View File

@ -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 <rajesh@moodle.com>
* @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 <rajesh@moodle.com>
* @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.
}

View File

@ -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 <rajesh@moodle.com>
* @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 <rajesh@moodle.com>
* @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.
}

View File

@ -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(

View File

@ -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]);
}
}

View File

@ -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 <rajesh@moodle.com>
* @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 <rajesh@moodle.com>
* @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'];
}
}

View File

@ -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 <rajesh@moodle.com>
* @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 <rajesh@moodle.com>
* @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'];
}
}

View File

@ -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.
*

View File

@ -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.
*

View File

@ -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();
}
}

View File

@ -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 <rajesh@moodle.com>
* @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 <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/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'];
}
}

View File

@ -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 <rajesh@moodle.com>
* @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 <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/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'];
}
}

View File

@ -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/>.
/**
* mod_data comment created event.
*
* @package mod_data
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @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 <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/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'];
}
}

View File

@ -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/>.
/**
* mod_data comment deleted event.
*
* @package mod_data
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @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 <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/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'];
}
}

View File

@ -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/>.
/**
* mod_glossary comment created event.
*
* @package mod_glossary
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @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 <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/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'];
}
}

View File

@ -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/>.
/**
* mod_glossary comment deleted event.
*
* @package mod_glossary
* @copyright 2013 Rajesh Taneja <rajesh@moodle.com>
* @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 <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/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'];
}
}

View File

@ -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'];
}
}

View File

@ -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'];
}
}

View File

@ -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;
}