]> git.mjollnir.org Git - moodle.git/commitdiff
Fixes a bug with user events created by an activity module.
authorgustav_delius <gustav_delius>
Sun, 26 Dec 2004 13:58:07 +0000 (13:58 +0000)
committergustav_delius <gustav_delius>
Sun, 26 Dec 2004 13:58:07 +0000 (13:58 +0000)
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
lib/datalib.php

index d2aeee4a8743933810b8e56d2038ed8ebb2e1b7c..5d206e6876d00aba96150629411e6d7962c093a2 100644 (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;
index dd81fb5d19340abd5915fee740b78d4e35720a0b..dc17f8aa5f05eb551e98b09db2e80a2fb4046405 100644 (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