how to enrol user to freshly created course via web services

how to enrol user to freshly created course via web services

by Tomas Madajevas -
Number of replies: 3

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

Average of ratings: -
In reply to Tomas Madajevas

Re: how to enrol user to freshly created course via web services

by Netram Dhakar -

Hi Tomas,

As per my understanding Your webservice user don't have permision to assign role (Means your token don't have permission to assign role).   please check the table "mdl_role_allow_assign". I think you need to do manual entry in this table.

For any more detial you can contact me at skype: netram.dhakar

Cheers

Netram Dhakar

 

In reply to Netram Dhakar

Re: how to enrol user to freshly created course via web services

by Michael Hughes -

You just need to make sure that your webservice user is assigned a special role and this role is able to assign roles - this can be set via the 'allow role assignments' tab on the define roles admin page http://themoodleurl/admin/roles/allow.php?mode=assign

Average of ratings: Useful (2)
In reply to Tomas Madajevas

Re: how to enrol user to freshly created course via web services

by Syed Nayab Bukhari -
Picture of Core developers

I think problem is here 

$einfo = moodle_int_course_enrol($einfo);

if $einfo is defined as above 

then here 

$einfo = moodle_int_course_enrol($einfo);

it is being redefine and getting function return value. 

 

if $einfo is newly defined then  moodle_int_course_enrol($einfo);

will return null because it has null value in parameter. 

 

Best of luck