Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/rest/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用gradereport\u user\u get\u grade\u项目的moodle web服务_Php_Rest - Fatal编程技术网

Php 使用gradereport\u user\u get\u grade\u项目的moodle web服务

Php 使用gradereport\u user\u get\u grade\u项目的moodle web服务,php,rest,Php,Rest,我正在使用Moodle api函数,我希望在特定课程中获得注册用户的所有分数。其目的是在excel文件中打印所有成绩。我试图从gradereport\u user\u get\u grade\u项中获取数据,但我的php代码在这里不起作用 <?php require_once('./curl.php'); $course_id=4; $domainname = '........'; //paste your domain here $wstoken = 'e521817f5cf979

我正在使用Moodle api函数,我希望在特定课程中获得注册用户的所有分数。其目的是在excel文件中打印所有成绩。我试图从gradereport\u user\u get\u grade\u项中获取数据,但我的php代码在这里不起作用

<?php
  require_once('./curl.php');
$course_id=4;
$domainname = '........'; //paste your domain here
$wstoken = 'e521817f5cf9798926e0563d452b7975';//here paste your getgradetoken 
$wsfunctionname = 'gradereport_user_get_grade_items';
$restformat='xml';//REST returned values format
$grade = array( 'courseid' => $course_id , 'user_id'=> $user_id );
$user_grades = array($grade);
$params = array('user_grades' => $user_grades);

//REST CALL
header('Content-Type: text/plain');
$serverurl = $domainname . "/webservice/rest/server.php?wstoken=" . $wstoken . "&wsfunction=" . $wsfunctionname;
$curl = new curl;

//if rest format == 'xml', then we do not add the param for backwardcompatibility with Moodle < 2.2

$restformat = ($restformat == 'json')?'&moodlewsrestformat=' . $restformat:'';
$resp = $curl->post($serverurl . $restformat, $params);
print_r($resp);

//EXCEL 
header("Content-Disposition: attachment; filename=\"gradereport.xls\"");
header("Content-Type: application/vnd.ms-excel;");
header("Pragma: no-cache");
header("Expires: 0");
$out = fopen("php://output", 'w');
foreach ($params as $data)
{
    if (is_array($data)){
        foreach ($data as $v) {

            fputcsv($out, $v,"\t");
        }
    }  
}
fclose($out);
?>
$course\u id,'user\u id'=>$user\u id);
$user_grades=数组($grade);
$params=数组('user\u grades'=>$user\u grades);
//休息电话
标题(“内容类型:文本/普通”);
$serverurl=$domainname。“/webservice/rest/server.php?wstoken=“$沃斯托肯。“&wsfunction=”$wsfunctionname;
$curl=新的curl;
//如果rest format='xml',那么我们不添加参数,以实现与Moodle<2.2的向后兼容性
$restformat=($restformat='json')?'&moodlewsrestformat='$REST格式:'';
$resp=$curl->post($serverurl.$restformat,$params);
印刷费($resp);
//胜过
标题(“内容处置:附件;文件名=\”gradereport.xls\”;
标题(“内容类型:application/vnd.ms excel;”);
标题(“杂注:无缓存”);
标题(“到期日:0”);
$out=fopen(“php://output“,‘w’”;
foreach($params作为$data)
{
if(is_数组($data)){
foreach($v数据){
fputcsv($out,$v,“\t”);
}
}  
}
fclose(美元外);
?>

它是否显示任何错误?输出:成绩分数无效参数值检测到无效参数值4 2它没有检索成绩,只是用4和2(课程ID和userid@LanaSDMalekD你能把那个错误写在帖子里吗?清除预期/实际输入/输出和错误有助于解决您的问题。您缺少服务器URL上所需的courseid参数