我尝试使用 Moodle Rest API
方法 enrol_manual_enrol_users()
为用户注册类(class),但它不会在 mdl_role_assignments
中创建任何内容> 表。
/// Connection
$token = 'ed874e6d9f51239e180f49f4d926d50f';
$domainname = 'http://localhost/moodle';
$functionname = 'enrol_manual_enrol_users';
$restformat = 'json';
//////// enrol_manual_enrol_users ////////
/// Paramètres
$enrolment = new stdClass();
$enrolment->roleid = 5; //estudante(student) -> 5; moderador(teacher) -> 4; professor(editingteacher) -> 3;
$enrolment->userid = 2;
$enrolment->courseid = 5;
$enrolments = array( $enrolment);
$params = array('enrolments' => $enrolments);
print_r($params);
header('Content-Type: text/plain');
$serverurl = $domainname . '/webservice/rest/server.php'. '?wstoken=' . $token . '&wsfunction='.$functionname;
require_once('./curl.php');
$curl = new curl;
//if rest format == 'xml', then we do not add the param for backward compatibility with Moodle < 2.2
$restformat = ($restformat == 'json')?'&moodlewsrestformat=' . $restformat:'';
$resp = $curl->post($serverurl . $restformat, $params);
print_r($resp);
我需要一种通过网络服务为用户注册 Moodle 类(class)的方法...
更新
返回以下响应:
"debuginfo":"Missing required key in single structure: enrolments"
参数为
'roleid' => new external_value(PARAM_INT, 'Role to assign to the user'),
'userid' => new external_value(PARAM_INT, 'The user that is going to be enrolled'),
'courseid' => new external_value(PARAM_INT, 'The course to enrol the user role in'),
'timestart' => new external_value(PARAM_INT, 'Timestamp when the enrolment start', VALUE_OPTIONAL),
'timeend' => new external_value(PARAM_INT, 'Timestamp when the enrolment end', VALUE_OPTIONAL),
'suspend' => new external_value(PARAM_INT, 'set to 1 to suspend the enrolment', VALUE_OPTIONAL)
用户ID和类(class)ID是有效的ID
最佳答案
我有同样的问题,但我可以做到:
header('Content-Type: text/plain; charset=utf-8');
$enrolment = new stdClass();
$enrolment->roleid = 5;
$enrolment->userid = 6030;
$enrolment->courseid = 48;
$enrolments = array( $enrolment);
$params = array('enrolments' => $enrolments);
$restformat = 'json';
$functionname = 'enrol_manual_enrol_users';
$serverurl = $domainname . 'webservice/rest/server.php' . '?wstoken=' . $token . '&wsfunction=' . $functionname;
$restformat = ($restformat == 'json')?'&moodlewsrestformat=' . $restformat:'';
$handler = curl_init();
curl_setopt($handler, CURLOPT_URL, $serverurl.$restformat);
curl_setopt($handler, CURLOPT_POST, true);
curl_setopt($handler, CURLOPT_POSTFIELDS, http_build_query($params));
$response = curl_exec($handler);
curl_close($handler);
return $response;
关于php - Moodle enrol_manual_enrol_users 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22227745/