本文整理汇总了PHP中navigation_cache::cached方法的典型用法代码示例。如果您正苦于以下问题:PHP navigation_cache::cached方法的具体用法?PHP navigation_cache::cached怎么用?PHP navigation_cache::cached使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类navigation_cache
的用法示例。
在下文中一共展示了navigation_cache::cached方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generate_user_settings
//.........这里部分代码省略.........
$url = new moodle_url('/user/editadvanced.php', array('id' => $user->id, 'course' => $course->id));
$usersetting->add(get_string('editmyprofile'), $url, self::TYPE_SETTING);
} else {
if (has_capability('moodle/user:editprofile', $usercontext) && !is_siteadmin($user) || $currentuser && has_capability('moodle/user:editownprofile', $systemcontext)) {
if ($userauthplugin && $userauthplugin->can_edit_profile()) {
$url = $userauthplugin->edit_profile_url();
if (empty($url)) {
$url = new moodle_url('/user/edit.php', array('id' => $user->id, 'course' => $course->id));
}
$usersetting->add(get_string('editmyprofile'), $url, self::TYPE_SETTING);
}
}
}
}
// Change password link
if ($userauthplugin && $currentuser && !session_is_loggedinas() && !isguestuser() && has_capability('moodle/user:changeownpassword', $systemcontext) && $userauthplugin->can_change_password()) {
$passwordchangeurl = $userauthplugin->change_password_url();
if (empty($passwordchangeurl)) {
$passwordchangeurl = new moodle_url('/login/change_password.php', array('id' => $course->id));
}
$usersetting->add(get_string("changepassword"), $passwordchangeurl, self::TYPE_SETTING);
}
// View the roles settings
if (has_any_capability(array('moodle/role:assign', 'moodle/role:safeoverride', 'moodle/role:override', 'moodle/role:manage'), $usercontext)) {
$roles = $usersetting->add(get_string('roles'), null, self::TYPE_SETTING);
$url = new moodle_url('/admin/roles/usersroles.php', array('userid' => $user->id, 'courseid' => $course->id));
$roles->add(get_string('thisusersroles', 'role'), $url, self::TYPE_SETTING);
$assignableroles = get_assignable_roles($usercontext, ROLENAME_BOTH);
if (!empty($assignableroles)) {
$url = new moodle_url('/admin/roles/assign.php', array('contextid' => $usercontext->id, 'userid' => $user->id, 'courseid' => $course->id));
$roles->add(get_string('assignrolesrelativetothisuser', 'role'), $url, self::TYPE_SETTING);
}
if (has_capability('moodle/role:review', $usercontext) || count(get_overridable_roles($usercontext, ROLENAME_BOTH)) > 0) {
$url = new moodle_url('/admin/roles/permissions.php', array('contextid' => $usercontext->id, 'userid' => $user->id, 'courseid' => $course->id));
$roles->add(get_string('permissions', 'role'), $url, self::TYPE_SETTING);
}
$url = new moodle_url('/admin/roles/check.php', array('contextid' => $usercontext->id, 'userid' => $user->id, 'courseid' => $course->id));
$roles->add(get_string('checkpermissions', 'role'), $url, self::TYPE_SETTING);
}
// Portfolio
if ($currentuser && !empty($CFG->enableportfolios) && has_capability('moodle/portfolio:export', $systemcontext)) {
require_once $CFG->libdir . '/portfoliolib.php';
if (portfolio_instances(true, false)) {
$portfolio = $usersetting->add(get_string('portfolios', 'portfolio'), null, self::TYPE_SETTING);
$url = new moodle_url('/user/portfolio.php', array('courseid' => $course->id));
$portfolio->add(get_string('configure', 'portfolio'), $url, self::TYPE_SETTING);
$url = new moodle_url('/user/portfoliologs.php', array('courseid' => $course->id));
$portfolio->add(get_string('logs', 'portfolio'), $url, self::TYPE_SETTING);
}
}
$enablemanagetokens = false;
if (!empty($CFG->enablerssfeeds)) {
$enablemanagetokens = true;
} else {
if (!is_siteadmin($USER->id) && !empty($CFG->enablewebservices) && has_capability('moodle/webservice:createtoken', get_system_context())) {
$enablemanagetokens = true;
}
}
// Security keys
if ($currentuser && $enablemanagetokens) {
$url = new moodle_url('/user/managetoken.php', array('sesskey' => sesskey()));
$usersetting->add(get_string('securitykeys', 'webservice'), $url, self::TYPE_SETTING);
}
// Repository
if (!$currentuser && $usercontext->contextlevel == CONTEXT_USER) {
if (!$this->cache->cached('contexthasrepos' . $usercontext->id)) {
require_once $CFG->dirroot . '/repository/lib.php';
$editabletypes = repository::get_editable_types($usercontext);
$haseditabletypes = !empty($editabletypes);
unset($editabletypes);
$this->cache->set('contexthasrepos' . $usercontext->id, $haseditabletypes);
} else {
$haseditabletypes = $this->cache->{'contexthasrepos' . $usercontext->id};
}
if ($haseditabletypes) {
$url = new moodle_url('/repository/manage_instances.php', array('contextid' => $usercontext->id));
$usersetting->add(get_string('repositories', 'repository'), $url, self::TYPE_SETTING);
}
}
// Messaging
if ($currentuser && has_capability('moodle/user:editownmessageprofile', $systemcontext) || !isguestuser($user) && has_capability('moodle/user:editmessageprofile', $usercontext) && !is_primary_admin($user->id)) {
$url = new moodle_url('/message/edit.php', array('id' => $user->id));
$usersetting->add(get_string('editmymessage', 'message'), $url, self::TYPE_SETTING);
}
// Blogs
if ($currentuser && !empty($CFG->bloglevel)) {
$blog = $usersetting->add(get_string('blogs', 'blog'), null, navigation_node::TYPE_CONTAINER, null, 'blogs');
$blog->add(get_string('preferences', 'blog'), new moodle_url('/blog/preferences.php'), navigation_node::TYPE_SETTING);
if (!empty($CFG->useexternalblogs) && $CFG->maxexternalblogsperuser > 0 && has_capability('moodle/blog:manageexternal', get_context_instance(CONTEXT_SYSTEM))) {
$blog->add(get_string('externalblogs', 'blog'), new moodle_url('/blog/external_blogs.php'), navigation_node::TYPE_SETTING);
$blog->add(get_string('addnewexternalblog', 'blog'), new moodle_url('/blog/external_blog_edit.php'), navigation_node::TYPE_SETTING);
}
}
// Login as ...
if (!$user->deleted and !$currentuser && !session_is_loggedinas() && has_capability('moodle/user:loginas', $coursecontext) && !is_siteadmin($user->id)) {
$url = new moodle_url('/course/loginas.php', array('id' => $course->id, 'user' => $user->id, 'sesskey' => sesskey()));
$usersetting->add(get_string('loginas'), $url, self::TYPE_SETTING);
}
return $usersetting;
}
示例2: generate_user_settings
//.........这里部分代码省略.........
$key .= $userid;
$prefurl->param('userid', $userid);
}
// Add a user setting branch.
if ($gstitle == 'usercurrentsettings') {
$dashboard = $this->add(get_string('myhome'), new moodle_url('/my/'), self::TYPE_CONTAINER, null, 'dashboard');
// This should be set to false as we don't want to show this to the user. It's only for generating the correct
// breadcrumb.
$dashboard->display = false;
if (get_home_page() == HOMEPAGE_MY) {
$dashboard->mainnavonly = true;
}
$iscurrentuser = $user->id == $USER->id;
$baseargs = array('id' => $user->id);
if ($course->id != $SITE->id && !$iscurrentuser) {
$baseargs['course'] = $course->id;
$issitecourse = false;
} else {
// Load all categories and get the context for the system.
$issitecourse = true;
}
// Add the user profile to the dashboard.
$profilenode = $dashboard->add(get_string('profile'), new moodle_url('/user/profile.php', array('id' => $user->id)), self::TYPE_SETTING, null, 'myprofile');
if (!empty($CFG->navadduserpostslinks)) {
// Add nodes for forum posts and discussions if the user can view either or both
// There are no capability checks here as the content of the page is based
// purely on the forums the current user has access too.
$forumtab = $profilenode->add(get_string('forumposts', 'forum'));
$forumtab->add(get_string('posts', 'forum'), new moodle_url('/mod/forum/user.php', $baseargs), null, 'myposts');
$forumtab->add(get_string('discussions', 'forum'), new moodle_url('/mod/forum/user.php', array_merge($baseargs, array('mode' => 'discussions'))), null, 'mydiscussions');
}
// Add blog nodes.
if (!empty($CFG->enableblogs)) {
if (!$this->cache->cached('userblogoptions' . $user->id)) {
require_once $CFG->dirroot . '/blog/lib.php';
// Get all options for the user.
$options = blog_get_options_for_user($user);
$this->cache->set('userblogoptions' . $user->id, $options);
} else {
$options = $this->cache->{'userblogoptions' . $user->id};
}
if (count($options) > 0) {
$blogs = $profilenode->add(get_string('blogs', 'blog'), null, navigation_node::TYPE_CONTAINER);
foreach ($options as $type => $option) {
if ($type == "rss") {
$blogs->add($option['string'], $option['link'], self::TYPE_SETTING, null, null, new pix_icon('i/rss', ''));
} else {
$blogs->add($option['string'], $option['link'], self::TYPE_SETTING, null, 'blog' . $type);
}
}
}
}
// Add the messages link.
// It is context based so can appear in the user's profile and in course participants information.
if (!empty($CFG->messaging)) {
$messageargs = array('user1' => $USER->id);
if ($USER->id != $user->id) {
$messageargs['user2'] = $user->id;
}
if ($course->id != $SITE->id) {
$messageargs['viewing'] = MESSAGE_VIEW_COURSE . $course->id;
}
$url = new moodle_url('/message/index.php', $messageargs);
$dashboard->add(get_string('messages', 'message'), $url, self::TYPE_SETTING, null, 'messages');
}
// Add the "My private files" link.
示例3: test_cache_set
public function test_cache_set()
{
$cache = new navigation_cache('unittest_nav');
$cache->anysetvariable = true;
$cache->set('software', 'Moodle');
$this->assertTrue($cache->cached('software'));
$this->assertEquals($cache->software, 'Moodle');
}
示例4: load_course_settings
//.........这里部分代码省略.........
//stop when the first visible plugin is found
$reportavailable = true;
break;
}
}
}
}
}
if ($reportavailable) {
$url = new moodle_url('/grade/report/index.php', array('id' => $course->id));
$gradenode = $coursenode->add(get_string('grades'), $url, self::TYPE_SETTING, null, 'grades', new pix_icon('i/grades', ''));
}
// Add outcome if permitted
if (!empty($CFG->enableoutcomes) && has_capability('moodle/course:update', $coursecontext)) {
$url = new moodle_url('/grade/edit/outcome/course.php', array('id' => $course->id));
$coursenode->add(get_string('outcomes', 'grades'), $url, self::TYPE_SETTING, null, 'outcomes', new pix_icon('i/outcomes', ''));
}
//Add badges navigation
require_once $CFG->libdir . '/badgeslib.php';
badges_add_course_navigation($coursenode, $course);
// Backup this course
if (has_capability('moodle/backup:backupcourse', $coursecontext)) {
$url = new moodle_url('/backup/backup.php', array('id' => $course->id));
$coursenode->add(get_string('backup'), $url, self::TYPE_SETTING, null, 'backup', new pix_icon('i/backup', ''));
}
// Restore to this course
if (has_capability('moodle/restore:restorecourse', $coursecontext)) {
$url = new moodle_url('/backup/restorefile.php', array('contextid' => $coursecontext->id));
$coursenode->add(get_string('restore'), $url, self::TYPE_SETTING, null, 'restore', new pix_icon('i/restore', ''));
}
// Import data from other courses
if (has_capability('moodle/restore:restoretargetimport', $coursecontext)) {
$url = new moodle_url('/backup/import.php', array('id' => $course->id));
$coursenode->add(get_string('import'), $url, self::TYPE_SETTING, null, 'import', new pix_icon('i/import', ''));
}
// Publish course on a hub
if (has_capability('moodle/course:publish', $coursecontext)) {
$url = new moodle_url('/course/publish/index.php', array('id' => $course->id));
$coursenode->add(get_string('publish'), $url, self::TYPE_SETTING, null, 'publish', new pix_icon('i/publish', ''));
}
// Reset this course
if (has_capability('moodle/course:reset', $coursecontext)) {
$url = new moodle_url('/course/reset.php', array('id' => $course->id));
$coursenode->add(get_string('reset'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/return', ''));
}
// Questions
require_once $CFG->libdir . '/questionlib.php';
question_extend_settings_navigation($coursenode, $coursecontext)->trim_if_empty();
if (has_capability('moodle/course:update', $coursecontext)) {
// Repository Instances
if (!$this->cache->cached('contexthasrepos' . $coursecontext->id)) {
require_once $CFG->dirroot . '/repository/lib.php';
$editabletypes = repository::get_editable_types($coursecontext);
$haseditabletypes = !empty($editabletypes);
unset($editabletypes);
$this->cache->set('contexthasrepos' . $coursecontext->id, $haseditabletypes);
} else {
$haseditabletypes = $this->cache->{'contexthasrepos' . $coursecontext->id};
}
if ($haseditabletypes) {
$url = new moodle_url('/repository/manage_instances.php', array('contextid' => $coursecontext->id));
$coursenode->add(get_string('repositories'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/repository', ''));
}
}
// Manage files
if ($course->legacyfiles == 2 and has_capability('moodle/course:managefiles', $coursecontext)) {
// hidden in new courses and courses where legacy files were turned off
$url = new moodle_url('/files/index.php', array('contextid' => $coursecontext->id));
$coursenode->add(get_string('courselegacyfiles'), $url, self::TYPE_SETTING, null, 'coursefiles', new pix_icon('i/folder', ''));
}
// Switch roles
$roles = array();
$assumedrole = $this->in_alternative_role();
if ($assumedrole !== false) {
$roles[0] = get_string('switchrolereturn');
}
if (has_capability('moodle/role:switchroles', $coursecontext)) {
$availableroles = get_switchable_roles($coursecontext);
if (is_array($availableroles)) {
foreach ($availableroles as $key => $role) {
if ($assumedrole == (int) $key) {
continue;
}
$roles[$key] = $role;
}
}
}
if (is_array($roles) && count($roles) > 0) {
$switchroles = $this->add(get_string('switchroleto'));
if (count($roles) == 1 && array_key_exists(0, $roles) || $assumedrole !== false) {
$switchroles->force_open();
}
foreach ($roles as $key => $name) {
$url = new moodle_url('/course/switchrole.php', array('id' => $course->id, 'sesskey' => sesskey(), 'switchrole' => $key, 'returnurl' => $this->page->url->out_as_local_url(false)));
$switchroles->add($name, $url, self::TYPE_SETTING, null, $key, new pix_icon('i/switchrole', ''));
}
}
// Return we are done
return $coursenode;
}
示例5: add_course_editing_links
/**
* Adds branches and links to the settings navigation to add course activities
* and resources.
*
* @param stdClass $course
*/
protected function add_course_editing_links($course) {
global $CFG;
require_once($CFG->dirroot.'/course/lib.php');
// Add `add` resources|activities branches
$structurefile = $CFG->dirroot.'/course/format/'.$course->format.'/lib.php';
if (file_exists($structurefile)) {
require_once($structurefile);
$requestkey = call_user_func('callback_'.$course->format.'_request_key');
$formatidentifier = optional_param($requestkey, 0, PARAM_INT);
} else {
$requestkey = get_string('section');
$formatidentifier = optional_param($requestkey, 0, PARAM_INT);
}
$sections = get_all_sections($course->id);
$addresource = $this->add(get_string('addresource'));
$addactivity = $this->add(get_string('addactivity'));
if ($formatidentifier!==0) {
$addresource->force_open();
$addactivity->force_open();
}
if (!$this->cache->cached('course'.$course->id.'resources')) {
$this->get_course_modules($course);
}
$resources = $this->cache->{'course'.$course->id.'resources'};
$activities = $this->cache->{'course'.$course->id.'activities'};
$textlib = textlib_get_instance();
foreach ($sections as $section) {
if ($formatidentifier !== 0 && $section->section != $formatidentifier) {
continue;
}
$sectionurl = new moodle_url('/course/view.php', array('id'=>$course->id, $requestkey=>$section->section));
if ($section->section == 0) {
$sectionresources = $addresource->add(get_string('course'), $sectionurl, self::TYPE_SETTING);
$sectionactivities = $addactivity->add(get_string('course'), $sectionurl, self::TYPE_SETTING);
} else {
$sectionname = get_section_name($course, $section);
$sectionresources = $addresource->add($sectionname, $sectionurl, self::TYPE_SETTING);
$sectionactivities = $addactivity->add($sectionname, $sectionurl, self::TYPE_SETTING);
}
foreach ($resources as $value=>$resource) {
$url = new moodle_url('/course/mod.php', array('id'=>$course->id, 'sesskey'=>sesskey(), 'section'=>$section->section));
$pos = strpos($value, '&type=');
if ($pos!==false) {
$url->param('add', $textlib->substr($value, 0,$pos));
$url->param('type', $textlib->substr($value, $pos+6));
} else {
$url->param('add', $value);
}
$sectionresources->add($resource, $url, self::TYPE_SETTING);
}
$subbranch = false;
foreach ($activities as $activityname=>$activity) {
if ($activity==='--') {
$subbranch = false;
continue;
}
if (strpos($activity, '--')===0) {
$subbranch = $sectionactivities->add(trim($activity, '-'));
continue;
}
$url = new moodle_url('/course/mod.php', array('id'=>$course->id, 'sesskey'=>sesskey(), 'section'=>$section->section));
$pos = strpos($activityname, '&type=');
if ($pos!==false) {
$url->param('add', $textlib->substr($activityname, 0,$pos));
$url->param('type', $textlib->substr($activityname, $pos+6));
} else {
$url->param('add', $activityname);
}
if ($subbranch !== false) {
$subbranch->add($activity, $url, self::TYPE_SETTING);
} else {
$sectionactivities->add($activity, $url, self::TYPE_SETTING);
}
}
}
}