CONTEXT_COURSE on web service

CONTEXT_COURSE on web service

by Balaji Kutty -
Number of replies: 0

Hi,

This is on Moodle 2.0 on Ubuntu GNU/Linux with Apache 2.0 and MySQL.

I created a user for web authentication and created a role called webaccess. This user is assigned to this role. I assigned all access to this role. I also created external services for xmlrpc with all functions added to it. I'm able to see the users using the function moodle_user_get_users_by_id. But, when I try to access the courses, I get the following error.

"error/You cannot execute functions in the course context (course id:2). The context error message was: Course or activity not accessible."

I using the following XML RPC code

<?php

include 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::autoload('Zend_Loader');

$function = "moodle_course_get_courses";

$params = array('options' => array('ids' => array(2)));

$serverurl = "http://localhost/moodle/webservice/xmlrpc/server.php?wstoken=4647d51e7a4cc7f97913658d044370a9";

$client = new Zend_XmlRpc_Client($serverurl);
echo "Testing xml rpc";
print "<pre>";
try {
    $data = $client->call($function, $params);
    var_dump ($data);
    echo $data;
} catch (exception $exception) {
    var_dump ($exception);
}
print "</pre>";
?>


I could get the course listed only after commenting out the context checking code in course/externallib.php like shown below.

/*            $context = get_context_instance(CONTEXT_COURSE, $course->id);
            try {
                self::validate_context($context);
            } catch (Exception $e) {
                $exceptionparam = new stdClass();
                $exceptionparam->message = $e->getMessage();
                $exceptionparam->courseid = $course->id;
                throw new moodle_exception(
                        get_string('errorcoursecontextnotvalid', 'webservice', $exceptionparam));
            }*/

I'm unable to get the context set for webservices. What should I do to have a seemless access to courses through webservice using xmlrpc?

 

Thanks

Balaji

Average of ratings: -