External web service in Moodle Mobile2

External web service in Moodle Mobile2

by Dickson Chan -
Number of replies: 6
Hi everyone, I am new to mm2. I need to  build a custom mm2 apps.   I need our customised lesson plugin work on mm2. How can I use our custom webservice  to build addons in mm2 ?  Anyone can help me? 



Average of ratings: -
In reply to Dickson Chan

Re: External web service in Moodle Mobile2

by Juan Leyva -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

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

Average of ratings: Useful (1)
In reply to Juan Leyva

Re: External web service in Moodle Mobile2

by Dickson Chan -
I have already enabled the external web service on our site, but the site.wsAvailable() always return false!

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;

});


In reply to Dickson Chan

Re: External web service in Moodle Mobile2

by Dickson Chan -

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?

  

In reply to Dickson Chan

Re: External web service in Moodle Mobile2

by Juan Leyva -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

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

Average of ratings: Useful (1)
In reply to Juan Leyva

Re: External web service in Moodle Mobile2

by Dickson Chan -

Thanks for your help!

I am using moodle 2.8.3, so  I build own functions for using our service on mm2.

Is there any built-in functions passing the current user info (id, password) and current  course module id to my own functions on mm2?

In reply to Dickson Chan

Re: External web service in Moodle Mobile2

by Juan Leyva -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

Hi Dickson,

I'm sorry but I don't understand your question, can you clarify it? what are you trying to achieve?

Regards, Juan