]> git.mjollnir.org Git - moodle.git/commitdiff
Added course module groupmodes in convertion to roles logic
authorvyshane <vyshane>
Wed, 20 Sep 2006 16:54:50 +0000 (16:54 +0000)
committervyshane <vyshane>
Wed, 20 Sep 2006 16:54:50 +0000 (16:54 +0000)
mod/forum/lib.php
mod/forum/restorelib.php

index e1d6384f7ae531528359d0a837241de419f2b824..12c87dfd5405f3828507a0f5e98b753c7afaf780 100644 (file)
@@ -4448,14 +4448,14 @@ function forum_reset_course_form($course) {
  * @param $forum        - a forum object with the same attributes as a record
  *                        from the forum database table
  * @param $forummodid   - the id of the forum module, from the modules table
- * @param $studentroles - array of roles that have the moodle/legacy:student
- *                        capability
- * @param $guestroles   - array of roles that have the moodle/legacy:guest
- *                        capability
+ * @param $teacherroles - array of roles that have moodle/legacy:teacher
+ * @param $studentroles - array of roles that have moodle/legacy:student
+ * @param $guestroles   - array of roles that have moodle/legacy:guest
  * @param $cmid         - the course_module id for this forum instance
  * @return boolean      - forum was converted or not
  */
-function forum_convert_to_roles($forum, $forummodid, $teacherroles=array(), $studentroles=array(), $guestroles=array(), $cmid=NULL) {
+function forum_convert_to_roles($forum, $forummodid, $teacherroles=array(),
+                                $studentroles=array(), $guestroles=array(), $cmid=NULL) {
     
     global $CFG;
     
@@ -4634,6 +4634,35 @@ function forum_convert_to_roles($forum, $forummodid, $teacherroles=array(), $stu
                 }
                 break;
         }
+        
+        if (empty($cm)) {
+            $cm = get_record('course_modules', 'id', $cmid);
+        }
+
+        // $cm->groupmode:
+        // 0 - No groups
+        // 1 - Separate groups
+        // 2 - Visible groups
+        switch ($cm->groupmode) {
+            case 0:
+                break;
+            case 1:
+                foreach ($studentroles as $studentrole) {
+                    assign_capability('moodle/site:accessallgroups', CAP_PREVENT, $studentrole->id, $context->id);
+                }
+                foreach ($teacherroles as $teacherrole) {
+                    assign_capability('moodle/site:accessallgroups', CAP_ALLOW, $teacherrole->id, $context->id);
+                }
+                break;
+            case 2:
+                foreach ($studentroles as $studentrole) {
+                    assign_capability('moodle/site:accessallgroups', CAP_ALLOW, $studentrole->id, $context->id);
+                }
+                foreach ($teacherroles as $teacherrole) {
+                    assign_capability('moodle/site:accessallgroups', CAP_ALLOW, $teacherrole->id, $context->id);
+                }
+                break;
+        }
     }
     return true;
 }
index 806b6f36c2666745a12faf08ddce11ff3dda08ab..90574083fa0eab6c267c0dd9daec6fa83fc8439c 100644 (file)
             // we need to convert the forum to use Roles. It means the backup
             // was made pre Moodle 1.7. We check the backup_version to make
             // sure.
-            if (($restore->backup_version < 2006082300) ||
-                            (isset($forum->open) && isset($forum->assesspublic))) {
-                
+            if (isset($forum->open) && isset($forum->assesspublic)) {
+            
                 $forummod = get_record('modules', 'name', 'forum');
                 
                 if (!$teacherroles = get_roles_with_capability('moodle/legacy:teacher', CAP_ALLOW)) {