下面是我在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'));
}其输出为:这是导航抽屉。我想只向管理员、教师和经理显示报告选项
有人能告诉我怎么做吗?
您需要在本地插件中创建一个功能。在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;
}