• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

PHP enrol_get_plugin函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中enrol_get_plugin函数的典型用法代码示例。如果您正苦于以下问题:PHP enrol_get_plugin函数的具体用法?PHP enrol_get_plugin怎么用?PHP enrol_get_plugin使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了enrol_get_plugin函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: definition

 function definition()
 {
     global $CFG, $DB;
     $mform = $this->_form;
     list($instance, $plugin, $course) = $this->_customdata;
     $coursecontext = context_course::instance($course->id);
     $enrol = enrol_get_plugin('cohort');
     $groups = array(0 => get_string('none'));
     foreach (groups_get_all_groups($course->id) as $group) {
         $groups[$group->id] = format_string($group->name, true, array('context' => $coursecontext));
     }
     $mform->addElement('header', 'general', get_string('pluginname', 'enrol_cohort'));
     $mform->addElement('text', 'name', get_string('custominstancename', 'enrol'));
     $mform->setType('name', PARAM_TEXT);
     $options = array(ENROL_INSTANCE_ENABLED => get_string('yes'), ENROL_INSTANCE_DISABLED => get_string('no'));
     $mform->addElement('select', 'status', get_string('status', 'enrol_cohort'), $options);
     if ($instance->id) {
         if ($cohort = $DB->get_record('cohort', array('id' => $instance->customint1))) {
             $cohorts = array($instance->customint1 => format_string($cohort->name, true, array('context' => context::instance_by_id($cohort->contextid))));
         } else {
             $cohorts = array($instance->customint1 => get_string('error'));
         }
         $mform->addElement('select', 'customint1', get_string('cohort', 'cohort'), $cohorts);
         $mform->setConstant('customint1', $instance->customint1);
         $mform->hardFreeze('customint1', $instance->customint1);
     } else {
         $cohorts = array('' => get_string('choosedots'));
         $allcohorts = cohort_get_available_cohorts($coursecontext, 0, 0, 0);
         foreach ($allcohorts as $c) {
             $cohorts[$c->id] = format_string($c->name);
         }
         $mform->addElement('select', 'customint1', get_string('cohort', 'cohort'), $cohorts);
         $mform->addRule('customint1', get_string('required'), 'required', null, 'client');
     }
     $roles = get_assignable_roles($coursecontext);
     $roles[0] = get_string('none');
     $roles = array_reverse($roles, true);
     // Descending default sortorder.
     $mform->addElement('select', 'roleid', get_string('assignrole', 'enrol_cohort'), $roles);
     $mform->setDefault('roleid', $enrol->get_config('roleid'));
     if ($instance->id and !isset($roles[$instance->roleid])) {
         if ($role = $DB->get_record('role', array('id' => $instance->roleid))) {
             $roles = role_fix_names($roles, $coursecontext, ROLENAME_ALIAS, true);
             $roles[$instance->roleid] = role_get_name($role, $coursecontext);
         } else {
             $roles[$instance->roleid] = get_string('error');
         }
     }
     $mform->addElement('select', 'customint2', get_string('addgroup', 'enrol_cohort'), $groups);
     $mform->addElement('hidden', 'courseid', null);
     $mform->setType('courseid', PARAM_INT);
     $mform->addElement('hidden', 'id', null);
     $mform->setType('id', PARAM_INT);
     if ($instance->id) {
         $this->add_action_buttons(true);
     } else {
         $this->add_action_buttons(true, get_string('addinstance', 'enrol'));
     }
     $this->set_data($instance);
 }
开发者ID:MoodleMetaData,项目名称:MoodleMetaData,代码行数:60,代码来源:edit_form.php


示例2: setUp

    protected function setUp() {
        global $DB, $CFG;
        $this->resetAfterTest(true);

        unset_config('noemailever');

        $CFG->enablecompletion = true;

        $user = $this->getDataGenerator()->create_user();

        $fordb = new stdClass();
        $fordb->id = null;
        $fordb->name = "Test badge";
        $fordb->description = "Testing badges";
        $fordb->timecreated = time();
        $fordb->timemodified = time();
        $fordb->usercreated = $user->id;
        $fordb->usermodified = $user->id;
        $fordb->issuername = "Test issuer";
        $fordb->issuerurl = "http://issuer-url.domain.co.nz";
        $fordb->issuercontact = "[email protected]";
        $fordb->expiredate = null;
        $fordb->expireperiod = null;
        $fordb->type = BADGE_TYPE_SITE;
        $fordb->courseid = null;
        $fordb->messagesubject = "Test message subject";
        $fordb->message = "Test message body";
        $fordb->attachment = 1;
        $fordb->notification = 0;
        $fordb->status = BADGE_STATUS_INACTIVE;

        $this->badgeid = $DB->insert_record('badge', $fordb, true);

        // Create a course with activity and auto completion tracking.
        $this->course = $this->getDataGenerator()->create_course(array('enablecompletion' => true));
        $this->user = $this->getDataGenerator()->create_user();
        $studentrole = $DB->get_record('role', array('shortname' => 'student'));
        $this->assertNotEmpty($studentrole);

        // Get manual enrolment plugin and enrol user.
        require_once($CFG->dirroot.'/enrol/manual/locallib.php');
        $manplugin = enrol_get_plugin('manual');
        $maninstance = $DB->get_record('enrol', array('courseid' => $this->course->id, 'enrol' => 'manual'), '*', MUST_EXIST);
        $manplugin->enrol_user($maninstance, $this->user->id, $studentrole->id);
        $this->assertEquals(1, $DB->count_records('user_enrolments'));

        $completionauto = array('completion' => COMPLETION_TRACKING_AUTOMATIC);
        $this->module = $this->getDataGenerator()->create_module('forum', array('course' => $this->course->id), $completionauto);

        // Build badge and criteria.
        $fordb->type = BADGE_TYPE_COURSE;
        $fordb->courseid = $this->course->id;
        $fordb->status = BADGE_STATUS_ACTIVE;

        $this->coursebadge = $DB->insert_record('badge', $fordb, true);
        $this->assertion = new stdClass();
        $this->assertion->badge = '{"uid":"%s","recipient":{"identity":"%s","type":"email","hashed":true,"salt":"%s"},"badge":"%s","verify":{"type":"hosted","url":"%s"},"issuedOn":"%d","evidence":"%s"}';
        $this->assertion->class = '{"name":"%s","description":"%s","image":"%s","criteria":"%s","issuer":"%s"}';
        $this->assertion->issuer = '{"name":"%s","url":"%s","email":"%s"}';
    }
开发者ID:rwijaya,项目名称:moodle,代码行数:60,代码来源:badgeslib_test.php


示例3: get_instance_info

 /**
  * Return guest enrolment instance information.
  *
  * @param int $instanceid instance id of guest enrolment plugin.
  * @return array warnings and instance information.
  * @since Moodle 3.1
  */
 public static function get_instance_info($instanceid)
 {
     global $DB;
     $params = self::validate_parameters(self::get_instance_info_parameters(), array('instanceid' => $instanceid));
     $warnings = array();
     // Retrieve guest enrolment plugin.
     $enrolplugin = enrol_get_plugin('guest');
     if (empty($enrolplugin)) {
         throw new moodle_exception('invaliddata', 'error');
     }
     require_login(null, false, null, false, true);
     $enrolinstance = $DB->get_record('enrol', array('id' => $params['instanceid']), '*', MUST_EXIST);
     $course = $DB->get_record('course', array('id' => $enrolinstance->courseid), '*', MUST_EXIST);
     $context = context_course::instance($course->id);
     if (!$course->visible and !has_capability('moodle/course:viewhiddencourses', $context)) {
         throw new moodle_exception('coursehidden');
     }
     $instanceinfo = $enrolplugin->get_enrol_info($enrolinstance);
     // Specific instance information.
     $instanceinfo->passwordrequired = $instanceinfo->requiredparam->passwordrequired;
     unset($instanceinfo->requiredparam);
     $result = array();
     $result['instanceinfo'] = $instanceinfo;
     $result['warnings'] = $warnings;
     return $result;
 }
开发者ID:rushi963,项目名称:moodle,代码行数:33,代码来源:external.php


示例4: get_instance_info

 /**
  * Return self-enrolment instance information.
  *
  * @param int $instanceid instance id of self enrolment plugin.
  * @return array instance information.
  * @throws moodle_exception
  */
 public static function get_instance_info($instanceid)
 {
     global $DB, $CFG;
     require_once $CFG->libdir . '/enrollib.php';
     $params = self::validate_parameters(self::get_instance_info_parameters(), array('instanceid' => $instanceid));
     // Retrieve self enrolment plugin.
     $enrolplugin = enrol_get_plugin('self');
     if (empty($enrolplugin)) {
         throw new moodle_exception('invaliddata', 'error');
     }
     // Note that we can't use validate_context because the user is not enrolled in the course.
     require_login(null, false, null, false, true);
     $enrolinstance = $DB->get_record('enrol', array('id' => $params['instanceid']), '*', MUST_EXIST);
     $course = $DB->get_record('course', array('id' => $enrolinstance->courseid), '*', MUST_EXIST);
     $context = context_course::instance($course->id);
     if (!$course->visible and !has_capability('moodle/course:viewhiddencourses', $context)) {
         throw new moodle_exception('coursehidden');
     }
     $instanceinfo = (array) $enrolplugin->get_enrol_info($enrolinstance);
     if (isset($instanceinfo['requiredparam']->enrolpassword)) {
         $instanceinfo['enrolpassword'] = $instanceinfo['requiredparam']->enrolpassword;
     }
     unset($instanceinfo->requiredparam);
     return $instanceinfo;
 }
开发者ID:parksandwildlife,项目名称:learning,代码行数:32,代码来源:externallib.php


示例5: definition

 function definition()
 {
     global $CFG, $DB;
     $mform = $this->_form;
     $course = $this->_customdata;
     $coursecontext = context_course::instance($course->id);
     $enrol = enrol_get_plugin('cohort');
     $cohorts = array('' => get_string('choosedots'));
     list($sqlparents, $params) = $DB->get_in_or_equal(get_parent_contexts($coursecontext));
     $sql = "SELECT id, name, contextid\n                  FROM {cohort}\n                 WHERE contextid {$sqlparents}\n              ORDER BY name ASC";
     $rs = $DB->get_recordset_sql($sql, $params);
     foreach ($rs as $c) {
         $context = get_context_instance_by_id($c->contextid);
         if (!has_capability('moodle/cohort:view', $context)) {
             continue;
         }
         $cohorts[$c->id] = format_string($c->name);
     }
     $rs->close();
     $roles = get_assignable_roles($coursecontext);
     $roles[0] = get_string('none');
     $roles = array_reverse($roles, true);
     // descending default sortorder
     $mform->addElement('header', 'general', get_string('pluginname', 'enrol_cohort'));
     $mform->addElement('select', 'cohortid', get_string('cohort', 'cohort'), $cohorts);
     $mform->addRule('cohortid', get_string('required'), 'required', null, 'client');
     $mform->addElement('select', 'roleid', get_string('role'), $roles);
     $mform->addRule('roleid', get_string('required'), 'required', null, 'client');
     $mform->setDefault('roleid', $enrol->get_config('roleid'));
     $mform->addElement('hidden', 'id', null);
     $mform->setType('id', PARAM_INT);
     $this->add_action_buttons(true, get_string('addinstance', 'enrol'));
     $this->set_data(array('id' => $course->id));
 }
开发者ID:nigeli,项目名称:moodle,代码行数:34,代码来源:addinstance_form.php


示例6: test_get_users_courses

 /**
  * Test get_users_courses
  */
 public function test_get_users_courses()
 {
     global $USER;
     $this->resetAfterTest(true);
     $course1 = self::getDataGenerator()->create_course();
     $course2 = self::getDataGenerator()->create_course();
     $courses = array($course1, $course2);
     // Enrol $USER in the courses.
     // We use the manual plugin.
     $enrol = enrol_get_plugin('manual');
     $roleid = null;
     foreach ($courses as $course) {
         $context = context_course::instance($course->id);
         $roleid = $this->assignUserCapability('moodle/course:viewparticipants', $context->id, $roleid);
         $enrolinstances = enrol_get_instances($course->id, true);
         foreach ($enrolinstances as $courseenrolinstance) {
             if ($courseenrolinstance->enrol == "manual") {
                 $instance = $courseenrolinstance;
                 break;
             }
         }
         $enrol->enrol_user($instance, $USER->id, $roleid);
     }
     // Call the external function.
     $enrolledincourses = core_enrol_external::get_users_courses($USER->id);
     // We need to execute the return values cleaning process to simulate the web service server.
     $enrolledincourses = external_api::clean_returnvalue(core_enrol_external::get_users_courses_returns(), $enrolledincourses);
     // Check we retrieve the good total number of enrolled users.
     $this->assertEquals(2, count($enrolledincourses));
 }
开发者ID:Burick,项目名称:moodle,代码行数:33,代码来源:externallib_test.php


示例7: execute

 public function execute()
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/cohort/lib.php';
     require_once $CFG->dirroot . '/enrol/cohort/locallib.php';
     foreach ($this->arguments as $argument) {
         $this->expandOptionsManually(array($argument));
         $options = $this->expandedOptions;
         // Sanity Checks.
         // Check if cohorst exists.
         if (!($cohorts = $DB->get_records('cohort', array('name' => $argument)))) {
             echo "Cohort does not exist\n";
             exit(0);
         }
         // Check if enough arguments.
         if (empty($options['courseid']) && empty($options['userid'])) {
             echo "Not enough arguments, provide userid or courseid\n";
         }
         // Check if course exists.
         $course = '';
         if (!empty($options['courseid'])) {
             if (!($course = $DB->get_record('course', array('id' => $options['courseid'])))) {
                 echo "Course does not exist\n";
                 exit(0);
             }
         }
         // Check if user exists.
         if (!empty($options['userid'])) {
             if (!($user = $DB->get_record('user', array('id' => $options['userid'])))) {
                 echo "User does not exist\n";
                 exit(0);
             }
         }
         // Add cohort to course
         if (!empty($course)) {
             foreach ($cohorts as $cohort) {
                 // Check if cohort enrolment already exists
                 if ($cohortenrolment = $DB->get_record('enrol', array('customint1' => $cohort->id, 'courseid' => $options['courseid']))) {
                     echo " Notice: Cohort already enrolled into course\n";
                 } else {
                     $enrol = enrol_get_plugin('cohort');
                     $studentrole = $DB->get_record('role', array('shortname' => 'student'));
                     $enrol->add_instance($course, array('name' => $argument . '_sync', 'status' => 0, 'customint1' => $cohort->id, 'roleid' => $studentrole->id, 'customint2' => '0'));
                     echo "Cohort enrolled\n";
                 }
                 $this->enrol_cohort_sync($course->id);
             }
         }
         if (!empty($user)) {
             foreach ($cohorts as $cohort) {
                 cohort_add_member($cohort->id, $options['userid']);
                 echo "User enrolled\n";
                 if (!empty($course)) {
                     $this->enrol_cohort_sync($course->id);
                 }
             }
         }
     }
 }
开发者ID:dariogs,项目名称:moosh,代码行数:59,代码来源:CohortEnrol.php


示例8: make_course_enrollable

 /**
  * Set up our main Moodle course to be enrollable
  */
 protected function make_course_enrollable()
 {
     set_config('enrol_plugins_enabled', 'manual');
     $enrol = enrol_get_plugin('manual');
     $course = new \stdClass();
     $course->id = 2;
     $enrol->add_instance($course);
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:11,代码来源:synchronizemoodleclassgrades_test.php


示例9: __construct

 /**
  * @param mr_fixture_course $course The course to enroll the user into
  * @param mr_fixture_user $user The user to enroll
  * @param enrol_plugin $enroll The enrollment plugin to use, defaults to enrol_get_plugin('manual')
  * @param mr_fixture_role|null $role The role to use for the enrollment, optional
  * @param array|object $options Parameters to pass to the enrol_plugin->enrol_user()
  */
 public function __construct(mr_fixture_course $course, mr_fixture_user $user, enrol_plugin $enroll = null, mr_fixture_role $role = null, $options = array())
 {
     parent::__construct();
     if (is_null($enroll)) {
         $enroll = enrol_get_plugin('manual');
     }
     $this->set_course($course)->set_user($user)->set_enroll($enroll)->set_role($role)->set_options($options);
 }
开发者ID:bgao-ca,项目名称:moodle-local_mr,代码行数:15,代码来源:enrollment.php


示例10: enrol_users

 /**
  * Enrolment of users.
  *
  * Function throw an exception at the first error encountered.
  * @param array $enrolments  An array of user enrolment
  * @since Moodle 2.2
  */
 public static function enrol_users($enrolments)
 {
     global $DB, $CFG;
     require_once $CFG->libdir . '/enrollib.php';
     $params = self::validate_parameters(self::enrol_users_parameters(), array('enrolments' => $enrolments));
     $transaction = $DB->start_delegated_transaction();
     // Rollback all enrolment if an error occurs
     // (except if the DB doesn't support it).
     // Retrieve the manual enrolment plugin.
     $enrol = enrol_get_plugin('manual');
     if (empty($enrol)) {
         throw new moodle_exception('manualpluginnotinstalled', 'enrol_manual');
     }
     foreach ($params['enrolments'] as $enrolment) {
         // Ensure the current user is allowed to run this function in the enrolment context.
         $context = context_course::instance($enrolment['courseid'], IGNORE_MISSING);
         self::validate_context($context);
         // Check that the user has the permission to manual enrol.
         require_capability('enrol/manual:enrol', $context);
         // Throw an exception if user is not able to assign the role.
         $roles = get_assignable_roles($context);
         if (!array_key_exists($enrolment['roleid'], $roles)) {
             $errorparams = new stdClass();
             $errorparams->roleid = $enrolment['roleid'];
             $errorparams->courseid = $enrolment['courseid'];
             $errorparams->userid = $enrolment['userid'];
             throw new moodle_exception('wsusercannotassign', 'enrol_manual', '', $errorparams);
         }
         // Check manual enrolment plugin instance is enabled/exist.
         $instance = null;
         $enrolinstances = enrol_get_instances($enrolment['courseid'], true);
         foreach ($enrolinstances as $courseenrolinstance) {
             if ($courseenrolinstance->enrol == "manual") {
                 $instance = $courseenrolinstance;
                 break;
             }
         }
         if (empty($instance)) {
             $errorparams = new stdClass();
             $errorparams->courseid = $enrolment['courseid'];
             throw new moodle_exception('wsnoinstance', 'enrol_manual', $errorparams);
         }
         // Check that the plugin accept enrolment (it should always the case, it's hard coded in the plugin).
         if (!$enrol->allow_enrol($instance)) {
             $errorparams = new stdClass();
             $errorparams->roleid = $enrolment['roleid'];
             $errorparams->courseid = $enrolment['courseid'];
             $errorparams->userid = $enrolment['userid'];
             throw new moodle_exception('wscannotenrol', 'enrol_manual', '', $errorparams);
         }
         // Finally proceed the enrolment.
         $enrolment['timestart'] = isset($enrolment['timestart']) ? $enrolment['timestart'] : 0;
         $enrolment['timeend'] = isset($enrolment['timeend']) ? $enrolment['timeend'] : 0;
         $enrolment['status'] = isset($enrolment['suspend']) && !empty($enrolment['suspend']) ? ENROL_USER_SUSPENDED : ENROL_USER_ACTIVE;
         $enrol->enrol_user($instance, $enrolment['userid'], $enrolment['roleid'], $enrolment['timestart'], $enrolment['timeend'], $enrolment['status']);
     }
     $transaction->allow_commit();
 }
开发者ID:Hirenvaghasiya,项目名称:moodle,代码行数:65,代码来源:externallib.php


示例11: test_can_delete_instance

    /**
     * Test can_delete_instance
     */
    public function test_can_delete_instance()
    {
        global $DB, $CFG;
        require_once $CFG->dirroot . '/enrol/uaims/lib.php';
        $this->resetAfterTest();
        // Create users to enrol.
        $user1 = $this->getDataGenerator()->create_user();
        $user2 = $this->getDataGenerator()->create_user();
        // User to use in IMS enrol.
        $user3 = $this->getDataGenerator()->create_user(array('idnumber' => 'testuser3'));
        $xmldoc = <<<DOC
<?xml version="1.0" encoding="utf-8"?>
<enterprise xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<group recstatus="1"> <sourcedid> <source>AIS</source> <id>IDNUMBER</id> </sourcedid>
<grouptype> <typevalue>Course</typevalue> </grouptype>
<description> <short>IDNUMBER</short> <long>Long description</long> </description>
<org /> <timeframe> <begin>1420441200</begin> <end>1431237600</end> </timeframe> <enrollcontrol />
<relationship> <sourcedid> <source>AIS</source> <id>UOFAB-TEST</id> </sourcedid> </relationship>
<extension> <settings> <setting>visible</setting> <value>0</value> </settings>
<settings> <setting>format</setting> <value>topics</value> </settings> </extension></group>
<membership> <sourcedid> <source>AIS</source> <id>IDNUMBER</id> </sourcedid>
<member> <idtype>1</idtype> <sourcedid> <source>AIS</source> <id>testuser3</id> </sourcedid> <role recstatus="1" roletype="05">
<status>1</status> </role> </member> </membership></enterprise>
DOC;
        $category = new stdClass();
        $category->name = "test";
        $category->description = "UOFAB-TEST";
        $category->idnumber = "UOFAB-TEST";
        $category->timemodified = time();
        $DB->insert_record('course_categories', $category);
        $enrol = new enrol_uaims_plugin();
        // Make sure the course does not already exist.
        $course = $DB->get_record('course', array('idnumber' => "IDNUMBER"), $fields = '*', $strictness = IGNORE_MISSING);
        $this->assertEquals(false, $course);
        // Process the IMS Doc.
        $enrol->process_imsdoc($xmldoc);
        $course = $DB->get_record('course', array('idnumber' => "IDNUMBER"), $fields = '*', $strictness = MUST_EXIST);
        $manplugin = enrol_get_plugin('manual');
        $uaimsplugin = enrol_get_plugin('uaims');
        // Get the manager and teacher roles.
        $managerrole = $DB->get_record('role', array('shortname' => 'manager'));
        $this->assertNotEmpty($managerrole);
        $teacherrole = $DB->get_record('role', array('shortname' => 'teacher'));
        $this->assertNotEmpty($teacherrole);
        $maninstance1 = $DB->get_record('enrol', array('courseid' => $course->id, 'enrol' => 'manual'), '*', MUST_EXIST);
        $uaimsinstance1 = $DB->get_record('enrol', array('courseid' => $course->id, 'enrol' => 'uaims'), '*', MUST_EXIST);
        // Manually enrol users since the IMS plugin incorrectly assigns roles. CC does this as a separate process.
        $manplugin->enrol_user($maninstance1, $user1->id, $managerrole->id);
        $manplugin->enrol_user($maninstance1, $user2->id, $teacherrole->id);
        // Test that managers can delete the UAIM enrol method.
        $this->setUser($user1);
        $this->assertEquals(true, $uaimsplugin->can_delete_instance($uaimsinstance1));
        // Test that teachers can NOT delete the UAIM enrol method.
        $this->setUser($user2);
        $this->assertEquals(false, $uaimsplugin->can_delete_instance($uaimsinstance1));
    }
开发者ID:MoodleMetaData,项目名称:MoodleMetaData,代码行数:59,代码来源:enrol_uaims_delete_test.php


示例12: enrol_into_course

function enrol_into_course($courseid, $userid, $roleid = 5)
{
    global $DB;
    $manualenrol = enrol_get_plugin('manual');
    // get the enrolment plugin
    $enrolinstance = $DB->get_record('enrol', array('courseid' => $courseid, 'status' => ENROL_INSTANCE_ENABLED, 'enrol' => 'manual'), '*', MUST_EXIST);
    // retrieve enrolment instance associated with your course
    return $manualenrol->enrol_user($enrolinstance, $userid, $roleid);
    // enrol the user
}
开发者ID:nagyistoce,项目名称:wp2moodle-moodle,代码行数:10,代码来源:login.php


示例13: test_get_instance_info

 /**
  * Test get_instance_info
  */
 public function test_get_instance_info()
 {
     global $DB;
     $this->resetAfterTest(true);
     // Check if guest enrolment plugin is enabled.
     $guestplugin = enrol_get_plugin('guest');
     $this->assertNotEmpty($guestplugin);
     $studentrole = $DB->get_record('role', array('shortname' => 'student'));
     $coursedata = new stdClass();
     $coursedata->visible = 0;
     $course = self::getDataGenerator()->create_course($coursedata);
     $student = self::getDataGenerator()->create_user();
     $this->getDataGenerator()->enrol_user($student->id, $course->id, $studentrole->id, 'manual');
     // Add enrolment methods for course.
     $instance = $guestplugin->add_instance($course, array('status' => ENROL_INSTANCE_ENABLED, 'name' => 'Test instance', 'customint6' => 1, 'roleid' => $studentrole->id));
     $this->setAdminUser();
     $result = enrol_guest_external::get_instance_info($instance);
     $result = external_api::clean_returnvalue(enrol_guest_external::get_instance_info_returns(), $result);
     $this->assertEquals($instance, $result['instanceinfo']['id']);
     $this->assertEquals($course->id, $result['instanceinfo']['courseid']);
     $this->assertEquals('guest', $result['instanceinfo']['type']);
     $this->assertEquals('Test instance', $result['instanceinfo']['name']);
     $this->assertTrue($result['instanceinfo']['status']);
     $this->assertFalse($result['instanceinfo']['passwordrequired']);
     $DB->set_field('enrol', 'status', ENROL_INSTANCE_DISABLED, array('id' => $instance));
     $result = enrol_guest_external::get_instance_info($instance);
     $result = external_api::clean_returnvalue(enrol_guest_external::get_instance_info_returns(), $result);
     $this->assertEquals($instance, $result['instanceinfo']['id']);
     $this->assertEquals($course->id, $result['instanceinfo']['courseid']);
     $this->assertEquals('guest', $result['instanceinfo']['type']);
     $this->assertEquals('Test instance', $result['instanceinfo']['name']);
     $this->assertFalse($result['instanceinfo']['status']);
     $this->assertFalse($result['instanceinfo']['passwordrequired']);
     $DB->set_field('enrol', 'status', ENROL_INSTANCE_ENABLED, array('id' => $instance));
     // Try to retrieve information using a normal user for a hidden course.
     $user = self::getDataGenerator()->create_user();
     $this->setUser($user);
     try {
         enrol_guest_external::get_instance_info($instance);
     } catch (moodle_exception $e) {
         $this->assertEquals('coursehidden', $e->errorcode);
     }
     // Student user.
     $DB->set_field('course', 'visible', 1, array('id' => $course->id));
     $this->setUser($student);
     $result = enrol_guest_external::get_instance_info($instance);
     $result = external_api::clean_returnvalue(enrol_guest_external::get_instance_info_returns(), $result);
     $this->assertEquals($instance, $result['instanceinfo']['id']);
     $this->assertEquals($course->id, $result['instanceinfo']['courseid']);
     $this->assertEquals('guest', $result['instanceinfo']['type']);
     $this->assertEquals('Test instance', $result['instanceinfo']['name']);
     $this->assertTrue($result['instanceinfo']['status']);
     $this->assertFalse($result['instanceinfo']['passwordrequired']);
 }
开发者ID:evltuma,项目名称:moodle,代码行数:57,代码来源:external_test.php


示例14: xmldb_enrol_metaplus_uninstall

function xmldb_enrol_metaplus_uninstall()
{
    global $CFG, $DB;
    $meta = enrol_get_plugin('metaplus');
    $rs = $DB->get_recordset('enrol', array('enrol' => 'metaplus'));
    foreach ($rs as $instance) {
        $meta->delete_instance($instance);
    }
    $rs->close();
    role_unassign_all(array('component' => 'enrol_metaplus'));
    return true;
}
开发者ID:unikent,项目名称:moodle-enrol_metaplus,代码行数:12,代码来源:uninstall.php


示例15: 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


示例16: xmldb_enrol_delayedcohort_uninstall

function xmldb_enrol_delayedcohort_uninstall()
{
    global $CFG, $DB;
    $cohort = enrol_get_plugin('delayedcohort');
    $rs = $DB->get_recordset('enrol', array('enrol' => 'delayedcohort'));
    foreach ($rs as $instance) {
        $cohort->delete_instance($instance);
    }
    $rs->close();
    role_unassign_all(array('component' => 'enrol_delayedcohort'));
    return true;
}
开发者ID:vfremaux,项目名称:moodle-enrol_delayedcohort,代码行数:12,代码来源:uninstall.php


示例17: test_get_instance_info

 /**
  * Test get_instance_info
  */
 public function test_get_instance_info()
 {
     global $DB;
     $this->resetAfterTest(true);
     // Check if self enrolment plugin is enabled.
     $selfplugin = enrol_get_plugin('self');
     $this->assertNotEmpty($selfplugin);
     $studentrole = $DB->get_record('role', array('shortname' => 'student'));
     $this->assertNotEmpty($studentrole);
     $coursedata = new stdClass();
     $coursedata->visible = 0;
     $course = self::getDataGenerator()->create_course($coursedata);
     // Add enrolment methods for course.
     $instanceid1 = $selfplugin->add_instance($course, array('status' => ENROL_INSTANCE_ENABLED, 'name' => 'Test instance 1', 'customint6' => 1, 'roleid' => $studentrole->id));
     $instanceid2 = $selfplugin->add_instance($course, array('status' => ENROL_INSTANCE_DISABLED, 'customint6' => 1, 'name' => 'Test instance 2', 'roleid' => $studentrole->id));
     $instanceid3 = $selfplugin->add_instance($course, array('status' => ENROL_INSTANCE_ENABLED, 'roleid' => $studentrole->id, 'customint6' => 1, 'name' => 'Test instance 3', 'password' => 'test'));
     $enrolmentmethods = $DB->get_records('enrol', array('courseid' => $course->id, 'status' => ENROL_INSTANCE_ENABLED));
     $this->assertCount(3, $enrolmentmethods);
     $this->setAdminUser();
     $instanceinfo1 = enrol_self_external::get_instance_info($instanceid1);
     $instanceinfo1 = external_api::clean_returnvalue(enrol_self_external::get_instance_info_returns(), $instanceinfo1);
     $this->assertEquals($instanceid1, $instanceinfo1['id']);
     $this->assertEquals($course->id, $instanceinfo1['courseid']);
     $this->assertEquals('self', $instanceinfo1['type']);
     $this->assertEquals('Test instance 1', $instanceinfo1['name']);
     $this->assertTrue($instanceinfo1['status']);
     $this->assertFalse(isset($instanceinfo1['enrolpassword']));
     $instanceinfo2 = enrol_self_external::get_instance_info($instanceid2);
     $instanceinfo2 = external_api::clean_returnvalue(enrol_self_external::get_instance_info_returns(), $instanceinfo2);
     $this->assertEquals($instanceid2, $instanceinfo2['id']);
     $this->assertEquals($course->id, $instanceinfo2['courseid']);
     $this->assertEquals('self', $instanceinfo2['type']);
     $this->assertEquals('Test instance 2', $instanceinfo2['name']);
     $this->assertEquals(get_string('canntenrol', 'enrol_self'), $instanceinfo2['status']);
     $this->assertFalse(isset($instanceinfo2['enrolpassword']));
     $instanceinfo3 = enrol_self_external::get_instance_info($instanceid3);
     $instanceinfo3 = external_api::clean_returnvalue(enrol_self_external::get_instance_info_returns(), $instanceinfo3);
     $this->assertEquals($instanceid3, $instanceinfo3['id']);
     $this->assertEquals($course->id, $instanceinfo3['courseid']);
     $this->assertEquals('self', $instanceinfo3['type']);
     $this->assertEquals('Test instance 3', $instanceinfo3['name']);
     $this->assertTrue($instanceinfo3['status']);
     $this->assertEquals(get_string('password', 'enrol_self'), $instanceinfo3['enrolpassword']);
     // Try to retrieve information using a normal user for a hidden course.
     $user = self::getDataGenerator()->create_user();
     $this->setUser($user);
     try {
         enrol_self_external::get_instance_info($instanceid3);
     } catch (moodle_exception $e) {
         $this->assertEquals('coursehidden', $e->errorcode);
     }
 }
开发者ID:parksandwildlife,项目名称:learning,代码行数:55,代码来源:externallib_test.php


示例18: __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


示例19: deleted

 public function deleted($cohort)
 {
     global $DB;
     // does anything want to sync with this parent?
     if (!($enrols = $DB->get_records('enrol', array('customint1' => $cohort->id, 'enrol' => 'cohort'), 'id ASC'))) {
         return true;
     }
     $plugin = enrol_get_plugin('cohort');
     foreach ($enrols as $enrol) {
         $plugin->delete_instance($enrol);
     }
     return true;
 }
开发者ID:rolandovanegas,项目名称:moodle,代码行数:13,代码来源:locallib.php


示例20: execute

 public function execute()
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/course/lib.php';
     foreach ($this->arguments as $argument) {
         $this->expandOptionsManually(array($argument));
         $options = $this->expandedOptions;
         // get the details for the course
         $course = $DB->get_record('course', array('id' => $argument), '*', MUST_EXIST);
         // get the details of the self enrolment plugin
         $plugin = enrol_get_plugin('self');
         if (!$plugin) {
             throw new \Exception('could not find self enrolment plugin');
         }
         // get the enrolment plugin instances for the course
         $instances = enrol_get_instances($course->id, false);
         // loop through the instances to find the instance ID for the self-enrolment plugin
         $selfEnrolInstance = 0;
         foreach ($instances as $instance) {
             if ($instance->enrol === 'self') {
                 $selfEnrolInstance = $instance;
             }
         }
         // if we didn't find an instance for the self enrolment plugin then we need to add
         // one to the course
         if (!$selfEnrolInstance) {
             // first try add an instance
             $plugin->add_default_instance($course);
             // then try retreive it
             $instances = enrol_get_instances($course->id, false);
             $selfEnrolInstance = 0;
             foreach ($instances as $instance) {
                 if ($instance->enrol === 'self') {
                     $selfEnrolInstance = $instance;
                 }
             }
             // if we still didn't get an instance - give up
             if (!$selfEnrolInstance) {
                 throw new \Exception('failed to create instance of self enrolment plugin');
             }
         }
         // activate self enrolment
         if ($selfEnrolInstance->status != ENROL_INSTANCE_ENABLED) {
             $plugin->update_status($selfEnrolInstance, ENROL_INSTANCE_ENABLED);
         }
         // set the enrolment key (always do this so running without the -k option will blank a pre-existing key)
         $instan 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP enrol_get_plugins函数代码示例发布时间:2022-05-15
下一篇:
PHP enrol_get_my_courses函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap