我正在使用Moodle 2.7
,Quiz activity
中有学习者的所有尝试次数的概述页面。
该表位于mymoodle/mod/quiz/report.php?id=50&mode=overview
目前只有管理员用户或具有功能 'mod/quiz:viewreports'
的用户才能看到该表。
如何添加用户而不使用任何功能,谁能看到此报告?
现在,没有该功能的每个用户都会从report.php
获取错误:
$reportlist = quiz_report_list($context);
if (empty($reportlist) !totara_is_manager($userid)) {
print_error('erroraccessingreport', 'quiz');
}
// Validate the requested report name.
if ($mode == '') {
// Default to first accessible report and redirect.
$url->param('mode', reset($reportlist));
redirect($url);
} else if (!in_array($mode, $reportlist)) {
print_error('erroraccessingreport', 'quiz');
}
if (!is_readable("report/$mode/report.php")) {
print_error('reportnotfound', 'quiz', '', $mode);
}
表 功能位于reportlib.php
下:
function quiz_report_list($context) {
global $DB;
static $reportlist = null;
if (!is_null($reportlist)) {
return $reportlist;
}
$reports = $DB->get_records('quiz_reports', null, 'displayorder DESC', 'name, capability');
$reportdirs = core_component::get_plugin_list('quiz');
// Order the reports tab in descending order of displayorder.
$reportcaps = array();
foreach ($reports as $key => $report) {
if (array_key_exists($report->name, $reportdirs)) {
$reportcaps[$report->name] = $report->capability;
}
}
// Add any other reports, which are on disc but not in the DB, on the end.
foreach ($reportdirs as $reportname => $notused) {
if (!isset($reportcaps[$reportname])) {
$reportcaps[$reportname] = null;
}
}
$reportlist = array();
foreach ($reportcaps as $name => $capability) {
if (empty($capability)) {
$capability = 'mod/quiz:viewreports';
}
if (has_capability($capability, $context)) {
$reportlist[] = $name;
}
}
return $reportlist;
}
我想通过 id 添加指定人员,他们将充当经理。
答案 0 :(得分:1)
如果你想完全绕过这些功能,那么查看报告的机制,然后你总是可以在access.php中注释对应于键> mod / quiz:viewreports'的数组值。换句话说,您可以转到/mod/quiz/db/access.php并替换
// View the quiz reports.
'mod/quiz:viewreports' => array(
'riskbitmask' => RISK_PERSONAL,
'captype' => 'read',
'contextlevel' => CONTEXT_MODULE,
'archetypes' => array(
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
)
),
与
// View the quiz reports.
'mod/quiz:viewreports' => array(
// 'riskbitmask' => RISK_PERSONAL,
// 'captype' => 'read',
// 'contextlevel' => CONTEXT_MODULE,
// 'archetypes' => array(
// 'teacher' => CAP_ALLOW,
// 'editingteacher' => CAP_ALLOW,
// 'manager' => CAP_ALLOW
)
),
或者,您可以根据需要调整或打开条目。有关更多信息,请参阅 https://docs.moodle.org/dev/Access_API
然后你可以
注意:我不会绕过功能机制,因为它可靠且安全。但是,您可以对其进行调整,以便仅允许您定义的用户组。