mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 14:27:22 +01:00
More flexible role_unassign() that allows setting of any combination of arguments
This commit is contained in:
parent
a70b3fbb4c
commit
1dc1f03795
@ -1162,20 +1162,26 @@ 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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user