mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 14:27:22 +01:00
Merge branch 'MDL-28557' of git://github.com/bostelm/moodle
This commit is contained in:
commit
ccee3cd67f
@ -1352,6 +1352,10 @@ function calendar_set_filters(array $courseeventsfrom, $ignorefilters = false) {
|
||||
$user = false;
|
||||
$group = false;
|
||||
|
||||
// capabilities that allow seeing group events from all groups
|
||||
// TODO: rewrite so that moodle/calendar:manageentries is not necessary here
|
||||
$allgroupscaps = array('moodle/site:accessallgroups', 'moodle/calendar:manageentries');
|
||||
|
||||
$isloggedin = isloggedin();
|
||||
|
||||
if ($ignorefilters || calendar_show_event_type(CALENDAR_EVENT_COURSE)) {
|
||||
@ -1377,26 +1381,35 @@ function calendar_set_filters(array $courseeventsfrom, $ignorefilters = false) {
|
||||
|
||||
if (!empty($courseeventsfrom) && (calendar_show_event_type(CALENDAR_EVENT_GROUP) || $ignorefilters)) {
|
||||
|
||||
if (!empty($CFG->calendar_adminseesall) && has_capability('moodle/calendar:manageentries', get_system_context())) {
|
||||
$group = true;
|
||||
} else if ($isloggedin) {
|
||||
$groupids = array();
|
||||
|
||||
// We already have the courses to examine in $courses
|
||||
// For each course...
|
||||
foreach ($courseeventsfrom as $courseid => $course) {
|
||||
// If the user is an editing teacher in there,
|
||||
if (!empty($USER->groupmember[$course->id])) {
|
||||
// We've already cached the users groups for this course so we can just use that
|
||||
$groupids = array_merge($groupids, $USER->groupmember[$course->id]);
|
||||
} else if (($course->groupmode != NOGROUPS || !$course->groupmodeforce) && has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_COURSE, $course->id))) {
|
||||
// If this course has groups, show events from all of them
|
||||
$coursegroups = groups_get_user_groups($course->id, $USER->id);
|
||||
$groupids = array_merge($groupids, $coursegroups['0']);
|
||||
}
|
||||
if (count($courseeventsfrom)==1) {
|
||||
$course = reset($courseeventsfrom);
|
||||
if (has_any_capability($allgroupscaps, get_context_instance(CONTEXT_COURSE, $course->id))) {
|
||||
$coursegroups = groups_get_all_groups($course->id, 0, 0, 'g.id');
|
||||
$group = array_keys($coursegroups);
|
||||
}
|
||||
if (!empty($groupids)) {
|
||||
$group = $groupids;
|
||||
}
|
||||
if ($group === false) {
|
||||
if (!empty($CFG->calendar_adminseesall) && has_any_capability($allgroupscaps, get_system_context())) {
|
||||
$group = true;
|
||||
} else if ($isloggedin) {
|
||||
$groupids = array();
|
||||
|
||||
// We already have the courses to examine in $courses
|
||||
// For each course...
|
||||
foreach ($courseeventsfrom as $courseid => $course) {
|
||||
// If the user is an editing teacher in there,
|
||||
if (!empty($USER->groupmember[$course->id])) {
|
||||
// We've already cached the users groups for this course so we can just use that
|
||||
$groupids = array_merge($groupids, $USER->groupmember[$course->id]);
|
||||
} else if ($course->groupmode != NOGROUPS || !$course->groupmodeforce) {
|
||||
// If this course has groups, show events from all of those related to the current user
|
||||
$coursegroups = groups_get_user_groups($course->id, $USER->id);
|
||||
$groupids = array_merge($groupids, $coursegroups['0']);
|
||||
}
|
||||
}
|
||||
if (!empty($groupids)) {
|
||||
$group = $groupids;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user