Skip to content

Commit

Permalink
MDL-29097 course: refactored to avoid having two seperate calls to ev…
Browse files Browse the repository at this point in the history
…ents_trigger()
  • Loading branch information
andyjdavis authored and wdjunaidi committed Feb 10, 2012
1 parent 8eabde9 commit e82f917
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions course/modedit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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))) {
Expand Down

0 comments on commit e82f917

Please sign in to comment.