繁体   English   中英

Moodle:获取登录用户的功能时出错

[英]Moodle: Error In fetching capabilities of logged-in User

class block_add extends block_base {

function init() {
    $this->title = get_string('pluginname', 'block_add');

}

function applicable_formats() {
    return array('all' => true, 'tag' => false);
}

function specialization() {
    $this->title = isset($this->config->title) ? $this->config->title : get_string('newblock', 'block_add');
}

function instance_allow_multiple() {
    return true;
}

function get_content()
{

    global $USER, $DB;

    if ($this->content !== NULL) {
        return $this->content;
    }

    $this->content = new stdClass();
    $roles = $DB->get_records('role_capabilities',['userid'=>$USER->id]);->(// in this lines i am getting error "error readig from database")
    var_dump($roles);
    foreach ($roles as $role) {
        $this->content->footer .= "Role Id  = ".$role->contextid."</br>"."Context Id  = ".$role->contextid."</br>"."Permission  = ".$role->capability."</br>" ;
    }

}




function has_config() {return true;}

}

我收到“从数据库读取错误” idk 为什么,我正在尝试打印登录用户的所有分配功能(例如:管理员),我是 php 以及 Moodle 的新手

role_capabilities表是针对角色能力而不是用户能力,所以没有userid

Moodle 中的功能(权限)相当复杂。 不同级别(上下文)的功能 - 站点、类别、课程、模块/活动、块、用户。 能力被分配给一个角色,而用户被分配给一个或多个角色。 这些功能也可以被覆盖。 所以这并不简单。

我建议在各种 get 函数中查看/lib/accesslib.php以查看是否有现有的 function 可以满足您的需求。

能力列表也会很长,所以可能不适合一个块。

您可以在以下位置查看用户的功能列表

站点管理 > 用户 > 权限 > 检查系统权限

以及一个角色的能力列表

站点管理 > 用户 > 权限 > 功能概述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM