Quantcast
Channel: Web services
Viewing all articles
Browse latest Browse all 2361

how to enrol user to freshly created course via web services

$
0
0
by Tomas Madajevas.  

hi, i'm trying to integrate moodle with drupal cms via web services. i've successfuly created categories, courses, users and also managed to extend moodle web services functionality by writing plugin by my own, but unfortunatelly i am not able to assign an editing teacher (ar any other) to my freshly created course. my code is:

 

$einfo = new stdClass;
$einfo->roleid = TEACHER; //iv defined an integer 2 (editingteacher's id)
$einfo->userid = $uid;    //moodle user's id
$einfo->courseid = $id;   //moodle course id

$einfo = moodle_int_course_enrol($einfo);
function moodle_int_course_enrol($info){
    $url = variable_get('moodleurl', '');
    $token = variable_get('moodletoken', '');
 
	$url .= '/webservice/xmlrpc/server.php'.'?wstoken='.$token;
  
    $params = array($info);
 
	$post = xmlrpc_encode_request('enrol_manual_enrol_users', array($params), array('encoding' => 'UTF-8', 'escaping' => 'markup'));

    $resp = drupal_http_request($url, array('headers' => array('Content-Type' => 'text/xml'), "method" => 'POST', 'data' => $post));
	$resp = xmlrpc_decode($resp->data);
    return $resp;
}

and then this gets executed i only have:
array(
'faultCode' => 21385713,
'faultString' => 'You don't have the permission to assign this role (3) to this user (6) in this course(27). | ERRORCODE: wsusercannotassign'
)

in $einfo variable;

does anybody know what am i doing wrong? any help appreciated


Viewing all articles
Browse latest Browse all 2361

Trending Articles