Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-28557 Calendar filters: show all group events in course to teacher

  • Loading branch information...
commit d9df0e34fc1ab8835fa8a3d489ff48dd9f5b594b 1 parent 7d3704f
@bostelm bostelm authored
Showing with 32 additions and 19 deletions.
  1. +32 −19 calendar/lib.php
View
51 calendar/lib.php
@@ -1237,6 +1237,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)) {
@@ -1262,26 +1266,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;
+ }
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.