我有以下查询来检索自定义Moodle插件中的学术顾问。
学术顾问角色的配置如下所示:https://docs.moodle.org/en/Parent_role
我已经在 Ad hoc数据库查询(以及MySQL Workbench)中运行它,并且它在这两个方面都运行良好,但由于某些奇怪的原因它在我的插件中不起作用
function addRecord()
{
var add= document.getElementById("add");
var addArray= [];
addArray.push(add.value);
}
:
let scanPoints = [2.0,0.0,2.0,0.0,2.0,0.0,0.0]
let postPoints = [4.0,2.0,0.0,0.0,1.0,0.0,0.0]
var combinedArray = [Double]()
for i in 0..<scanPoints.count {
let newValue = scanPoints[i] + postPoints[i]
combinedArray.append(newValue)
}
在我的db_update.php
页面中,该页面包含在function get_academic_advisees($userid) {
global $DB;
$sql = 'SELECT child.username, child.firstname, child.lastname
FROM {user} user
JOIN {role_assignments} ra ON ra.userid = user.id
JOIN {role} role ON role.id = ra.roleid
JOIN {context} ctx ON ctx.id = ra.contextid
AND ctx.contextlevel = 30
JOIN {user} child ON child.id = ctx.instanceid
WHERE role.shortname = "academic_adviser"
and user.username = ?';
return $DB->get_records_sql($sql, array($userid));
}
(调用attendance_form.php
)中:
attendance.php
答案 0 :(得分:2)
该函数采用参数'userid',但在查询中它尝试将其与'user.username'匹配。
所以,你需要把:
$userid = $USER->username;
如果您希望它以您的形式运作。
另外,请删除&amp;来自$ mform =&amp; $ this-&gt; _form - Moodle很久以前就停止支持PHP 4了!
答案 1 :(得分:0)
所以正确的代码是(感谢@davosmith):
function get_academic_advisees($userid) {
global $DB;
$sql = 'SELECT child.username, child.firstname, child.lastname
FROM {user} user
JOIN {role_assignments} ra ON ra.userid = user.id
JOIN {role} role ON role.id = ra.roleid
JOIN {context} ctx ON ctx.id = ra.contextid
AND ctx.contextlevel = 30
JOIN {user} child ON child.id = ctx.instanceid
WHERE role.shortname = "academic_adviser"
and user.id = ?';
return $DB->get_records_sql($sql, array($userid));
}