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


PHP Navigation::get_user_role方法代码示例

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


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

示例1: Navigation

    // If, so far, we think a button should be printed, so check if they will be
    // allowed to access it.
    if ($viewobj->buttontext) {
        if (!$viewobj->moreattempts) {
            $viewobj->buttontext = '';
        } else {
            if ($canattempt && ($viewobj->preventmessages = $viewobj->accessmanager->prevent_access())) {
                $viewobj->buttontext = '';
            }
        }
    }
}
$viewobj->showbacktocourse = $viewobj->buttontext === '' && course_get_format($course)->has_view_page();
echo $OUTPUT->header();
if (isguestuser()) {
    // Guests can't do a quiz, so offer them a choice of logging in or going back.
    echo $output->view_page_guest($course, $quiz, $cm, $context, $viewobj->infomessages);
} else {
    if (!isguestuser() && !($canattempt || $canpreview || $viewobj->canreviewmine)) {
        // If they are not enrolled in this course in a good enough role, tell them to enrol.
        echo $output->view_page_notenrolled($course, $quiz, $cm, $context, $viewobj->infomessages);
    } else {
        echo $output->view_page($course, $quiz, $cm, $context, $viewobj);
    }
}
$nav = new Navigation();
$roleid = $nav->get_user_role();
if ($roleid == 4) {
    die;
}
echo $OUTPUT->footer();
开发者ID:sirromas,项目名称:lms,代码行数:31,代码来源:view.php

示例2: grade_extend_settings

/**
 * This method adds settings to the settings block for the grade system and its
 * plugins
 *
 * @global moodle_page $PAGE
 */
function grade_extend_settings($plugininfo, $courseid)
{
    global $PAGE;
    $nav = new Navigation();
    $roleid = $nav->get_user_role();
    $gradenode = $PAGE->settingsnav->prepend(get_string('gradeadministration', 'grades'), null, navigation_node::TYPE_CONTAINER);
    $strings = array_shift($plugininfo);
    if ($reports = grade_helper::get_plugins_reports($courseid)) {
        foreach ($reports as $report) {
            if ($roleid == 4) {
                //echo "Report link: ". $report->link."<br>";
                if ($report->id != 'history' && $report->id != 'outcomes' && $report->id != 'user') {
                    $gradenode->add($report->string, $report->link, navigation_node::TYPE_SETTING, null, $report->id, new pix_icon('i/report', ''));
                }
                // end if
            } else {
                $gradenode->add($report->string, $report->link, navigation_node::TYPE_SETTING, null, $report->id, new pix_icon('i/report', ''));
            }
            // end else
        }
        // end foreach
    }
    if ($settings = grade_helper::get_info_manage_settings($courseid)) {
        $settingsnode = $gradenode->add($strings['settings'], null, navigation_node::TYPE_CONTAINER);
        foreach ($settings as $setting) {
            $settingsnode->add($setting->string, $setting->link, navigation_node::TYPE_SETTING, null, $setting->id, new pix_icon('i/settings', ''));
        }
    }
    if ($imports = grade_helper::get_plugins_import($courseid)) {
        $importnode = $gradenode->add($strings['import'], null, navigation_node::TYPE_CONTAINER);
        foreach ($imports as $import) {
            $importnode->add($import->string, $import->link, navigation_node::TYPE_SETTING, null, $import->id, new pix_icon('i/import', ''));
        }
    }
    if ($exports = grade_helper::get_plugins_export($courseid)) {
        $exportnode = $gradenode->add($strings['export'], null, navigation_node::TYPE_CONTAINER);
        foreach ($exports as $export) {
            if ($roleid == 4) {
                if ($export->id != 'ods' && $export->id != 'xml') {
                    $exportnode->add($export->string, $export->link, navigation_node::TYPE_SETTING, null, $export->id, new pix_icon('i/export', ''));
                }
                // end if
            } else {
                $exportnode->add($export->string, $export->link, navigation_node::TYPE_SETTING, null, $export->id, new pix_icon('i/export', ''));
            }
            // end else
        }
        // end foreach
    }
    if ($letters = grade_helper::get_info_letters($courseid)) {
        $letters = array_shift($letters);
        $gradenode->add($strings['letter'], $letters->link, navigation_node::TYPE_SETTING, null, $letters->id, new pix_icon('i/settings', ''));
    }
    if ($outcomes = grade_helper::get_info_outcomes($courseid)) {
        $outcomes = array_shift($outcomes);
        $gradenode->add($strings['outcome'], $outcomes->link, navigation_node::TYPE_SETTING, null, $outcomes->id, new pix_icon('i/outcomes', ''));
    }
    if ($scales = grade_helper::get_info_scales($courseid)) {
        $gradenode->add($strings['scale'], $scales->link, navigation_node::TYPE_SETTING, null, $scales->id, new pix_icon('i/scales', ''));
    }
    if ($gradenode->contains_active_node()) {
        // If the gradenode is active include the settings base node (gradeadministration) in
        // the navbar, typcially this is ignored.
        $PAGE->navbar->includesettingsbase = true;
        // If we can get the course admin node make sure it is closed by default
        // as in this case the gradenode will be opened
        if ($coursenode = $PAGE->settingsnav->get('courseadmin', navigation_node::TYPE_COURSE)) {
            $coursenode->make_inactive();
            $coursenode->forceopen = false;
        }
        // end if
    }
    $setionsnode = $PAGE->settingsnav->prepend('Navigation', null, navigation_node::TYPE_CONTAINER);
    $pageid = $nav->get_page_id();
    if ($pageid > 0) {
        $link = "http://" . $_SERVER['SERVER_NAME'] . "/lms/mod/page/view.php?id={$pageid}";
        $setionsnode->add('Assignment', $link, navigation_node::TYPE_SETTING, null, 2, new pix_icon('i/report', ''));
    }
    $forumid = $nav->get_forum_id();
    if ($forumid > 0) {
        $link = "http://" . $_SERVER['SERVER_NAME'] . "/lms/mod/forum/view.php?id={$forumid}";
        $setionsnode->add('Discussion board', $link, navigation_node::TYPE_SETTING, null, 2, new pix_icon('i/report', ''));
    }
    $quizid = $nav->get_quiz_id();
    if ($quizid > 0) {
        $link = "http://" . $_SERVER['SERVER_NAME'] . "/lms/mod/quiz/view.php?id={$quizid}";
        $setionsnode->add('Quiz', $link, navigation_node::TYPE_SETTING, null, 2, new pix_icon('i/report', ''));
    }
}
开发者ID:sirromas,项目名称:lms,代码行数:95,代码来源:lib.php

示例3: 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;
     $nav = new Navigation();
     $roleid = $nav->get_user_role();
     $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
     //echo "Role ID: ".$roleid."<br>";
     if ($roleid != 4) {
         $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', ''));
             }
         } else {
             if (has_capability('moodle/course:tag', $coursecontext)) {
                 $url = new moodle_url('/course/tags.php', array('id' => $course->id));
                 $coursenode->add(get_string('coursetags', 'tag'), $url, self::TYPE_SETTING, null, 'coursetags', 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, 'coursereports', 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;
                         }
                     }
//.........这里部分代码省略.........
开发者ID:sirromas,项目名称:lms,代码行数:101,代码来源:navigationlib.php

示例4: user_menu

 /**
  * Construct a user menu, returning HTML that can be echoed out by a
  * layout file.
  *
  * @param stdClass $user A user object, usually $USER.
  * @param bool $withlinks true if a dropdown should be built.
  * @return string HTML fragment.
  */
 public function user_menu($user = null, $withlinks = null)
 {
     global $USER, $CFG;
     require_once $CFG->dirroot . '/user/lib.php';
     $nav = new Navigation();
     $roleid = $nav->get_user_role();
     $subscription_info = $nav->get_subscription_info();
     if (is_null($user)) {
         $user = $USER;
     }
     // Note: this behaviour is intended to match that of core_renderer::login_info,
     // but should not be considered to be good practice; layout options are
     // intended to be theme-specific. Please don't copy this snippet anywhere else.
     if (is_null($withlinks)) {
         $withlinks = empty($this->page->layout_options['nologinlinks']);
     }
     // Add a class for when $withlinks is false.
     $usermenuclasses = 'usermenu';
     if (!$withlinks) {
         $usermenuclasses .= ' withoutlinks';
     }
     $returnstr = "";
     if ($roleid == 5) {
         $returnstr .= "<span>{$subscription_info}</span>&nbsp;&nbsp;";
     }
     // If during initial install, return the empty return string.
     if (during_initial_install()) {
         return $returnstr;
     }
     $loginpage = $this->is_login_page();
     $loginurl = get_login_url();
     // If not logged in, show the typical not-logged-in string.
     if (!isloggedin()) {
         $returnstr = get_string('loggedinnot', 'moodle');
         if (!$loginpage) {
             $returnstr .= " (<a href=\"{$loginurl}\">" . get_string('login') . '</a>)';
         }
         return html_writer::div(html_writer::span($returnstr, 'login'), $usermenuclasses);
     }
     // If logged in as a guest user, show a string to that effect.
     if (isguestuser()) {
         $returnstr = get_string('loggedinasguest');
         if (!$loginpage && $withlinks) {
             $returnstr .= " (<a href=\"{$loginurl}\">" . get_string('login') . '</a>)';
         }
         return html_writer::div(html_writer::span($returnstr, 'login'), $usermenuclasses);
     }
     // Get some navigation opts.
     $opts = user_get_user_navigation_info($user, $this->page);
     $avatarclasses = "avatars";
     $avatarcontents = html_writer::span($opts->metadata['useravatar'], 'avatar current');
     $usertextcontents = $opts->metadata['userfullname'];
     // Other user.
     if (!empty($opts->metadata['asotheruser'])) {
         $avatarcontents .= html_writer::span($opts->metadata['realuseravatar'], 'avatar realuser');
         $usertextcontents = $opts->metadata['realuserfullname'];
         $usertextcontents .= html_writer::tag('span', get_string('loggedinas', 'moodle', html_writer::span($opts->metadata['userfullname'], 'value')), array('class' => 'meta viewingas'));
     }
     // Role.
     if (!empty($opts->metadata['asotherrole'])) {
         $role = core_text::strtolower(preg_replace('#[ ]+#', '-', trim($opts->metadata['rolename'])));
         $usertextcontents .= html_writer::span($opts->metadata['rolename'], 'meta role role-' . $role);
     }
     // User login failures.
     if (!empty($opts->metadata['userloginfail'])) {
         $usertextcontents .= html_writer::span($opts->metadata['userloginfail'], 'meta loginfailures');
     }
     // MNet.
     if (!empty($opts->metadata['asmnetuser'])) {
         $mnet = strtolower(preg_replace('#[ ]+#', '-', trim($opts->metadata['mnetidprovidername'])));
         $usertextcontents .= html_writer::span($opts->metadata['mnetidprovidername'], 'meta mnet mnet-' . $mnet);
     }
     $returnstr .= html_writer::span(html_writer::span($usertextcontents, 'usertext') . html_writer::span($avatarcontents, $avatarclasses), 'userbutton');
     // Create a divider (well, a filler).
     $divider = new action_menu_filler();
     $divider->primary = false;
     $am = new action_menu();
     $am->initialise_js($this->page);
     $am->set_menu_trigger($returnstr);
     $am->set_alignment(action_menu::TR, action_menu::BR);
     $am->set_nowrap_on_items();
     if ($withlinks) {
         $navitemcount = count($opts->navitems);
         $idx = 0;
         foreach ($opts->navitems as $key => $value) {
             if ($USER->id != 2 && $USER->id != 3 && $roleid >= 4 && $value->title != 'Log out') {
                 continue;
             }
             // end if
             switch ($value->itemtype) {
                 case 'divider':
                     // If the nav item is a divider, add one and skip link processing.
//.........这里部分代码省略.........
开发者ID:sirromas,项目名称:lms,代码行数:101,代码来源:outputrenderers.php

示例5: Navigation

 /**
  * Gets the content for this block by grabbing it from $this->page
  */
 function get_content()
 {
     global $CFG, $OUTPUT;
     $nav = new Navigation();
     $roleid = $nav->get_user_role();
     $userid = $nav->user->id;
     // First check if we have already generated, don't waste cycles
     if ($this->contentgenerated === true) {
         return true;
     }
     if ($roleid == 5 && $userid != 2 && $userid != 3) {
         return null;
     }
     // JS for navigation moved to the standard theme, the code will probably have to depend on the actual page structure
     // $this->page->requires->js('/lib/javascript-navigation.js');
     block_settings::$navcount++;
     // Check if this block has been docked
     if ($this->docked === null) {
         $this->docked = get_user_preferences('nav_in_tab_panel_settingsnav' . block_settings::$navcount, 0);
     }
     // Check if there is a param to change the docked state
     if ($this->docked && optional_param('undock', null, PARAM_INT) == $this->instance->id) {
         unset_user_preference('nav_in_tab_panel_settingsnav' . block_settings::$navcount, 0);
         $url = $this->page->url;
         $url->remove_params(array('undock'));
         redirect($url);
     } else {
         if (!$this->docked && optional_param('dock', null, PARAM_INT) == $this->instance->id) {
             set_user_preferences(array('nav_in_tab_panel_settingsnav' . block_settings::$navcount => 1));
             $url = $this->page->url;
             $url->remove_params(array('dock'));
             redirect($url);
         }
     }
     $renderer = $this->page->get_renderer('block_settings');
     $this->content = new stdClass();
     $this->content->text = $renderer->settings_tree($this->page->settingsnav);
     // only do search if you have moodle/site:config
     if (!empty($this->content->text)) {
         if (has_capability('moodle/site:config', context_system::instance())) {
             $this->content->footer = $renderer->search_form(new moodle_url("{$CFG->wwwroot}/{$CFG->admin}/search.php"), optional_param('query', '', PARAM_RAW));
         } else {
             $this->content->footer = '';
         }
         if (!empty($this->config->enabledock) && $this->config->enabledock == 'yes') {
             user_preference_allow_ajax_update('nav_in_tab_panel_settingsnav' . block_settings::$navcount, PARAM_INT);
         }
     }
     $this->contentgenerated = true;
     return true;
 }
开发者ID:sirromas,项目名称:lms,代码行数:54,代码来源:block_settings.php

示例6: Navigation

 /**
  * Gets the content for this block by grabbing it from $this->page
  *
  * @return object $this->content
  */
 function get_content()
 {
     global $CFG;
     $nav = new Navigation();
     $roleid = $nav->get_user_role();
     $userid = $nav->user->id;
     // First check if we have already generated, don't waste cycles
     if ($this->contentgenerated === true) {
         return $this->content;
     }
     if (($roleid == 5 || $roleid == 4) && $userid != 2 && $userid != 3) {
         return null;
     }
     // JS for navigation moved to the standard theme, the code will probably have to depend on the actual page structure
     // $this->page->requires->js('/lib/javascript-navigation.js');
     // Navcount is used to allow us to have multiple trees although I dont' know why
     // you would want two trees the same
     block_navigation::$navcount++;
     // Check if this block has been docked
     if ($this->docked === null) {
         $this->docked = get_user_preferences('nav_in_tab_panel_globalnav' . block_navigation::$navcount, 0);
     }
     // Check if there is a param to change the docked state
     if ($this->docked && optional_param('undock', null, PARAM_INT) == $this->instance->id) {
         unset_user_preference('nav_in_tab_panel_globalnav' . block_navigation::$navcount);
         $url = $this->page->url;
         $url->remove_params(array('undock'));
         redirect($url);
     } else {
         if (!$this->docked && optional_param('dock', null, PARAM_INT) == $this->instance->id) {
             set_user_preferences(array('nav_in_tab_panel_globalnav' . block_navigation::$navcount => 1));
             $url = $this->page->url;
             $url->remove_params(array('dock'));
             redirect($url);
         }
     }
     $trimmode = self::TRIM_RIGHT;
     $trimlength = 50;
     if (!empty($this->config->trimmode)) {
         $trimmode = (int) $this->config->trimmode;
     }
     if (!empty($this->config->trimlength)) {
         $trimlength = (int) $this->config->trimlength;
     }
     // Get the navigation object or don't display the block if none provided.
     if (!($navigation = $this->get_navigation())) {
         return null;
     }
     $expansionlimit = null;
     if (!empty($this->config->expansionlimit)) {
         $expansionlimit = $this->config->expansionlimit;
         $navigation->set_expansion_limit($this->config->expansionlimit);
     }
     $this->trim($navigation, $trimmode, $trimlength, ceil($trimlength / 2));
     // Get the expandable items so we can pass them to JS
     $expandable = array();
     $navigation->find_expandable($expandable);
     if ($expansionlimit) {
         foreach ($expandable as $key => $node) {
             if ($node['type'] > $expansionlimit && !($expansionlimit == navigation_node::TYPE_COURSE && $node['type'] == $expansionlimit && $node['branchid'] == SITEID)) {
                 unset($expandable[$key]);
             }
         }
     }
     $limit = 20;
     if (!empty($CFG->navcourselimit)) {
         $limit = $CFG->navcourselimit;
     }
     $expansionlimit = 0;
     if (!empty($this->config->expansionlimit)) {
         $expansionlimit = $this->config->expansionlimit;
     }
     $arguments = array('id' => $this->instance->id, 'instance' => $this->instance->id, 'candock' => $this->instance_can_be_docked(), 'courselimit' => $limit, 'expansionlimit' => $expansionlimit);
     $options = array();
     $options['linkcategories'] = !empty($this->config->linkcategories) && $this->config->linkcategories == 'yes';
     // Grab the items to display
     $renderer = $this->page->get_renderer($this->blockname);
     $this->content = new stdClass();
     $this->content->text = $renderer->navigation_tree($navigation, $expansionlimit, $options);
     // Set content generated to true so that we know it has been done
     $this->contentgenerated = true;
     return $this->content;
 }
开发者ID:sirromas,项目名称:lms,代码行数:88,代码来源:block_navigation.php


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