【问题标题】:How to show navigation bar options to specific users in moodle lms?如何在moodle lms中向特定用户显示导航栏选项?
【发布时间】:2022-01-06 02:19:55
【问题描述】:

下面是我在 Moodle LMS 帐户的导航抽屉中显示额外选项的代码。

function local_report_extend_navigation(global_navigation $navigation)

{

$main_node = $navigation->add(get_string('pluginname', 'local_report'), '/local/report/');
$main_node->nodetype = 1;
$main_node->collapse = false;
$main_node->force_open = true;
$main_node->isexpandable = false;
$main_node->showinflatnavigation = true; 
// $main_node->icon = new pix_icon('i/settings', get_string('pluginname', 'local_report'));
$main_node->icon = new pix_icon('i/files', get_string('pluginname', 'local_report'));

} 它的输出是: This is the navigation-drawer. I want to show the Reports option to only admin, teacher and manager

谁能告诉我如何做到这一点?

【问题讨论】:

    标签: moodle moodle-api moodle-theme


    【解决方案1】:

    您需要在本地插件中创建一项功能。在local/report/db/access.php

    $capabilities = array(
        'local/report:canview' => array(
            'captype' => 'read',
            'contextlevel' => CONTEXT_SYSTEM,
            'archetypes' => array(
                'manager' => CAP_ALLOW,
                'teacher' => CAP_ALLOW,
                'editingteacher' => CAP_ALLOW,
            ),
        ),
    );
    

    然后在你的函数中使用类似的东西。

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

    【讨论】:

    • 现在报告选项完全隐藏了
    • 添加新功能时,您还需要更新插件。因此,提高版本号以便安装该功能。然后使用具有该能力的用户对其进行测试。
    • 我照你说的做了。经理有权访问,但每当我以教师身份登录(编辑)时,报告选项不可见。仅当我是管理员或经理时可见
    猜你喜欢
    • 1970-01-01
    • 2017-08-13
    • 1970-01-01
    • 2021-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-14
    相关资源
    最近更新 更多