]> git.mjollnir.org Git - moodle.git/commitdiff
More flexible role_unassign() that allows setting of any combination of arguments
authormoodler <moodler>
Fri, 1 Sep 2006 06:10:45 +0000 (06:10 +0000)
committermoodler <moodler>
Fri, 1 Sep 2006 06:10:45 +0000 (06:10 +0000)
lib/accesslib.php

index b2db35c2e1c4d4ea419fc95daf38ae381538de00..122eb277ebed16a6ed0723f31456fe2264c4e05d 100755 (executable)
@@ -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
+?>