我正在尝试在Moodle
中开发一个插件。其中一项要求是在element
菜单中添加Settings
,我可以在本指南的帮助下实现这一目标
https://docs.moodle.org/dev/Local_plugins#Adding_an_element_to_the_settings_menu
这是我在local/myplugin/lib.php
<?php
function local_myplugin_extends_settings_navigation($settingsnav, $context) {
// question_extend_settings_navigation
global $CFG, $PAGE;
// Only add this settings item on non-site course pages.
if (!$PAGE->course or $PAGE->course->id == 1) {
return;
}
// Only let users with the appropriate capability see this settings item.
/*if (!has_capability('moodle/backup:backupcourse', context_course::instance($PAGE->course->id))) {
return;
}*/
if ($settingnode = $settingsnav->find('courseadmin', navigation_node::TYPE_COURSE)) {
$strfoo = get_string('classrecord', 'local_myplugin');
$url = new moodle_url('/course/classrecord.php', array('id' => $PAGE->course->id));
$foonode = navigation_node::create(
$strfoo,
$url,
navigation_node::NODETYPE_LEAF,
'myplugin',
'myplugin',
new pix_icon('i/grades', $strfoo)
);
if ($PAGE->url->compare($url, URL_MATCH_BASE)) {
$foonode->make_active();
}
$settingnode->add_node($foonode);
}
}
?>
我允许学生在设置菜单中看到“班级记录”元素
我担心的是如何隐藏/显示我添加的Class Record
?
任何想法都会很棒!
答案 0 :(得分:1)
如果您只想让某些用户看到该链接,请在local / myplugin / db / access.php中创建适当的功能,例如&#39; local / myplugin:viewclassrecord&#39;,默认分配给&#39;学生&#39;角色。然后在您定义的函数中检查它。
e.g。
if (!has_capability('local/myplugin:viewclassrecord', $context)) {
return;
}