本文整理汇总了PHP中course_enrolment_manager::get_users方法的典型用法代码示例。如果您正苦于以下问题:PHP course_enrolment_manager::get_users方法的具体用法?PHP course_enrolment_manager::get_users怎么用?PHP course_enrolment_manager::get_users使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类course_enrolment_manager
的用法示例。
在下文中一共展示了course_enrolment_manager::get_users方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_course_user_ids
protected function get_course_user_ids()
{
global $DB, $PAGE;
if (!isset($this->courseid)) {
return array();
} else {
$course = $DB->get_record('course', array('id' => $this->courseid));
$courseenrolmentmanager = new course_enrolment_manager($PAGE, $course);
$users = $courseenrolmentmanager->get_users('lastname', $perpage = 0);
// Only return the keys (user ids).
return array_keys($users);
}
}
示例2: array
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @version Moodle 2.0
*/
// security
if (!defined('MOODLE_INTERNAL')) {
print_error('errorillegaldirectaccess', 'flashcard');
}
if ($action == 'reset') {
$userid = required_param('userid', PARAM_INT);
$DB->delete_records('flashcard_card', array('flashcardid' => $flashcard->id, 'userid' => $userid));
}
require_once $CFG->dirroot . '/enrol/locallib.php';
$course_context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
$course = $DB->get_record('course', array('id' => $COURSE->id), '*', MUST_EXIST);
$manager = new course_enrolment_manager($PAGE, $course);
$courseusers = $manager->get_users('lastname', 'ASC', 0, 250);
$struser = get_string('username');
$strdeckstates = get_string('deckstates', 'flashcard');
$strcounts = get_string('counters', 'flashcard');
$table = new html_table();
$table->head = array("<b>{$struser}</b>", "<b>{$strdeckstates}</b>", "<b>{$strcounts}</b>");
$table->size = array('30%', '50%', '20%');
$table->width = '90%';
echo $out;
if (!empty($courseusers)) {
foreach ($courseusers as $auser) {
$status = flashcard_get_deck_status($flashcard, $auser->id);
$userbox = $OUTPUT->user_picture($auser);
$userbox .= fullname($auser);
if ($status) {
$flashcard->cm =& $cm;
示例3: test_get_users
/**
* Verify get_users() returned number of users expected in every situation.
*/
public function test_get_users()
{
global $PAGE;
$this->resetAfterTest();
// All users filtering.
$manager = new course_enrolment_manager($PAGE, $this->course);
$users = $manager->get_users('id');
$this->assertCount(6, $users, 'All users must be returned when no filtering is applied.');
$this->assertArrayHasKey($this->users['user0']->id, $users);
$this->assertArrayHasKey($this->users['user1']->id, $users);
$this->assertArrayHasKey($this->users['user21']->id, $users);
$this->assertArrayHasKey($this->users['user22']->id, $users);
$this->assertArrayHasKey($this->users['userall']->id, $users);
$this->assertArrayHasKey($this->users['usertch']->id, $users);
// Student role filtering.
$manager = new course_enrolment_manager($PAGE, $this->course, null, 5);
$users = $manager->get_users('id');
$this->assertCount(5, $users, 'Only students must be returned when student role filtering is applied.');
$this->assertArrayHasKey($this->users['user0']->id, $users);
$this->assertArrayHasKey($this->users['user1']->id, $users);
$this->assertArrayHasKey($this->users['user21']->id, $users);
$this->assertArrayHasKey($this->users['user22']->id, $users);
$this->assertArrayHasKey($this->users['userall']->id, $users);
// Teacher role filtering.
$manager = new course_enrolment_manager($PAGE, $this->course, null, 3);
$users = $manager->get_users('id');
$this->assertCount(1, $users, 'Only teacher must be returned when teacher role filtering is applied.');
$this->assertArrayHasKey($this->users['usertch']->id, $users);
// Search user filtering.
$manager = new course_enrolment_manager($PAGE, $this->course, null, 0, 'userall');
$users = $manager->get_users('id');
$this->assertCount(1, $users, 'Only searchable user must be returned when search filtering is applied.');
$this->assertArrayHasKey($this->users['userall']->id, $users);
// Group 1 filtering.
$manager = new course_enrolment_manager($PAGE, $this->course, null, 0, '', $this->groups['group1']->id);
$users = $manager->get_users('id');
$this->assertCount(2, $users, 'Only group members must be returned when group filtering is applied.');
$this->assertArrayHasKey($this->users['user1']->id, $users);
$this->assertArrayHasKey($this->users['userall']->id, $users);
// Group 2 filtering.
$manager = new course_enrolment_manager($PAGE, $this->course, null, 0, '', $this->groups['group2']->id);
$users = $manager->get_users('id');
$this->assertCount(3, $users, 'Only group members must be returned when group filtering is applied.');
$this->assertArrayHasKey($this->users['user21']->id, $users);
$this->assertArrayHasKey($this->users['user22']->id, $users);
$this->assertArrayHasKey($this->users['userall']->id, $users);
// 'No groups' filtering.
$manager = new course_enrolment_manager($PAGE, $this->course, null, 0, '', -1);
$users = $manager->get_users('id');
$this->assertCount(2, $users, 'Only non-group members must be returned when \'no groups\' filtering is applied.');
$this->assertArrayHasKey($this->users['user0']->id, $users);
$this->assertArrayHasKey($this->users['usertch']->id, $users);
// Active users filtering.
$manager = new course_enrolment_manager($PAGE, $this->course, null, 0, '', 0, ENROL_USER_ACTIVE);
$users = $manager->get_users('id');
$this->assertCount(5, $users, 'Only active users must be returned when active users filtering is applied.');
$this->assertArrayHasKey($this->users['user0']->id, $users);
$this->assertArrayHasKey($this->users['user1']->id, $users);
$this->assertArrayHasKey($this->users['user21']->id, $users);
$this->assertArrayHasKey($this->users['userall']->id, $users);
$this->assertArrayHasKey($this->users['usertch']->id, $users);
// Suspended users filtering.
$manager = new course_enrolment_manager($PAGE, $this->course, null, 0, '', 0, ENROL_USER_SUSPENDED);
$users = $manager->get_users('id');
$this->assertCount(1, $users, 'Only suspended users must be returned when suspended users filtering is applied.');
$this->assertArrayHasKey($this->users['user22']->id, $users);
}
示例4: IN
if ($currentgroup) {
/*
$sql = "SELECT u.*
FROM {role_assignments} ra, {user} u, {course} c, {context} cxt
WHERE ra.userid = u.id
AND ra.contextid = cxt.id
AND cxt.contextlevel = 50
AND cxt.instanceid = c.id
AND c.id = ?
AND roleid =5
AND u.id IN (SELECT userid FROM {groups_members} gm WHERE gm.groupid = ?)
ORDER BY u.$sort ASC";
$params = array($cm->course, $currentgroup);
$students = $DB->get_records_sql($sql, $params);
*/
$students = $manager->get_users($sort);
// FIXME add $currentgroup somehow
} else {
$students = $manager->get_users($sort);
}
$sort = $sort == 'firstname' ? 'firstname' : 'lastname';
/// Now we need a menu for separategroups as well!
if ($groupmode == VISIBLEGROUPS || $groupmode && has_capability('moodle/site:accessallgroups', $context)) {
groups_print_activity_menu($cm, $CFG->wwwroot . "/mod/attforblock/attendances.php?id={$id}&sessionid={$sessionid}&sort={$sort}");
}
$statuses = get_statuses($course->id);
if (count($statuses) == 0) {
// maybe we don't have them set yet? no sense in doing everything else
echo '<p>';
echo get_string('settingsareempty', 'attforblock');
echo ': <a href="attsettings.php?id=' . $cm->id . '">' . get_string('settings', 'attforblock') . '</a>';
示例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);
}
}
}
示例6: 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])) {
//.........这里部分代码省略.........
示例7: IN
if ($currentgroup) {
/*
$sql = "SELECT u.*
FROM {role_assignments} ra, {user} u, {course} c, {context} cxt
WHERE ra.userid = u.id
AND ra.contextid = cxt.id
AND cxt.contextlevel = 50
AND cxt.instanceid = c.id
AND c.id = ?
AND roleid =5
AND u.id IN (SELECT userid FROM {groups_members} gm WHERE gm.groupid = ?)
ORDER BY u.$sort ASC";
$params = array($cm->course, $currentgroup);
$students = $DB->get_records_sql($sql, $params);
*/
$students = $manager->get_users('lastname');
// FIXME add $currentgroup somehow
} else {
$students = $manager->get_users('lastname');
}
// display date interval selector
$rec = $DB->get_record_sql("SELECT MIN(sessdate) AS min, MAX(sessdate) AS max \n FROM {attendance_sessions}\n WHERE courseid=? AND sessdate >= ?", array($course->id, $course->startdate));
$firstdate = $rec->min;
$lastdate = $rec->max;
$now = time();
$current = $current == 0 ? $now : $current;
list(, , , $wday, $syear, $smonth, $sday) = array_values(usergetdate($firstdate));
$wday = $wday == 0 ? 7 : $wday;
//////////////////////////////////////////////////// Нужна проверка настройки календаря
$startdate = make_timestamp($syear, $smonth, $sday - $wday + 1);
//GMT timestamp but for local midnight of monday