Skip to content

Commit

Permalink
Merge branch 'MDL-39959-master' of git://github.com/ankitagarwal/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaglancy committed Sep 17, 2013
2 parents ba57caa + 63deb5c commit 4a91055
Show file tree
Hide file tree
Showing 9 changed files with 724 additions and 48 deletions.
25 changes: 13 additions & 12 deletions course/dnduploadlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -703,18 +703,19 @@ protected function finish_setup_course_module($instanceid) {
$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);

add_to_log($this->course->id, "course", "add mod",
"../mod/{$mod->modname}/view.php?id=$mod->id",
"{$mod->modname} $instanceid");
// 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, $mod->modname, "add",
"view.php?id=$mod->id",
"$instanceid", $mod->id);
Expand Down
26 changes: 13 additions & 13 deletions course/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
}

Expand Down
55 changes: 32 additions & 23 deletions course/modlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,45 +140,44 @@ 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;
}


/**
* 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))) {
Expand Down Expand Up @@ -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);
}
Expand Down
Loading

0 comments on commit 4a91055

Please sign in to comment.