Addning Course enrolment method through webservices.

Addning Course enrolment method through webservices.

by santosh Suwarnkar -
Number of replies: 1

Hi,

I have installed "Webservice functions for cohort enrolment" plug in to Add a cohort enrolment instance to a course.

I have implemented code for  "local_ws_enrolcohort_add_instance" function but for some cohorts its working and for some cohorts its showing below errors
Array
(
[faultCode] => 10648825
[faultString] => Object is not available at this context! | DEBUG INFO: Cohort with id 39 is not available at this context. | ERRORCODE: unavailableatcontext
)

Can any one please explain where is my mistake?


My Code -
/// SETUP - NEED TO BE CHANGED
$token = '41d74182154a8b8197d41730373faf16';
$domainname = 'http://redchipmoodle.in/noodlenow/';
$functionname = 'local_ws_enrolcohort_add_instance';

$params = new stdClass();
$params->courseid  = 6;
$params->cohortid = 42;
$params->roleid = 5;
/// XML-RPC CALL
$serverurl = $domainname . '/webservice/xmlrpc/server.php'. '?wstoken=' . $token;
require_once('curl.php');
$curl = new curl;
$curl->setHeader('Content-type: text/xml');
$post = xmlrpc_encode_request($functionname, array($params));
$resp = xmlrpc_decode($curl->post($serverurl, $post));
echo "<pre>";
print_r($resp);

Average of ratings: -
In reply to santosh Suwarnkar

Re: Addning Course enrolment method through webservices.

by Thomas Schröder -

Hello,

We experienced the same issue and will just quickly note our guess (and a possible solution):

in externallib.php of moodle-local_ws_enrolcohort in line 329

cohort_get_available_cohorts($context)

is called. This has a hardcoded limit of 25 items as seen in line 239 of

https://github.com/moodle/moodle/blob/master/cohort/lib.php

This limit makes some sense for paged views, but of course is not helpful here, as whenever there are more than 25 cohorts, only the first 25 will be returned.

Changing the call to

cohort_get_available_cohorts($context, 0, 0, 0)

resolves the problem for us.

Best regards,

thoschi