如何使导航选项仅对特定用户可见

问题描述 投票:0回答:1

this is the screenshot.我在导航块中添加了考勤选项,但我希望它只对教师可见

我以这种方式添加了 lib.php 代码

function local_newattendance_extend_navigation(global_navigation $navigation)
 {
    global $CFG;
    if (!has_capability('local/newattendance:viewnewattendance', \context_system::instance())) {
        return;
    }
    $main_node = $navigation->add(get_string('pluginname', 'local_newattendance'), $CFG->attendance);
    $main_node->nodetype = 1;
    $main_node->collapse = false;
    $main_node->force_open = true;
    $main_node->isexpandable = false;
    $main_node->showinflatnavigation = true; 
}

这是access.php

    defined('MOODLE_INTERNAL') || die();


    $capabilities = array(
    'local/newattendance:viewnewattendance' => array(
        'captype' => 'read',
        'contextlevel' => CONTEXT_SYSTEM,
        'archetypes' => array(
            //'manager' => CAP_ALLOW,
            'teacher' => CAP_ALLOW,
            //'student'=>CAP_PREVENT,
            'editingteacher' => CAP_ALLOW,
        ),
    ),
);

这是 lang/en 中的 local_newattendance.php

 $string['pluginname'] = 'Attendance';
$string['newattendance:viewnewattendance'] = 'View local newattendance';
plugins navigation-drawer moodle
1个回答
0
投票

您可以为此使用功能,例如:

function local_report_extend_navigation(global_navigation $navigation) {

    if (!has_capability('local/report:viewreport', context_system::instance()))) {
        return;
    }

要创建功能,请将其添加到

/local/report/db/access.php

defined('MOODLE_INTERNAL') || die();

$capabilities = array(

    'local/report:viewreport' => array(
        'captype' => 'read',
        'contextlevel' => CONTEXT_SYSTEM,
        'archetypes' => array(
            'teacher' => CAP_ALLOW,
            'editingteacher' => CAP_ALLOW,
        ),
    ),

);

并为功能添加一个字符串

/local/report/lang/en/local_report.php

$string['report:viewreport'] = 'View local report';

您需要在

/local/reports/version.php
中输入版本号才能安装该功能

© www.soinside.com 2019 - 2024. All rights reserved.