Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Moodle Mobile 2 (Ionic 1) Remote add-ons

From MoodleDocs
Revision as of 11:08, 20 May 2016 by Daniel Palou (talk | contribs)

Moodle 3.1

Only available for Moodle 3.1 onwards.

A Moodle Mobile remote add-on is the mobile app version of a Moodle plugin that will be loaded when a user accesses the site on the app.

Moodle Mobile remote add-ons are stored within a Moodle plugin and are downloaded and lazy-loaded by the Mobile app in every site that uses them.

Moodle plugins can include several Mobile add-ons. They can also declare dependencies between plugins.

We can say that a remote add-on is a special version of a Moodle Mobile add-on. The main differences are:

  • Mobile remote add-ons are placed inside Moodle plugins (outside the Mobile app).
  • Mobile remote add-ons language files must include the whole component prefix.
  • Mobile remote add-ons uses special placeholders for paths inside CSS files or Javascript code.

How to create a remote add-on

Remote add-ons must be developed first as standard Moodle Mobile add-ons and then packaged as a remote add-on.

These are the main required steps:

  • Develop the required Moodle Web Services
  • Develop a standard Moodle Mobile add-on
  • Package the Moodle Mobile add-on as a remote add-on
  • Include the remote add-on in your Moodle plugin

Web Services

Most of Mobile add-ons require Web Services to work, but in some cases (like add-ons implementing question types) it won't be necessary.

Please refer to Web services documentation, you have an example here: https://github.com/markn86/moodle-mod_certificate/blob/MOODLE_31_STABLE/classes/external.php

Once the Web Services are developed, you must include them into the Mobile service using the "services" field when declaring external functions, see: https://github.com/markn86/moodle-mod_certificate/blob/MOODLE_31_STABLE/db/services.php

Remember that this is only available from Moodle 3.1 onwards.

Mobile add-on

Refer to Moodle Mobile Plugins Development

Remote add-on packaging

Some requirements need to be met to make the remote add-on work in the app. These are the steps you need to follow in order to make it work:

  • Place all the JavaScript code of your addon in a single file named addon.js. This file needs to be in your addon's root folder.
  • In this addon.js, replace the paths to your addon folder with $ADDONPATH$. For example, if you have
templateUrl: 'addons/myaddon/templates/index.html'

you should set it like this:

templateUrl: '$ADDONPATH$/templates/index.html'
  • Add your addon's prefix to language strings. That is, if you have a string like this:
"getcertificate": "Get your certificate"

you need to set it like this:

"mma.mod_certificate.getcertificate": "Get your certificate".

It's important that language files are inside a "lang" folder in your addon's root folder.

  • Place all the styles of your addon in a single file named styles.css. This file needs to be in your addon's root folder.

Once all this is done you need to create a zip file with your addon files. Please make sure that the files addon.js and styles.css are in the root of this zip file.

Remote add-on publishing

Once you have a zip file containing the remote add-on, you must include it into the Moodle plugin.

Please, refer to Activity_modules#mobile.php for instructions. Basically you will need to create a db/mobile.php and place the zip file into mobile/addonname.zip