MDL-56120 calendar: Fix disabled modules showing events.

calendar_get_events now checks for disabled activities
and only shows events for active modules.
This commit is contained in:
Adrian Greeve 2016-11-04 12:49:34 +08:00
parent 7eb34671c1
commit 7a33494d71

View File

@ -737,12 +737,12 @@ function calendar_get_events($tstart, $tend, $users, $groups, $courses, $withdur
// Events from a number of users
if(!empty($whereclause)) $whereclause .= ' OR';
list($insqlusers, $inparamsusers) = $DB->get_in_or_equal($users, SQL_PARAMS_NAMED);
$whereclause .= " (userid $insqlusers AND courseid = 0 AND groupid = 0)";
$whereclause .= " (e.userid $insqlusers AND e.courseid = 0 AND e.groupid = 0)";
$params = array_merge($params, $inparamsusers);
} else if($users === true) {
// Events from ALL users
if(!empty($whereclause)) $whereclause .= ' OR';
$whereclause .= ' (userid != 0 AND courseid = 0 AND groupid = 0)';
$whereclause .= ' (e.userid != 0 AND e.courseid = 0 AND e.groupid = 0)';
} else if($users === false) {
// No user at all, do nothing
}
@ -751,24 +751,24 @@ function calendar_get_events($tstart, $tend, $users, $groups, $courses, $withdur
// Events from a number of groups
if(!empty($whereclause)) $whereclause .= ' OR';
list($insqlgroups, $inparamsgroups) = $DB->get_in_or_equal($groups, SQL_PARAMS_NAMED);
$whereclause .= " groupid $insqlgroups ";
$whereclause .= " e.groupid $insqlgroups ";
$params = array_merge($params, $inparamsgroups);
} else if($groups === true) {
// Events from ALL groups
if(!empty($whereclause)) $whereclause .= ' OR ';
$whereclause .= ' groupid != 0';
$whereclause .= ' e.groupid != 0';
}
// boolean false (no groups at all): we don't need to do anything
if ((is_array($courses) && !empty($courses)) or is_numeric($courses)) {
if(!empty($whereclause)) $whereclause .= ' OR';
list($insqlcourses, $inparamscourses) = $DB->get_in_or_equal($courses, SQL_PARAMS_NAMED);
$whereclause .= " (groupid = 0 AND courseid $insqlcourses)";
$whereclause .= " (e.groupid = 0 AND e.courseid $insqlcourses)";
$params = array_merge($params, $inparamscourses);
} else if ($courses === true) {
// Events from ALL courses
if(!empty($whereclause)) $whereclause .= ' OR';
$whereclause .= ' (groupid = 0 AND courseid != 0)';
$whereclause .= ' (e.groupid = 0 AND e.courseid != 0)';
}
// Security check: if, by now, we have NOTHING in $whereclause, then it means
@ -780,10 +780,10 @@ function calendar_get_events($tstart, $tend, $users, $groups, $courses, $withdur
}
if($withduration) {
$timeclause = '(timestart >= '.$tstart.' OR timestart + timeduration > '.$tstart.') AND timestart <= '.$tend;
$timeclause = '(e.timestart >= '.$tstart.' OR e.timestart + e.timeduration > '.$tstart.') AND e.timestart <= '.$tend;
}
else {
$timeclause = 'timestart >= '.$tstart.' AND timestart <= '.$tend;
$timeclause = 'e.timestart >= '.$tstart.' AND e.timestart <= '.$tend;
}
if(!empty($whereclause)) {
// We have additional constraints
@ -795,10 +795,17 @@ function calendar_get_events($tstart, $tend, $users, $groups, $courses, $withdur
}
if ($ignorehidden) {
$whereclause .= ' AND visible = 1';
$whereclause .= ' AND e.visible = 1';
}
$events = $DB->get_records_select('event', $whereclause, $params, 'timestart');
$sql = "SELECT e.*
FROM {event} e
LEFT JOIN {modules} m ON e.modulename = m.name
-- Non visible modules will have a value of 0.
WHERE (m.visible = 1 OR m.visible IS NULL) AND $whereclause
ORDER BY e.timestart";
$events = $DB->get_records_sql($sql, $params);
if ($events === false) {
$events = array();
}