WorkshopHow to develop a new
plugin for Moodle Mobile
Juan LeyvaMoodlemoot Spain 2013
26, 27 y 28 September
Speakers
Juan Leyva
Moodle Developer (since 2003) working @ CV&A Consulting
Moodle Mobile official app creator and maintainer
Developer of plugins:● Configurable Reports● jmail● LTI Provider● UMM (Unofficial Moodle Mobile)● Anonymous posting in forums, Collaborative real-time editor,
ConfigTabs, Forum discuss subscription,
What we are going to do
● Understand how Moodle Mobile talks with a Moodle installation● Understand the basics about Moodle Mobile Architecture● Set up your Moodle Mobile development environment● Set up your Moodle installation● Package a existing Webservice to be used inside a local plugin● Configure new “Mobile Services” in your Moodle installation● Set up your MoodleMobile app● Develop a MoodleMobile plugin● Change the name and appearance of your app● Build your MoodleMobile rebranded app
The new plugin
● Display user grades in activities
How Moodle Mobile talks with Moodle
Moodle Mobile is a REST+JSON based Web Services client
HTTPS is recommended
User session is emulated using unique tokens
File upload and downloads are done using standard HTTP requests
Moodle Mobile Architecture basics
Set up the development environment
● Install Google Chrome● Create a direct access or script for launching Google Chrome
with these flags: --disable-web-security --allow-file-access-from-files
● With Google Chrome and the F12 or "Developer tools" you can emulate mobile devices changing user-agent, orientation, resolution, geo-location, touch events, etc..
● Just open the Developers tools, click on the wheel bottom-right corner to see the Override options.
● It's interesting also disabling the Cache (in general options)
Set up your Moodle Installation
● Enable debugging
● Disable all caches
● Enable WebServices in Advanced options
● Enable WebServices protocols (REST)
● Enable Mobile Services (in Plugins -> WebServices
-> Services)
Package an existing WebService
● https://github.com/cvaconsulting/moodle-
local_custommm
Configure the new service
● A service is a set of functions for an specific purpose. Since Moodle 2.1 there is a pre-built service for Moodle M.
● This service cannot be edited for adding new functions so we don't have a simple way for make available our new Web Service function to the mobile app.
● The only way for fix this is creating a new Service in Moodle, and configuring our app for pointing to this new service.
● There are two ways of creating a Service in Moodle:○ Using a db/services.php in your plugin as mentioned here:
External services description○ Creating the service in your Moodle installation using the forms in
Admin > Plugins > Web Services > External Services
Configure the new service
● In this case we've created the service using the Moodle forms because it gives more flexibility in some aspects.
● There is a big impediment, due tohttps://tracker.moodle.org/browse/MDL-29807 in order to add a shortname for the new Service, we have to edit manually the Moodle database for adding the shortname in the dbprefix_external_services table
Set up your MoodleMobile app
● Download the last version of the MoodleMobile source code from https://github.com/moodlehq/moodlemobile
● Edit the config.json file and change the wsservice parameter in order to point to the shortname of the Service you created before.
● You have to add also the name of the plugin you are developing at the final of the plugins parameter:
● "plugins" : ["notifications", "upload", "contents", "participants", "addcontact", "addnote", "sendmessage", "grades"],
● Notice that, for avoid errors, this last change should be done once the file plugins/grades/main.js file exists
Develop the MoodleMobile plugin
● https://github.com/cvaconsulting/moodlemobile-grades
● plugin/grades/lang/en.json - Contains the language strings
● plugin/grades/icon.png - The plugin icon
● plugin/grades/activities.html - The template for the activities list
● plugin/grades/activitygrade.html - The template for showing the
grade
● plugin/grades/main.js - The plugin's main code
Develop the MoodleMobile plugin (main.js)
Develop the MoodleMobile plugin (main.js)
Develop the MoodleMobile plugin (main.js)
Develop the MoodleMobile plugin (main.js)
Change the name an appearance
● Edit the config.xml to change the app name● Replace all the icons found in the app● Edit also the config.json file for additional changes● Load a custom CSS from your plugin:
$('head').append('<link rel="stylesheet" href="plugins/myplugin/mycss.css" type="text/css" />');MM.registerPlugin(plugin);
Build your MoodleMobile rebranded app
● Use PhoneGap Build https://build.phonegap.com/
● Create a free account pointing to your github repository or upload a zip file with your app
● Sign the app using your Android and iOs certificates
● Publish your app in Google Play and Apple app Store
Thanks for coming!
You have more information here:
http://docs.moodle.org/dev/Moodle_Mobile
Top Related