我已经安装了本地插件并设法检索单个数组。但是当我尝试加载数组列表时,它会抛出错误。
“课程名称”存储在结果数组的第二个位置,如下所示。
class local_get_completion_overview_external extends external_api {
public static function get_completion_overview_parameters() {
return new external_function_parameters(
array(
'field' => new external_value(PARAM_ALPHA, 'The field to search can be left empty for all courses or:
id: course id', VALUE_DEFAULT, '')
)
);
}
public static function get_completion_overview(){
global $CFG, $DB;
require_once($CFG->dirroot . '/course/lib.php');
require_once($CFG->libdir . '/filterlib.php');
$params = self::validate_parameters(self::get_completion_overview_parameters($field = ''),
array(
'field' => $field
)
);
$sql = "SELECT DISTINCT cr.id AS courseid,
cr.fullname AS coursename,
COUNT(DISTINCT ra.id ) AS enrols,
COUNT(DISTINCT cc.timecompleted) AS completed
FROM {course} cr
JOIN {context} ct ON ( ct.instanceid = cr.id )
LEFT JOIN {role_assignments} ra ON ( ra.contextid = ct.id ) and ra.roleid = 5
LEFT JOIN {course_completions} cc ON cc.course = cr.id
GROUP BY cr.fullname, cr.id
ORDER BY coursename";
$courseids = array();
$warnings = array();
// $requestedcourseids = $params['field'];
if (empty($params['field'])) {
$courses = $DB->get_records_sql($sql, array());
}
if(!empty($courses)){
$coursesdata = array();
$currentcourseid = null;
$course = null;
我发现一个 Moodle 论坛说不好的语言类型会导致这个问题,所以应该改变它。(https://moodle.org/mod/forum/discuss.php?d=355334)我想这可能是这种情况,因为错误从 return() 中的第二个数组抛出,这是一个文本值,但我可能是错的最好在我做下一步之前问清楚。
提前致谢,如有任何帮助,我们将不胜感激!
Cats萌萌