本文整理汇总了PHP中enrol_is_enabled函数的典型用法代码示例。如果您正苦于以下问题:PHP enrol_is_enabled函数的具体用法?PHP enrol_is_enabled怎么用?PHP enrol_is_enabled使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了enrol_is_enabled函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: user_loggedin
/**
* Triggered via the user_loggedin event, when a user logs in.
*
* @param stdClass $event
*/
public static function user_loggedin($event)
{
global $DB;
$eventdata = $event->get_data();
if (!enrol_is_enabled('auto')) {
return;
}
if (is_siteadmin($eventdata['userid'])) {
// Don't enrol site admins
return;
}
// Get all courses that have an auto enrol plugin, set to auto enrol on login, where the user isn't enrolled yet
$sql = "SELECT e.courseid\n FROM {enrol} e\n LEFT JOIN {user_enrolments} ue ON e.id = ue.enrolid AND ue.userid = ?\n WHERE e.enrol = 'auto'\n AND e.status = ?\n AND e.customint3 = ?\n AND ue.id IS NULL";
if (!($courses = $DB->get_records_sql($sql, array($eventdata['userid'], ENROL_INSTANCE_ENABLED, ENROL_AUTO_LOGIN)))) {
return;
}
$autoplugin = enrol_get_plugin('auto');
foreach ($courses as $course) {
if (!($instance = $autoplugin->get_instance_for_course($course->courseid))) {
continue;
}
$autoplugin->enrol_user($instance, $eventdata['userid'], $instance->roleid);
// Send welcome message.
if ($instance->customint2) {
$autoplugin = enrol_get_plugin('auto');
$autoplugin->email_welcome_message($instance, $DB->get_record('user', array('id' => $eventdata['userid'])));
}
}
}
开发者ID:ninelanterns,项目名称:scaffold-enrol_auto,代码行数:34,代码来源:observer.php
示例2: member_added
/**
* Event processor - cohort member added
* @param stdClass $ca
* @return bool
*/
public function member_added($ca)
{
global $DB;
if (!enrol_is_enabled('cohort')) {
return true;
}
// does any enabled cohort instance want to sync with this cohort?
$sql = "SELECT e.*, r.id as roleexists\n FROM {enrol} e\n LEFT JOIN {role} r ON (r.id = e.roleid)\n WHERE customint1 = :cohortid AND enrol = 'cohort'\n ORDER BY id ASC";
if (!($instances = $DB->get_records_sql($sql, array('cohortid' => $ca->cohortid)))) {
return true;
}
$plugin = enrol_get_plugin('cohort');
foreach ($instances as $instance) {
if ($instance->status != ENROL_INSTANCE_ENABLED) {
// no roles for disabled instances
$instance->roleid = 0;
} else {
if ($instance->roleid and !$instance->roleexists) {
// invalid role - let's just enrol, they will have to create new sync and delete this one
$instance->roleid = 0;
}
}
unset($instance->roleexists);
// no problem if already enrolled
$plugin->enrol_user($instance, $ca->userid, $instance->roleid, 0, 0, ENROL_USER_ACTIVE);
}
return true;
}
开发者ID:raymondAntonio,项目名称:moodle,代码行数:33,代码来源:locallib.php
示例3: test_basics
public function test_basics()
{
$this->assertFalse(enrol_is_enabled('paypal'));
$plugin = enrol_get_plugin('paypal');
$this->assertInstanceOf('enrol_paypal_plugin', $plugin);
$this->assertEquals(ENROL_EXT_REMOVED_SUSPENDNOROLES, get_config('enrol_paypal', 'expiredaction'));
}
开发者ID:pzhu2004,项目名称:moodle,代码行数:7,代码来源:paypal_test.php
示例4: test_basics
public function test_basics()
{
$this->assertTrue(enrol_is_enabled('self'));
$plugin = enrol_get_plugin('self');
$this->assertInstanceOf('enrol_self_plugin', $plugin);
$this->assertEquals(1, get_config('enrol_self', 'defaultenrol'));
$this->assertEquals(ENROL_EXT_REMOVED_KEEP, get_config('enrol_self', 'expiredaction'));
}
开发者ID:evltuma,项目名称:moodle,代码行数:8,代码来源:self_test.php
示例5: xmldb_enrol_elis_install
/**
* Install function for this plugin
*
* @return boolean true Returns true to satisfy install procedure
*/
function xmldb_enrol_elis_install()
{
global $CFG;
if (!enrol_is_enabled('elis')) {
// force the elis plugin to be enabled
set_config('enrol_plugins_enabled', $CFG->enrol_plugins_enabled . ',elis');
}
return true;
}
开发者ID:jamesmcq,项目名称:elis,代码行数:14,代码来源:install.php
示例6: course_updated
/**
* Called after updating/inserting course.
*
* @param bool $inserted true if course just inserted
* @param stdClass $course
* @param stdClass $data form data
* @return void
*/
public function course_updated($inserted, $course, $data)
{
global $CFG;
if (!enrol_is_enabled('category')) {
return;
}
// Sync category enrols.
require_once "{$CFG->dirroot}/enrol/category/locallib.php";
enrol_category_sync_course($course);
}
开发者ID:ruddj,项目名称:moodle,代码行数:18,代码来源:lib.php
示例7: instance_deleteable
/**
* Is it possible to delete enrol instance via standard UI?
*
* @param stdClass $instance
* @return bool
*/
public function instance_deleteable($instance)
{
if (!enrol_is_enabled('database')) {
return true;
}
if (!$this->get_config('dbtype') or !$this->get_config('dbhost') or !$this->get_config('remoteenroltable') or !$this->get_config('remotecoursefield') or !$this->get_config('remoteuserfield')) {
return true;
}
//TODO: connect to external system and make sure no users are to be enrolled in this course
return false;
}
开发者ID:vinoth4891,项目名称:clinique,代码行数:17,代码来源:lib.php
示例8: execute
/**
* Do the job.
* Throw exceptions on errors (the job will be retried).
*/
public function execute()
{
global $CFG;
require_once $CFG->dirroot . '/enrol/flatfile/lib.php';
if (!enrol_is_enabled('flatfile')) {
return;
}
// Instance of enrol_flatfile_plugin.
$plugin = enrol_get_plugin('flatfile');
$result = $plugin->sync(new \null_progress_trace());
return $result;
}
开发者ID:evltuma,项目名称:moodle,代码行数:16,代码来源:flatfile_sync_task.php
示例9: enrol_jwc_sync
/**
* Sync all jwc course links.
* @param int $courseid one course, empty mean all
* @return void
*/
function enrol_jwc_sync($courseid = NULL)
{
global $CFG, $DB;
// unfortunately this may take a long time
@set_time_limit(0);
//if this fails during upgrade we can continue from cron, no big deal
$jwc = new jwc_helper();
$jwc_enrol = enrol_get_plugin('jwc');
if (enrol_is_enabled('jwc')) {
$params = array();
$onecourse = "";
if ($courseid) {
$params['courseid'] = $courseid;
$onecourse = "AND courseid = :courseid";
}
$select = "enrol = :jwc AND status = :status {$onecourse}";
$params['jwc'] = 'jwc';
$params['status'] = ENROL_INSTANCE_ENABLED;
$instances = $DB->get_records_select('enrol', $select, $params);
foreach ($instances as $instance) {
// 课程必须有cas认证的教师
$teachers = enrol_jwc_get_cas_teachers($instance->courseid);
if (empty($teachers)) {
$DB->set_field('enrol', 'customchar2', '此课程没有使用HITID的教师', array('id' => $instance->id));
continue;
}
// 从教务处获取所有选修该课程的学生
$return_msg = '';
$students = $jwc->get_students($instance->customchar1, $teachers, $jwc_enrol->get_config('semester'), $return_msg);
$DB->set_field('enrol', 'customchar2', $return_msg, array('id' => $instance->id));
if (!$students) {
// 出错
continue;
// skip this instance. 就算出错,也别清理选课,以免意外。管理员更改学期名时再清理所有选课
}
// 开始同步
// 选课
foreach ($students as $userid) {
$jwc_enrol->enrol_user($instance, $userid, $instance->roleid);
}
// 取消教务处删除的选课
if (empty($students)) {
$where = "enrolid = {$instance->id}";
} else {
$where = "enrolid = {$instance->id} AND userid NOT IN (" . implode(',', $students) . ')';
}
$ues = $DB->get_records_select('user_enrolments', $where);
foreach ($ues as $ue) {
$jwc_enrol->unenrol_user($instance, $ue->userid);
}
}
}
}
开发者ID:hit-moodle,项目名称:moodle-enrol_jwc,代码行数:58,代码来源:locallib.php
示例10: __construct
/**
* Sets up the table.
*
* @param string $courseid The id of the course.
*/
public function __construct($courseid)
{
parent::__construct('enrol_lti_manage_table');
$this->define_columns(array('name', 'url', 'secret', 'edit'));
$this->define_headers(array(get_string('name'), get_string('url'), get_string('secret', 'enrol_lti'), get_string('edit')));
$this->collapsible(false);
$this->sortable(false);
// Set the variables we need access to.
$this->ltiplugin = enrol_get_plugin('lti');
$this->ltienabled = enrol_is_enabled('lti');
$this->canconfig = has_capability('moodle/course:enrolconfig', \context_course::instance($courseid));
$this->courseid = $courseid;
}
开发者ID:evltuma,项目名称:moodle,代码行数:18,代码来源:manage_table.php
示例11: test_basics
public function test_basics()
{
# disabled by default
$this->assertFalse(enrol_is_enabled('auto'));
# correct enrol instance
$plugin = enrol_get_plugin('auto');
$this->assertInstanceOf('enrol_auto_plugin', $plugin);
# default config checks
$this->assertEquals('1', get_config('enrol_auto', 'defaultenrol'));
$this->assertEquals('1', get_config('enrol_auto', 'status'));
$this->assertEquals(ENROL_AUTO_COURSE_VIEWED, get_config('enrol_auto', 'enrolon'));
$this->assertEquals('1', get_config('enrol_auto', 'sendcoursewelcomemessage'));
$this->assertEquals('', get_config('enrol_auto', 'modviewmods'));
}
开发者ID:ninelanterns,项目名称:scaffold-enrol_auto,代码行数:14,代码来源:auto_test.php
示例12: execute
/**
* Performs the synchronisation of members.
*/
public function execute()
{
if (!is_enabled_auth('lti')) {
mtrace('Skipping task - ' . get_string('pluginnotenabled', 'auth', get_string('pluginname', 'auth_lti')));
return;
}
// Check if the enrolment plugin is disabled - isn't really necessary as the task should not run if
// the plugin is disabled, but there is no harm in making sure core hasn't done something wrong.
if (!enrol_is_enabled('lti')) {
mtrace('Skipping task - ' . get_string('enrolisdisabled', 'enrol_lti'));
return;
}
$this->dataconnector = new data_connector();
// Get all the enabled tools.
$tools = helper::get_lti_tools(array('status' => ENROL_INSTANCE_ENABLED, 'membersync' => 1));
foreach ($tools as $tool) {
mtrace("Starting - Member sync for published tool '{$tool->id}' for course '{$tool->courseid}'.");
// Variables to keep track of information to display later.
$usercount = 0;
$enrolcount = 0;
$unenrolcount = 0;
// Fetch consumer records mapped to this tool.
$consumers = $this->dataconnector->get_consumers_mapped_to_tool($tool->id);
// Perform processing for each consumer.
foreach ($consumers as $consumer) {
mtrace("Requesting membership service for the tool consumer '{$consumer->getRecordId()}'");
// Get members through this tool consumer.
$members = $this->fetch_members_from_consumer($consumer);
// Check if we were able to fetch the members.
if ($members === false) {
mtrace("Skipping - Membership service request failed.\n");
continue;
}
// Fetched members count.
$membercount = count($members);
mtrace("{$membercount} members received.\n");
// Process member information.
list($usercount, $enrolcount) = $this->sync_member_information($tool, $consumer, $members);
}
// Now we check if we have to unenrol users who were not listed.
if ($this->should_sync_unenrol($tool->membersyncmode)) {
$unenrolcount = $this->sync_unenrol($tool);
}
mtrace("Completed - Synced members for tool '{$tool->id}' in the course '{$tool->courseid}'. " . "Processed {$usercount} users; enrolled {$enrolcount} members; unenrolled {$unenrolcount} members.\n");
}
// Sync the user profile photos.
mtrace("Started - Syncing user profile images.");
$countsyncedimages = $this->sync_profile_images();
mtrace("Completed - Synced {$countsyncedimages} profile images.");
}
开发者ID:lucaboesch,项目名称:moodle,代码行数:53,代码来源:sync_members.php
示例13: can_delete_instance
/**
* Is it possible to delete enrol instance via standard UI?
*
* @param stdClass $instance
* @return bool
*/
public function can_delete_instance($instance)
{
$context = context_course::instance($instance->courseid);
if (!has_capability('enrol/database:config', $context)) {
return false;
}
if (!enrol_is_enabled('database')) {
return true;
}
if (!$this->get_config('dbtype') or !$this->get_config('remoteenroltable') or !$this->get_config('remotecoursefield') or !$this->get_config('remoteuserfield')) {
return true;
}
//TODO: connect to external system and make sure no users are to be enrolled in this course
return false;
}
开发者ID:alanaipe2015,项目名称:moodle,代码行数:21,代码来源:lib.php
示例14: get_manual_enrol_link
/**
* Returns link to manual enrol UI if exists.
* Does the access control tests automatically.
*
* @param object $instance
* @return moodle_url
*/
public function get_manual_enrol_link($instance)
{
$name = $this->get_name();
if ($instance->enrol !== $name) {
throw new coding_exception('invalid enrol instance!');
}
if (!enrol_is_enabled($name)) {
return NULL;
}
$context = get_context_instance(CONTEXT_COURSE, $instance->courseid, MUST_EXIST);
if (!has_capability('enrol/manual:manage', $context) or !has_capability('enrol/manual:enrol', $context) or !has_capability('enrol/manual:unenrol', $context)) {
return NULL;
}
return new moodle_url('/enrol/manual/manage.php', array('enrolid' => $instance->id, 'id' => $instance->courseid));
}
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:22,代码来源:lib.php
示例15: enrol_user
function enrol_user($userid, $courseid)
{
global $DB;
if (!enrol_is_enabled('manual')) {
return false;
}
if (!($enrol = enrol_get_plugin('manual'))) {
return false;
}
$params = array('enrol' => 'manual', 'courseid' => $courseid, 'status' => ENROL_INSTANCE_ENABLED);
if (!($instances = $DB->get_records('enrol', $params, 'sortorder,id ASC'))) {
return false;
}
$instance = reset($instances);
$enrol->enrol_user($instance, $userid, $instance->roleid, time(), time() + 24 * 60 * 60 * 30);
}
开发者ID:advancingdesign,项目名称:moodle-quiz_papercopy,代码行数:16,代码来源:createuser.php
示例16: member_added
public function member_added($ca)
{
global $DB;
if (!enrol_is_enabled('cohort')) {
return true;
}
// does anything want to sync with this parent?
//TODO: add join to role table to make sure that roleid actually exists
if (!($enrols = $DB->get_records('enrol', array('customint1' => $ca->cohortid, 'enrol' => 'cohort'), 'id ASC'))) {
return true;
}
$plugin = enrol_get_plugin('cohort');
foreach ($enrols as $enrol) {
// no problem if already enrolled
$plugin->enrol_user($enrol, $ca->userid, $enrol->roleid);
}
return true;
}
开发者ID:rolandovanegas,项目名称:moodle,代码行数:18,代码来源:locallib.php
示例17: test_utils
/**
* Test utility methods used in syn test, fail here means something
* in core accesslib was changed, but it is possible that only this test
* is affected, nto the plugin itself...
*/
public function test_utils()
{
global $DB;
$this->resetAfterTest();
$syscontext = context_system::instance();
$this->assertFalse(enrol_is_enabled('category'));
$this->enable_plugin();
$this->assertTrue(enrol_is_enabled('category'));
$roles = get_roles_with_capability('enrol/category:synchronised', CAP_ALLOW, $syscontext);
$this->assertEmpty($roles);
$studentrole = $DB->get_record('role', array('shortname' => 'student'));
$this->assertNotEmpty($studentrole);
$this->enable_role_sync($studentrole->id);
$roles = get_roles_with_capability('enrol/category:synchronised', CAP_ALLOW, $syscontext);
$this->assertEquals(1, count($roles));
$this->assertEquals($studentrole, reset($roles));
$this->disable_role_sync($studentrole->id);
$roles = get_roles_with_capability('enrol/category:synchronised', CAP_ALLOW, $syscontext);
$this->assertEmpty($roles);
}
开发者ID:JP-Git,项目名称:moodle,代码行数:25,代码来源:sync_test.php
示例18: role_unassigned
/**
* Triggered when user role is unassigned.
*
* @param \core\event\role_unassigned $event
*/
public static function role_unassigned(\core\event\role_unassigned $event)
{
global $DB;
if (!enrol_is_enabled('category')) {
return;
}
$ra = new stdClass();
$ra->userid = $event->relateduserid;
$ra->contextid = $event->contextid;
// only category level roles are interesting
$parentcontext = context::instance_by_id($ra->contextid);
if ($parentcontext->contextlevel != CONTEXT_COURSECAT) {
return;
}
// Now this is going to be a bit slow, take all enrolments in child courses and verify each separately.
$syscontext = context_system::instance();
if (!($roles = get_roles_with_capability('enrol/category:synchronised', CAP_ALLOW, $syscontext))) {
return;
}
$plugin = enrol_get_plugin('category');
$sql = "SELECT e.*\n FROM {course} c\n JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :courselevel AND ctx.path LIKE :match)\n JOIN {enrol} e ON (e.courseid = c.id AND e.enrol = 'category')\n JOIN {user_enrolments} ue ON (ue.enrolid = e.id AND ue.userid = :userid)";
$params = array('courselevel' => CONTEXT_COURSE, 'match' => $parentcontext->path . '/%', 'userid' => $ra->userid);
$rs = $DB->get_recordset_sql($sql, $params);
list($roleids, $params) = $DB->get_in_or_equal(array_keys($roles), SQL_PARAMS_NAMED, 'r');
$params['userid'] = $ra->userid;
foreach ($rs as $instance) {
$coursecontext = context_course::instance($instance->courseid);
$contextids = $coursecontext->get_parent_context_ids();
array_pop($contextids);
// Remove system context, we are interested in categories only.
list($contextids, $contextparams) = $DB->get_in_or_equal($contextids, SQL_PARAMS_NAMED, 'c');
$params = array_merge($params, $contextparams);
$sql = "SELECT ra.id\n FROM {role_assignments} ra\n WHERE ra.userid = :userid AND ra.contextid {$contextids} AND ra.roleid {$roleids}";
if (!$DB->record_exists_sql($sql, $params)) {
// User does not have any interesting role in any parent context, let's unenrol.
$plugin->unenrol_user($instance, $ra->userid);
}
}
$rs->close();
}
开发者ID:evltuma,项目名称:moodle,代码行数:45,代码来源:observer.php
示例19: member_added
/**
* Event processor - cohort member added.
* @param \core\event\cohort_member_added $event
* @return bool
*/
public static function member_added(\core\event\cohort_member_added $event)
{
global $DB, $CFG;
require_once "{$CFG->dirroot}/group/lib.php";
if (!enrol_is_enabled('cohort')) {
return true;
}
// Does any enabled cohort instance want to sync with this cohort?
$sql = "SELECT e.*, r.id as roleexists\n FROM {enrol} e\n LEFT JOIN {role} r ON (r.id = e.roleid)\n WHERE e.customint1 = :cohortid AND e.enrol = 'cohort' AND e.status = :enrolstatus\n ORDER BY e.id ASC";
$params['cohortid'] = $event->objectid;
$params['enrolstatus'] = ENROL_INSTANCE_ENABLED;
if (!($instances = $DB->get_records_sql($sql, $params))) {
return true;
}
$plugin = enrol_get_plugin('cohort');
foreach ($instances as $instance) {
if ($instance->status != ENROL_INSTANCE_ENABLED) {
// No roles for disabled instances.
$instance->roleid = 0;
} else {
if ($instance->roleid and !$instance->roleexists) {
// Invalid role - let's just enrol, they will have to create new sync and delete this one.
$instance->roleid = 0;
}
}
unset($instance->roleexists);
// No problem if already enrolled.
$plugin->enrol_user($instance, $event->relateduserid, $instance->roleid, 0, 0, ENROL_USER_ACTIVE);
// Sync groups.
if ($instance->customint2) {
if (!groups_is_member($instance->customint2, $event->relateduserid)) {
if ($group = $DB->get_record('groups', array('id' => $instance->customint2, 'courseid' => $instance->courseid))) {
groups_add_member($group->id, $event->relateduserid, 'enrol_cohort', $instance->id);
}
}
}
}
return true;
}
开发者ID:stronk7,项目名称:moodle,代码行数:44,代码来源:locallib.php
示例20: require_login
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');
开发者ID:dg711,项目名称:moodle,代码行数:31,代码来源:ajax.php
注:本文中的enrol_is_enabled函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论