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.
This commit is contained in:
gustav_delius
2004-12-26 13:58:07 +00:00
parent 6741221e34
commit b63c0ee521
2 changed files with 10 additions and 10 deletions
+6 -8
View File
@@ -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 = '<img height="16" width="16" src="'.$icon.'" alt="" title="'.$modulename.'" style="vertical-align: middle;" />';
$output[$outkey]->referer = '<a href="'.$CFG->wwwroot.'/mod/'.$event->modulename.'/view.php?id='.$module->id.'">'.$event->name.'</a>';
$output[$outkey]->time = $eventtime;
$output[$outkey]->courselink = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$event->courseid.'">'.$coursecache[$event->courseid]->fullname.'</a>';
$output[$outkey]->courselink = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$module->course.'">'.$coursecache[$module->course]->fullname.'</a>';
$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;
+4 -2
View File
@@ -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