本文整理汇总了PHP中course_enrolment_manager::unenrol_user方法的典型用法代码示例。如果您正苦于以下问题:PHP course_enrolment_manager::unenrol_user方法的具体用法?PHP course_enrolment_manager::unenrol_user怎么用?PHP course_enrolment_manager::unenrol_user使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类course_enrolment_manager
的用法示例。
在下文中一共展示了course_enrolment_manager::unenrol_user方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: stdClass
require_login($course);
require_capability('moodle/course:enrolreview', $context);
require_sesskey();
echo $OUTPUT->header();
// send headers
$manager = new course_enrolment_manager($PAGE, $course);
$outcome = new 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');
示例2: array
$table = new course_enrolment_users_table($manager, $PAGE);
// The URL of the enrolled users page for the course.
$usersurl = new moodle_url('/enrol/users.php', array('id' => $course->id));
// The URl to return the user too after this screen.
$returnurl = new moodle_url($usersurl, $manager->get_url_params() + $table->get_url_params());
// The URL of this page
$url = new moodle_url('/enrol/globalclassroom/unenroluser.php', $returnurl->params());
$url->param('ue', $ueid);
$PAGE->set_url($url);
$PAGE->set_pagelayout('admin');
navigation_node::override_active_url($usersurl);
list($instance, $plugin) = $manager->get_user_enrolment_components($ue);
if (!$plugin->allow_unenrol($instance) || $instance->enrol != 'globalclassroom' || !$plugin instanceof enrol_globalclassroom_plugin) {
print_error('erroreditenrolment', 'enrol');
}
// If the unenrolment has been confirmed and the sesskey is valid unenrol the user.
if ($confirm && confirm_sesskey() && $manager->unenrol_user($ue)) {
redirect($returnurl);
}
$yesurl = new moodle_url($PAGE->url, array('confirm' => 1, 'sesskey' => sesskey()));
$message = get_string('unenroluser', 'enrol_globalclassroom', array('user' => fullname($user, true), 'course' => format_string($course->fullname)));
$fullname = fullname($user);
$title = get_string('unenrol', 'enrol_globalclassroom');
$PAGE->set_title($title);
$PAGE->set_heading($title);
$PAGE->navbar->add($title);
$PAGE->navbar->add($fullname);
echo $OUTPUT->header();
echo $OUTPUT->heading($fullname);
echo $OUTPUT->confirm($message, $yesurl, $returnurl);
echo $OUTPUT->footer();
示例3: 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) {
/**
* Unenrols a user from this course (including removing all of their grades)
*/
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 && $plugin->allow_unenrol($instance) && has_capability("enrol/{$instance->enrol}:unenrol", $manager->get_context())) {
if ($confirm && $manager->unenrol_user($ue)) {
redirect($PAGE->url);
} else {
$user = $DB->get_record('user', array('id' => $ue->userid), '*', MUST_EXIST);
$yesurl = new moodle_url($PAGE->url, array('action' => 'unenrol', 'ue' => $ue->id, 'confirm' => 1, 'sesskey' => sesskey()));
$message = get_string('unenrolconfirm', 'enrol', array('user' => fullname($user, true), 'course' => format_string($course->fullname)));
$pagetitle = get_string('unenrol', 'enrol');
$pagecontent = $OUTPUT->confirm($message, $yesurl, $PAGE->url);
}
$actiontaken = true;
}
break;
/**
* Removes a role from the user with this course
*/
/**
示例4: unenrol
/**
* Unenrol a user from a courses
* @param object $user
* @param array $courseids
* @param int $companyid
* @return void
*/
public static function unenrol($user, $courseids, $companyid = null)
{
global $DB, $PAGE;
foreach ($courseids as $courseid) {
if (!$DB->get_record('iomad_courses', array('courseid' => $courseid, 'shared' => 0))) {
$shared = true;
} else {
$shared = false;
}
$course = $DB->get_record('course', array('id' => $courseid));
$courseenrolmentmanager = new course_enrolment_manager($PAGE, $course);
$ues = $courseenrolmentmanager->get_user_enrolments($user->id);
foreach ($ues as $ue) {
if ($ue->enrolmentinstance->courseid == $courseid) {
$courseenrolmentmanager->unenrol_user($ue);
if ($shared) {
if (!empty($companyid)) {
company::remove_user_from_shared_course($courseid, $user->id, $companyid);
}
}
}
}
}
}
示例5: unenroll_all
private function unenroll_all($id)
{
global $DB, $PAGE;
// Unenroll everybody from given course.
// Get list of enrollments.
$course = $DB->get_record('course', array('id' => $id));
$courseenrolment = new course_enrolment_manager($PAGE, $course);
$userlist = $courseenrolment->get_users('', 'ASC', 0, 0);
foreach ($userlist as $user) {
$ues = $courseenrolment->get_user_enrolments($user->id);
foreach ($ues as $ue) {
$courseenrolment->unenrol_user($ue);
}
}
}