Webservice for Cohorts

Webservice for Cohorts

by Lorenz Ulrich -
Number of replies: 9

Hi everyone

We would like to assign users to cohorts by using Moodle webservices. Is there anyone out there who already wrote the externallib for that stuff and if not - is there a general interest in making that a part of Moodle? We could then provide the code for integration.

Thanks for your feedback and best regards,

Lorenz

Average of ratings: -
In reply to Lorenz Ulrich

Re: Webservice for Cohorts

by Patrick Pollet -

Most of the cohorts operations are implemented in OK Tech WS that has been recently 'intregrated' to Moodle 2.0 WS infrastructure (i.e a local/oktech/externallib.php file). see http://moodle.org/mod/forum/discuss.php?d=67947#p773621

Currently operations are

add_cohort affect_user_to_cohort affect_users_to_cohort delete_cohort

get_all_cohorts get_cohort_byid get_cohort_byidnumber get_cohort_members get_cohorts_byname get_my_cohorts

remove_user_from_cohort remove_users_from_cohort

update_cohort

 

Cheers

In reply to Patrick Pollet

Re: Webservice for Cohorts

by Lorenz Ulrich -

Hi Patrick

Thanks for your information. I just installed the OK Tech WS and will use them!

Lorenz

In reply to Patrick Pollet

Re: Webservice for Cohorts

by Lorenz Ulrich -

I'm testing the services now but got trouble accessing the functions. The code below works fine for getting stuff from the built-in Moodle webservice functions, but it doesn't work for the OK Tech services:

$client = new SoapClient($moodleWebserviceUrl . '?wstoken=' . $moodleToken . '&wsdl=1');

$client = $this->moodleSoapClient->__getFunctions();

The OK Tech webservices are not showing up in the function list and cannot be called. Do I need to prefix the functions in a special way, like

$client = $this->moodleSoapClient->oktech_moodle_get_version();

?

Thanks for your help.

In reply to Lorenz Ulrich

Re: Webservice for Cohorts

by Patrick Pollet -

Initially OK Tech was not meant to be called from Moodle 2.0 infrastructure and had (and still have) its own authentication process and wsdl emission.

If you want to 'see' the oktech operations under Moodle 2.0 admins screens you must copy the content of folder wspp/moodle2integration (i.e the folder named oktech) in Moodle's local directory AND visit the Notifications link of site administration. See the README file within that folder

Currently your 'call' works (and returns quite a well formed WSDL) if you comment out line 885 of webservice/lib.php that states :

throw new moodle_exception('erroroptionalparamarray', 'webservice', '', $name);

This is due to the fact that the structures named 'datum' declared in local/oktech/oktech_classlib.php and used in all add_xxx and update_xxxx operations are erroneously declared as optional by the lines :

parent::__construct($content, $desc,VALUE_OPTIONAL,null);

where they should be

parent::__construct($content, $desc,VALUE_REQUIRED,null);

I shall try to fix this real soon...

EDIT : this has been just fixed of github see latest commit , so not need to change Moodle 2.0 official code wink

https://github.com/patrickpollet/moodlews/commit/88dbea6d04093be5fb86efa8b17d1162d4b53075

(pick up the latest oktech_classlib.php file and copy it in your local/oktech folder...

Furthermore OK Tech has its own 'standard wsdl' that can be reached at

http://yourmoodle/wspp/wsdl_pp2.php,

 

Cheers.

In reply to Patrick Pollet

Re: Webservice for Cohorts

by Lorenz Ulrich -

Hi Patrick

Thanks a lot for your answer. After reading the README again and again I found out that I missed to copy the moodle2integration contents to local. After doing that the webservice started working for me smile.

Still I got some problem with returns I could only solve by editing the code:

In mdl_baseserver.class.php I had to change

require_once ('/classes/MoodleWS.php');

to

require_once ($CFG->dirroot . '/classes/MoodleWS.php');

to make it work. And I had problems with return values of webservice requests. Shouldn't a successful request just return TRUE? It's hard doing foreach loops if I get back status messages.

Thanks also for the latest commit to Github, I will check these changes out.

Lorenz

In reply to Lorenz Ulrich

Re: Webservice for Cohorts

by Patrick Pollet -

@Lorenz,

>in mdl_baseserver.class.php I had to change  require_once ('/classes/MoodleWS.php');

 

Strange. Normally in mdl_baseserver this line correctly states

require_once ('classes/MoodleWS.php'); with NO leading slashes

If you has to change it to  require_once ($CFG->dirroot . '/classes/MoodleWS.php'); that mean that you install is NOT correct. OKTech MUST be in a directory named wspp UNDER root of Moodle installation, so you should have require_once ($CFG->dirroot . '/wspp/classes/MoodleWS.php'); and this absolute referencing is normally not needed...

This is where the Moodle2 integration pack expects to find it....

Cheers.

In reply to Patrick Pollet

Re: Webservice for Cohorts

by Lorenz Ulrich -

Hi Patrick

Thanks for you answer. You're completely right, I put some files in wrong directories because I used a ZIP from Github that had a different folder structure.

Since we will move the installation to a new server anyway, I will set it up correctly then. Since I'm new to Moodle I'd be grateful for advice:

ATM we're checking out the Moodle sources from the Git repository. What is the best way to include your webservices without losing the possibility to update Moodle/MoodleWS?

Thanks in advance and best regards,

Lorenz

In reply to Patrick Pollet

Re: Webservice for Cohorts

by Lorenz Ulrich -

By the way, Patrick, can you confirm that the webservice fails (Invalid response value detected, execution can not continue.) if I ask for all users of a cohort (get_cohort_members) and there is no member yet? Is that the right behaviour?

In my script I want to check if a user is already affected to a cohort before I try to affect him to (because affecting a user to a cohort who is already affected would throw an error, too). This way I can't.

In reply to Lorenz Ulrich

Re: Webservice for Cohorts

by Egli Michael -

I just have found a little but irritating bug in the wssp function "oktech_affect_users_to_cohort". The calling parameter "cohortid" and "userids" are reversed!!!