本文整理汇总了PHP中enrol_user_sees_own_courses函数的典型用法代码示例。如果您正苦于以下问题:PHP enrol_user_sees_own_courses函数的具体用法?PHP enrol_user_sees_own_courses怎么用?PHP enrol_user_sees_own_courses使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了enrol_user_sees_own_courses函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: initialise
/**
* Initialises the navigation object.
*
* This causes the navigation object to look at the current state of the page
* that it is associated with and then load the appropriate content.
*
* This should only occur the first time that the navigation structure is utilised
* which will normally be either when the navbar is called to be displayed or
* when a block makes use of it.
*
* @return bool
*/
public function initialise()
{
global $CFG, $SITE, $USER;
// Check if it has already been initialised
if ($this->initialised || during_initial_install()) {
return true;
}
$this->initialised = true;
// Set up the five base root nodes. These are nodes where we will put our
// content and are as follows:
// site: Navigation for the front page.
// myprofile: User profile information goes here.
// currentcourse: The course being currently viewed.
// mycourses: The users courses get added here.
// courses: Additional courses are added here.
// users: Other users information loaded here.
$this->rootnodes = array();
if (get_home_page() == HOMEPAGE_SITE) {
// The home element should be my moodle because the root element is the site
if (isloggedin() && !isguestuser()) {
// Makes no sense if you aren't logged in
$this->rootnodes['home'] = $this->add(get_string('myhome'), new moodle_url('/my/'), self::TYPE_SETTING, null, 'home');
}
} else {
// The home element should be the site because the root node is my moodle
$this->rootnodes['home'] = $this->add(get_string('sitehome'), new moodle_url('/'), self::TYPE_SETTING, null, 'home');
if (!empty($CFG->defaulthomepage) && $CFG->defaulthomepage == HOMEPAGE_MY) {
// We need to stop automatic redirection
$this->rootnodes['home']->action->param('redirect', '0');
}
}
$this->rootnodes['site'] = $this->add_course($SITE);
$this->rootnodes['myprofile'] = $this->add(get_string('profile'), null, self::TYPE_USER, null, 'myprofile');
$this->rootnodes['currentcourse'] = $this->add(get_string('currentcourse'), null, self::TYPE_ROOTNODE, null, 'currentcourse');
$this->rootnodes['mycourses'] = $this->add(get_string('mycourses'), null, self::TYPE_ROOTNODE, null, 'mycourses');
$this->rootnodes['courses'] = $this->add(get_string('courses'), new moodle_url('/course/index.php'), self::TYPE_ROOTNODE, null, 'courses');
$this->rootnodes['users'] = $this->add(get_string('users'), null, self::TYPE_ROOTNODE, null, 'users');
// We always load the frontpage course to ensure it is available without
// JavaScript enabled.
$this->add_front_page_course_essentials($this->rootnodes['site'], $SITE);
$this->load_course_sections($SITE, $this->rootnodes['site']);
$course = $this->page->course;
// $issite gets set to true if the current pages course is the sites frontpage course
$issite = $this->page->course->id == $SITE->id;
// Determine if the user is enrolled in any course.
$enrolledinanycourse = enrol_user_sees_own_courses();
$this->rootnodes['currentcourse']->mainnavonly = true;
if ($enrolledinanycourse) {
$this->rootnodes['mycourses']->isexpandable = true;
if ($CFG->navshowallcourses) {
// When we show all courses we need to show both the my courses and the regular courses branch.
$this->rootnodes['courses']->isexpandable = true;
}
} else {
$this->rootnodes['courses']->isexpandable = true;
}
// Load the users enrolled courses if they are viewing the My Moodle page AND the admin has not
// set that they wish to keep the My Courses branch collapsed by default.
if (!empty($CFG->navexpandmycourses) && $this->page->pagelayout === 'mydashboard') {
$this->rootnodes['mycourses']->forceopen = true;
$this->load_courses_enrolled();
} else {
$this->rootnodes['mycourses']->collapse = true;
$this->rootnodes['mycourses']->make_inactive();
}
$canviewcourseprofile = true;
// Next load context specific content into the navigation
switch ($this->page->context->contextlevel) {
case CONTEXT_SYSTEM:
// Nothing left to do here I feel.
break;
case CONTEXT_COURSECAT:
// This is essential, we must load categories.
$this->load_all_categories($this->page->context->instanceid, true);
break;
case CONTEXT_BLOCK:
case CONTEXT_COURSE:
if ($issite) {
// Nothing left to do here.
break;
}
// Load the course associated with the current page into the navigation.
$coursenode = $this->add_course($course, false, self::COURSE_CURRENT);
// If the course wasn't added then don't try going any further.
if (!$coursenode) {
$canviewcourseprofile = false;
break;
}
//.........这里部分代码省略.........
开发者ID:evltuma,项目名称:moodle,代码行数:101,代码来源:navigationlib.php
示例2: initialise
/**
* Initialise the navigation given the type and id for the branch to expand.
*
* @param int $branchtype One of navigation_node::TYPE_*
* @param int $id
* @return array The expandable nodes
*/
public function initialise()
{
global $CFG, $DB, $SITE;
if ($this->initialised || during_initial_install()) {
return $this->expandable;
}
$this->initialised = true;
$this->rootnodes = array();
$this->rootnodes['site'] = $this->add_course($SITE);
$this->rootnodes['mycourses'] = $this->add(get_string('mycourses'), new moodle_url('/my'), self::TYPE_ROOTNODE, null, 'mycourses');
$this->rootnodes['courses'] = $this->add(get_string('courses'), null, self::TYPE_ROOTNODE, null, 'courses');
if (function_exists('enrol_user_sees_own_courses')) {
// Determine if the user is enrolled in any course.
$enrolledinanycourse = enrol_user_sees_own_courses();
if ($enrolledinanycourse) {
$this->rootnodes['mycourses']->isexpandable = true;
if ($CFG->navshowallcourses) {
// When we show all courses we need to show both the my courses and the regular courses branch.
$this->rootnodes['courses']->isexpandable = true;
}
} else {
$this->rootnodes['courses']->isexpandable = true;
}
}
$this->expand($this->branchtype, $this->instanceid);
}
开发者ID:CourseBit,项目名称:moodle-theme_social,代码行数:33,代码来源:lib.php
示例3: test_enrol_user_sees_own_courses
public function test_enrol_user_sees_own_courses()
{
global $DB, $CFG;
$this->resetAfterTest();
$studentrole = $DB->get_record('role', array('shortname' => 'student'));
$this->assertNotEmpty($studentrole);
$teacherrole = $DB->get_record('role', array('shortname' => 'teacher'));
$this->assertNotEmpty($teacherrole);
$admin = get_admin();
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
$user3 = $this->getDataGenerator()->create_user();
$user4 = $this->getDataGenerator()->create_user();
$user5 = $this->getDataGenerator()->create_user();
$user6 = $this->getDataGenerator()->create_user();
$category1 = $this->getDataGenerator()->create_category(array('visible' => 0));
$category2 = $this->getDataGenerator()->create_category();
$course1 = $this->getDataGenerator()->create_course(array('category' => $category1->id));
$course2 = $this->getDataGenerator()->create_course(array('category' => $category2->id));
$course3 = $this->getDataGenerator()->create_course(array('category' => $category2->id, 'visible' => 0));
$course4 = $this->getDataGenerator()->create_course(array('category' => $category2->id));
$maninstance1 = $DB->get_record('enrol', array('courseid' => $course1->id, 'enrol' => 'manual'), '*', MUST_EXIST);
$DB->set_field('enrol', 'status', ENROL_INSTANCE_DISABLED, array('id' => $maninstance1->id));
$maninstance1 = $DB->get_record('enrol', array('courseid' => $course1->id, 'enrol' => 'manual'), '*', MUST_EXIST);
$maninstance2 = $DB->get_record('enrol', array('courseid' => $course2->id, 'enrol' => 'manual'), '*', MUST_EXIST);
$maninstance3 = $DB->get_record('enrol', array('courseid' => $course3->id, 'enrol' => 'manual'), '*', MUST_EXIST);
$maninstance4 = $DB->get_record('enrol', array('courseid' => $course4->id, 'enrol' => 'manual'), '*', MUST_EXIST);
$manual = enrol_get_plugin('manual');
$this->assertNotEmpty($manual);
$manual->enrol_user($maninstance1, $admin->id, $studentrole->id);
$manual->enrol_user($maninstance3, $user1->id, $teacherrole->id);
$manual->enrol_user($maninstance2, $user2->id, $studentrole->id);
$manual->enrol_user($maninstance1, $user3->id, $studentrole->id, 1, time() + 60 * 60);
$manual->enrol_user($maninstance2, $user3->id, 0, 1, time() - 60 * 60);
$manual->enrol_user($maninstance3, $user2->id, $studentrole->id);
$manual->enrol_user($maninstance4, $user2->id, 0, 0, 0, ENROL_USER_SUSPENDED);
$manual->enrol_user($maninstance1, $user4->id, $teacherrole->id, 0, 0, ENROL_USER_SUSPENDED);
$manual->enrol_user($maninstance3, $user4->id, 0, 0, 0, ENROL_USER_SUSPENDED);
$this->assertFalse(enrol_user_sees_own_courses($CFG->siteguest));
$this->assertFalse(enrol_user_sees_own_courses(0));
$this->assertFalse(enrol_user_sees_own_courses($admin));
$this->assertFalse(enrol_user_sees_own_courses(-222));
// Nonexistent user.
$this->assertTrue(enrol_user_sees_own_courses($user1));
$this->assertTrue(enrol_user_sees_own_courses($user2->id));
$this->assertFalse(enrol_user_sees_own_courses($user3->id));
$this->assertFalse(enrol_user_sees_own_courses($user4));
$this->assertFalse(enrol_user_sees_own_courses($user5));
$this->setAdminUser();
$this->assertFalse(enrol_user_sees_own_courses());
$this->setGuestUser();
$this->assertFalse(enrol_user_sees_own_courses());
$this->setUser(0);
$this->assertFalse(enrol_user_sees_own_courses());
$this->setUser($user1);
$this->assertTrue(enrol_user_sees_own_courses());
$this->setUser($user2);
$this->assertTrue(enrol_user_sees_own_courses());
$this->setUser($user3);
$this->assertFalse(enrol_user_sees_own_courses());
$this->setUser($user4);
$this->assertFalse(enrol_user_sees_own_courses());
$this->setUser($user5);
$this->assertFalse(enrol_user_sees_own_courses());
$user1 = $DB->get_record('user', array('id' => $user1->id));
$this->setUser($user1);
$reads = $DB->perf_get_reads();
$this->assertTrue(enrol_user_sees_own_courses());
$this->assertGreaterThan($reads, $DB->perf_get_reads());
$user1 = $DB->get_record('user', array('id' => $user1->id));
$this->setUser($user1);
require_login($course3);
$reads = $DB->perf_get_reads();
$this->assertTrue(enrol_user_sees_own_courses());
$this->assertEquals($reads, $DB->perf_get_reads());
}
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:76,代码来源:enrollib_test.php
示例4: initialise
/**
* Initialise the navigation given the type and id for the branch to expand.
*
* @param int $branchtype One of navigation_node::TYPE_*
* @param int $id
* @return array The expandable nodes
*/
public function initialise()
{
global $CFG, $DB, $SITE, $PAGE;
if ($this->initialised || during_initial_install()) {
return $this->expandable;
}
$this->initialised = true;
$this->rootnodes = array();
$this->rootnodes['site'] = $this->add_course($SITE);
$this->rootnodes['currentcourse'] = $this->add(get_string('currentcourse'), null, self::TYPE_ROOTNODE, null, 'currentcourse');
$this->rootnodes['mycourses'] = $this->add(get_string('mycourses'), new moodle_url('/my'), self::TYPE_ROOTNODE, null, 'mycourses');
$this->rootnodes['courses'] = $this->add(get_string('courses'), null, self::TYPE_ROOTNODE, null, 'courses');
if (!empty($PAGE->theme->settings->coursesleafonly) || !empty($PAGE->theme->settings->coursesloggedinonly) && !isloggedin()) {
$this->expandtocourses = false;
}
if (function_exists('enrol_user_sees_own_courses')) {
// Determine if the user is enrolled in any course.
$enrolledinanycourse = enrol_user_sees_own_courses();
if ($enrolledinanycourse) {
$this->rootnodes['mycourses']->isexpandable = true;
if ($CFG->navshowallcourses) {
// When we show all courses we need to show both the my courses and the regular courses branch.
$this->rootnodes['courses']->isexpandable = true;
}
} else {
$this->rootnodes['courses']->isexpandable = true;
}
}
$PAGE->requires->data_for_js('siteadminexpansion', false);
$this->expand($this->branchtype, $this->instanceid);
}
开发者ID:actXc,项目名称:moodle-theme_decaf,代码行数:38,代码来源:lib.php
注:本文中的enrol_user_sees_own_courses函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论