mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
Merge branch 'MDL-39959-master' of git://github.com/ankitagarwal/moodle
This commit is contained in:
commit
4a91055f7c
9 changed files with 723 additions and 47 deletions
|
@ -703,18 +703,19 @@ class dndupload_ajax_processor {
|
|||
$mod->groupmodelink = $this->cm->groupmodelink;
|
||||
$mod->groupmode = $this->cm->groupmode;
|
||||
|
||||
// Trigger mod_created event with information about this module.
|
||||
$eventdata = new stdClass();
|
||||
$eventdata->modulename = $mod->modname;
|
||||
$eventdata->name = $mod->name;
|
||||
$eventdata->cmid = $mod->id;
|
||||
$eventdata->courseid = $this->course->id;
|
||||
$eventdata->userid = $USER->id;
|
||||
events_trigger('mod_created', $eventdata);
|
||||
// Trigger course module created event.
|
||||
$event = \core\event\course_module_created::create(array(
|
||||
'courseid' => $this->course->id,
|
||||
'context' => context_module::instance($mod->id),
|
||||
'objectid' => $mod->id,
|
||||
'other' => array(
|
||||
'modulename' => $mod->modname,
|
||||
'name' => $mod->name,
|
||||
'instanceid' => $instanceid
|
||||
)
|
||||
));
|
||||
$event->trigger();
|
||||
|
||||
add_to_log($this->course->id, "course", "add mod",
|
||||
"../mod/{$mod->modname}/view.php?id=$mod->id",
|
||||
"{$mod->modname} $instanceid");
|
||||
add_to_log($this->course->id, $mod->modname, "add",
|
||||
"view.php?id=$mod->id",
|
||||
"$instanceid", $mod->id);
|
||||
|
|
|
@ -1619,7 +1619,7 @@ function set_coursemodule_visible($id, $visible) {
|
|||
* @since 2.5
|
||||
*/
|
||||
function course_delete_module($cmid) {
|
||||
global $CFG, $DB, $USER;
|
||||
global $CFG, $DB;
|
||||
|
||||
require_once($CFG->libdir.'/gradelib.php');
|
||||
require_once($CFG->dirroot.'/blog/lib.php');
|
||||
|
@ -1702,18 +1702,18 @@ function course_delete_module($cmid) {
|
|||
"Cannot delete the module $modulename (instance) from section.");
|
||||
}
|
||||
|
||||
// Trigger a mod_deleted event with information about this module.
|
||||
$eventdata = new stdClass();
|
||||
$eventdata->modulename = $modulename;
|
||||
$eventdata->cmid = $cm->id;
|
||||
$eventdata->courseid = $cm->course;
|
||||
$eventdata->userid = $USER->id;
|
||||
events_trigger('mod_deleted', $eventdata);
|
||||
|
||||
add_to_log($cm->course, 'course', "delete mod",
|
||||
"view.php?id=$cm->course",
|
||||
"$modulename $cm->instance", $cm->id);
|
||||
|
||||
// Trigger event for course module delete action.
|
||||
$event = \core\event\course_module_deleted::create(array(
|
||||
'courseid' => $cm->course,
|
||||
'context' => $modcontext,
|
||||
'objectid' => $cm->id,
|
||||
'other' => array(
|
||||
'modulename' => $modulename,
|
||||
'instanceid' => $cm->instance,
|
||||
)
|
||||
));
|
||||
$event->add_record_snapshot('course_modules', $cm);
|
||||
$event->trigger();
|
||||
rebuild_course_cache($cm->course, true);
|
||||
}
|
||||
|
||||
|
|
|
@ -140,16 +140,24 @@ function add_moduleinfo($moduleinfo, $course, $mform = null) {
|
|||
condition_info::update_cm_from_form((object)array('id'=>$moduleinfo->coursemodule), $moduleinfo, false);
|
||||
}
|
||||
|
||||
$eventname = 'mod_created';
|
||||
// Trigger event based on the action we did.
|
||||
$event = \core\event\course_module_created::create(array(
|
||||
'courseid' => $course->id,
|
||||
'context' => $modcontext,
|
||||
'objectid' => $moduleinfo->coursemodule,
|
||||
'other' => array(
|
||||
'modulename' => $moduleinfo->modulename,
|
||||
'name' => $moduleinfo->name,
|
||||
'instanceid' => $moduleinfo->instance
|
||||
)
|
||||
));
|
||||
$event->trigger();
|
||||
|
||||
add_to_log($course->id, "course", "add mod",
|
||||
"../mod/$moduleinfo->modulename/view.php?id=$moduleinfo->coursemodule",
|
||||
"$moduleinfo->modulename $moduleinfo->instance");
|
||||
add_to_log($course->id, $moduleinfo->modulename, "add",
|
||||
"view.php?id=$moduleinfo->coursemodule",
|
||||
"$moduleinfo->instance", $moduleinfo->coursemodule);
|
||||
|
||||
$moduleinfo = edit_module_post_actions($moduleinfo, $course, 'mod_created');
|
||||
$moduleinfo = edit_module_post_actions($moduleinfo, $course);
|
||||
|
||||
return $moduleinfo;
|
||||
}
|
||||
|
@ -157,28 +165,19 @@ function add_moduleinfo($moduleinfo, $course, $mform = null) {
|
|||
|
||||
/**
|
||||
* Common create/update module module actions that need to be processed as soon as a module is created/updaded.
|
||||
* For example: trigger event, create grade parent category, add outcomes, rebuild caches, regrade, save plagiarism settings...
|
||||
* For example:create grade parent category, add outcomes, rebuild caches, regrade, save plagiarism settings...
|
||||
* Please note this api does not trigger events as of MOODLE 2.6. Please trigger events before calling this api.
|
||||
*
|
||||
* @param object $moduleinfo the module info
|
||||
* @param object $course the course of the module
|
||||
* @param string $eventname the event name to trigger
|
||||
*
|
||||
* return object moduleinfo update with grading management info
|
||||
* @return object moduleinfo update with grading management info
|
||||
*/
|
||||
function edit_module_post_actions($moduleinfo, $course, $eventname) {
|
||||
global $USER, $CFG;
|
||||
function edit_module_post_actions($moduleinfo, $course) {
|
||||
global $CFG;
|
||||
|
||||
$modcontext = context_module::instance($moduleinfo->coursemodule);
|
||||
|
||||
// Trigger mod_created/mod_updated event with information about this module.
|
||||
$eventdata = new stdClass();
|
||||
$eventdata->modulename = $moduleinfo->modulename;
|
||||
$eventdata->name = $moduleinfo->name;
|
||||
$eventdata->cmid = $moduleinfo->coursemodule;
|
||||
$eventdata->courseid = $course->id;
|
||||
$eventdata->userid = $USER->id;
|
||||
events_trigger($eventname, $eventdata);
|
||||
|
||||
// Sync idnumber with grade_item.
|
||||
if ($grade_item = grade_item::fetch(array('itemtype'=>'mod', 'itemmodule'=>$moduleinfo->modulename,
|
||||
'iteminstance'=>$moduleinfo->instance, 'itemnumber'=>0, 'courseid'=>$course->id))) {
|
||||
|
@ -490,14 +489,24 @@ function update_moduleinfo($cm, $moduleinfo, $course, $mform = null) {
|
|||
$completion->reset_all_state($cm);
|
||||
}
|
||||
|
||||
add_to_log($course->id, "course", "update mod",
|
||||
"../mod/$moduleinfo->modulename/view.php?id=$moduleinfo->coursemodule",
|
||||
"$moduleinfo->modulename $moduleinfo->instance");
|
||||
// Trigger event based on the action we did.
|
||||
$event = \core\event\course_module_updated::create(array(
|
||||
'courseid' => $course->id,
|
||||
'context' => $modcontext,
|
||||
'objectid' => $moduleinfo->coursemodule,
|
||||
'other' => array(
|
||||
'modulename' => $moduleinfo->modulename,
|
||||
'name' => $moduleinfo->name,
|
||||
'instanceid' => $moduleinfo->instance
|
||||
)
|
||||
));
|
||||
$event->trigger();
|
||||
|
||||
add_to_log($course->id, $moduleinfo->modulename, "update",
|
||||
"view.php?id=$moduleinfo->coursemodule",
|
||||
"$moduleinfo->instance", $moduleinfo->coursemodule);
|
||||
|
||||
$moduleinfo = edit_module_post_actions($moduleinfo, $course, 'mod_updated');
|
||||
$moduleinfo = edit_module_post_actions($moduleinfo, $course);
|
||||
|
||||
return array($cm, $moduleinfo);
|
||||
}
|
||||
|
|
|
@ -317,6 +317,7 @@ class core_course_courselib_testcase extends advanced_testcase {
|
|||
// Test specific to the module.
|
||||
$modulerunasserts = $modulename.'_create_run_asserts';
|
||||
$this->$modulerunasserts($moduleinfo, $dbmodinstance);
|
||||
return $moduleinfo;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -569,6 +570,7 @@ class core_course_courselib_testcase extends advanced_testcase {
|
|||
// Test specific to the module.
|
||||
$modulerunasserts = $modulename.'_update_run_asserts';
|
||||
$this->$modulerunasserts($moduleinfo, $dbmodinstance);
|
||||
return $moduleinfo;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1887,4 +1889,298 @@ class core_course_courselib_testcase extends advanced_testcase {
|
|||
$this->assertEquals($section0->id, $cms[$quiz->cmid]->section);
|
||||
$this->assertEquals(2, count($cms));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for event related to course module creation.
|
||||
*/
|
||||
public function test_course_module_created_event() {
|
||||
global $USER, $DB;
|
||||
$this->resetAfterTest();
|
||||
|
||||
// Create an assign module.
|
||||
$sink = $this->redirectEvents();
|
||||
$modinfo = $this->create_specific_module_test('assign');
|
||||
$events = $sink->get_events();
|
||||
$event = array_pop($events);
|
||||
$sink->close();
|
||||
|
||||
$cm = $DB->get_record('course_modules', array('id' => $modinfo->coursemodule), '*', MUST_EXIST);
|
||||
$mod = $DB->get_record('assign', array('id' => $modinfo->instance), '*', MUST_EXIST);
|
||||
|
||||
// Validate event data.
|
||||
$this->assertInstanceOf('\core\event\course_module_created', $event);
|
||||
$this->assertEquals($cm->id, $event->objectid);
|
||||
$this->assertEquals($USER->id, $event->userid);
|
||||
$this->assertEquals('course_modules', $event->objecttable);
|
||||
$url = new moodle_url('/mod/assign/view.php', array('id' => $mod->id));
|
||||
$this->assertEquals($url, $event->get_url());
|
||||
|
||||
// Test legacy data.
|
||||
$this->assertSame('mod_created', $event->get_legacy_eventname());
|
||||
$eventdata = new stdClass();
|
||||
$eventdata->modulename = 'assign';
|
||||
$eventdata->name = $mod->name;
|
||||
$eventdata->cmid = $cm->id;
|
||||
$eventdata->courseid = $cm->course;
|
||||
$eventdata->userid = $USER->id;
|
||||
$this->assertEventLegacyData($eventdata, $event);
|
||||
|
||||
$arr = array($cm->course, "course", "add mod", "../mod/assign/view.php?id=$mod->id", "assign $cm->instance");
|
||||
$this->assertEventLegacyLogData($arr, $event);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for event validations related to course module creation.
|
||||
*/
|
||||
public function test_course_module_created_event_exceptions() {
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
// Generate data.
|
||||
$modinfo = $this->create_specific_module_test('assign');
|
||||
$context = context_module::instance($modinfo->coursemodule);
|
||||
|
||||
// Test not setting instanceid.
|
||||
try {
|
||||
$event = \core\event\course_module_created::create(array(
|
||||
'courseid' => $modinfo->course,
|
||||
'context' => $context,
|
||||
'objectid' => $modinfo->coursemodule,
|
||||
'other' => array(
|
||||
'modulename' => 'assign',
|
||||
'name' => 'My assignment',
|
||||
)
|
||||
));
|
||||
$this->fail("Event validation should not allow \\core\\event\\course_module_created to be triggered without
|
||||
other['instanceid']");
|
||||
} catch (coding_exception $e) {
|
||||
$this->assertContains("Field other['instanceid'] cannot be empty", $e->getMessage());
|
||||
}
|
||||
|
||||
// Test not setting modulename.
|
||||
try {
|
||||
$event = \core\event\course_module_created::create(array(
|
||||
'courseid' => $modinfo->course,
|
||||
'context' => $context,
|
||||
'objectid' => $modinfo->coursemodule,
|
||||
'other' => array(
|
||||
'instanceid' => $modinfo->instance,
|
||||
'name' => 'My assignment',
|
||||
)
|
||||
));
|
||||
$this->fail("Event validation should not allow \\core\\event\\course_module_created to be triggered without
|
||||
other['modulename']");
|
||||
} catch (coding_exception $e) {
|
||||
$this->assertContains("Field other['modulename'] cannot be empty", $e->getMessage());
|
||||
}
|
||||
|
||||
// Test not setting name.
|
||||
|
||||
try {
|
||||
$event = \core\event\course_module_created::create(array(
|
||||
'courseid' => $modinfo->course,
|
||||
'context' => $context,
|
||||
'objectid' => $modinfo->coursemodule,
|
||||
'other' => array(
|
||||
'modulename' => 'assign',
|
||||
'instanceid' => $modinfo->instance,
|
||||
)
|
||||
));
|
||||
$this->fail("Event validation should not allow \\core\\event\\course_module_created to be triggered without
|
||||
other['name']");
|
||||
} catch (coding_exception $e) {
|
||||
$this->assertContains("Field other['name'] cannot be empty", $e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for event related to course module updates.
|
||||
*/
|
||||
public function test_course_module_updated_event() {
|
||||
global $USER, $DB;
|
||||
$this->resetAfterTest();
|
||||
|
||||
// Update a forum module.
|
||||
$sink = $this->redirectEvents();
|
||||
$modinfo = $this->update_specific_module_test('forum');
|
||||
$events = $sink->get_events();
|
||||
$event = array_pop($events);
|
||||
$sink->close();
|
||||
|
||||
$cm = $DB->get_record('course_modules', array('id' => $modinfo->coursemodule), '*', MUST_EXIST);
|
||||
$mod = $DB->get_record('forum', array('id' => $cm->instance), '*', MUST_EXIST);
|
||||
|
||||
// Validate event data.
|
||||
$this->assertInstanceOf('\core\event\course_module_updated', $event);
|
||||
$this->assertEquals($cm->id, $event->objectid);
|
||||
$this->assertEquals($USER->id, $event->userid);
|
||||
$this->assertEquals('course_modules', $event->objecttable);
|
||||
$url = new moodle_url('/mod/forum/view.php', array('id' => $mod->id));
|
||||
$this->assertEquals($url, $event->get_url());
|
||||
|
||||
// Test legacy data.
|
||||
$this->assertSame('mod_updated', $event->get_legacy_eventname());
|
||||
$eventdata = new stdClass();
|
||||
$eventdata->modulename = 'forum';
|
||||
$eventdata->name = $mod->name;
|
||||
$eventdata->cmid = $cm->id;
|
||||
$eventdata->courseid = $cm->course;
|
||||
$eventdata->userid = $USER->id;
|
||||
$this->assertEventLegacyData($eventdata, $event);
|
||||
|
||||
$arr = array($cm->course, "course", "update mod", "../mod/forum/view.php?id=$mod->id", "forum $cm->instance");
|
||||
$this->assertEventLegacyLogData($arr, $event);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for event validations related to course module update.
|
||||
*/
|
||||
public function test_course_module_updated_event_exceptions() {
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
// Generate data.
|
||||
$modinfo = $this->create_specific_module_test('assign');
|
||||
$context = context_module::instance($modinfo->coursemodule);
|
||||
|
||||
// Test not setting instanceid.
|
||||
try {
|
||||
$event = \core\event\course_module_updated::create(array(
|
||||
'courseid' => $modinfo->course,
|
||||
'context' => $context,
|
||||
'objectid' => $modinfo->coursemodule,
|
||||
'other' => array(
|
||||
'modulename' => 'assign',
|
||||
'name' => 'My assignment',
|
||||
)
|
||||
));
|
||||
$this->fail("Event validation should not allow \\core\\event\\course_module_updated to be triggered without
|
||||
other['instanceid']");
|
||||
} catch (coding_exception $e) {
|
||||
$this->assertContains("Field other['instanceid'] cannot be empty", $e->getMessage());
|
||||
}
|
||||
|
||||
// Test not setting modulename.
|
||||
try {
|
||||
$event = \core\event\course_module_updated::create(array(
|
||||
'courseid' => $modinfo->course,
|
||||
'context' => $context,
|
||||
'objectid' => $modinfo->coursemodule,
|
||||
'other' => array(
|
||||
'instanceid' => $modinfo->instance,
|
||||
'name' => 'My assignment',
|
||||
)
|
||||
));
|
||||
$this->fail("Event validation should not allow \\core\\event\\course_module_updated to be triggered without
|
||||
other['modulename']");
|
||||
} catch (coding_exception $e) {
|
||||
$this->assertContains("Field other['modulename'] cannot be empty", $e->getMessage());
|
||||
}
|
||||
|
||||
// Test not setting name.
|
||||
|
||||
try {
|
||||
$event = \core\event\course_module_updated::create(array(
|
||||
'courseid' => $modinfo->course,
|
||||
'context' => $context,
|
||||
'objectid' => $modinfo->coursemodule,
|
||||
'other' => array(
|
||||
'modulename' => 'assign',
|
||||
'instanceid' => $modinfo->instance,
|
||||
)
|
||||
));
|
||||
$this->fail("Event validation should not allow \\core\\event\\course_module_updated to be triggered without
|
||||
other['name']");
|
||||
} catch (coding_exception $e) {
|
||||
$this->assertContains("Field other['name'] cannot be empty", $e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for event related to course module delete.
|
||||
*/
|
||||
public function test_course_module_deleted_event() {
|
||||
global $USER, $DB;
|
||||
$this->resetAfterTest();
|
||||
|
||||
// Create and delete a module.
|
||||
$sink = $this->redirectEvents();
|
||||
$modinfo = $this->create_specific_module_test('forum');
|
||||
$cm = $DB->get_record('course_modules', array('id' => $modinfo->coursemodule), '*', MUST_EXIST);
|
||||
course_delete_module($modinfo->coursemodule);
|
||||
$events = $sink->get_events();
|
||||
$event = array_pop($events); // delete module event.;
|
||||
$sink->close();
|
||||
|
||||
// Validate event data.
|
||||
$this->assertInstanceOf('\core\event\course_module_deleted', $event);
|
||||
$this->assertEquals($cm->id, $event->objectid);
|
||||
$this->assertEquals($USER->id, $event->userid);
|
||||
$this->assertEquals('course_modules', $event->objecttable);
|
||||
$this->assertEquals(null, $event->get_url());
|
||||
$this->assertEquals($cm, $event->get_record_snapshot('course_modules', $cm->id));
|
||||
|
||||
// Test legacy data.
|
||||
$this->assertSame('mod_deleted', $event->get_legacy_eventname());
|
||||
$eventdata = new stdClass();
|
||||
$eventdata->modulename = 'forum';
|
||||
$eventdata->cmid = $cm->id;
|
||||
$eventdata->courseid = $cm->course;
|
||||
$eventdata->userid = $USER->id;
|
||||
$this->assertEventLegacyData($eventdata, $event);
|
||||
|
||||
$arr = array($cm->course, 'course', "delete mod", "view.php?id=$cm->course", "forum $cm->instance", $cm->id);
|
||||
$this->assertEventLegacyLogData($arr, $event);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for event validations related to course module deletion.
|
||||
*/
|
||||
public function test_course_module_deleted_event_exceptions() {
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
// Generate data.
|
||||
$modinfo = $this->create_specific_module_test('assign');
|
||||
$context = context_module::instance($modinfo->coursemodule);
|
||||
|
||||
// Test not setting instanceid.
|
||||
try {
|
||||
$event = \core\event\course_module_deleted::create(array(
|
||||
'courseid' => $modinfo->course,
|
||||
'context' => $context,
|
||||
'objectid' => $modinfo->coursemodule,
|
||||
'other' => array(
|
||||
'modulename' => 'assign',
|
||||
'name' => 'My assignment',
|
||||
)
|
||||
));
|
||||
$this->fail("Event validation should not allow \\core\\event\\course_module_deleted to be triggered without
|
||||
other['instanceid']");
|
||||
} catch (coding_exception $e) {
|
||||
$this->assertContains("Field other['instanceid'] cannot be empty", $e->getMessage());
|
||||
}
|
||||
|
||||
// Test not setting modulename.
|
||||
try {
|
||||
$event = \core\event\course_module_deleted::create(array(
|
||||
'courseid' => $modinfo->course,
|
||||
'context' => $context,
|
||||
'objectid' => $modinfo->coursemodule,
|
||||
'other' => array(
|
||||
'instanceid' => $modinfo->instance,
|
||||
'name' => 'My assignment',
|
||||
)
|
||||
));
|
||||
$this->fail("Event validation should not allow \\core\\event\\course_module_deleted to be triggered without
|
||||
other['modulename']");
|
||||
} catch (coding_exception $e) {
|
||||
$this->assertContains("Field other['modulename'] cannot be empty", $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -665,6 +665,9 @@ $string['eventcoursecategorydeleted'] = 'Category deleted';
|
|||
$string['eventcoursecontentdeleted'] = 'Course content deleted';
|
||||
$string['eventcoursecreated'] = 'Course created';
|
||||
$string['eventcoursedeleted'] = 'Course deleted';
|
||||
$string['eventcoursemodulecreated'] = 'Course module created';
|
||||
$string['eventcoursemoduledeleted'] = 'Course module deleted';
|
||||
$string['eventcoursemoduleupdated'] = 'Course module updated';
|
||||
$string['eventcourserestored'] = 'Course restored';
|
||||
$string['eventcourseupdated'] = 'Course updated';
|
||||
$string['eventcoursesectionupdated'] = ' Course section updated';
|
||||
|
|
126
lib/classes/event/course_module_created.php
Normal file
126
lib/classes/event/course_module_created.php
Normal file
|
@ -0,0 +1,126 @@
|
|||
<?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/>.
|
||||
|
||||
/**
|
||||
* Event to be triggered when a new course module is created.
|
||||
*
|
||||
* @package core
|
||||
* @copyright 2013 Ankit Agarwal
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
|
||||
*/
|
||||
|
||||
namespace core\event;
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Class course_module_created
|
||||
*
|
||||
* Class for event to be triggered when a new course module is created.
|
||||
*
|
||||
* @package core
|
||||
* @copyright 2013 Ankit Agarwal
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
|
||||
*/
|
||||
class course_module_created extends base {
|
||||
|
||||
/**
|
||||
* Set basic properties for the event.
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['objecttable'] = 'course_modules';
|
||||
$this->data['crud'] = 'c';
|
||||
$this->data['level'] = self::LEVEL_TEACHING;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns localised general event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return get_string('eventcoursemodulecreated', 'core');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns non-localised event description with id's for admin use only.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return 'The '. $this->other['modulename'] . ' module ' . $this->other['name']. ' was created by user with id '.
|
||||
$this->userid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns relevant URL.
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new \moodle_url('/mod/' . $this->other['modulename'] . '/view.php', array('id' => $this->other['instanceid']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Legacy event name.
|
||||
*
|
||||
* @return string legacy event name
|
||||
*/
|
||||
public static function get_legacy_eventname() {
|
||||
return 'mod_created';
|
||||
}
|
||||
|
||||
/**
|
||||
* Legacy event data.
|
||||
*
|
||||
* @return \stdClass
|
||||
*/
|
||||
protected function get_legacy_eventdata() {
|
||||
$eventdata = new \stdClass();
|
||||
$eventdata->modulename = $this->other['modulename'];
|
||||
$eventdata->name = $this->other['name'];
|
||||
$eventdata->cmid = $this->objectid;
|
||||
$eventdata->courseid = $this->courseid;
|
||||
$eventdata->userid = $this->userid;
|
||||
return $eventdata;
|
||||
}
|
||||
|
||||
/**
|
||||
* replace add_to_log() statement.
|
||||
*
|
||||
* @return array of parameters to be passed to legacy add_to_log() function.
|
||||
*/
|
||||
protected function get_legacy_logdata() {
|
||||
return array ($this->courseid, "course", "add mod", "../mod/" . $this->other['modulename'] . "/view.php?id=" .
|
||||
$this->other['instanceid'], $this->other['modulename'] . " " . $this->other['instanceid']);
|
||||
}
|
||||
|
||||
/**
|
||||
* custom validations
|
||||
*
|
||||
* Throw \coding_exception notice in case of any problems.
|
||||
*/
|
||||
protected function validate_data() {
|
||||
if (!isset($this->other['modulename'])) {
|
||||
throw new \coding_exception("Field other['modulename'] cannot be empty");
|
||||
}
|
||||
if (!isset($this->other['instanceid'])) {
|
||||
throw new \coding_exception("Field other['instanceid'] cannot be empty");
|
||||
}
|
||||
if (!isset($this->other['name'])) {
|
||||
throw new \coding_exception("Field other['name'] cannot be empty");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
114
lib/classes/event/course_module_deleted.php
Normal file
114
lib/classes/event/course_module_deleted.php
Normal file
|
@ -0,0 +1,114 @@
|
|||
<?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/>.
|
||||
|
||||
/**
|
||||
* Event to be triggered when a new course module is deleted.
|
||||
*
|
||||
* @package core
|
||||
* @copyright 2013 Ankit Agarwal
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
|
||||
*/
|
||||
|
||||
namespace core\event;
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Class course_module_deleted
|
||||
*
|
||||
* Class for event to be triggered when a course module is deleted.
|
||||
*
|
||||
* @package core
|
||||
* @copyright 2013 Ankit Agarwal
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
|
||||
*/
|
||||
class course_module_deleted extends base {
|
||||
|
||||
/**
|
||||
* Set basic properties for the event.
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['objecttable'] = 'course_modules';
|
||||
$this->data['crud'] = 'd';
|
||||
$this->data['level'] = self::LEVEL_TEACHING;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns localised general event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return get_string('eventcoursemoduledeleted', 'core');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns non-localised event description with id's for admin use only.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return 'The module ' . $this->other['modulename'] . ' with instance id ' . $this->other['instanceid']. ' was deleted by
|
||||
user with id ' . $this->userid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Legacy event name.
|
||||
*
|
||||
* @return string legacy event name
|
||||
*/
|
||||
public static function get_legacy_eventname() {
|
||||
return 'mod_deleted';
|
||||
}
|
||||
|
||||
/**
|
||||
* Legacy event data.
|
||||
*
|
||||
* @return \stdClass
|
||||
*/
|
||||
protected function get_legacy_eventdata() {
|
||||
$eventdata = new \stdClass();
|
||||
$eventdata->modulename = $this->other['modulename'];
|
||||
$eventdata->cmid = $this->objectid;
|
||||
$eventdata->courseid = $this->courseid;
|
||||
$eventdata->userid = $this->userid;
|
||||
return $eventdata;
|
||||
}
|
||||
|
||||
/**
|
||||
* replace add_to_log() statement.
|
||||
*
|
||||
* @return array of parameters to be passed to legacy add_to_log() function.
|
||||
*/
|
||||
protected function get_legacy_logdata() {
|
||||
return array ($this->courseid, "course", "delete mod", "view.php?id=$this->courseid",
|
||||
$this->other['modulename'] . " " . $this->other['instanceid'], $this->objectid);
|
||||
}
|
||||
|
||||
/**
|
||||
* custom validations
|
||||
*
|
||||
* Throw \coding_exception notice in case of any problems.
|
||||
*/
|
||||
protected function validate_data() {
|
||||
if (!isset($this->other['modulename'])) {
|
||||
throw new \coding_exception("Field other['modulename'] cannot be empty");
|
||||
}
|
||||
if (!isset($this->other['instanceid'])) {
|
||||
throw new \coding_exception("Field other['instanceid'] cannot be empty");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
126
lib/classes/event/course_module_updated.php
Normal file
126
lib/classes/event/course_module_updated.php
Normal file
|
@ -0,0 +1,126 @@
|
|||
<?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/>.
|
||||
|
||||
/**
|
||||
* Event to be triggered when a new course module is updated.
|
||||
*
|
||||
* @package core
|
||||
* @copyright 2013 Ankit Agarwal
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
|
||||
*/
|
||||
|
||||
namespace core\event;
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Class course_module_updated
|
||||
*
|
||||
* Class for event to be triggered when a course module is updated.
|
||||
*
|
||||
* @package core
|
||||
* @copyright 2013 Ankit Agarwal
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
|
||||
*/
|
||||
class course_module_updated extends base {
|
||||
|
||||
/**
|
||||
* Set basic properties for the event.
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['objecttable'] = 'course_modules';
|
||||
$this->data['crud'] = 'u';
|
||||
$this->data['level'] = self::LEVEL_TEACHING;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns localised general event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return get_string('eventcoursemoduleupdated', 'core');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns non-localised event description with id's for admin use only.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return 'The ' . $this->other['modulename'] . ' module ' . $this->other['name']. ' was updated by user with id '.
|
||||
$this->userid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns relevant URL.
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new \moodle_url('/mod/' . $this->other['modulename'] . '/view.php', array('id' => $this->other['instanceid']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Legacy event name.
|
||||
*
|
||||
* @return string legacy event name
|
||||
*/
|
||||
public static function get_legacy_eventname() {
|
||||
return 'mod_updated';
|
||||
}
|
||||
|
||||
/**
|
||||
* Legacy event data.
|
||||
*
|
||||
* @return \stdClass
|
||||
*/
|
||||
protected function get_legacy_eventdata() {
|
||||
$eventdata = new \stdClass();
|
||||
$eventdata->modulename = $this->other['modulename'];
|
||||
$eventdata->name = $this->other['name'];
|
||||
$eventdata->cmid = $this->objectid;
|
||||
$eventdata->courseid = $this->courseid;
|
||||
$eventdata->userid = $this->userid;
|
||||
return $eventdata;
|
||||
}
|
||||
|
||||
/**
|
||||
* replace add_to_log() statement.
|
||||
*
|
||||
* @return array of parameters to be passed to legacy add_to_log() function.
|
||||
*/
|
||||
protected function get_legacy_logdata() {
|
||||
return array ($this->courseid, "course", "update mod", "../mod/" . $this->other['modulename'] . "/view.php?id=" .
|
||||
$this->other['instanceid'], $this->other['modulename'] . " " . $this->other['instanceid']);
|
||||
}
|
||||
|
||||
/**
|
||||
* custom validations
|
||||
*
|
||||
* Throw \coding_exception notice in case of any problems.
|
||||
*/
|
||||
protected function validate_data() {
|
||||
if (!isset($this->other['modulename'])) {
|
||||
throw new \coding_exception("Field other['modulename'] cannot be empty");
|
||||
}
|
||||
if (!isset($this->other['instanceid'])) {
|
||||
throw new \coding_exception("Field other['instanceid'] cannot be empty");
|
||||
}
|
||||
if (!isset($this->other['name'])) {
|
||||
throw new \coding_exception("Field other['name'] cannot be empty");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -141,6 +141,7 @@ Event triggering and event handlers:
|
|||
* groups_groupings_groups_removed -> (no replacement)
|
||||
* groups_groups_deleted -> \core\event\group_deleted
|
||||
* groups_groupings_deleted -> \core\event\grouping_deleted
|
||||
* edit_module_post_actions() does not trigger events any more.
|
||||
|
||||
=== 2.5.1 ===
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue