Hi,
you have our developer documentation here: https://docs.moodle.org/dev/Moodle_Mobile
Please, notice that right now if you want to build a custom addon for the app you will have to build your custom app, we are working in a new improvement in the app to support addons without having to build a custom app. In any case, the required changes between the first and second approach will be minimum
Juan
1.Who can help me?
Here is my code:
main.js
angular.module('mm.addons.mylesson', [])
.config(function($stateProvider) {
$stateProvider
.state('site.mylesson', {
url: '/mylesson',
params: {
moduleid: null
},
views: {
'site': {
controller: 'mmamylessonPageCtrl',
templateUrl: 'addons/mylesson/templates/view.html'
}
}
});
})
.config(function($mmCourseDelegateProvider) {
$mmCourseDelegateProvider.registerContentHandler('mmamylesson', 'mylesson', '$mmamylessonHandlers.courseContent');
});
mylesson.js
angular.module('mm.addons.mylesson')
.factory('$mmamylesson', function($mmSite, $q, $mmUser, $mmSitesManager) {
var self = {};
self.getmylessonPagesById = function(cmid) {
var params = {
"moduleid" : cmid
}
return $mmSite.read('mylessonws_get_mypages_by_id', params).then(function(response) {
if (response.id && response.id.length) {
return response;
} else {
return $q.reject();
}
});
};
self.isPluginEnabled = function(siteId) {
siteId = siteId || $mmSite.getId();
return $mmSitesManager.getSite(siteId).then(function(site) {
return site.wsAvailable('mylessonws_get_mylessonpages_by_id');
});
};
return self;
});
handlers.js
angular.module('mm.addons.mylesson')
.factory('$mmamylessonHandlers', function($mmCourse, $mmamylesson, $state, $mmUtil, $q) {
var self = {};
self.courseContent = function() {
var self = {};
self.isEnabled = function() {
return $mmamylesson.isPluginEnabled();
};
self.getController = function(moduleid) {
return function($scope) {
$scope.title = module.name;
$scope.icon = $mmCourse.getModuleIconSrc('mylesson');
$scope.action = function(e) {
if (e) {
e.preventDefault();
e.stopPropagation();
}
$state.go('site.mylesson', {moduleid: moduleid});
};
};
};
return self;
};
return self;
});
I have found the problem, the wsAvailable() only contain the methods which is written by officical.
Updated question:
1. Is there anyway for to read, write, check the services written by myself?
2. I have test site token which cannot use my services, is there any build-in methods for developer to get token?
Hi Dickson,
for Moodle 3.1 you can inject your Web Services in the mobile or local_mobile service via the services attribute, see: https://github.com/jleyva/moodle-mod_certificate/blob/CONTRIB-6313/db/services.php#L35
In previous versions, you will have to use your custom Moodle Service adding your own functions, you must change the wsservice value in the config.json file to point to your custom service shortname.
You can manually create tokens for users via Administration - Plugins - Web Services - Manage tokens, alternatively, you can use the login/token.php script (passing as parameter a username, password and service (service shortname)
Regards, Juan