本文整理汇总了PHP中course_enrolment_manager::assign_role_to_user方法的典型用法代码示例。如果您正苦于以下问题:PHP course_enrolment_manager::assign_role_to_user方法的具体用法?PHP course_enrolment_manager::assign_role_to_user怎么用?PHP course_enrolment_manager::assign_role_to_user使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类course_enrolment_manager
的用法示例。
在下文中一共展示了course_enrolment_manager::assign_role_to_user方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array
}
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':
$otheruserroles = optional_param('otherusers', false, PARAM_BOOL);
$outcome->response = $manager->get_assignable_roles_for_json($otheruserroles);
break;
case 'searchotherusers':
$search = optional_param('search', '', PARAM_RAW);
$page = optional_param('page', 0, PARAM_INT);
$outcome->response = $manager->search_other_users($search, $searchanywhere, $page);
$extrafields = get_extra_user_fields($context);
$useroptions = array();
// User is not enrolled, either link to site profile or do not link at all.
示例2: array
break;
/**
* Assigns a new role to a user enrolled within this course.
* A user must be enrolled in the course in order for this script to action
*/
/**
* Assigns a new role to a user enrolled within this course.
* A user must be enrolled in the course in order for this script to action
*/
case 'assign':
$user = $DB->get_record('user', array('id' => required_param('user', PARAM_INT)), '*', MUST_EXIST);
if (is_enrolled($context, $user) && has_capability('moodle/role:assign', $manager->get_context())) {
$mform = new enrol_users_assign_form(NULL, array('user' => $user, 'course' => $course, 'assignable' => $manager->get_assignable_roles()));
$mform->set_data($PAGE->url->params());
$data = $mform->get_data();
if ($mform->is_cancelled() || $data && array_key_exists($data->roleid, $manager->get_assignable_roles()) && $manager->assign_role_to_user($data->roleid, $user->id)) {
redirect($PAGE->url);
} else {
$pagetitle = get_string('assignroles', 'role');
}
$actiontaken = true;
}
break;
/**
* Removes the user from the given group
*/
/**
* Removes the user from the given group
*/
case 'removemember':
if (has_capability('moodle/course:managegroups', $manager->get_context())) {