MDL-49453 course: Move view trigger event to a new API function

This commit is contained in:
Juan Leyva
2015-03-26 16:30:15 +01:00
parent 20d38830ae
commit 2258883544
3 changed files with 23 additions and 9 deletions
+20
View File
@@ -3756,3 +3756,23 @@ function course_change_sortorder_after_course($courseorid, $moveaftercourseid) {
cache_helper::purge_by_event('changesincourse');
return true;
}
/**
* Trigger course viewed event. This API function is used when course view actions happens,
* usually in course/view.php but also in external functions.
*
* @param stdClass $context course context object
* @param int $sectionnumber section number
* @since Moodle 2.9
*/
function course_view($context, $sectionnumber = 0) {
$eventdata = array('context' => $context);
if (!empty($sectionnumber)) {
$eventdata['other']['coursesectionnumber'] = $sectionnumber;
}
$event = \core\event\course_viewed::create($eventdata);
$event->trigger();
}
+1 -6
View File
@@ -285,12 +285,7 @@
// Trigger course viewed event.
// We don't trust $context here. Course format inclusion above executes in the global space. We can't assume
// anything after that point.
$eventdata = array('context' => context_course::instance($course->id));
if (!empty($section) && (int)$section == $section) {
$eventdata['other'] = array('coursesectionnumber' => $section);
}
$event = \core\event\course_viewed::create($eventdata);
$event->trigger();
course_view(context_course::instance($course->id), $section);
// Include course AJAX
include_course_ajax($course, $modnamesused);
+2 -3
View File
@@ -78,9 +78,8 @@ if (get_home_page() != HOMEPAGE_SITE) {
}
}
$eventparams = array('context' => context_course::instance(SITEID));
$event = \core\event\course_viewed::create($eventparams);
$event->trigger();
// Trigger event.
course_view(context_course::instance(SITEID));
// If the hub plugin is installed then we let it take over the homepage here.
if (file_exists($CFG->dirroot.'/local/hub/lib.php') and get_config('local_hub', 'hubenabled')) {