]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-10888: Groupings - add support for groupmembersonly flag.
authormattc-catalyst <mattc-catalyst>
Mon, 20 Aug 2007 21:30:40 +0000 (21:30 +0000)
committermattc-catalyst <mattc-catalyst>
Mon, 20 Aug 2007 21:30:40 +0000 (21:30 +0000)
Make the following respect the groupmembersonly flag:

- Course front page
- Activities block
- Recent Activity, including full report
- Calendar

lib/grouplib.php

index 4f3cae8eb5a298df28ed81749e86eddab3ab6968..c12a4848698db5bf89434ab4e8421d543a440a1d 100644 (file)
@@ -331,4 +331,32 @@ function groups_get_activity_group($cm, $update=false) {
     return $SESSION->activegroup[$cm->course][$groupmode][$cm->groupingid];
 }
 
+/**
+ * Determine if a course module is currently visible to a user
+ * @uses $USER If $userid is null, use the global object.
+ * @param int $cm The course module
+ * @param int $userid The user to check against the group.
+ * @return boolean True if the user can view the course module, false otherwise.
+ */
+function groups_course_module_visible($cm, $userid=null) {
+    global $CFG, $USER;
+    
+    if (empty($userid)) {
+        $userid = $USER->id;
+    }
+    if (empty($CFG->enablegroupings)) {
+        return(true);
+    }
+    if (empty($cm->groupmembersonly)) {
+        return(true);
+    }
+    if (has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_MODULE, $cm->id), $userid)) {
+        return(true);
+    }
+    if (groups_has_membership($cm, $userid)) {
+        return(true);
+    }
+    return(false);
+}
+
 ?>