Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit d9df0e34fc1ab8835fa8a3d489ff48dd9f5b594b 1 parent 7d3704f
Henning Bostelmann authored October 22, 2011

Showing 1 changed file with 32 additions and 19 deletions. Show diff stats Hide diff stats

  1. 51  calendar/lib.php
51  calendar/lib.php
@@ -1237,6 +1237,10 @@ function calendar_set_filters(array $courseeventsfrom, $ignorefilters = false) {
1237 1237
     $user = false;
1238 1238
     $group = false;
1239 1239
 
  1240
+    // capabilities that allow seeing group events from all groups
  1241
+    // TODO: rewrite so that moodle/calendar:manageentries is not necessary here
  1242
+    $allgroupscaps = array('moodle/site:accessallgroups', 'moodle/calendar:manageentries');
  1243
+
1240 1244
     $isloggedin = isloggedin();
1241 1245
 
1242 1246
     if ($ignorefilters || calendar_show_event_type(CALENDAR_EVENT_COURSE)) {
@@ -1262,26 +1266,35 @@ function calendar_set_filters(array $courseeventsfrom, $ignorefilters = false) {
1262 1266
 
1263 1267
     if (!empty($courseeventsfrom) && (calendar_show_event_type(CALENDAR_EVENT_GROUP) || $ignorefilters)) {
1264 1268
 
1265  
-        if (!empty($CFG->calendar_adminseesall) && has_capability('moodle/calendar:manageentries', get_system_context())) {
1266  
-            $group = true;
1267  
-        } else if ($isloggedin) {
1268  
-            $groupids = array();
1269  
-
1270  
-            // We already have the courses to examine in $courses
1271  
-            // For each course...
1272  
-            foreach ($courseeventsfrom as $courseid => $course) {
1273  
-                // If the user is an editing teacher in there,
1274  
-                if (!empty($USER->groupmember[$course->id])) {
1275  
-                    // We've already cached the users groups for this course so we can just use that
1276  
-                    $groupids = array_merge($groupids, $USER->groupmember[$course->id]);
1277  
-                } else if (($course->groupmode != NOGROUPS || !$course->groupmodeforce) && has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_COURSE, $course->id))) {
1278  
-                    // If this course has groups, show events from all of them
1279  
-                    $coursegroups = groups_get_user_groups($course->id, $USER->id);
1280  
-                    $groupids = array_merge($groupids, $coursegroups['0']);
1281  
-                }
  1269
+        if (count($courseeventsfrom)==1) {
  1270
+            $course = reset($courseeventsfrom);
  1271
+            if (has_any_capability($allgroupscaps, get_context_instance(CONTEXT_COURSE, $course->id))) {
  1272
+                $coursegroups = groups_get_all_groups($course->id, 0, 0, 'g.id');
  1273
+                $group = array_keys($coursegroups);
1282 1274
             }
1283  
-            if (!empty($groupids)) {
1284  
-                $group = $groupids;
  1275
+        }
  1276
+        if ($group === false) {
  1277
+            if (!empty($CFG->calendar_adminseesall) && has_any_capability($allgroupscaps, get_system_context())) {
  1278
+                $group = true;
  1279
+            } else if ($isloggedin) {
  1280
+                $groupids = array();
  1281
+                
  1282
+                // We already have the courses to examine in $courses
  1283
+                // For each course...
  1284
+                foreach ($courseeventsfrom as $courseid => $course) {
  1285
+                    // If the user is an editing teacher in there,
  1286
+                    if (!empty($USER->groupmember[$course->id])) {
  1287
+                        // We've already cached the users groups for this course so we can just use that
  1288
+                        $groupids = array_merge($groupids, $USER->groupmember[$course->id]);
  1289
+                    } else if ($course->groupmode != NOGROUPS || !$course->groupmodeforce) {
  1290
+                        // If this course has groups, show events from all of those related to the current user
  1291
+                        $coursegroups = groups_get_user_groups($course->id, $USER->id);
  1292
+                        $groupids = array_merge($groupids, $coursegroups['0']);
  1293
+                    }
  1294
+                }
  1295
+                if (!empty($groupids)) {
  1296
+                    $group = $groupids;
  1297
+                }
1285 1298
             }
1286 1299
         }
1287 1300
     }

0 notes on commit d9df0e3

Please sign in to comment.
Something went wrong with that request. Please try again.