本文整理汇总了PHP中course_enrolment_manager类的典型用法代码示例。如果您正苦于以下问题:PHP course_enrolment_manager类的具体用法?PHP course_enrolment_manager怎么用?PHP course_enrolment_manager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了course_enrolment_manager类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:nadavkav,项目名称:moodle-block_ajax_marking,代码行数:35,代码来源:nodes_builder_test.php
示例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;
}
开发者ID:ncsu-delta,项目名称:moodle,代码行数:19,代码来源:lib.php
示例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);
}
}
开发者ID:sumitnegi933,项目名称:Moodle_lms_New,代码行数:13,代码来源:user_selectors.php
示例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;
}
开发者ID:danielneis,项目名称:moodle-availability_timesinceenrol,代码行数:20,代码来源:condition.php
示例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;
}
开发者ID:bqfan,项目名称:enrol_invitation,代码行数:33,代码来源:locallib.php
示例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) {
开发者ID:GaoxinHuang,项目名称:moodle-enrol_invitation,代码行数:31,代码来源:editenrolment.php
示例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)
*/
开发者ID:esyacelga,项目名称:sisadmaca,代码行数:31,代码来源:users.php
示例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');
}
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:31,代码来源:unenroluser.php
示例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);
开发者ID:JP-Git,项目名称:moodle,代码行数:31,代码来源:unenroluser.php
示例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;
}
开发者ID:masaterutakeno,项目名称:MoodleMobile,代码行数:31,代码来源:lib.php
示例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);
}
开发者ID:Hirenvaghasiya,项目名称:moodle,代码行数:33,代码来源:deprecatedlib.php
示例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':
开发者ID:JP-Git,项目名称:moodle,代码行数:31,代码来源:ajax.php
示例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);
}
开发者ID:janeklb,项目名称:moodle,代码行数:70,代码来源:course_enrolment_manager_test.php
示例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);
*/
开发者ID:netspotau,项目名称:moodle-mod_attforblock,代码行数:31,代码来源:attendances.php
示例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']);
}
}
开发者ID:nmicha,项目名称:moodle,代码行数:31,代码来源:otherusers.php
示例16: 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);
}
}
}
}
}
}
开发者ID:sumitnegi933,项目名称:Moodle_lms_New,代码行数:31,代码来源:user.php
示例17: required_param
require_once "{$CFG->dirroot}/group/lib.php";
$id = required_param('id', PARAM_INT);
// course id
$bulkuserop = required_param('bulkuserop', PARAM_ALPHANUMEXT);
$userids = required_param_array('bulkuser', PARAM_INT);
$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($PAGE, $course, $filter);
$table = new course_enrolment_users_table($manager, $PAGE);
$returnurl = new moodle_url('/enrol/users.php', $table->get_combined_url_params());
$actionurl = new moodle_url('/enrol/bulkchange.php', $table->get_combined_url_params() + array('bulkuserop' => $bulkuserop));
$PAGE->set_url($actionurl);
navigation_node::override_active_url(new moodle_url('/enrol/users.php', array('id' => $id)));
$ops = $table->get_bulk_user_enrolment_operations();
if (!array_key_exists($bulkuserop, $ops)) {
throw new moodle_exception('invalidbulkenrolop');
}
$operation = $ops[$bulkuserop];
// Prepare the properties of the form
$users = $manager->get_users_enrolments($userids);
// Get the form for the bulk operation
$mform = $operation->get_form($actionurl, array('users' => $users));
// If the mform is false then attempt an immediate process. This may be an immediate action that
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:31,代码来源:bulkchange.php
示例18: get_users_for_display
/**
* Gets an array of users for display, this includes minimal user information
* as well as minimal information on the users roles, groups, and enrolments.
*
* @param core_enrol_renderer $renderer
* @param moodle_url $pageurl
* @param int $sort
* @param string $direction ASC or DESC
* @param int $page
* @param int $perpage
* @return array
*/
public function get_users_for_display(course_enrolment_manager $manager, $sort, $direction, $page, $perpage)
{
$pageurl = $manager->get_moodlepage()->url;
$users = $this->get_users($sort, $direction, $page, $perpage);
$now = time();
$straddgroup = get_string('addgroup', 'group');
$strunenrol = get_string('unenrol', 'enrol');
$stredit = get_string('edit');
$allroles = $this->get_all_roles();
$assignable = $this->get_assignable_roles();
$allgroups = $this->get_all_groups();
$context = $this->get_context();
$canmanagegroups = has_capability('moodle/course:managegroups', $context);
$url = new moodle_url($pageurl, $this->get_url_params());
$extrafields = get_extra_user_fields($context);
$enabledplugins = $this->get_enrolment_plugins(true);
$userdetails = array();
foreach ($users as $user) {
$details = $this->prepare_user_for_display($user, $extrafields, $now);
// Roles
$details['roles'] = array();
foreach ($this->get_user_roles($user->id) as $rid => $rassignable) {
$unchangeable = !$rassignable;
if (!is_siteadmin() and !isset($assignable[$rid])) {
$unchangeable = true;
}
$details['roles'][$rid] = array('text' => $allroles[$rid]->localname, 'unchangeable' => $unchangeable);
}
// Users
$usergroups = $this->get_user_groups($user->id);
$details['groups'] = array();
foreach ($usergroups as $gid => $unused) {
$details['groups'][$gid] = $allgroups[$gid]->name;
}
// Enrolments
$details['enrolments'] = array();
foreach ($this->get_user_enrolments($user->id) as $ue) {
if (!isset($enabledplugins[$ue->enrolmentinstance->enrol])) {
$details['enrolments'][$ue->id] = array('text' => $ue->enrolmentinstancename, 'period' => null, 'dimmed' => true, 'actions' => array());
continue;
} else {
if ($ue->timestart and $ue->timeend) {
$period = get_string('periodstartend', 'enrol', array('start' => userdate($ue->timestart), 'end' => userdate($ue->timeend)));
$periodoutside = $ue->timestart && $ue->timeend && ($now < $ue->timestart || $now > $ue->timeend);
} else {
if ($ue->timestart) {
$period = get_string('periodstart', 'enrol', userdate($ue->timestart));
$periodoutside = $ue->timestart && $now < $ue->timestart;
} else {
if ($ue->timeend) {
$period = get_string('periodend', 'enrol', userdate($ue->timeend));
$periodoutside = $ue->timeend && $now > $ue->timeend;
} else {
// If there is no start or end show when user was enrolled.
$period = get_string('periodnone', 'enrol', userdate($ue->timecreated));
$periodoutside = false;
}
}
}
}
$details['enrolments'][$ue->id] = array('text' => $ue->enrolmentinstancename, 'period' => $period, 'dimmed' => $periodoutside or $ue->status != ENROL_USER_ACTIVE or $ue->enrolmentinstance->status != ENROL_INSTANCE_ENABLED, 'actions' => $ue->enrolmentplugin->get_user_enrolment_actions($manager, $ue));
}
$userdetails[$user->id] = $details;
}
return $userdetails;
}
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:78,代码来源:locallib.php
示例19: required_param
require_once $CFG->dirroot . '/group/lib.php';
$id = required_param('id', PARAM_INT);
// Course id.
$action = required_param('action', PARAM_ALPHANUMEXT);
$PAGE->set_url(new moodle_url('/enrol/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 = '';
$searchanywhere = get_user_preferences('userselector_searchanywhere', false);
switch ($action) {
case 'getassignable':
$otheruserroles = optional_param('otherusers', false, PARAM_BOOL);
$outcome->response = array_reverse($manager->get_assignable_roles($otheruserroles), true);
break;
case 'searchusers':
$enrolid = required_param('enrolid', PARAM_INT);
$search = optional_param('search', '', PARAM_RAW);
$page = optional_param('page', 0, PARAM_INT);
$outcome->response = $manager->get_potential_users($enrolid, $search, $searchanywhere, $page);
开发者ID:vinoth4891,项目名称:clinique,代码行数:31,代码来源:ajax.php
示例20: enrol_cohort_search_cohorts
/**
* Gets cohorts the user is able to view.
*
* @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 $DB;
$context = $manager->get_context();
$cohorts = array();
$instances = $manager->get_enrolment_instances();
$enrolled = array();
foreach ($instances as $instance) {
if ($instance->enrol == 'cohort') {
$enrolled[] = $instance->customint1;
}
}
list($sqlparents, $params) = $DB->get_in_or_equal($context->get_parent_context_ids());
// Add some additional sensible conditions.
$tests = array('contextid ' . $sqlparents);
// Modify the query to perform the search if required.
if (!empty($search)) {
$conditions = array('name', 'idnumber', 'description');
$searchparam = '%' . $DB->sql_like_escape($search) . '%';
foreach ($conditions as $key => $condition) {
$conditions[$key] = $DB->sql_like($condition, "?", false);
$params[] = $searchparam;
}
$tests[] = '(' . implode(' OR ', $conditions) . ')';
}
$wherecondition = implode(' AND ', $tests);
$sql = "SELECT id, name, idnumber, contextid, description\n FROM {cohort}\n WHERE {$wherecondition}\n ORDER BY name ASC, idnumber ASC";
$rs = $DB->get_recordset_sql($sql, $params, $offset);
// Produce the output respecting parameters.
foreach ($rs as $c) {
// Track offset.
$offset++;
// Check capabilities.
$context = context::instance_by_id($c->contextid);
if (!has_capability('moodle/cohort:view', $context)) {
continue;
}
if ($limit === 0) {
// We have reached the required number of items and know that there are more, exit now.
$offset--;
break;
}
$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' => $DB->count_records('cohort_members', array('cohortid' => $c->id)), 'enrolled' => in_array($c->id, $enrolled));
// Count items.
$limit--;
}
$rs->close();
return array('more' => !(bool) $limit, 'offset' => $offset, 'cohorts' => $cohorts);
}
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:59,代码来源:locallib.php
注:本文中的course_enrolment_manager类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论