Skip to content

Commit

Permalink
Fixes a bug with user events created by an activity module.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gustav_delius committed Dec 26, 2004
1 parent 6741221 commit b63c0ee
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
14 changes: 6 additions & 8 deletions calendar/lib.php
Expand Up @@ -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?
Expand All @@ -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;


Expand Down Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions lib/datalib.php
Expand Up @@ -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
Expand Down

0 comments on commit b63c0ee

Please sign in to comment.