Moodle for mobile

$mmSite: WS function 'bat_grades_overview' is not available, even in compatibility mode.

 
Picture of Daniel Romero
$mmSite: WS function 'bat_grades_overview' is not available, even in compatibility mode.
 

Hello, I am trying to call a web service that i created on the my Moodle Web version from my Mobile version but I am getting the following error : $mmSite: WS function 'bat_grades_overview' is not available, even in compatibility mode.

From the root directory, my plugin is located in moodle(root)/report/grade/batoverview here is my code. In essence, the mobile version calls the webservice of the web version. Thanks in advance for any help

On the web version (moodle(root)/report/grade/batoverview/db/services.php)

$services = array(
'bat_overview_service' => array( //the name of the web service
'functions' => array ('bat_grades_overview', 'bat_grades_details'), //web service functions of this service
'requiredcapability' => '', //if set, the web service user need this capability to access
//any function of this service. For example: 'some/capability:specified'
'restrictedusers' =>0, //if enabled, the Moodle administrator must link some user to this service
//into the administration
'enabled'=>1, //if enabled, the service can be reachable on a default installation
)
);

$functions = array(
'bat_grades_overview' => array(
'classname' => 'gradereport_batoverview_external',
'methodname' => 'get_grades',
'classpath' => 'grade/report/batoverview/externallib.php',
'description' => 'Get the user/s report grades table for a course',
'type' => 'read',
'capabilities' => 'gradereport/user:view'
),
'bat_grades_details' => array(
'classname' => 'gradereport_batoverview_external',
'methodname' => 'get_grades_details',
'classpath' => 'grade/report/batoverview/externallib.php',
'description' => 'Get the users detailed report',
'type' => 'read',
'capabilities' => 'gradereport/user:view'
)
);
class gradereport_batoverview_external extends external_api {

public static function get_grades_parameters() {
return new external_function_parameters (
array(
'courseid' => new external_value(PARAM_INT, 'Course Id', VALUE_REQUIRED),
'userid' => new external_value(PARAM_INT, 'Return grades only for this user (optional)', VALUE_DEFAULT, 0)
)
);
}

public static function get_grades($courseid, $userid = 0) { logic that should be found by mobile web service call!! }

On the mobile version : 

var data = {courseid: courseId, userid: userId };
return $mmSite.read('bat_grades_overview', data, {}).then(function(rtndata) {
if(rtndata.length != 0) return rtndata;
else $q.reject();
});


 
Average of ratings: -
Picture of Juan Leyva
Re: $mmSite: WS function 'bat_grades_overview' is not available, even in compatibility mode.
Core developersMoodle HQParticularly helpful MoodlersPlugin developersTesters

Hi,

what Moodle version are you using?

is your custom app using a custom Mobile service?

In any case, you should inject your web service functions to the official Mobile service, this can be done adding something like this in the function declaration:

'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE),

Remember to bump your module version.php number anytime you do a change so the Web Services are reloaded and updated correctly in the Moodle database.


 
Average of ratings: -
Picture of Daniel Romero
Re: $mmSite: WS function 'bat_grades_overview' is not available, even in compatibility mode.
 

Hello Juan, Thanks for your reply.

I wish just missing the 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE),


Thank you so much!! 

 
Average of ratings: -