From b63c0ee52119419ee91950ad5afbf5c66a352bb2 Mon Sep 17 00:00:00 2001 From: gustav_delius Date: Sun, 26 Dec 2004 13:58:07 +0000 Subject: [PATCH] Fixes a bug with user events created by an activity module. The old code assumed that the courseid would always be set but that is only the case for course events, not for user or group events. (See http://moodle.org/mod/forum/discuss.php?d=4466#20827 for a discussion about the meaning of the courseid field in the event table) I also made the $courseid argument to get_coursemodule_from_instance() optional. It is not needed and in some cases it will not be know, as for example for non-course events created by activity modules. --- calendar/lib.php | 14 ++++++-------- lib/datalib.php | 6 ++++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/calendar/lib.php b/calendar/lib.php index d2aeee4a87..5d206e6876 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -338,11 +338,9 @@ function calendar_get_upcoming($courses, $groups, $users, $daysinfuture, $maxeve // The module name is set. I will assume that it has to be displayed, and // also that it is an automatically-generated event. And of course that the - // three fields for get_coursemodule_from_instance are set correctly. + // fields for get_coursemodule_from_instance are set correctly. - calendar_get_course_cached($coursecache, $event->courseid); - - $module = calendar_get_module_cached($coursecache, $event->modulename, $event->instance, $event->courseid); + $module = calendar_get_module_cached($coursecache, $event->modulename, $event->instance); if ($module === false) { // This shouldn't have happened. What to do now? @@ -357,7 +355,7 @@ function calendar_get_upcoming($courses, $groups, $users, $daysinfuture, $maxeve $output[$outkey]->icon = ''; $output[$outkey]->referer = ''.$event->name.''; $output[$outkey]->time = $eventtime; - $output[$outkey]->courselink = ''.$coursecache[$event->courseid]->fullname.''; + $output[$outkey]->courselink = ''.$coursecache[$module->course]->fullname.''; $output[$outkey]->cmid = $module->id; @@ -862,11 +860,11 @@ function calendar_events_by_day($events, $month, $year, &$eventsbyday, &$duratio return; } -function calendar_get_module_cached(&$coursecache, $modulename, $instance, $courseid) { - $module = get_coursemodule_from_instance($modulename, $instance, $courseid); +function calendar_get_module_cached(&$coursecache, $modulename, $instance) { + $module = get_coursemodule_from_instance($modulename, $instance); if($module === false) return false; - if(!calendar_get_course_cached($coursecache, $courseid)) { + if(!calendar_get_course_cached($coursecache, $module->course)) { return false; } return $module; diff --git a/lib/datalib.php b/lib/datalib.php index dd81fb5d19..dc17f8aa5f 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -2452,15 +2452,17 @@ function get_course_mods($courseid) { * @return array * @todo Finish documenting this function */ -function get_coursemodule_from_instance($modulename, $instance, $courseid) { +function get_coursemodule_from_instance($modulename, $instance, $courseid=0) { global $CFG; + + $courseselect = ($courseid) ? "cm.course = '$courseid' AND " : ''; return get_record_sql("SELECT cm.*, m.name FROM {$CFG->prefix}course_modules cm, {$CFG->prefix}modules md, {$CFG->prefix}$modulename m - WHERE cm.course = '$courseid' AND + WHERE $courseselect cm.deleted = '0' AND cm.instance = m.id AND md.name = '$modulename' AND -- 2.39.5