]> git.mjollnir.org Git - moodle.git/commitdiff
accesslib: role_switch() supports unswitching by passing $roleid=0
authormartinlanghoff <martinlanghoff>
Wed, 19 Sep 2007 07:06:03 +0000 (07:06 +0000)
committermartinlanghoff <martinlanghoff>
Wed, 19 Sep 2007 07:06:03 +0000 (07:06 +0000)
It is a good idea, silly of me to remove it...

lib/accesslib.php

index 35d8aeed070751c2536daad26fbd3fea93b89056..96ae096b205f0efd64919a26acd1e24097290581 100755 (executable)
@@ -4954,6 +4954,8 @@ function get_roles_on_exact_context($context) {
  *   (hint, use get_assignable_roles())
  * - that the requested role is NOT $CFG->defaultuserroleid
  *
+ * To "unswitch" pass 0 as the roleid.
+ *
  * This function *will* modify $USER->access - beware
  * 
  * @param integer $roleid
@@ -4986,6 +4988,14 @@ function role_switch($roleid, $context) {
     // To un-switch just unset($USER->access['rsw'][$path])
     // 
 
+    if ($roleid == 0) {
+        unset($USER->access['rsw'][$context->path]);
+        if (empty($USER->access['rsw'])) {
+            unset($USER->access['rsw']);
+        }
+        return true;
+    }
+
     // Add the switch RA
     if (!isset($USER->access['rsw'])) {
         $USER->access['rsw'] = array();