我以这种方式添加了 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';
您可以为此使用功能,例如:
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
中输入版本号才能安装该功能