/** * Gets a list of roles that this user can override in this context * @param object $context * @return array */ function get_overridable_roles($context) { $options = array(); if ($roles = get_all_roles()) { foreach ($roles as $role) { if (user_can_override($context, $role->id)) { $options[$role->id] = strip_tags(format_string($role->name, true)); } } } return $options; }
$baseurl .= '&courseid=' . $courseid; } if ($cancel) { redirect($baseurl); } /// needed for tabs.php $overridableroles = get_overridable_roles($context); $assignableroles = get_assignable_roles($context); /// Get some language strings $strroletooverride = get_string('roletooverride', 'role'); $straction = get_string('overrideroles', 'role'); $strcurrentrole = get_string('currentrole', 'role'); $strparticipants = get_string('participants'); /// Make sure this user can override that role if ($roleid) { if (!user_can_override($context, $roleid)) { error('you can not override this role in this context'); } } if ($userid) { $user = get_record('user', 'id', $userid); $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $context)); } /// get all cababilities $capabilities = fetch_context_capabilities($context); /// Process incoming role override if ($data = data_submitted() and $roleid and confirm_sesskey()) { $allowed_values = array(CAP_INHERIT, CAP_ALLOW, CAP_PREVENT, CAP_PROHIBIT); $localoverrides = get_records_select('role_capabilities', "roleid = {$roleid} AND contextid = {$context->id}", '', 'capability, permission, id'); foreach ($capabilities as $cap) { if (!isset($data->{$cap->name})) {
/** * Gets a list of roles that this user can override in this context * @param object $context * @return array */ function get_overridable_roles($context, $field = 'name', $rolenamedisplay = ROLENAME_ALIAS) { $options = array(); if ($roles = get_all_roles()) { foreach ($roles as $role) { if (user_can_override($context, $role->id)) { $options[$role->id] = $role->{$field}; } } } return role_fix_names($options, $context, $rolenamedisplay); }