From: moodler Date: Fri, 1 Sep 2006 06:10:45 +0000 (+0000) Subject: More flexible role_unassign() that allows setting of any combination of arguments X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=1dc1f0379599202fc1c225d65d110f8e889c4dcd;p=moodle.git More flexible role_unassign() that allows setting of any combination of arguments --- diff --git a/lib/accesslib.php b/lib/accesslib.php index b2db35c2e1..122eb277eb 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -1162,19 +1162,25 @@ function role_assign($roleid, $userid, $groupid, $contextid, $timestart=0, $time /** - * Deletes a role assignment. + * Deletes one or more role assignments. You must specify at least one parameter. * @param $roleid * @param $userid * @param $groupid * @param $contextid * @return boolean - success or failure */ -function role_unassign($roleid, $userid, $groupid, $contextid) { - if ($groupid && empty($userid)) { - return delete_records('role_assignments', 'groupid', $groupid, 'roleid', $roleid, 'contextid', $contextid); - } else { - return delete_records('role_assignments', 'userid', $userid, 'roleid', $roleid, 'contextid', $contextid); - } +function role_unassign($roleid=0, $userid=0, $groupid=0, $contextid=0) { + $args = array('roleid', 'userid', 'groupid', 'contextid'); + $select = array(); + foreach ($args as $arg) { + if ($$arg) { + $select[] = $arg.' = '.$$arg; + } + } + if ($select) { + return delete_records_select('role_assignments', implode(' AND ', $select)); + } + return false; } @@ -1921,4 +1927,4 @@ function get_users_by_capability($context, $capability, $fields='distinct u.*', return get_records_sql($select.$from.$where); } -?> \ No newline at end of file +?>