GETTING STARTED



One of the challenges in Moodle development is finding a good starting point for creating a Moodle plug-in. I thought it would be cool to build a step-wise tutorial on the subject as I embark on a personal whim:

Building a Moodle Module that allows the Student to post their Moodle Forum posts to FaceBook, and elicits responses from their group of friends into a totally separate forum. Perhaps too ambitious for a first project, but it hits all of the major challenges.

I will start by coming up with a cool name for the plug-in. I am thinking of calling it InYourFace ?  This particular exercise will focus on building an activity module - a module that provides an activity that can be added to any Moodle course.

WHERE DO WE START?

NOTE: This tutorial assumes that you already have a working installation of Moodle 1.9.x available, and that you have at least one course installed in your Moodle instance.  It also assumes that you have some basic knowledge of PHP and MySQL.

Before we embark on writing our first Moodle module, let's download a template provided by the folks at Moodle.org. In our case, we will be writing our module for Moodle version 1.9.x:

Download Link for The Module Template for Moodle 1.9

We end up with a file called NEWMODULE.zip which we need to save to our local drive and unzip. In my case, I download to the Public folder, unzip the file and end up with .\Public\NEWMODULE.

NEXT ARTICLE IN SERIES

Tuesday, May 18, 2010

09MOD: Moodle Module Development - Adding Our Custom Code to the Module

TO START THE TUTORIAL FROM THE BEGINNING, CLICK HERE

 After the Module is setup and configured correctly, it's time to add our own logic.  This is what we had been waiting for!

The bulk of our logic goes into three scripts in our module's directory:
  • view.php
  • lib.php
  • locallib.php

THE MODULE'S VIEW.PHP SCRIPT

This script handles the display of the activity once it is added to a course section.  If we look at the code provided in the template, it already handles the following:
  • Determining the instance of the module for the current course
  • Entering the view as an the activity to the Moodle log
  • Displaying the Moodle header and footer

Thursday, May 13, 2010

08MOD: Moodle Module Development - Generate Upgrade snippet with XMLDB Editor

TO START THE TUTORIAL FROM THE BEGINNING, CLICK HERE

During our initial setup of the Module we modified the install.xml file.  We are now faced with a dillema - while modifying the module's form we introduced a new database column.  This value is needed by the module's logic and needs to be saved to our inyourface table (mdl_inyourface if your installation uses the default table prefix).

To handle this new challenge, we have to set up our first module upgrade.  We accomplish the upgrade by following a number of simple steps:

  • We generate XMLDB code that we use in our module's .\mod\inyourface\db\upgrade.php script
  • We paste the new code into the upgrade.php script
  • We update our .\mod\inyourface\version.php file
  • We run notifications from the Moodle admin menu

When we finish these steps, we can verify that our changes took effect by changing the Post Limit value in our module's form, and making sure that the change took place.


07MOD: Moodle Module Development - Testing the module's form

TO START THE TUTORIAL FROM THE BEGINNING, CLICK HERE

We have just completed our changes to the module's form.  This form is called when the user adds our activity to a Moodle course.  Let's test the form, and make sure that it works correctly.
 
1. Let's navigate to a Moodle course

Click Image to Zoom

06MOD: Moodle Module Development - The module's form

TO START THE TUTORIAL FROM THE BEGINNING, CLICK HERE

Moodle follows a very specific pattern for activity modules:
  • User selects a course
  • User turns editing on
  • User selects a topic or week
  • User selects an activity to add
Once the activity has been selected from the dropdown box, the module's form is displayed.  In our case, selection of the "Facebook Integration" activity calls the form described in the .\mod\inyourface\mod_form.php script.

05MOD: Moodle Module Development - The module's language file

TO START THE TUTORIAL FROM THE BEGINNING, CLICK HERE

When we first set our module up, we simply completed a series of search & replace for the the phrase "NEWMODULE" and replaced them with our Module's name. This is enough to get the Module registered, but it leaves a very ugly footprint in Moodle.