本文整理汇总了PHP中course_enrolment_manager::get_all_groups方法的典型用法代码示例。如果您正苦于以下问题:PHP course_enrolment_manager::get_all_groups方法的具体用法?PHP course_enrolment_manager::get_all_groups怎么用?PHP course_enrolment_manager::get_all_groups使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类course_enrolment_manager
的用法示例。
在下文中一共展示了course_enrolment_manager::get_all_groups方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array
$pagecontent = $OUTPUT->confirm($message, $yesurl, $PAGE->url);
}
$actiontaken = true;
}
break;
/**
* Makes the user a member of a given group
*/
/**
* Makes the user a member of a given group
*/
case 'addmember':
if (has_capability('moodle/course:managegroups', $manager->get_context())) {
$userid = required_param('user', PARAM_INT);
$user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
$mform = new enrol_users_addmember_form(NULL, array('user' => $user, 'course' => $course, 'allgroups' => $manager->get_all_groups()));
$mform->set_data($PAGE->url->params());
$data = $mform->get_data();
if ($mform->is_cancelled() || $data && $manager->add_user_to_group($user, $data->groupid)) {
redirect($PAGE->url);
} else {
$pagetitle = get_string('addgroup', 'group');
}
$actiontaken = true;
}
break;
/**
* Edits the details of a users enrolment in the course
*/
/**
* Edits the details of a users enrolment in the course
示例2: array
$pagecontent = $OUTPUT->confirm($message, $yesurl, $PAGE->url);
}
$actiontaken = true;
}
break;
/**
* Makes the user a member of a given group
*/
/**
* Makes the user a member of a given group
*/
case 'addmember':
if (has_capability('moodle/course:managegroups', $manager->get_context())) {
$userid = required_param('user', PARAM_INT);
$user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
$mform = new enrol_users_addmember_form(NULL, array('user' => $user, 'course' => $course, 'allgroups' => $manager->get_all_groups()));
$mform->set_data($PAGE->url->params());
$data = $mform->get_data();
if ($mform->is_cancelled()) {
redirect($PAGE->url);
}
if (!empty($data->groupids)) {
foreach ($data->groupids as $groupid) {
$manager->add_user_to_group($user, $groupid);
}
redirect($PAGE->url);
} else {
$pagetitle = get_string('addgroup', 'group');
}
$actiontaken = true;
}
示例3: process_uploaded_groups
/**
* enrol and add user to groups in course
* @param object $course
* @param csv_import_reader $reader
* @param int $roleid
*/
public function process_uploaded_groups($course, $reader, $roleid)
{
global $DB, $PAGE;
$usercol = null;
// Index of username column.
$groupcol = null;
// Index of group column.
// Find the index of the needed columns.
$i = 0;
foreach ($reader->get_columns() as $col) {
$col = strtoupper(trim($col));
switch ($col) {
case 'USERNAME':
$usercol = $i;
break;
case 'GROUP':
$groupcol = $i;
break;
}
$i++;
}
// Get the manual enrolment plugin.
$enrolinstances = enrol_get_instances($course->id, true);
$manualinstance = null;
foreach ($enrolinstances as $instance) {
if ($instance->enrol == 'manual') {
$manualinstance = $instance;
break;
}
}
$manualenroler = enrol_get_plugin('manual');
// Get the list of enrolled users for the course.
$manager = new course_enrolment_manager($PAGE, $course);
$totalusers = $manager->get_total_users();
/*
* Since the number of fields being retrieved are limited (email, id, lastaccess, and lastseen),
* I feel comfortable retrieving the entire enrolled userbase for this course.
*/
$users = $manager->get_users('firstname', 'ASC', 0, $totalusers);
$groups = $manager->get_all_groups();
$groupids = array();
foreach ($groups as $group) {
$groupids[$group->name] = $group->id;
}
// Prep the returned array.
$output = array('group_created' => array(), 'user_enrolled' => array(), 'member_added' => array(), 'error' => array('user_not_found' => array(), 'group_failed' => array(), 'enrol_failed' => array(), 'member_failed' => array(), 'user_not_added' => array()));
// Loop through the records.
$reader->init();
while ($line = $reader->next()) {
$username = trim($line[$usercol]);
$groupname = trim($line[$groupcol]);
// Check if the user exists.
$user = $DB->get_record('user', array('username' => $username));
if ($user === false) {
$output['error']['user_not_found'][] = $username;
continue;
}
// Enroll the user as needed.
if (!isset($users[$user->id])) {
try {
$manualenroler->enrol_user($manualinstance, $user->id, $roleid);
$output['user_enrolled'][] = $username;
} catch (Exception $e) {
$output['error']['enroll_failed'][] = $username;
}
}
// Create the group as needed.
if (!isset($groupids[$groupname])) {
if ($groupname != '') {
$data = new stdClass();
$data->courseid = $course->id;
$data->name = $groupname;
$newgroupid = groups_create_group($data);
} else {
$newgroupid = false;
}
if ($newgroupid === false) {
if ($groupname != '') {
$output['error']['group_failed'][] = $groupname;
}
} else {
$groupids[$groupname] = $newgroupid;
$output['group_created'][] = $groupname;
}
}
// Add the user to the group.
if ($groupname != '') {
if (groups_add_member($groupids[$groupname], $user->id)) {
if (!isset($output['member_added'][$groupname])) {
$output['member_added'][$groupname] = array();
}
$output['member_added'][$groupname][] = $username;
} else {
if (!isset($output['error']['member_failed'][$groupname])) {
//.........这里部分代码省略.........