php - 仅向测验事件中的选定用户显示数据

标签 php mysql moodle

我正在使用 Moodle 2.7Quiz 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添加指定人员,他们将充当经理

最佳答案

如果你想完全绕过查看报告的功能机制,那么你总是可以注释 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

那么你可以

  1. 检查当前用户的ID($USER->id)和
  2. 编写一些自定义函数来决定该用户是否可以查看报告。

注意:不过,我不会绕过功能机制,因为它既可靠又安全。但是,您可以调整它以仅允许您定义的用户组。

关于php - 仅向测验事件中的选定用户显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38007304/

相关文章:

php - 将 MySQL 变量保存在 PHP $_SESSION 变量中

mysql - Moodle 3.4 性能很差

php - 在不使用 API 和库但使用标题类型的情况下将 Html + CSS 页面呈现为 PDF

php - PDO:MySQL 服务器已经消失,无法捕获异常

php - Javascript 比较数组中的字符串

php - 模拟库可以用来创建多个日志文件吗?

mysql - WordPress 和 Haversine 公式

mysql - mysql查询的IN子句

Moodle 获取类(class)中的所有测验/事件

java - 使用java登录并下载网页并存储cookie