Permalink
Browse files

MDL-29097 course: refactored to avoid having two seperate calls to ev…

…ents_trigger()
  • Loading branch information...
1 parent 216f6d8 commit c85cf7df5c290ec1fdbd6c96eedd660f33ecf079 @andyjdavis andyjdavis committed Dec 30, 2011
Showing with 14 additions and 16 deletions.
  1. +14 −16 course/modedit.php
View
30 course/modedit.php
@@ -316,6 +316,9 @@
$fromform->completiongradeitemnumber = null;
}
+ // the type of event to trigger (mod_created/mod_updated)
+ $eventname = '';
+
if (!empty($fromform->update)) {
if (!empty($course->groupmodeforce) or !isset($fromform->groupmode)) {
@@ -380,14 +383,7 @@
$completion->reset_all_state($cm);
}
- // Trigger mod_updated event with information about this module.
- $eventdata = new stdClass();
- $eventdata->modulename = $fromform->modulename;
- $eventdata->name = $fromform->name;
- $eventdata->cmid = $fromform->coursemodule;
- $eventdata->courseid = $course->id;
- $eventdata->userid = $USER->id;
- events_trigger('mod_updated', $eventdata);
+ $eventname = 'mod_updated';
add_to_log($course->id, "course", "update mod",
"../mod/$fromform->modulename/view.php?id=$fromform->coursemodule",
@@ -492,14 +488,7 @@
condition_info::update_cm_from_form((object)array('id'=>$fromform->coursemodule), $fromform, false);
}
- // Trigger mod_created event with information about this module.
- $eventdata = new stdClass();
- $eventdata->modulename = $fromform->modulename;
- $eventdata->name = $fromform->name;
- $eventdata->cmid = $fromform->coursemodule;
- $eventdata->courseid = $course->id;
- $eventdata->userid = $USER->id;
- events_trigger('mod_created', $eventdata);
+ $eventname = 'mod_created';
add_to_log($course->id, "course", "add mod",
"../mod/$fromform->modulename/view.php?id=$fromform->coursemodule",
@@ -511,6 +500,15 @@
print_error('invaliddata');
}
+ // Trigger mod_created/mod_updated event with information about this module.
+ $eventdata = new stdClass();
+ $eventdata->modulename = $fromform->modulename;
+ $eventdata->name = $fromform->name;
+ $eventdata->cmid = $fromform->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'=>$fromform->modulename,
'iteminstance'=>$fromform->instance, 'itemnumber'=>0, 'courseid'=>$course->id))) {

0 comments on commit c85cf7d

Please sign in to comment.