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

PHP enrol_get_instances函数代码示例

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

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



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

示例1: 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);
     // Check we retrieve the good total number of enrolled users.
     $this->assertEquals(2, count($enrolledincourses));
 }
开发者ID:vinoth4891,项目名称:clinique,代码行数:31,代码来源:externallib_test.php


示例2: manual_enrol_users

 /**
  * Enrolment of users
  * Function throw an exception at the first error encountered.
  * @param array $enrolments  An array of user enrolment
  * @return null
  */
 public static function manual_enrol_users($enrolments)
 {
     global $DB, $CFG;
     require_once $CFG->libdir . '/enrollib.php';
     $params = self::validate_parameters(self::manual_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 = get_context_instance(CONTEXT_COURSE, $enrolment['courseid']);
         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 (!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
         $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:sebastiansanio,项目名称:tallerdeprogramacion2fiuba,代码行数:63,代码来源:externallib.php


示例3: 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)
         $instance_fromDB = $DB->get_record('enrol', array('courseid' => $course->id, 'enrol' => 'self', 'id' => $selfEnrolInstance->id), '*', MUST_EXIST);
         $instance_fromDB->password = $options['key'];
         $DB->update_record('enrol', $instance_fromDB);
     }
 }
开发者ID:dariogs,项目名称:moosh,代码行数:51,代码来源:CourseEnableselfenrol.php


示例4: block_csv_enrol_enrol_users

function block_csv_enrol_enrol_users($courseid, $csvcontent)
{
    global $DB, $CFG;
    require_once $CFG->libdir . '/enrollib.php';
    //get enrolment instance (manual and student)
    $instances = enrol_get_instances($courseid, false);
    $enrolment = "";
    foreach ($instances as $instance) {
        if ($instance->enrol === 'manual') {
            $enrolment = $instance;
            break;
        }
    }
    //get enrolment plugin
    $manual = enrol_get_plugin('manual');
    $context = get_context_instance(CONTEXT_COURSE, $courseid);
    $stats = new StdClass();
    $stats->success = $stats->failed = 0;
    //init counters
    $log = get_string('enrolling', 'block_csv_enrol') . "\r\n";
    $lines = explode("\n", $csvcontent);
    foreach ($lines as $line) {
        if ($line == "") {
            continue;
        }
        $user = $DB->get_record('user', array('email' => trim($line)));
        if ($user && !$user->deleted) {
            if (is_enrolled($context, $user)) {
                $log .= get_string('enrollinguser', 'block_csv_enrol', fullname($user) . ' (' . $user->username . ')') . "\r\n";
            } else {
                $log .= get_string('alreadyenrolled', 'block_csv_enrol', fullname($user) . ' (' . $user->username . ')') . "\r\n";
                $manual->enrol_user($enrolment, $user->id, $enrolment->roleid, time());
            }
            $stats->success++;
        } else {
            $log .= get_string('emailnotfound', 'block_csv_enrol', trim($line)) . "\r\n";
            $stats->failed++;
        }
    }
    $log .= get_string('done', 'block_csv_enrol') . "\r\n";
    $log = get_string('status', 'block_csv_enrol', $stats) . ' ' . get_string('enrolmentlog', 'block_csv_enrol') . "\r\n\r\n" . $log;
    return $log;
}
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:43,代码来源:locallib.php


示例5: import_file

 /**
  * Make a role assignment in the specified course using the specified role
  * id for the user whose id information is passed in the line data.
  *
  * @access public
  * @static
  * @param stdClass      $course           Course in which to make the role assignment
  * @param stdClass      $enrol_instance   Enrol instance to use for adding users to course
  * @param string        $ident_field      The field (column) name in Moodle user rec against which to query using the imported data
  * @param int           $role_id          Id of the role to use in the role assignment
  * @param boolean       $group_assign     Whether or not to assign users to groups
  * @param int           $group_id         Id of group to assign to, 0 indicates use group name from import file
  * @param boolean       $group_create     Whether or not to create new groups if needed
  * @param stored_file   $import_file      File in local repository from which to get enrollment and group data
  * @return string                         String message with results
  *
  * @uses $DB
  */
 public static function import_file(stdClass $course, stdClass $enrol_instance, $ident_field, $role_id, $group_assign, $group_id, $group_create, stored_file $import_file)
 {
     global $DB;
     // Default return value
     $result = '';
     // Need one of these in the loop
     $course_context = context_course::instance($course->id);
     // Choose the regex pattern based on the $ident_field
     switch ($ident_field) {
         case 'email':
             $regex_pattern = '/^"?\\s*([a-z0-9][\\w.%-]*@[a-z0-9][a-z0-9.-]{0,61}[a-z0-9]\\.[a-z]{2,6})\\s*"?(?:\\s*[;,\\t]\\s*"?\\s*([a-z0-9][\\w\' .,&-]*))?\\s*"?$/Ui';
             break;
         case 'idnumber':
             $regex_pattern = '/^"?\\s*(\\d{1,32})\\s*"?(?:\\s*[;,\\t]\\s*"?\\s*([a-z0-9][\\w\' .,&-]*))?\\s*"?$/Ui';
             break;
         default:
             $regex_pattern = '/^"?\\s*([a-z0-9][\\[email protected]]*)\\s*"?(?:\\s*[;,\\t]\\s*"?\\s*([a-z0-9][\\w\' .,&-]*))?\\s*"?$/Ui';
             break;
     }
     // If doing group assignments, want to know the valid
     // groups for the course
     $selected_group = null;
     if ($group_assign) {
         if (false === ($existing_groups = groups_get_all_groups($course->id))) {
             $existing_groups = array();
         }
         if ($group_id > 0) {
             if (array_key_exists($group_id, $existing_groups)) {
                 $selected_group = $existing_groups[$group_id];
             } else {
                 // Error condition
                 return sprintf(get_string('ERR_INVALID_GROUP_ID', self::PLUGIN_NAME), $group_id);
             }
         }
     }
     // Iterate the list of active enrol plugins looking for
     // the meta course plugin
     $metacourse = false;
     $enrols_enabled = enrol_get_instances($course->id, true);
     foreach ($enrols_enabled as $enrol) {
         if ($enrol->enrol == 'meta') {
             $metacourse = true;
             break;
         }
     }
     // Get an instance of the enrol_manual_plugin (not to be confused
     // with the enrol_instance arg)
     $manual_enrol_plugin = enrol_get_plugin('manual');
     $user_rec = $new_group = $new_grouping = null;
     // Open and fetch the file contents
     $fh = $import_file->get_content_file_handle();
     $line_num = 0;
     while (false !== ($line = fgets($fh))) {
         $line_num++;
         // Clean these up for each iteration
         unset($user_rec, $new_group, $new_grouping);
         if (!($line = trim($line))) {
             continue;
         }
         // Parse the line, from which we may get one or two
         // matches since the group name is an optional item
         // on a line by line basis
         if (!preg_match($regex_pattern, $line, $matches)) {
             $result .= sprintf(get_string('ERR_PATTERN_MATCH', self::PLUGIN_NAME), $line_num, $line);
             continue;
         }
         $ident_value = $matches[1];
         $group_name = isset($matches[2]) ? $matches[2] : '';
         // User must already exist, we import enrollments
         // into courses, not users into the system. Exclude
         // records marked as deleted. Because idnumber is
         // not enforced unique, possible multiple records
         // returned when using that identifying field, so
         // use ->get_records method to make that detection
         // and inform user
         $user_rec_array = $DB->get_records('user', array($ident_field => addslashes($ident_value), 'deleted' => 0));
         // Should have one and only one record, otherwise
         // report it and move on to the next
         $user_rec_count = count($user_rec_array);
         if ($user_rec_count == 0) {
             // No record found
             $result .= sprintf(get_string('ERR_USERID_INVALID', self::PLUGIN_NAME), $line_num, $ident_value);
//.........这里部分代码省略.........
开发者ID:aj-michael,项目名称:moodle-local_userenrols,代码行数:101,代码来源:lib.php


示例6: create_moodle_course

 /**
  * Create a course in Moodle (Migration)
  *
  * @global type $DB
  * @global type $CFG
  * @global type $USER
  * @param int $tiicourseid The course id on Turnitin
  * @param string $tiicoursetitle The course title on Turnitin
  * @param string $coursename The new course name on Moodle
  * @param int $coursecategory The category that the course is to be created in
  * @return mixed course object if created or 0 if failed
  */
 public static function create_moodle_course($tiicourseid, $tiicoursetitle, $coursename, $coursecategory)
 {
     global $DB, $CFG, $USER;
     require_once $CFG->dirroot . "/course/lib.php";
     $data = new stdClass();
     $data->category = $coursecategory;
     $data->fullname = $coursename;
     $data->shortname = "Turnitin (" . $tiicourseid . ")";
     $data->maxbytes = 2097152;
     if ($course = create_course($data)) {
         $turnitincourse = new stdClass();
         $turnitincourse->courseid = $course->id;
         $turnitincourse->turnitin_cid = $tiicourseid;
         $turnitincourse->turnitin_ctl = $tiicoursetitle;
         $turnitincourse->ownerid = $USER->id;
         $turnitincourse->course_type = 'TT';
         // Enrol user as instructor on course in moodle if they are not a site admin.
         if (!is_siteadmin()) {
             // Get the role id for a teacher.
             $roles1 = get_roles_with_capability('mod/turnitintooltwo:grade');
             $roles2 = get_roles_with_capability('mod/turnitintooltwo:addinstance');
             $roles = array_intersect_key($roles1, $roles2);
             $role = current($roles);
             // Enrol $USER in the courses using the manual plugin.
             $enrol = enrol_get_plugin('manual');
             $enrolinstances = enrol_get_instances($course->id, true);
             foreach ($enrolinstances as $courseenrolinstance) {
                 if ($courseenrolinstance->enrol == "manual") {
                     $instance = $courseenrolinstance;
                     break;
                 }
             }
             $enrol->enrol_user($instance, $USER->id, $role->id);
         } else {
             // Enrol admin as an instructor incase they are not on the account.
             $turnitintooltwouser = new turnitintooltwo_user($USER->id, "Instructor");
             $turnitintooltwouser->join_user_to_class($tiicourseid);
         }
         if (!($insertid = $DB->insert_record('turnitintooltwo_courses', $turnitincourse))) {
             turnitintooltwo_activitylog(get_string('migrationcoursecreatederror', 'turnitintooltwo', $tiicourseid) . ' - ' . $course->id, "REQUEST");
             return 0;
         } else {
             turnitintooltwo_activitylog(get_string('migrationcoursecreated', 'turnitintooltwo') . ' - ' . $course->id . ' (' . $tiicourseid . ')', "REQUEST");
             return $course;
         }
     } else {
         turnitintooltwo_activitylog(get_string('migrationcoursecreateerror', 'turnitintooltwo', $tiicourseid), "REQUEST");
         return 0;
     }
 }
开发者ID:sk-unikent,项目名称:moodle-mod_turnitintooltwo-1,代码行数:62,代码来源:turnitintooltwo_assignment.class.php


示例7: test_enrolment_data

 public function test_enrolment_data()
 {
     $this->resetAfterTest(true);
     $mode = tool_uploadcourse_processor::MODE_CREATE_NEW;
     $updatemode = tool_uploadcourse_processor::UPDATE_ALL_WITH_DATA_ONLY;
     $data = array('shortname' => 'c1', 'summary' => 'S', 'fullname' => 'FN', 'category' => '1');
     $data['enrolment_1'] = 'manual';
     $data['enrolment_1_role'] = 'teacher';
     $data['enrolment_1_startdate'] = '2nd July 2013';
     $data['enrolment_1_enddate'] = '2nd August 2013';
     $data['enrolment_1_enrolperiod'] = '10 days';
     $co = new tool_uploadcourse_course($mode, $updatemode, $data);
     $this->assertTrue($co->prepare());
     $co->proceed();
     // Enrolment methods.
     $enroldata = array();
     $instances = enrol_get_instances($co->get_id(), false);
     foreach ($instances as $instance) {
         $enroldata[$instance->enrol] = $instance;
     }
     $this->assertNotEmpty($enroldata['manual']);
     $this->assertEquals(ENROL_INSTANCE_ENABLED, $enroldata['manual']->status);
     $this->assertEquals(strtotime($data['enrolment_1_startdate']), $enroldata['manual']->enrolstartdate);
     $this->assertEquals(strtotime('1970-01-01 GMT + ' . $data['enrolment_1_enrolperiod']), $enroldata['manual']->enrolperiod);
     $this->assertEquals(strtotime('12th July 2013'), $enroldata['manual']->enrolenddate);
 }
开发者ID:evltuma,项目名称:moodle,代码行数:26,代码来源:course_test.php


示例8: reset_course_userdata


//.........这里部分代码省略.........
        $course = $DB->get_record('course', array('id' => $data->courseid));
        $cc = new completion_info($course);
        $cc->delete_all_completion_data();
        $status[] = array('component' => $componentstr, 'item' => get_string('deletecompletiondata', 'completion'), 'error' => false);
    }
    if (!empty($data->reset_competency_ratings)) {
        \core_competency\api::hook_course_reset_competency_ratings($data->courseid);
        $status[] = array('component' => $componentstr, 'item' => get_string('deletecompetencyratings', 'core_competency'), 'error' => false);
    }
    $componentstr = get_string('roles');
    if (!empty($data->reset_roles_overrides)) {
        $children = $context->get_child_contexts();
        foreach ($children as $child) {
            $DB->delete_records('role_capabilities', array('contextid' => $child->id));
        }
        $DB->delete_records('role_capabilities', array('contextid' => $context->id));
        // Force refresh for logged in users.
        $context->mark_dirty();
        $status[] = array('component' => $componentstr, 'item' => get_string('deletecourseoverrides', 'role'), 'error' => false);
    }
    if (!empty($data->reset_roles_local)) {
        $children = $context->get_child_contexts();
        foreach ($children as $child) {
            role_unassign_all(array('contextid' => $child->id));
        }
        // Force refresh for logged in users.
        $context->mark_dirty();
        $status[] = array('component' => $componentstr, 'item' => get_string('deletelocalroles', 'role'), 'error' => false);
    }
    // First unenrol users - this cleans some of related user data too, such as forum subscriptions, tracking, etc.
    $data->unenrolled = array();
    if (!empty($data->unenrol_users)) {
        $plugins = enrol_get_plugins(true);
        $instances = enrol_get_instances($data->courseid, true);
        foreach ($instances as $key => $instance) {
            if (!isset($plugins[$instance->enrol])) {
                unset($instances[$key]);
                continue;
            }
        }
        foreach ($data->unenrol_users as $withroleid) {
            if ($withroleid) {
                $sql = "SELECT ue.*\n                          FROM {user_enrolments} ue\n                          JOIN {enrol} e ON (e.id = ue.enrolid AND e.courseid = :courseid)\n                          JOIN {context} c ON (c.contextlevel = :courselevel AND c.instanceid = e.courseid)\n                          JOIN {role_assignments} ra ON (ra.contextid = c.id AND ra.roleid = :roleid AND ra.userid = ue.userid)";
                $params = array('courseid' => $data->courseid, 'roleid' => $withroleid, 'courselevel' => CONTEXT_COURSE);
            } else {
                // Without any role assigned at course context.
                $sql = "SELECT ue.*\n                          FROM {user_enrolments} ue\n                          JOIN {enrol} e ON (e.id = ue.enrolid AND e.courseid = :courseid)\n                          JOIN {context} c ON (c.contextlevel = :courselevel AND c.instanceid = e.courseid)\n                     LEFT JOIN {role_assignments} ra ON (ra.contextid = c.id AND ra.userid = ue.userid)\n                         WHERE ra.id IS null";
                $params = array('courseid' => $data->courseid, 'courselevel' => CONTEXT_COURSE);
            }
            $rs = $DB->get_recordset_sql($sql, $params);
            foreach ($rs as $ue) {
                if (!isset($instances[$ue->enrolid])) {
                    continue;
                }
                $instance = $instances[$ue->enrolid];
                $plugin = $plugins[$instance->enrol];
                if (!$plugin->allow_unenrol($instance) and !$plugin->allow_unenrol_user($instance, $ue)) {
                    continue;
                }
                $plugin->unenrol_user($instance, $ue->userid);
                $data->unenrolled[$ue->userid] = $ue->userid;
            }
            $rs->close();
        }
    }
    if (!empty($data->unenrolled)) {
开发者ID:lucaboesch,项目名称:moodle,代码行数:67,代码来源:moodlelib.php


示例9: test_message_get_providers_for_user_more

 public function test_message_get_providers_for_user_more()
 {
     global $DB;
     $this->resetAfterTest();
     // Create a course.
     $course = $this->getDataGenerator()->create_course();
     $coursecontext = context_course::instance($course->id);
     // It would probably be better to use a quiz instance as it has capability controlled messages
     // however mod_quiz doesn't have a data generator.
     // Instead we're going to use backup notifications and give and take away the capability at various levels.
     $assign = $this->getDataGenerator()->create_module('assign', array('course' => $course->id));
     $modulecontext = context_module::instance($assign->cmid);
     // Create and enrol a teacher.
     $teacherrole = $DB->get_record('role', array('shortname' => 'editingteacher'), '*', MUST_EXIST);
     $teacher = $this->getDataGenerator()->create_user();
     role_assign($teacherrole->id, $teacher->id, $coursecontext);
     $enrolplugin = enrol_get_plugin('manual');
     $enrolplugin->add_instance($course);
     $enrolinstances = enrol_get_instances($course->id, false);
     foreach ($enrolinstances as $enrolinstance) {
         if ($enrolinstance->enrol === 'manual') {
             break;
         }
     }
     $enrolplugin->enrol_user($enrolinstance, $teacher->id);
     // Make the teacher the current user.
     $this->setUser($teacher);
     // Teacher shouldn't have the required capability so they shouldn't be able to see the backup message.
     $this->assertFalse(has_capability('moodle/site:config', $modulecontext));
     $providers = message_get_providers_for_user($teacher->id);
     $this->assertFalse($this->message_type_present('moodle', 'backup', $providers));
     // Give the user the required capability in an activity module.
     // They should now be able to see the backup message.
     assign_capability('moodle/site:config', CAP_ALLOW, $teacherrole->id, $modulecontext->id, true);
     accesslib_clear_all_caches_for_unit_testing();
     $modulecontext = context_module::instance($assign->cmid);
     $this->assertTrue(has_capability('moodle/site:config', $modulecontext));
     $providers = message_get_providers_for_user($teacher->id);
     $this->assertTrue($this->message_type_present('moodle', 'backup', $providers));
     // Prohibit the capability for the user at the course level.
     // This overrules the CAP_ALLOW at the module level.
     // They should not be able to see the backup message.
     assign_capability('moodle/site:config', CAP_PROHIBIT, $teacherrole->id, $coursecontext->id, true);
     accesslib_clear_all_caches_for_unit_testing();
     $modulecontext = context_module::instance($assign->cmid);
     $this->assertFalse(has_capability('moodle/site:config', $modulecontext));
     $providers = message_get_providers_for_user($teacher->id);
     // Actually, handling PROHIBITs would be too expensive. We do not
     // care if users with PROHIBITs see a few more preferences than they should.
     // $this->assertFalse($this->message_type_present('moodle', 'backup', $providers));
 }
开发者ID:LepilkinaElena,项目名称:moodle,代码行数:51,代码来源:messagelib_test.php


示例10: get_course_public_information

 /**
  * Return the course information that is public (visible by every one)
  *
  * @param  course_in_list $course        course in list object
  * @param  stdClass       $coursecontext course context object
  * @return array the course information
  * @since  Moodle 3.2
  */
 protected static function get_course_public_information(course_in_list $course, $coursecontext)
 {
     static $categoriescache = array();
     // Category information.
     if (!array_key_exists($course->category, $categoriescache)) {
         $categoriescache[$course->category] = coursecat::get($course->category, IGNORE_MISSING);
     }
     $category = $categoriescache[$course->category];
     // Retrieve course overview used files.
     $files = array();
     foreach ($course->get_course_overviewfiles() as $file) {
         $fileurl = moodle_url::make_webservice_pluginfile_url($file->get_contextid(), $file->get_component(), $file->get_filearea(), null, $file->get_filepath(), $file->get_filename())->out(false);
         $files[] = array('filename' => $file->get_filename(), 'fileurl' => $fileurl, 'filesize' => $file->get_filesize(), 'filepath' => $file->get_filepath(), 'mimetype' => $file->get_mimetype(), 'timemodified' => $file->get_timemodified());
     }
     // Retrieve the course contacts,
     // we need here the users fullname since if we are not enrolled can be difficult to obtain them via other Web Services.
     $coursecontacts = array();
     foreach ($course->get_course_contacts() as $contact) {
         $coursecontacts[] = array('id' => $contact['user']->id, 'fullname' => $contact['username']);
     }
     // Allowed enrolment methods (maybe we can self-enrol).
     $enroltypes = array();
     $instances = enrol_get_instances($course->id, true);
     foreach ($instances as $instance) {
         $enroltypes[] = $instance->enrol;
     }
     // Format summary.
     list($summary, $summaryformat) = external_format_text($course->summary, $course->summaryformat, $coursecontext->id, 'course', 'summary', null);
     $displayname = get_course_display_name_for_list($course);
     $coursereturns = array();
     $coursereturns['id'] = $course->id;
     $coursereturns['fullname'] = external_format_string($course->fullname, $coursecontext->id);
     $coursereturns['displayname'] = external_format_string($displayname, $coursecontext->id);
     $coursereturns['shortname'] = external_format_string($course->shortname, $coursecontext->id);
     $coursereturns['categoryid'] = $course->category;
     $coursereturns['categoryname'] = $category == null ? '' : $category->name;
     $coursereturns['summary'] = $summary;
     $coursereturns['summaryformat'] = $summaryformat;
     $coursereturns['summaryfiles'] = external_util::get_area_files($coursecontext->id, 'course', 'summary', false, false);
     $coursereturns['overviewfiles'] = $files;
     $coursereturns['contacts'] = $coursecontacts;
     $coursereturns['enrollmentmethods'] = $enroltypes;
     return $coursereturns;
 }
开发者ID:dg711,项目名称:moodle,代码行数:52,代码来源:externallib.php


示例11: create_users

 /**
  * Creates a number of user accounts and enrols them on the course.
  * Note: Existing user accounts that were created by this system are
  * reused if available.
  */
 private function create_users()
 {
     global $DB;
     // Work out total number of users.
     $count = self::$paramusers[$this->size];
     // Get existing users in order. We will 'fill up holes' in this up to
     // the required number.
     $this->log('checkaccounts', $count);
     $nextnumber = 1;
     $rs = $DB->get_recordset_select('user', $DB->sql_like('username', '?'), array('tool_generator_%'), 'username', 'id, username');
     foreach ($rs as $rec) {
         // Extract number from username.
         $matches = array();
         if (!preg_match('~^tool_generator_([0-9]{6})$~', $rec->username, $matches)) {
             continue;
         }
         $number = (int) $matches[1];
         // Create missing users in range up to this.
         if ($number != $nextnumber) {
             $this->create_user_accounts($nextnumber, min($number - 1, $count));
         } else {
             $this->userids[$number] = (int) $rec->id;
         }
         // Stop if we've got enough users.
         $nextnumber = $number + 1;
         if ($number >= $count) {
             break;
         }
     }
     $rs->close();
     // Create users from end of existing range.
     if ($nextnumber <= $count) {
         $this->create_user_accounts($nextnumber, $count);
     }
     // Assign all users to course.
     $this->log('enrol', $count, true);
     $enrolplugin = enrol_get_plugin('manual');
     $instances = enrol_get_instances($this->course->id, true);
     foreach ($instances as $instance) {
         if ($instance->enrol === 'manual') {
             break;
         }
     }
     if ($instance->enrol !== 'manual') {
         throw new coding_exception('No manual enrol plugin in course');
     }
     $role = $DB->get_record('role', array('shortname' => 'student'), '*', MUST_EXIST);
     for ($number = 1; $number <= $count; $number++) {
         // Enrol user.
         $enrolplugin->enrol_user($instance, $this->userids[$number], $role->id);
         $this->dot($number, $count);
     }
     // Sets the pointer at the beginning to be aware of the users we use.
     reset($this->userids);
     $this->end_log();
 }
开发者ID:verbazend,项目名称:AWFA,代码行数:61,代码来源:course_backend.php


示例12: search_courses

 /**
  * Search courses following the specified criteria.
  *
  * @param string $criterianame  Criteria name (search, modulelist (only admins), blocklist (only admins), tagid)
  * @param string $criteriavalue Criteria value
  * @param int $page             Page number (for pagination)
  * @param int $perpage          Items per page
  * @param array $requiredcapabilities Optional list of required capabilities (used to filter the list).
  * @param int $limittoenrolled  Limit to only enrolled courses
  * @return array of course objects and warnings
  * @since Moodle 3.0
  * @throws moodle_exception
  */
 public static function search_courses($criterianame, $criteriavalue, $page = 0, $perpage = 0, $requiredcapabilities = array(), $limittoenrolled = 0)
 {
     global $CFG;
     require_once $CFG->libdir . '/coursecatlib.php';
     $warnings = array();
     $parameters = array('criterianame' => $criterianame, 'criteriavalue' => $criteriavalue, 'page' => $page, 'perpage' => $perpage, 'requiredcapabilities' => $requiredcapabilities);
     $params = self::validate_parameters(self::search_courses_parameters(), $parameters);
     self::validate_context(context_system::instance());
     $allowedcriterianames = array('search', 'modulelist', 'blocklist', 'tagid');
     if (!in_array($params['criterianame'], $allowedcriterianames)) {
         throw new invalid_parameter_exception('Invalid value for criterianame parameter (value: ' . $params['criterianame'] . '),' . 'allowed values are: ' . implode(',', $allowedcriterianames));
     }
     if ($params['criterianame'] == 'modulelist' or $params['criterianame'] == 'blocklist') {
         require_capability('moodle/site:config', context_system::instance());
     }
     $paramtype = array('search' => PARAM_RAW, 'modulelist' => PARAM_PLUGIN, 'blocklist' => PARAM_INT, 'tagid' => PARAM_INT);
     $params['criteriavalue'] = clean_param($params['criteriavalue'], $paramtype[$params['criterianame']]);
     // Prepare the search API options.
     $searchcriteria = array();
     $searchcriteria[$params['criterianame']] = $params['criteriavalue'];
     $options = array();
     if ($params['perpage'] != 0) {
         $offset = $params['page'] * $params['perpage'];
         $options = array('offset' => $offset, 'limit' => $params['perpage']);
     }
     // Search the courses.
     $courses = coursecat::search_courses($searchcriteria, $options, $params['requiredcapabilities']);
     $totalcount = coursecat::search_courses_count($searchcriteria, $options, $params['requiredcapabilities']);
     if (!empty($limittoenrolled)) {
         // Get the courses where the current user has access.
         $enrolled = enrol_get_my_courses(array('id', 'cacherev'));
     }
     $finalcourses = array();
     $categoriescache = array();
     foreach ($courses as $course) {
         if (!empty($limittoenrolled)) {
             // Filter out not enrolled courses.
             if (!isset($enrolled[$course->id])) {
                 $totalcount--;
                 continue;
             }
         }
         $coursecontext = context_course::instance($course->id);
         // Category information.
         if (!isset($categoriescache[$course->category])) {
             $categoriescache[$course->category] = coursecat::get($course->category);
         }
         $category = $categoriescache[$course->category];
         // Retrieve course overfiew used files.
         $files = array();
         foreach ($course->get_course_overviewfiles() as $file) {
             $fileurl = moodle_url::make_webservice_pluginfile_url($file->get_contextid(), $file->get_component(), $file->get_filearea(), null, $file->get_filepath(), $file->get_filename())->out(false);
             $files[] = array('filename' => $file->get_filename(), 'fileurl' => $fileurl, 'filesize' => $file->get_filesize());
         }
         // Retrieve the course contacts,
         // we need here the users fullname since if we are not enrolled can be difficult to obtain them via other Web Services.
         $coursecontacts = array();
         foreach ($course->get_course_contacts() as $contact) {
             $coursecontacts[] = array('id' => $contact['user']->id, 'fullname' => $contact['username']);
         }
         // Allowed enrolment methods (maybe we can self-enrol).
         $enroltypes = array();
         $instances = enrol_get_instances($course->id, true);
         foreach ($instances as $instance) {
             $enroltypes[] = $instance->enrol;
         }
         // Format summary.
         list($summary, $summaryformat) = external_format_text($course->summary, $course->summaryformat, $coursecontext->id, 'course', 'summary', null);
         $displayname = get_course_display_name_for_list($course);
         $coursereturns = array();
         $coursereturns['id'] = $course->id;
         $coursereturns['fullname'] = external_format_string($course->fullname, $coursecontext->id);
         $coursereturns['displayname'] = external_format_string($displayname, $coursecontext->id);
         $coursereturns['shortname'] = external_format_string($course->shortname, $coursecontext->id);
         $coursereturns['categoryid'] = $course->category;
         $coursereturns['categoryname'] = $category->name;
         $coursereturns['summary'] = $summary;
         $coursereturns['summaryformat'] = $summaryformat;
         $coursereturns['overviewfiles'] = $files;
         $coursereturns['contacts'] = $coursecontacts;
         $coursereturns['enrollmentmethods'] = $enroltypes;
         $finalcourses[] = $coursereturns;
     }
     return array('total' => $totalcount, 'courses' => $finalcourses, 'warnings' => $warnings);
 }
开发者ID:jackdaniels79,项目名称:moodle,代码行数:98,代码来源:externallib.php


示例13: get_course_detail_array

 /**
  * Returns course details in an array ready to be printed.
  *
  * @global \moodle_database $DB
  * @param \course_in_list $course
  * @return array
  */
 public static function get_course_detail_array(\course_in_list $course)
 {
     global $DB;
     $canaccess = $course->can_access();
     $format = \course_get_format($course->id);
     $modinfo = \get_fast_modinfo($course->id);
     $modules = $modinfo->get_used_module_names();
     $sections = array();
     if ($format->uses_sections()) {
         foreach ($modinfo->get_section_info_all() as $section) {
             if ($section->uservisible) {
                 $sections[] = $format->get_section_name($section);
             }
         }
     }
     $category = \coursecat::get($course->category);
     $categoryurl = new \moodle_url('/course/management.php', array('categoryid' => $course->category));
     $categoryname = $category->get_formatted_name();
     $details = array('fullname' => array('key' => \get_string('fullname'), 'value' => $course->get_formatted_fullname()), 'shortname' => array('key' => \get_string('shortname'), 'value' => $course->get_formatted_shortname()), 'idnumber' => array('key' => \get_string('idnumber'), 'value' => s($course->idnumber)), 'category' => array('key' => \get_string('category'), 'value' => \html_writer::link($categoryurl, $categoryname)));
     if (has_capability('moodle/site:accessallgroups', $course->get_context())) {
         $groups = \groups_get_course_data($course->id);
         $details += array('groupings' => array('key' => \get_string('groupings', 'group'), 'value' => count($groups->groupings)), 'groups' => array('key' => \get_string('groups'), 'value' => count($groups->groups)));
     }
     if ($canaccess) {
         $names = \role_get_names($course->get_context());
         $sql = 'SELECT ra.roleid, COUNT(ra.id) AS rolecount
                   FROM {role_assignments} ra
                  WHERE ra.contextid = :contextid
               GROUP BY ra.roleid';
         $rolecounts = $DB->get_records_sql($sql, array('contextid' => $course->get_context()->id));
         $roledetails = array();
         foreach ($rolecounts as $result) {
             $a = new \stdClass();
             $a->role = $names[$result->roleid]->localname;
             $a->count = $result->rolecount;
             $roledetails[] = \get_string('assignedrolecount', 'moodle', $a);
         }
         $details['roleassignments'] = array('key' => \get_string('roleassignments'), 'value' => join('<br />', $roledetails));
     }
     if ($course->can_review_enrolments()) {
         $enrolmentlines = array();
         $instances = \enrol_get_instances($course->id, true);
         $plugins = \enrol_get_plugins(true);
         foreach ($instances as $instance) {
             if (!isset($plugins[$instance->enrol])) {
                 // Weird.
                 continue;
             }
             $plugin = $plugins[$instance->enrol];
             $enrolmentlines[] = $plugin->get_instance_name($instance);
         }
         $details['enrolmentmethods'] = array('key' => \get_string('enrolmentmethods'), 'value' => join('<br />', $enrolmentlines));
     }
     if ($canaccess) {
         $details['format'] = array('key' => \get_string('format'), 'value' => \course_get_format($course)->get_format_name());
         $details['sections'] = array('key' => \get_string('sections'), 'value' => join('<br />', $sections));
         $details['modulesused'] = array('key' => \get_string('modulesused'), 'value' => join('<br />', $modules));
     }
     return $details;
 }
开发者ID:EsdrasCaleb,项目名称:moodle,代码行数:67,代码来源:helper.php


示例14: course_enrol_methods

 function course_enrol_methods($course_id)
 {
     $instances = enrol_get_instances($course_id, true);
     $i = 0;
     foreach ($instances as $method) {
         $m[$i]['id'] = $method->id;
         $m[$i]['enrol'] = $method->enrol;
         $m[$i]['enrolstartdate'] = $method->enrolstartdate;
         $m[$i]['enrolenddate'] = $method->enrolenddate;
         $i++;
     }
     return $m;
 }
开发者ID:anawu2006,项目名称:PeerLearning,代码行数:13,代码来源:auth.php


示例15: process_enrolment_data

 /**
  * Add the enrolment data for the course.
  *
  * @param object $course course record.
  * @return void
  */
 protected function process_enrolment_data($course)
 {
     global $DB;
     $enrolmentdata = $this->enrolmentdata;
     if (empty($enrolmentdata)) {
         return;
     }
     $enrolmentplugins = tool_uploadcourse_helper::get_enrolment_plugins();
     $instances = enrol_get_instances($course->id, false);
     foreach ($enrolmentdata as $enrolmethod => $method) {
         $instance = null;
         foreach ($instances as $i) {
             if ($i->enrol == $enrolmethod) {
                 $instance = $i;
                 break;
             }
         }
         $todelete = isset($method['delete']) && $method['delete'];
         $todisable = isset($method['disable']) && $method['disable'];
         unset($method['delete']);
         unset($method['disable']);
         if (!empty($instance) && $todelete) {
             // Remove the enrolment method.
             foreach ($instances as $instance) {
                 if ($instance->enrol == $enrolmethod) {
                     $plugin = $enrolmentplugins[$instance->enrol];
                     $plugin->delete_instance($instance);
                     break;
                 }
             }
         } else {
             if (!empty($instance) && $todisable) {
                 // Disable the enrolment.
                 foreach ($instances as $instance) {
                     if ($instance->enrol == $enrolmethod) {
                         $plugin = $enrolmentplugins[$instance->enrol];
           

鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
PHP enrol_get_my_courses函数代码示例发布时间:2022-05-15
下一篇:
PHP enrol_get_enrolment_end函数代码示例发布时间: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