Assign Role to User

Assign Role to User

by Nelson Gomez -
Number of replies: 7

I hope you are well.


I need your help, can you please tell me how a user is assigned a
using the webservices role.

I was doing this:

enrolRecord enrolRecord role = new enrolRecord();
rol.userid = "GR67";
rol.enrol = "Student-Company";

But the user is assigned to the role. Chances are you are doing something
wrong. Can you please help me?

Average of ratings: -
In reply to Nelson Gomez

Re: Assign Role to User

by Netram Dhakar -
In reply to Netram Dhakar

Re: Assign Role to User

by Nelson Gomez -

hello Netram Dhakar
Thank you very much for answering,

I'm really new at this and I am implementing the webservices oktech.
It managed to create users, create categories, adding courses to moodle.

But not as assigning a user to a specific role in Moodle.

Can you please help me?

I utlizando programming language C #. Net

or any idea in java.

In reply to Nelson Gomez

Re: Assign Role to User

by Netram Dhakar -

Hi Nelson,

can you tell me which version of moodle you are using.

In moodle2.0.x there is already a webservice function to assign role in moodle courses named as "moodle_role_assign". If you are using moodle1.9.x then you can wright a new webservice function to assignment With the help of following URL

http://docs.moodle.org/dev/Creating_a_web_service_and_a_web_service_function

thanks

Netram Dhakar

In reply to Nelson Gomez

Re: Assign Role to User

by Patrick Pollet -

@Nelson,

   In OKTech ws there are many oprations to assign/remove role to users into courses such as :

  •  function affect_user_to_course($client, $sesskey, $userid, $courseid, $rolename) 
  • function remove_user_from_course($client, $sesskey, $userid, $courseid, $rolename) 
these two functions expects a Moodle userid, a Moodle course id and a role shortname (teacher,student, editingteacher...)
for the three legacy roles you can also use
  • public function add_student($client,$sesskey,$courseid,$courseidfield,$userid,$useridfield)  
  • public function remove_student($client,$sesskey,$courseid,$courseidfield,$userid,$useridfield) 
  • public function add_teacher($client,$sesskey,$courseid,$courseidfield,$userid,$useridfield)
  • public function add_noneditingteacher($client,$sesskey,$courseid,$courseidfield,$userid,$useridfield)  
  • ...
that expects a couple of values to uniquely identify the course (by id, idnumber or shortname) and the target user (by username,id,idnumer or email) such as :
add_student(client,sesskey,'chem101','idnumber','jdoe','username')
or 
remove_teacher(client,sesskey,'12345','idnumber','jdoe@somewhere.com','email')
...
all these functions returns an affectRecord()  with a boolean status and an eventual error message.

see the javadoc here : http://prope.insa-lyon.fr/~ppollet/moodlews/java/javadoc2/fr/insa_lyon/prope/moodle_195/wspp/wsdl2/Mdl_soapserverBindingStub.html

to get sample code in java see http://docs.moodle.org/dev/Web_Services:OK_Tech_Web_Services#Writing_a_client_in_Java for use with many java libraries such as Axis 1.4, Ksoap2 or Gson.

Cheers.

In reply to Patrick Pollet

assign roles globals to user with oktech

by Nelson Gomez -

Patrick good morning hope you are well.
Excellent your answer helped me a lot.

But there is one detail, I need to create a user with webservices allow me to assign rolesoktech global-

Can you please auydarme that?