本文整理汇总了PHP中course_enrolment_manager类的典型用法代码示例。如果您正苦于以下问题:PHP course_enrolment_manager类的具体用法?PHP course_enrolment_manager怎么用?PHP course_enrolment_manager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了course_enrolment_manager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
/**
* Gets a blank course with 2 teachers and 10 students ready for each test.
*/
protected function setUp()
{
global $PAGE, $DB;
// First test will set up DB submissions, so we keep it hanging around for the others.
$this->resetAfterTest();
// Make a course.
$generator = $this->getDataGenerator();
$this->course = $generator->create_course();
$this->setAdminUser();
$PAGE->set_course($this->course);
$manager = new course_enrolment_manager($PAGE, $this->course);
$plugins = $manager->get_enrolment_plugins();
$instances = $manager->get_enrolment_instances();
/* @var enrol_manual_plugin $manualenrolplugin */
$manualenrolplugin = reset($plugins);
$manualenrolinstance = reset($instances);
$studentroleid = $DB->get_field('role', 'id', array('shortname' => 'student'));
$teacherroleid = $DB->get_field('role', 'id', array('shortname' => 'teacher'));
// Make some students.
for ($i = 0; $i < 10; $i++) {
$student = $generator->create_user();
$this->students[$student->id] = $student;
$manualenrolplugin->enrol_user($manualenrolinstance, $student->id, $studentroleid);
}
// Make a couple of teachers.
$teacher1 = $generator->create_user();
$this->teachers[$teacher1->id] = $teacher1;
$manualenrolplugin->enrol_user($manualenrolinstance, $teacher1->id, $teacherroleid);
$teacher2 = $generator->create_user();
$this->teachers[$teacher2->id] = $teacher2;
$manualenrolplugin->enrol_user($manualenrolinstance, $teacher2->id, $teacherroleid);
}
示例2: get_user_enrolment_actions
/**
* Gets an array of the user enrolment actions
*
* @param course_enrolment_manager $manager
* @param stdClass $ue A user enrolment object
* @return array An array of user_enrolment_actions
*/
public function get_user_enrolment_actions(course_enrolment_manager $manager, $ue) {
$actions = array();
$context = $manager->get_context();
$instance = $ue->enrolmentinstance;
$params = $manager->get_moodlepage()->url->params();
$params['ue'] = $ue->id;
if ($this->allow_unenrol_user($instance, $ue) && has_capability('enrol/database:unenrol', $context)) {
$url = new moodle_url('/enrol/unenroluser.php', $params);
$actions[] = new user_enrolment_action(new pix_icon('t/delete', ''), get_string('unenrol', 'enrol'), $url, array('class'=>'unenrollink', 'rel'=>$ue->id));
}
return $actions;
}
示例3: 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);
}
}
示例4: is_available
public function is_available($not, \core_availability\info $info, $grabthelot, $userid)
{
global $PAGE, $CFG;
require_once $CFG->dirroot . '/enrol/locallib.php';
$course = $info->get_course();
$enrolmanager = new \course_enrolment_manager($PAGE, $course);
$allow = true;
if (!($enrolments = $enrolmanager->get_user_enrolments($userid))) {
$allow = false;
}
foreach ($enrolments as $enrol) {
if (time() - $enrol->timestart < $this->mintimesinceenrol) {
$allow = false;
}
}
if (!$not) {
$allow = !$allow;
}
return $allow;
}
示例5: get_invitation_instance
/**
* Return the invitation instance for a specific course.
*
* Note: as using $PAGE variable, this function can only be called in a
* Moodle script page.
*
* @param int $courseid
* @param boolean $mustexist when set, an exception is thrown if no instance is found
* @return object
*/
public function get_invitation_instance($courseid, $mustexist = false)
{
global $PAGE, $CFG, $DB;
if ($courseid == $this->courseid and !empty($this->enrolinstance)) {
return $this->enrolinstance;
}
// Find enrolment instance.
$instance = null;
require_once "{$CFG->dirroot}/enrol/locallib.php";
$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
$manager = new course_enrolment_manager($PAGE, $course);
foreach ($manager->get_enrolment_instances() as $tempinstance) {
if ($tempinstance->enrol == 'invitation') {
if ($instance === null) {
$instance = $tempinstance;
}
}
}
if ($mustexist and empty($instance)) {
throw new moodle_exception('noinvitationinstanceset', 'enrol_invitation');
}
return $instance;
}
示例6: list
// Get the course the enrolment is to.
list($ctxsql, $ctxjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
$sql = "SELECT c.* {$ctxsql} FROM {course} c LEFT JOIN {enrol} e ON e.courseid = c.id {$ctxjoin} WHERE e.id = :enrolid";
$params = array('enrolid' => $ue->enrolid);
$course = $DB->get_record_sql($sql, $params, MUST_EXIST);
context_instance_preload($course);
// Make sure its not the front page course.
if ($course->id == SITEID) {
redirect(new moodle_url('/'));
}
// Obviously.
require_login($course);
// Make sure the user can manage invitation enrolments for this course.
require_capability("enrol/invitation:manage", context_course::instance($course->id, MUST_EXIST));
// Get the enrolment manager for this course.
$manager = new course_enrolment_manager($PAGE, $course, $filter);
// Get an enrolment users table object. Doign this will automatically retrieve the the URL params
// relating to table the user was viewing before coming here, and allows us to return the user to the
// exact page of the users screen they can from.
$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/invitation/editenrolment.php', $returnurl->params());
$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_manage($instance) || $instance->enrol != 'invitation' || !$plugin instanceof enrol_invitation_plugin) {
示例7: required_param
require_once "{$CFG->dirroot}/enrol/users_forms.php";
require_once "{$CFG->dirroot}/enrol/renderer.php";
require_once "{$CFG->dirroot}/group/lib.php";
$id = required_param('id', PARAM_INT);
// course id
$action = optional_param('action', '', PARAM_ACTION);
$filter = optional_param('ifilter', 0, PARAM_INT);
$course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST);
$context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST);
if ($course->id == SITEID) {
redirect(new moodle_url('/'));
}
require_login($course);
require_capability('moodle/course:enrolreview', $context);
$PAGE->set_pagelayout('admin');
$manager = new course_enrolment_manager($course, $filter);
$table = new course_enrolment_users_table($manager, $PAGE);
$PAGE->set_url('/enrol/users.php', $manager->get_url_params() + $table->get_url_params());
// Check if there is an action to take
if ($action) {
// 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)
*/
示例8: array
// Get the user enrolment object
$ue = $DB->get_record('user_enrolments', array('id' => $ueid), '*', MUST_EXIST);
// Get the user for whom the enrolment is
$user = $DB->get_record('user', array('id' => $ue->userid), '*', MUST_EXIST);
// Get the course the enrolment is to
list($ctxsql, $ctxjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
$sql = "SELECT c.* {$ctxsql}\n FROM {course} c\n LEFT JOIN {enrol} e ON e.courseid = c.id\n {$ctxjoin}\n WHERE e.id = :enrolid";
$params = array('enrolid' => $ue->enrolid);
$course = $DB->get_record_sql($sql, $params, MUST_EXIST);
context_instance_preload($course);
if ($course->id == SITEID) {
redirect(new moodle_url('/'));
}
require_login($course);
require_capability("enrol/globalclassroom:unenrol", get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST));
$manager = new course_enrolment_manager($PAGE, $course, $filter);
$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');
}
示例9: array
$ue = $DB->get_record('user_enrolments', array('id' => $ueid), '*', MUST_EXIST);
$user = $DB->get_record('user', array('id' => $ue->userid), '*', MUST_EXIST);
$instance = $DB->get_record('enrol', array('id' => $ue->enrolid), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $instance->courseid), '*', MUST_EXIST);
$context = context_course::instance($course->id);
// set up PAGE url first!
$PAGE->set_url('/enrol/unenroluser.php', array('ue' => $ueid, 'ifilter' => $filter));
require_login($course);
if (!enrol_is_enabled($instance->enrol)) {
print_error('erroreditenrolment', 'enrol');
}
$plugin = enrol_get_plugin($instance->enrol);
if (!$plugin->allow_unenrol_user($instance, $ue) or !has_capability("enrol/{$instance->enrol}:unenrol", $context)) {
print_error('erroreditenrolment', 'enrol');
}
$manager = new course_enrolment_manager($PAGE, $course, $filter);
$table = new course_enrolment_users_table($manager, $PAGE);
$returnurl = new moodle_url('/enrol/users.php', array('id' => $course->id) + $manager->get_url_params() + $table->get_url_params());
$usersurl = new moodle_url('/enrol/users.php', array('id' => $course->id));
$PAGE->set_pagelayout('admin');
navigation_node::override_active_url($usersurl);
// If the unenrolment has been confirmed and the sesskey is valid unenrol the user.
if ($confirm && confirm_sesskey()) {
$plugin->unenrol_user($instance, $ue->userid);
redirect($returnurl);
}
$yesurl = new moodle_url($PAGE->url, array('confirm' => 1, 'sesskey' => sesskey()));
$message = get_string('unenrolconfirm', 'core_enrol', array('user' => fullname($user, true), 'course' => format_string($course->fullname)));
$fullname = fullname($user);
$title = get_string('unenrol', 'core_enrol');
$PAGE->set_title($title);
示例10: get_manual_enrol_button
/**
* Returns a button to enrol a cohort or its users through the manual enrolment plugin.
*
* This function also adds a quickenrolment JS ui to the page so that users can be enrolled
* via AJAX.
*
* @param course_enrolment_manager $manager
* @return enrol_user_button
*/
public function get_manual_enrol_button(course_enrolment_manager $manager)
{
$course = $manager->get_course();
if (!$this->can_add_new_instances($course->id)) {
return false;
}
$cohorturl = new moodle_url('/enrol/cohort/edit.php', array('courseid' => $course->id));
$button = new enrol_user_button($cohorturl, get_string('enrolcohort', 'enrol'), 'get');
$button->class .= ' enrol_cohort_plugin';
$button->strings_for_js(array('enrol', 'synced', 'enrolcohort', 'enrolcohortusers'), 'enrol');
$button->strings_for_js(array('ajaxmore', 'cohortsearch'), 'enrol_cohort');
$button->strings_for_js('assignroles', 'role');
$button->strings_for_js('cohort', 'cohort');
$button->strings_for_js('users', 'moodle');
// No point showing this at all if the user cant manually enrol users.
$hasmanualinstance = has_capability('enrol/manual:enrol', $manager->get_context()) && $manager->has_instance('manual');
$modules = array('moodle-enrol_cohort-quickenrolment', 'moodle-enrol_cohort-quickenrolment-skin');
$function = 'M.enrol_cohort.quickenrolment.init';
$arguments = array('courseid' => $course->id, 'ajaxurl' => '/enrol/cohort/ajax.php', 'url' => $manager->get_moodlepage()->url->out(false), 'manualEnrolment' => $hasmanualinstance);
$button->require_yui_module($modules, $function, array($arguments));
return $button;
}
示例11: enrol_cohort_search_cohorts
/**
* Gets cohorts the user is able to view.
*
* @deprecated since Moodle 2.8 MDL-35618 this functionality is removed
*
* @global moodle_database $DB
* @param course_enrolment_manager $manager
* @param int $offset limit output from
* @param int $limit items to output per load
* @param string $search search string
* @return array Array(more => bool, offset => int, cohorts => array)
*/
function enrol_cohort_search_cohorts(course_enrolment_manager $manager, $offset = 0, $limit = 25, $search = '')
{
global $CFG;
debugging('enrol_cohort_search_cohorts() is deprecated. This functionality is moved to enrol_manual.', DEBUG_DEVELOPER);
require_once $CFG->dirroot . '/cohort/lib.php';
$context = $manager->get_context();
$cohorts = array();
$instances = $manager->get_enrolment_instances();
$enrolled = array();
foreach ($instances as $instance) {
if ($instance->enrol === 'cohort') {
$enrolled[] = $instance->customint1;
}
}
$rawcohorts = cohort_get_available_cohorts($context, COHORT_COUNT_MEMBERS, $offset, $limit, $search);
// Produce the output respecting parameters.
foreach ($rawcohorts as $c) {
$cohorts[$c->id] = array('cohortid' => $c->id, 'name' => shorten_text(format_string($c->name, true, array('context' => context::instance_by_id($c->contextid))), 35), 'users' => $c->memberscnt, 'enrolled' => in_array($c->id, $enrolled));
}
return array('more' => !(bool) $limit, 'offset' => $offset, 'cohorts' => $cohorts);
}
示例12: required_param
// Must have the sesskey.
$id = required_param('id', PARAM_INT);
// course id
$action = required_param('action', PARAM_ALPHANUMEXT);
$PAGE->set_url(new moodle_url('/enrol/cohort/ajax.php', array('id' => $id, 'action' => $action)));
$course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST);
$context = context_course::instance($course->id, MUST_EXIST);
if ($course->id == SITEID) {
throw new moodle_exception('invalidcourse');
}
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 = '';
switch ($action) {
case 'getassignable':
$otheruserroles = optional_param('otherusers', false, PARAM_BOOL);
$outcome->response = array_reverse($manager->get_assignable_roles($otheruserroles), true);
break;
case 'getdefaultcohortrole':
//TODO: use in ajax UI MDL-24280
$cohortenrol = enrol_get_plugin('cohort');
$outcome->response = $cohortenrol->get_config('roleid');
break;
case 'getcohorts':
示例13: 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);
}
示例14: print_error
if (!($sessdata = $DB->get_record('attendance_sessions', array('id' => $sessionid)))) {
print_error("Required Information is missing", "manage.php?id=" . $id);
}
$help = $OUTPUT->help_icon('updateattendance', 'attforblock', '');
$update = $DB->count_records('attendance_log', array('sessionid' => $sessionid));
if ($update) {
require_capability('mod/attforblock:changeattendances', $context);
echo $OUTPUT->heading(get_string('update', 'attforblock') . ' ' . get_string('attendanceforthecourse', 'attforblock') . ' :: ' . $course->fullname . $help);
} else {
require_capability('mod/attforblock:takeattendances', $context);
echo $OUTPUT->heading(get_string('attendanceforthecourse', 'attforblock') . ' :: ' . $course->fullname . $help);
}
/// find out current groups mode
$groupmode = groups_get_activity_groupmode($cm);
$currentgroup = groups_get_activity_group($cm, true);
$manager = new course_enrolment_manager($course);
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);
*/
示例15: required_param
require_once "{$CFG->dirroot}/enrol/locallib.php";
require_once "{$CFG->dirroot}/enrol/renderer.php";
require_once "{$CFG->dirroot}/group/lib.php";
$id = required_param('id', PARAM_INT);
// course id
$action = optional_param('action', '', PARAM_ACTION);
$filter = optional_param('ifilter', 0, PARAM_INT);
$course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST);
$context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST);
require_login($course);
require_capability('moodle/role:assign', $context);
if ($course->id == SITEID) {
redirect("{$CFG->wwwroot}/");
}
$PAGE->set_pagelayout('admin');
$manager = new course_enrolment_manager($PAGE, $course, $filter);
$table = new course_enrolment_other_users_table($manager, $PAGE);
$PAGE->set_url('/enrol/otherusers.php', $manager->get_url_params() + $table->get_url_params());
$userdetails = array('picture' => false, 'firstname' => get_string('firstname'), 'lastname' => get_string('lastname'));
$extrafields = get_extra_user_fields($context);
foreach ($extrafields as $field) {
$userdetails[$field] = get_user_field_name($field);
}
$fields = array('userdetails' => $userdetails, 'lastseen' => get_string('lastaccess'), 'role' => get_string('roles', 'role'));
// Remove hidden fields if the user has no access
if (!has_capability('moodle/course:viewhiddenuserfields', $context)) {
$hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields));
if (isset($hiddenfields['lastaccess'])) {
unset($fields['lastseen']);
}
}