本文整理汇总了PHP中course_enrolment_manager::unassign_role_from_user方法的典型用法代码示例。如果您正苦于以下问题:PHP course_enrolment_manager::unassign_role_from_user方法的具体用法?PHP course_enrolment_manager::unassign_role_from_user怎么用?PHP course_enrolment_manager::unassign_role_from_user使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类course_enrolment_manager
的用法示例。
在下文中一共展示了course_enrolment_manager::unassign_role_from_user方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: stdClass
$outcome->success = true;
$outcome->response = new stdClass();
$outcome->error = '';
$searchanywhere = get_user_preferences('userselector_searchanywhere', false);
switch ($action) {
case 'unenrol':
$ue = $DB->get_record('user_enrolments', array('id' => required_param('ue', PARAM_INT)), '*', MUST_EXIST);
list($instance, $plugin) = $manager->get_user_enrolment_components($ue);
if (!$instance || !$plugin || !enrol_is_enabled($instance->enrol) || !$plugin->allow_unenrol_user($instance, $ue) || !has_capability("enrol/{$instance->enrol}:unenrol", $manager->get_context()) || !$manager->unenrol_user($ue)) {
throw new enrol_ajax_exception('unenrolnotpermitted');
}
break;
case 'unassign':
$role = required_param('role', PARAM_INT);
$user = required_param('user', PARAM_INT);
if (!has_capability('moodle/role:assign', $manager->get_context()) || !$manager->unassign_role_from_user($user, $role)) {
throw new enrol_ajax_exception('unassignnotpermitted');
}
break;
case 'assign':
$user = $DB->get_record('user', array('id' => required_param('user', PARAM_INT)), '*', MUST_EXIST);
$roleid = required_param('roleid', PARAM_INT);
if (!array_key_exists($roleid, $manager->get_assignable_roles())) {
throw new enrol_ajax_exception('invalidrole');
}
if (!has_capability('moodle/role:assign', $manager->get_context()) || !$manager->assign_role_to_user($roleid, $user->id)) {
throw new enrol_ajax_exception('assignnotpermitted');
}
$outcome->response->roleid = $roleid;
break;
case 'getassignable':
示例2: switch
// Check if the page is confirmed (and sesskey is correct)
$confirm = optional_param('confirm', false, PARAM_BOOL) && confirm_sesskey();
$actiontaken = false;
$pagetitle = '';
$pageheading = '';
$mform = null;
$pagecontent = null;
switch ($action) {
/**
* Removes a role from the user with this course
*/
case 'unassign':
if (has_capability('moodle/role:assign', $manager->get_context())) {
$role = required_param('roleid', PARAM_INT);
$user = required_param('user', PARAM_INT);
if ($confirm && $manager->unassign_role_from_user($user, $role)) {
redirect($PAGE->url);
} else {
$user = $DB->get_record('user', array('id' => $user), '*', MUST_EXIST);
$allroles = $manager->get_all_roles();
$role = $allroles[$role];
$yesurl = new moodle_url($PAGE->url, array('action' => 'unassign', 'roleid' => $role->id, 'user' => $user->id, 'confirm' => 1, 'sesskey' => sesskey()));
$message = get_string('unassignconfirm', 'role', array('user' => fullname($user, true), 'role' => $role->localname));
$pagetitle = get_string('unassignarole', 'role', $role->localname);
$pagecontent = $OUTPUT->confirm($message, $yesurl, $PAGE->url);
}
$actiontaken = true;
}
break;
/**
* Assigns a new role to a user enrolled within this course.