Innovative LMS developments

Headstart Innovation labs is interested in many exciting features related to Learning Management systems. More the challenging we like to breakthrough. In terms of facilitating eLearning, Moodle is a well-known PHP based eLearning platform. Moodle has been our base in building a successful LMS that we built up so far. With the beginning of this article, we are going to explain some of the exciting lessons learned and development we went through in our innovative journey.

How to develop a local plugin for Moodle

In this tutorial, we try to tell you basic steps for develop a local plugin for Moodle. We will take a plugin called school_details as an example. Let’s see how it is going to be developed. When we develop a local plugin we need to maintain following basic folder structure as a good practice.

1. /local/plugin_name/version.php – version of script (must be incremented after changes)

2. /local/plugin_name/db/install.xml – executed during installation (new version.php found)

3. /local/plugin_name/db/install.php – executed right after installation.xml

4. /local/plugin_name/db/upgrade.php – executed after version.php changed

5. /local/plugin_name/db/access.php – definition of capabilities

6. /local/plugin_name/lib.php – function library, automatically included by config.php


1. Create a folder inside the local folder called “school_details”


2. Create “version.php” file inside “school_details” folder

It is mandatory to have this file otherwise when admin or manager login to the system they will get an error message.


Now open version.php in a text editor and lets start to edit it. This is how a basic version.php looks like.


$plugin->version is the version of the plugin you are going to create. Normally it is specified based on date format such as YYYYMMDDXX. XX is an incremental number. You may gradually increase it when you upgrade the plugin.

$plugin->requires This is the minimum version of Moodle core where the plugin can be installed in to. So you will get an error when you try to install into older versions.

$plugin->component The full frankenstyle component name in the form of plugintype_pluginname. It is used during the installation and upgrade process for diagnostics and validation purposes to make sure the plugin code has been deployed to the correct location within the Moodle code tree.

$plugin->maturity Its identification of the level of maturity of this plugin version, that is how stable it is. Supported value is any of the predefined constants  MATURITY_ALPHA, MATURITY_BETA, MATURITY_RC or MATURITY_STABLE These are the primary component of version.php if you need more clarification about version.php please visit link


Now we need a separate table in the database for our plugin. For that we need to create a folder called “db” inside our plugin folder (/school_details) and inside that we will create an xml file called “install.xml”. This install.xml file will be executed when our plugin is being installed. Following is the basic structure of install.xml file.


When we specify fields of the table it has several predefined data types (int, char, text, binary, datetime, float, number).

Now we are ready to install new plugin in our Moodle setup.


If you logged in as an admin you will see this kind of window.

img 4.png

In this window you can see “Current version”, “New version”, “Requires” and “Status”. Since this is the first time this plugin is going to be installed “Current version” filed will be empty. “New versions” and “Requires” values are as in your version.php. Now click the button “upgrade Moodle database now”. If it is successfully installed you will get following window.


Then you click on “Continue” and you can find the new table in Moodle database.



As the final step of this tutorial we will see how to upgrade your plugin and alter your table. For this we need to create another new file inside that db folder called “upgrade.php”. Its basic structure is like this.


Function name should be local_plugin_name_upgarde. And this function has a parameter to get older version details of the plugin. Now I need to add a new column in my local_school_details table. What we should do is, first open version.php and change $plugin->version to a higher version as follows.

$plugin->version = 2016060900 to 2016060901;

Now edit “upgarde.php” file as in the below.


Now you can write your logic inside the if condition as you prefer.


Now again we need to do step 4 and you will get that same window as in the below.


This time you will notice that “Current version” filed is not empty and that makes sense. And “status” field has also been changed to “To be upgraded”. After click on “Upgrade Moodle database now” you can see that new field has been successfully added to the table in the database.


Likewise the process of developing a plugin is going to be challenging, yet when clearly understood, it can be followed and summarized to repeat in few steps. We went through the exciting journey, hope you will have a less bumpy ride ahead.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s