在moodle 4.1中,由于一些安全原因,我必须从经过身份验证的用户中删除日历:管理自己的条目功能。我必须将此功能分配给经过身份验证的用户,该用户是任何课程的教师。 此功能是在仪表板页面的日历上显示“添加事件”按钮。
我从经过身份验证的用户角色中删除了该功能,并将此功能分配给课程级别而不是系统级别的教师角色。我知道老师也是经过身份验证的用户。因此,如果我从经过身份验证的用户中删除该功能,它也不适用于教师(课程级别)。
所以请让我知道如何在教师(课程级别)的日历上显示“添加事件”按钮?
首先:不要编辑calendar/lib.php中的代码。这是核心代码的一部分,在任何情况下都不应该碰它。 你可以做的是编写一个插件或子插件。
您可以通过编程方式检查网站上的任何地方是否有人是老师,如下所示:(不是我的代码,但他知道我经常使用它^^)
function isTeacherAnywhere() : bool {
// function to check if user is a teacher on any course, which ever it is across the site
global $DB, $USER;
//we retrieve the id of the editingteacher role (we could hardcode this but it's prone to change)
$roleid = $DB->get_field('role', 'id', ['shortname' => 'editingteacher']);
//we check on mdl_role_assignments if there exist at least one couple whith the user id and the editingteacher's role id
$isteacheranywhere = $DB->record_exists('role_assignments', ['userid' => $USER->id, 'roleid' => $roleid]);
if(isloggedin() && $isteacheranywhere): //well, not sur the isloggedin was necessary but better be too cautious^^
return true;
else:
return false;
endif;
}
如果返回 true,您可以将角色分配给教师(它会检查连接的用户)。您可以调整该函数以定位所有用户,但请注意,根据您拥有的用户数量,这可能是一个糟糕的查询, (我们有几千个用户,这样的请求可能会超时结束)。
在站点内,您还可以转到管理>用户>角色。您可以做的是将角色的授权直接添加到编辑教师角色中(不是很好)。另一种更干净的方法(即使有点乏味)是手动分配角色。这是避免冲突/编程错误和每个查询的最佳方法。但这取决于您的组织。