当前位置: 首页>>代码示例>>PHP>>正文


PHP navigation_cache::set方法代码示例

本文整理汇总了PHP中navigation_cache::set方法的典型用法代码示例。如果您正苦于以下问题:PHP navigation_cache::set方法的具体用法?PHP navigation_cache::set怎么用?PHP navigation_cache::set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在navigation_cache的用法示例。


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

示例1: generate_user_settings

 /**
  * This function gets called by {@link settings_navigation::load_user_settings()} and actually works out
  * what can be shown/done
  *
  * @param int $courseid The current course' id
  * @param int $userid The user id to load for
  * @param string $gstitle The string to pass to get_string for the branch title
  * @return navigation_node|false
  */
 protected function generate_user_settings($courseid, $userid, $gstitle = 'usercurrentsettings')
 {
     global $DB, $CFG, $USER, $SITE;
     if ($courseid != $SITE->id) {
         if (!empty($this->page->course->id) && $this->page->course->id == $courseid) {
             $course = $this->page->course;
         } else {
             $select = context_helper::get_preload_record_columns_sql('ctx');
             $sql = "SELECT c.*, {$select}\n                          FROM {course} c\n                          JOIN {context} ctx ON c.id = ctx.instanceid\n                         WHERE c.id = :courseid AND ctx.contextlevel = :contextlevel";
             $params = array('courseid' => $courseid, 'contextlevel' => CONTEXT_COURSE);
             $course = $DB->get_record_sql($sql, $params, MUST_EXIST);
             context_helper::preload_from_record($course);
         }
     } else {
         $course = $SITE;
     }
     $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
     // Course context
     $systemcontext = get_system_context();
     $currentuser = $USER->id == $userid;
     if ($currentuser) {
         $user = $USER;
         $usercontext = get_context_instance(CONTEXT_USER, $user->id);
         // User context
     } else {
         $select = context_helper::get_preload_record_columns_sql('ctx');
         $sql = "SELECT u.*, {$select}\n                      FROM {user} u\n                      JOIN {context} ctx ON u.id = ctx.instanceid\n                     WHERE u.id = :userid AND ctx.contextlevel = :contextlevel";
         $params = array('userid' => $userid, 'contextlevel' => CONTEXT_USER);
         $user = $DB->get_record_sql($sql, $params, IGNORE_MISSING);
         if (!$user) {
             return false;
         }
         context_helper::preload_from_record($user);
         // Check that the user can view the profile
         $usercontext = get_context_instance(CONTEXT_USER, $user->id);
         // User context
         $canviewuser = has_capability('moodle/user:viewdetails', $usercontext);
         if ($course->id == $SITE->id) {
             if ($CFG->forceloginforprofiles && !has_coursecontact_role($user->id) && !$canviewuser) {
                 // Reduce possibility of "browsing" userbase at site level
                 // Teachers can browse and be browsed at site level. If not forceloginforprofiles, allow access (bug #4366)
                 return false;
             }
         } else {
             $canviewusercourse = has_capability('moodle/user:viewdetails', $coursecontext);
             $canaccessallgroups = has_capability('moodle/site:accessallgroups', $coursecontext);
             if (!$canviewusercourse && !$canviewuser || !can_access_course($course, $user->id)) {
                 return false;
             }
             if (!$canaccessallgroups && groups_get_course_groupmode($course) == SEPARATEGROUPS) {
                 // If groups are in use, make sure we can see that group
                 return false;
             }
         }
     }
     $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $this->page->context));
     $key = $gstitle;
     if ($gstitle != 'usercurrentsettings') {
         $key .= $userid;
     }
     // Add a user setting branch
     $usersetting = $this->add(get_string($gstitle, 'moodle', $fullname), null, self::TYPE_CONTAINER, null, $key);
     $usersetting->id = 'usersettings';
     if ($this->page->context->contextlevel == CONTEXT_USER && $this->page->context->instanceid == $user->id) {
         // Automatically start by making it active
         $usersetting->make_active();
     }
     // Check if the user has been deleted
     if ($user->deleted) {
         if (!has_capability('moodle/user:update', $coursecontext)) {
             // We can't edit the user so just show the user deleted message
             $usersetting->add(get_string('userdeleted'), null, self::TYPE_SETTING);
         } else {
             // We can edit the user so show the user deleted message and link it to the profile
             if ($course->id == $SITE->id) {
                 $profileurl = new moodle_url('/user/profile.php', array('id' => $user->id));
             } else {
                 $profileurl = new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $course->id));
             }
             $usersetting->add(get_string('userdeleted'), $profileurl, self::TYPE_SETTING);
         }
         return true;
     }
     $userauthplugin = false;
     if (!empty($user->auth)) {
         $userauthplugin = get_auth_plugin($user->auth);
     }
     // Add the profile edit link
     if (isloggedin() && !isguestuser($user) && !is_mnet_remote_user($user)) {
         if (($currentuser || is_siteadmin($USER) || !is_siteadmin($user)) && has_capability('moodle/user:update', $systemcontext)) {
             $url = new moodle_url('/user/editadvanced.php', array('id' => $user->id, 'course' => $course->id));
//.........这里部分代码省略.........
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:101,代码来源:navigationlib.php

示例2: generate_user_settings

 /**
  * This function gets called by {@link settings_navigation::load_user_settings()} and actually works out
  * what can be shown/done
  *
  * @param int $courseid The current course' id
  * @param int $userid The user id to load for
  * @param string $gstitle The string to pass to get_string for the branch title
  * @return navigation_node|false
  */
 protected function generate_user_settings($courseid, $userid, $gstitle = 'usercurrentsettings')
 {
     global $DB, $CFG, $USER, $SITE;
     if ($courseid != $SITE->id) {
         if (!empty($this->page->course->id) && $this->page->course->id == $courseid) {
             $course = $this->page->course;
         } else {
             $select = context_helper::get_preload_record_columns_sql('ctx');
             $sql = "SELECT c.*, {$select}\n                          FROM {course} c\n                          JOIN {context} ctx ON c.id = ctx.instanceid\n                         WHERE c.id = :courseid AND ctx.contextlevel = :contextlevel";
             $params = array('courseid' => $courseid, 'contextlevel' => CONTEXT_COURSE);
             $course = $DB->get_record_sql($sql, $params, MUST_EXIST);
             context_helper::preload_from_record($course);
         }
     } else {
         $course = $SITE;
     }
     $coursecontext = context_course::instance($course->id);
     // Course context
     $systemcontext = context_system::instance();
     $currentuser = $USER->id == $userid;
     if ($currentuser) {
         $user = $USER;
         $usercontext = context_user::instance($user->id);
         // User context
     } else {
         $select = context_helper::get_preload_record_columns_sql('ctx');
         $sql = "SELECT u.*, {$select}\n                      FROM {user} u\n                      JOIN {context} ctx ON u.id = ctx.instanceid\n                     WHERE u.id = :userid AND ctx.contextlevel = :contextlevel";
         $params = array('userid' => $userid, 'contextlevel' => CONTEXT_USER);
         $user = $DB->get_record_sql($sql, $params, IGNORE_MISSING);
         if (!$user) {
             return false;
         }
         context_helper::preload_from_record($user);
         // Check that the user can view the profile
         $usercontext = context_user::instance($user->id);
         // User context
         $canviewuser = has_capability('moodle/user:viewdetails', $usercontext);
         if ($course->id == $SITE->id) {
             if ($CFG->forceloginforprofiles && !has_coursecontact_role($user->id) && !$canviewuser) {
                 // Reduce possibility of "browsing" userbase at site level
                 // Teachers can browse and be browsed at site level. If not forceloginforprofiles, allow access (bug #4366)
                 return false;
             }
         } else {
             $canviewusercourse = has_capability('moodle/user:viewdetails', $coursecontext);
             $userisenrolled = is_enrolled($coursecontext, $user->id, '', true);
             if (!$canviewusercourse && !$canviewuser || !$userisenrolled) {
                 return false;
             }
             $canaccessallgroups = has_capability('moodle/site:accessallgroups', $coursecontext);
             if (!$canaccessallgroups && groups_get_course_groupmode($course) == SEPARATEGROUPS && !$canviewuser) {
                 // If groups are in use, make sure we can see that group (MDL-45874). That does not apply to parents.
                 if ($courseid == $this->page->course->id) {
                     $mygroups = get_fast_modinfo($this->page->course)->groups;
                 } else {
                     $mygroups = groups_get_user_groups($courseid);
                 }
                 $usergroups = groups_get_user_groups($courseid, $userid);
                 if (!array_intersect_key($mygroups[0], $usergroups[0])) {
                     return false;
                 }
             }
         }
     }
     $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $this->page->context));
     $key = $gstitle;
     $prefurl = new moodle_url('/user/preferences.php');
     if ($gstitle != 'usercurrentsettings') {
         $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');
//.........这里部分代码省略.........
开发者ID:evltuma,项目名称:moodle,代码行数:101,代码来源:navigationlib.php

示例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');
 }
开发者ID:alanaipe2015,项目名称:moodle,代码行数:8,代码来源:navigationlib_test.php

示例4: load_course_settings

 /**
  * This function loads the course settings that are available for the user
  *
  * @param bool $forceopen If set to true the course node will be forced open
  * @return navigation_node|false
  */
 protected function load_course_settings($forceopen = false)
 {
     global $CFG;
     $course = $this->page->course;
     $coursecontext = context_course::instance($course->id);
     // note: do not test if enrolled or viewing here because we need the enrol link in Course administration section
     $coursenode = $this->add(get_string('courseadministration'), null, self::TYPE_COURSE, null, 'courseadmin');
     if ($forceopen) {
         $coursenode->force_open();
     }
     if ($this->page->user_allowed_editing()) {
         // Add the turn on/off settings
         if ($this->page->url->compare(new moodle_url('/course/view.php'), URL_MATCH_BASE)) {
             // We are on the course page, retain the current page params e.g. section.
             $baseurl = clone $this->page->url;
             $baseurl->param('sesskey', sesskey());
         } else {
             // Edit on the main course page.
             $baseurl = new moodle_url('/course/view.php', array('id' => $course->id, 'return' => $this->page->url->out_as_local_url(false), 'sesskey' => sesskey()));
         }
         $editurl = clone $baseurl;
         if ($this->page->user_is_editing()) {
             $editurl->param('edit', 'off');
             $editstring = get_string('turneditingoff');
         } else {
             $editurl->param('edit', 'on');
             $editstring = get_string('turneditingon');
         }
         $coursenode->add($editstring, $editurl, self::TYPE_SETTING, null, 'turneditingonoff', new pix_icon('i/edit', ''));
     }
     if (has_capability('moodle/course:update', $coursecontext)) {
         // Add the course settings link
         $url = new moodle_url('/course/edit.php', array('id' => $course->id));
         $coursenode->add(get_string('editsettings'), $url, self::TYPE_SETTING, null, 'editsettings', new pix_icon('i/settings', ''));
         // Add the course completion settings link
         if ($CFG->enablecompletion && $course->enablecompletion) {
             $url = new moodle_url('/course/completion.php', array('id' => $course->id));
             $coursenode->add(get_string('coursecompletion', 'completion'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/settings', ''));
         }
     }
     // add enrol nodes
     enrol_add_course_navigation($coursenode, $course);
     // Manage filters
     if (has_capability('moodle/filter:manage', $coursecontext) && count(filter_get_available_in_context($coursecontext)) > 0) {
         $url = new moodle_url('/filter/manage.php', array('contextid' => $coursecontext->id));
         $coursenode->add(get_string('filters', 'admin'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/filter', ''));
     }
     // View course reports.
     if (has_capability('moodle/site:viewreports', $coursecontext)) {
         // Basic capability for listing of reports.
         $reportnav = $coursenode->add(get_string('reports'), null, self::TYPE_CONTAINER, null, null, new pix_icon('i/stats', ''));
         $coursereports = core_component::get_plugin_list('coursereport');
         foreach ($coursereports as $report => $dir) {
             $libfile = $CFG->dirroot . '/course/report/' . $report . '/lib.php';
             if (file_exists($libfile)) {
                 require_once $libfile;
                 $reportfunction = $report . '_report_extend_navigation';
                 if (function_exists($report . '_report_extend_navigation')) {
                     $reportfunction($reportnav, $course, $coursecontext);
                 }
             }
         }
         $reports = get_plugin_list_with_function('report', 'extend_navigation_course', 'lib.php');
         foreach ($reports as $reportfunction) {
             $reportfunction($reportnav, $course, $coursecontext);
         }
     }
     // Add view grade report is permitted
     $reportavailable = false;
     if (has_capability('moodle/grade:viewall', $coursecontext)) {
         $reportavailable = true;
     } else {
         if (!empty($course->showgrades)) {
             $reports = core_component::get_plugin_list('gradereport');
             if (is_array($reports) && count($reports) > 0) {
                 // Get all installed reports
                 arsort($reports);
                 // user is last, we want to test it first
                 foreach ($reports as $plugin => $plugindir) {
                     if (has_capability('gradereport/' . $plugin . ':view', $coursecontext)) {
                         //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)) {
//.........这里部分代码省略.........
开发者ID:achocoza,项目名称:moodle26,代码行数:101,代码来源:navigationlib.php

示例5: load_generic_course_sections

    /**
     * Generically loads the course sections into the course's navigation.
     *
     * @param stdClass $course
     * @param navigation_node $coursenode
     * @param string $name The string that identifies each section. e.g Topic, or Week
     * @param string $activeparam The url used to identify the active section
     * @return array An array of course section nodes
     */
    public function load_generic_course_sections(stdClass $course, navigation_node $coursenode, $courseformat='unknown') {
        global $CFG, $DB, $USER;

        require_once($CFG->dirroot.'/course/lib.php');

        if (!$this->cache->cached('modinfo'.$course->id)) {
            $this->cache->set('modinfo'.$course->id, get_fast_modinfo($course));
        }
        $modinfo = $this->cache->{'modinfo'.$course->id};

        if (!$this->cache->cached('coursesections'.$course->id)) {
            $this->cache->set('coursesections'.$course->id, array_slice(get_all_sections($course->id), 0, $course->numsections+1, true));
        }
        $sections = $this->cache->{'coursesections'.$course->id};

        $viewhiddensections = has_capability('moodle/course:viewhiddensections', $this->page->context);

        $activesection = course_get_display($course->id);

        $namingfunction = 'callback_'.$courseformat.'_get_section_name';
        $namingfunctionexists = (function_exists($namingfunction));

        $activeparamfunction = 'callback_'.$courseformat.'_request_key';
        if (function_exists($activeparamfunction)) {
            $activeparam = $activeparamfunction();
        } else {
            $activeparam = 'section';
        }
        $navigationsections = array();
        foreach ($sections as $sectionid=>$section) {
            $section = clone($section);
            if ($course->id == SITEID) {
                $this->load_section_activities($coursenode, $section->section, $modinfo);
            } else {
                if ((!$viewhiddensections && !$section->visible) || (!$this->showemptysections && !array_key_exists($section->section, $modinfo->sections))) {
                    continue;
                }
                if ($namingfunctionexists) {
                    $sectionname = $namingfunction($course, $section, $sections);
                } else {
                    $sectionname = get_string('section').' '.$section->section;
                }
                //$url = new moodle_url('/course/view.php', array('id'=>$course->id));
                $url = null;
                $sectionnode = $coursenode->add($sectionname, $url, navigation_node::TYPE_SECTION, null, $section->id);
                $sectionnode->nodetype = navigation_node::NODETYPE_BRANCH;
                $sectionnode->hidden = (!$section->visible);
                if ($this->page->context->contextlevel != CONTEXT_MODULE && ($sectionnode->isactive || ($activesection && $section->section == $activesection))) {
                    $sectionnode->force_open();
                    $this->load_section_activities($sectionnode, $section->section, $modinfo);
                }
                $section->sectionnode = $sectionnode;
                $navigationsections[$sectionid] = $section;
            }
        }
        return $navigationsections;
    }
开发者ID:nikita777,项目名称:moodle,代码行数:66,代码来源:navigationlib.php


注:本文中的navigation_cache::set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。