From 1c886b238dee157d612d6155dc15ab3058f1e860 Mon Sep 17 00:00:00 2001 From: martinlanghoff Date: Wed, 19 Sep 2007 07:06:03 +0000 Subject: [PATCH] accesslib: role_switch() supports unswitching by passing $roleid=0 It is a good idea, silly of me to remove it... --- lib/accesslib.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/accesslib.php b/lib/accesslib.php index 35d8aeed07..96ae096b20 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -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(); -- 2.39.5