本文整理匯總了PHP中is_enrolled函數的典型用法代碼示例。如果您正苦於以下問題:PHP is_enrolled函數的具體用法?PHP is_enrolled怎麽用?PHP is_enrolled使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了is_enrolled函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: get_content
public function get_content()
{
global $COURSE, $USER;
if ($this->content !== null) {
return $this->content;
}
$this->content = new stdClass();
$this->content->text = var_export($this->context, true);
$coursecontext = context_course::instance($COURSE->id);
if (has_capability('block/demostudent:addinstance', $coursecontext)) {
// If DemoStudent has not yet been enrolled, allow user to create/enrol one.
$demostudentusername = generate_demostudent_name($USER->username);
$demostudentuser = get_complete_user_data('username', $demostudentusername);
if (!$demostudentuser || !is_enrolled($coursecontext, $demostudentuser)) {
$this->render_view('firstuse');
} else {
$this->render_view('instructor');
}
} else {
if (has_capability('block/demostudent:seedemostudentblock', $coursecontext)) {
$this->render_view('demostudent');
} else {
// If the user does not need to see the block, do not display it at all.
$this->content->text = '';
$this->content->footer = '';
}
}
return $this->content;
}
示例2: local_compile_extends_settings_navigation
/**
* Add a "Compile" menu link to the Course Admin block as the top link.
*
* @author Gerald Albion
* date 2014-10-31
* @copyright 2014 Royal Roads University
* @param object $settingsnav Main navigation object.
* @param object $context Course context.
*/
function local_compile_extends_settings_navigation($settingsnav, $context)
{
// Context must be course.
if ($context->contextlevel != CONTEXT_COURSE) {
return;
}
// Must be in a valid course: Cannot be course id 0.
if ($context->instanceid == 0) {
return;
}
// Must be in a valid course: Course must be retrievable.
if (!($course = get_course($context->instanceid))) {
return;
}
// Must be enrolled or otherwise allowed to view the course.
if (!(is_enrolled($context) || is_viewing($context))) {
return;
}
// Must have a course admin menu in which to add link.
if (!($coursenode = $settingsnav->find('courseadmin', navigation_node::TYPE_COURSE))) {
return;
}
// Good to go. Build the menu item.
$url = new moodle_url('/local/compile/list_modules.php', array('id' => $course->id));
$newnode = navigation_node::create(get_string('menucaption', 'local_compile'), $url, navigation_node::NODETYPE_LEAF, 'compile', 'compile', new pix_icon('i/settings', ''));
// We want to put this link at the top: find the existing top (first) node.
$firstnode = $coursenode->get_children_key_list()[0];
// Add the menu item to the menu, before the first node.
$coursenode->add_node($newnode, $firstnode);
}
示例3: get_file_info
/**
* Return information about this specific context level
*
* @param $component
* @param $filearea
* @param $itemid
* @param $filepath
* @param $filename
*/
public function get_file_info($component, $filearea, $itemid, $filepath, $filename)
{
if (!is_enrolled($this->context) and !is_viewing($this->context)) {
// no peaking here if not enrolled or inspector
return null;
}
if (empty($component)) {
return $this;
}
if ($component == 'mod_' . $this->modname and $filearea === 'intro') {
return $this->get_area_intro($itemid, $filepath, $filename);
} else {
if ($component == 'backup' and $filearea === 'activity') {
return $this->get_area_backup($itemid, $filepath, $filename);
}
}
$functionname = 'mod_' . $this->modname . '_get_file_info';
$functionname_old = $this->modname . '_get_file_info';
if (function_exists($functionname)) {
return $functionname($this->browser, $this->areas, $this->course, $this->cm, $this->context, $filearea, $itemid, $filepath, $filename);
} else {
if (function_exists($functionname_old)) {
return $functionname_old($this->browser, $this->areas, $this->course, $this->cm, $this->context, $filearea, $itemid, $filepath, $filename);
}
}
return null;
}
示例4: test_enrol_users
/**
* Test get_enrolled_users
*/
public function test_enrol_users()
{
global $DB;
$this->resetAfterTest(true);
$user = self::getDataGenerator()->create_user();
$this->setUser($user);
$course1 = self::getDataGenerator()->create_course();
$course2 = self::getDataGenerator()->create_course();
$user1 = self::getDataGenerator()->create_user();
$user2 = self::getDataGenerator()->create_user();
$context1 = context_course::instance($course1->id);
$context2 = context_course::instance($course2->id);
$instance1 = $DB->get_record('enrol', array('courseid' => $course1->id, 'enrol' => 'manual'), '*', MUST_EXIST);
$instance2 = $DB->get_record('enrol', array('courseid' => $course2->id, 'enrol' => 'manual'), '*', MUST_EXIST);
// Set the required capabilities by the external function.
$roleid = $this->assignUserCapability('enrol/manual:enrol', $context1->id);
$this->assignUserCapability('moodle/course:view', $context1->id, $roleid);
$this->assignUserCapability('moodle/role:assign', $context1->id, $roleid);
$this->assignUserCapability('enrol/manual:enrol', $context2->id, $roleid);
$this->assignUserCapability('moodle/course:view', $context2->id, $roleid);
$this->assignUserCapability('moodle/role:assign', $context2->id, $roleid);
allow_assign($roleid, 3);
// Call the external function.
enrol_manual_external::enrol_users(array(array('roleid' => 3, 'userid' => $user1->id, 'courseid' => $course1->id), array('roleid' => 3, 'userid' => $user2->id, 'courseid' => $course1->id)));
$this->assertEquals(2, $DB->count_records('user_enrolments', array('enrolid' => $instance1->id)));
$this->assertEquals(0, $DB->count_records('user_enrolments', array('enrolid' => $instance2->id)));
$this->assertTrue(is_enrolled($context1, $user1));
$this->assertTrue(is_enrolled($context1, $user2));
// Call without required capability.
$DB->delete_records('user_enrolments');
$this->unassignUserCapability('enrol/manual:enrol', $context1->id, $roleid);
try {
enrol_manual_external::enrol_users(array(array('roleid' => 3, 'userid' => $user1->id, 'courseid' => $course1->id)));
$this->fail('Exception expected if not having capability to enrol');
} catch (moodle_exception $e) {
$this->assertInstanceOf('required_capability_exception', $e);
$this->assertSame('nopermissions', $e->errorcode);
}
$this->assignUserCapability('enrol/manual:enrol', $context1->id, $roleid);
$this->assertEquals(0, $DB->count_records('user_enrolments'));
// Call with forbidden role.
try {
enrol_manual_external::enrol_users(array(array('roleid' => 1, 'userid' => $user1->id, 'courseid' => $course1->id)));
$this->fail('Exception expected if not allowed to assign role.');
} catch (moodle_exception $e) {
$this->assertSame('wsusercannotassign', $e->errorcode);
}
$this->assertEquals(0, $DB->count_records('user_enrolments'));
// Call for course without manual instance.
$DB->delete_records('user_enrolments');
$DB->delete_records('enrol', array('courseid' => $course2->id));
try {
enrol_manual_external::enrol_users(array(array('roleid' => 3, 'userid' => $user1->id, 'courseid' => $course1->id), array('roleid' => 3, 'userid' => $user1->id, 'courseid' => $course2->id)));
$this->fail('Exception expected if course does not have manual instance');
} catch (moodle_exception $e) {
$this->assertSame('wsnoinstance', $e->errorcode);
}
}
示例5: execute
function execute($userid, $context, $data)
{
global $DB, $CFG;
// Everyone should be enrolled at the system level.
if ($context == context_system::instance()) {
return true;
}
return is_enrolled($context, $userid);
}
示例6: groups_add_member
/**
* Adds a specified user to a group
*
* @param mixed $grouporid The group id or group object
* @param mixed $userorid The user id or user object
* @param string $component Optional component name e.g. 'enrol_imsenterprise'
* @param int $itemid Optional itemid associated with component
* @return bool True if user added successfully or the user is already a
* member of the group, false otherwise.
*/
function groups_add_member($grouporid, $userorid, $component = null, $itemid = 0)
{
global $DB;
if (is_object($userorid)) {
$userid = $userorid->id;
$user = $userorid;
} else {
$userid = $userorid;
$user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
}
if (is_object($grouporid)) {
$groupid = $grouporid->id;
$group = $grouporid;
} else {
$groupid = $grouporid;
$group = $DB->get_record('groups', array('id' => $groupid), '*', MUST_EXIST);
}
//check if the user a participant of the group course
if (!is_enrolled(context_course::instance($group->courseid), $userid)) {
return false;
}
if (groups_is_member($groupid, $userid)) {
return true;
}
$member = new stdClass();
$member->groupid = $groupid;
$member->userid = $userid;
$member->timeadded = time();
$member->component = '';
$member->itemid = 0;
// Check the component exists if specified
if (!empty($component)) {
$dir = get_component_directory($component);
if ($dir && is_dir($dir)) {
// Component exists and can be used
$member->component = $component;
$member->itemid = $itemid;
} else {
throw new coding_exception('Invalid call to groups_add_member(). An invalid component was specified');
}
}
if ($itemid !== 0 && empty($member->component)) {
// An itemid can only be specified if a valid component was found
throw new coding_exception('Invalid call to groups_add_member(). A component must be specified if an itemid is given');
}
$DB->insert_record('groups_members', $member);
//update group info
$DB->set_field('groups', 'timemodified', $member->timeadded, array('id' => $groupid));
//trigger groups events
$eventdata = new stdClass();
$eventdata->groupid = $groupid;
$eventdata->userid = $userid;
$eventdata->component = $member->component;
$eventdata->itemid = $member->itemid;
events_trigger('groups_member_added', $eventdata);
return true;
}
示例7: data_for_report
/**
* Loads the data required to render the report.
*
* @param int $courseid The course id
* @param int $userid The user id
* @return \stdClass
*/
public static function data_for_report($courseid, $userid)
{
global $PAGE;
$params = self::validate_parameters(self::data_for_report_parameters(), array('courseid' => $courseid, 'userid' => $userid));
$context = context_course::instance($params['courseid']);
self::validate_context($context);
if (!is_enrolled($context, $params['userid'], 'moodle/competency:coursecompetencygradable')) {
throw new coding_exception('invaliduser');
}
$renderable = new output\report($params['courseid'], $params['userid']);
$renderer = $PAGE->get_renderer('report_competency');
$data = $renderable->export_for_template($renderer);
return $data;
}
示例8: is_available
public function is_available($not, \core_availability\info $info, $grabthelot, $userid)
{
$allow = true;
if ($this->expectedpublicprivate == PUBLICPRIVATE_PRIVATE) {
$modinfo = $info->get_modinfo();
$course = $modinfo->get_course();
$context = \context_course::instance($course->id);
$allow = is_enrolled($context, $userid, '', true) || has_capability('moodle/course:view', $context);
}
if ($not) {
$allow = !$allow;
}
return $allow;
}
示例9: groups_add_member
/**
* Adds a specified user to a group
*
* @param mixed $grouporid The group id or group object
* @param mixed $userorid The user id or user object
* @return bool True if user added successfully or the user is already a
* member of the group, false otherwise.
*/
function groups_add_member($grouporid, $userorid) {
global $DB;
if (is_object($userorid)) {
$userid = $userorid->id;
$user = $userorid;
} else {
$userid = $userorid;
$user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST);
}
if (is_object($grouporid)) {
$groupid = $grouporid->id;
$group = $grouporid;
} else {
$groupid = $grouporid;
$group = $DB->get_record('groups', array('id'=>$groupid), '*', MUST_EXIST);
}
//check if the user a participant of the group course
if (!is_enrolled(get_context_instance(CONTEXT_COURSE, $group->courseid), $userid)) {
return false;
}
if (groups_is_member($groupid, $userid)) {
return true;
}
$member = new stdClass();
$member->groupid = $groupid;
$member->userid = $userid;
$member->timeadded = time();
$DB->insert_record('groups_members', $member);
//update group info
$DB->set_field('groups', 'timemodified', $member->timeadded, array('id'=>$groupid));
//trigger groups events
$eventdata = new stdClass();
$eventdata->groupid = $groupid;
$eventdata->userid = $userid;
events_trigger('groups_member_added', $eventdata);
return true;
}
示例10: 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;
}
示例11: get_file_info
/**
* Return information about this specific context level
*
* @param $component
* @param $filearea
* @param $itemid
* @param $filepath
* @param $filename
*/
public function get_file_info($component, $filearea, $itemid, $filepath, $filename)
{
// try to emulate require_login() tests here
if (!isloggedin()) {
return null;
}
$coursecontext = get_course_context($this->context);
if (!$this->course->visible and !has_capability('moodle/course:viewhiddencourses', $coursecontext)) {
return null;
}
if (!is_viewing($this->context) and !is_enrolled($this->context)) {
// no peaking here if not enrolled or inspector
return null;
}
$modinfo = get_fast_modinfo($this->course);
$cminfo = $modinfo->get_cm($this->cm->id);
if (!$cminfo->uservisible) {
// activity hidden sorry
return null;
}
if (empty($component)) {
return $this;
}
if ($component == 'mod_' . $this->modname and $filearea === 'intro') {
return $this->get_area_intro($itemid, $filepath, $filename);
} else {
if ($component == 'backup' and $filearea === 'activity') {
return $this->get_area_backup($itemid, $filepath, $filename);
}
}
$functionname = 'mod_' . $this->modname . '_get_file_info';
$functionname_old = $this->modname . '_get_file_info';
if (function_exists($functionname)) {
return $functionname($this->browser, $this->areas, $this->course, $this->cm, $this->context, $filearea, $itemid, $filepath, $filename);
} else {
if (function_exists($functionname_old)) {
return $functionname_old($this->browser, $this->areas, $this->course, $this->cm, $this->context, $filearea, $itemid, $filepath, $filename);
}
}
return null;
}
示例12: report_outline_can_access_user_report
/**
* Is current user allowed to access this report
*
* @private defined in lib.php for performance reasons
*
* @param stdClass $user
* @param stdClass $course
* @return bool
*/
function report_outline_can_access_user_report($user, $course)
{
global $USER;
$coursecontext = context_course::instance($course->id);
$personalcontext = context_user::instance($user->id);
if (has_capability('report/outline:view', $coursecontext)) {
return true;
}
if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext)) {
if ($course->showreports and (is_viewing($coursecontext, $user) or is_enrolled($coursecontext, $user))) {
return true;
}
} else {
if ($user->id == $USER->id) {
if ($course->showreports and (is_viewing($coursecontext, $USER) or is_enrolled($coursecontext, $USER))) {
return true;
}
}
}
return false;
}
示例13: get_file_info
/**
* Return information about this specific context level
*
* @param string $component component
* @param string $filearea file area
* @param int $itemid item ID
* @param string $filepath file path
* @param string $filename file name
* @return file_info|null file_info instance or null if not found or access not allowed
*/
public function get_file_info($component, $filearea, $itemid, $filepath, $filename)
{
// try to emulate require_login() tests here
if (!isloggedin()) {
return null;
}
if (!$this->course->visible and !has_capability('moodle/course:viewhiddencourses', $this->context)) {
return null;
}
if (!is_viewing($this->context) and !is_enrolled($this->context)) {
// no peaking here if not enrolled or inspector
return null;
}
if (empty($component)) {
return $this;
}
$methodname = "get_area_{$component}_{$filearea}";
if (method_exists($this, $methodname)) {
return $this->{$methodname}($itemid, $filepath, $filename);
}
return null;
}
示例14: stdClass
if ($duration > 0) {
// sanity check
$timeend = $today + $duration;
}
}
$manual->enrol_user($manualcache[$courseid], $user->id, $rid, $today, $timeend);
$a = new stdClass();
$a->course = $shortname;
$a->role = $rolecache[$rid]->name;
$upt->track('enrolments', get_string('enrolledincourserole', 'enrol_manual', $a));
}
}
// find group to add to
if (!empty($user->{'group' . $i})) {
// make sure user is enrolled into course before adding into groups
if (!is_enrolled($coursecontext, $user->id)) {
$upt->track('enrolments', get_string('addedtogroupnotenrolled', '', $user->{'group' . $i}), 'error');
continue;
}
//build group cache
if (is_null($ccache[$shortname]->groups)) {
$ccache[$shortname]->groups = array();
if ($groups = groups_get_all_groups($courseid)) {
foreach ($groups as $gid => $group) {
$ccache[$shortname]->groups[$gid] = new stdClass();
$ccache[$shortname]->groups[$gid]->id = $gid;
$ccache[$shortname]->groups[$gid]->name = $group->name;
if (!is_numeric($group->name)) {
// only non-numeric names are supported!!!
$ccache[$shortname]->groups[$group->name] = new stdClass();
$ccache[$shortname]->groups[$group->name]->id = $gid;
示例15: forum_get_user_digest_options
$digestoptions = forum_get_user_digest_options();
$digestoptions_selector = new single_select(new moodle_url('/mod/forum/maildigest.php', array('backtoindex' => 1)), 'maildigest', $digestoptions, null, '');
$digestoptions_selector->method = 'post';
// Start of the table for General Forums
$generaltable = new html_table();
$generaltable->head = array($strforum, $strdescription, $strdiscussions);
$generaltable->align = array('left', 'left', 'center');
if ($usetracking = forum_tp_can_track_forums()) {
$untracked = forum_tp_get_untracked_forums($USER->id, $course->id);
$generaltable->head[] = $strunreadposts;
$generaltable->align[] = 'center';
$generaltable->head[] = $strtracking;
$generaltable->align[] = 'center';
}
$subscribed_forums = forum_get_subscribed_forums($course);
$can_subscribe = is_enrolled($coursecontext);
if ($can_subscribe) {
$generaltable->head[] = $strsubscribed;
$generaltable->align[] = 'center';
$generaltable->head[] = $stremaildigest . ' ' . $OUTPUT->help_icon('emaildigesttype', 'mod_forum');
$generaltable->align[] = 'center';
}
if ($show_rss = ($can_subscribe || $course->id == SITEID) && isset($CFG->enablerssfeeds) && isset($CFG->forum_enablerssfeeds) && $CFG->enablerssfeeds && $CFG->forum_enablerssfeeds) {
$generaltable->head[] = $strrss;
$generaltable->align[] = 'center';
}
$usesections = course_format_uses_sections($course->format);
$table = new html_table();
// Parse and organise all the forums. Most forums are course modules but
// some special ones are not. These get placed in the general forums
// category with the forums in section 0.