Book Image

Moodle 1.9 Extension Development

Book Image

Moodle 1.9 Extension Development

Overview of this book

Moodle gives you the power to create and customize feature-rich plug-ins. If you can write Moodle plug-ins, you can make it do just about anything. From making the site easier to administer, to new features, to completely changing the way it looks; plug-ins are the method Moodle offers to customize and extend its functionality. This book will show you how to build all sorts of Moodle plug-ins: admin plug-ins, Blocks, Activities, Grading components, Reports, Fliters that change the way your site works and looks. You will develop standard Moodle plug-ins such as Activities, Filters, and Blocks by creating functioning code that you can execute in your own Moodle installation. Writing modular plug-ins for Moodle will be a large focus of this book.This book will take you inside Moodle and provide you with the ability to develop code the “Moodle way”.This book will expose you to all of the core code functions in Moodle, in a progressive, understandable way. You will learn what libraries are available, what the API calls are, how it is structured and how it can be expanded beyond the plug-in system.You will begin by getting an understanding of the basic architecture that Moodle uses to operate in. Next you will build your first plug-in; a block. You will carry on building other Moodle plug-ins, gaining knowledge of the “Moodle way” of coding, before plunging deeper into the API and inner libraries. Lastly, you will learn how to integrate Moodle with other systems using a variety of methods.When you have completed, you will have a solid understanding of Moodle programming and knowledge of how to extend its functionality in whatever way you want.
Table of Contents (19 chapters)
Moodle 1.9 Extension Development
Credits
About the Authors
About the Reviewer
Preface

Moodle's API


Moodle's API is a mix of library functions and classes. Moodle was originally based on the version 4 series of PHP, and as such, most of its API is built around functions defined in PHP library files. However, some of the newer constructs of Moodle use object-oriented structures and as such provide extensible classes.

Most of Moodle's main libraries are kept in the /lib/ directory. All of these files generally adhere to the naming convention [function]lib.php. Some of the examples are textlib.php and weblib.php. These library files contain Moodle's API.

Almost all of the core libraries are included in the execution stream when you load config.php via its inclusion of /lib/setup.php. The setup.php file includes these via the following lines:

require_once($CFG->libdir .'/textlib.class.php'); // Functions to handle multibyte strings
require_once($CFG->libdir .'/weblib.php'); // Functions for producing HTML
require_once($CFG->libdir .'/dmllib.php'); // Functions to handle DB data (DML)
require_once($CFG->libdir .'/datalib.php'); // Legacy lib with a big-mix of functions.
require_once($CFG->libdir .'/accesslib.php'); // Access control functions
require_once($CFG->libdir .'/deprecatedlib.php'); // Deprecated functions included for backward compatibility
require_once($CFG->libdir .'/moodlelib.php'); // Other general-purpose functions
require_once($CFG->libdir .'/eventslib.php'); // Events functions
require_once($CFG->libdir .'/grouplib.php'); // Groups functions

These by no means define all of the functions available in Moodle, and in fact each of these libraries may include other libraries. However, the core of the functions that you will need are contained within these libraries. In fact, the ones that you will need to look at the most are:

  • moodlelib.php

  • weblib.php

  • dmllib.php

  • accesslib.php

  • grouplib.php

There are many other libraries that you will use, as you start to carry out specific functions. Most of these are stored in the /lib/ directory. However, others may be in specific functional areas such as /course/ and /blocks/.

Many of the specific libraries define classes that you can use. Libraries such as /lib/pagelib.php and /lib/formslib.php define classes that are designed to be extended in order to handle output to screen. pagelib.php defines specific page types, with all of the functions necessary to manage page output and create your own page types. Likewise, formslib.php defines Moodle's implementation of the PEAR QuickForm classes in order to handle web-based forms.

There is no single, all-encompassing document for all of Moodle's API. However, you can find out more about each specific area in the developer documentation at Moodle Docs. A good place to start is http://docs.moodle.org/en/Development:Developer_documentation#Core_components_that_affect_everything.

Another resource that can help is the Moodle code cross reference. This is an online resource that is generated from the code and inline comments in order to produce documentation. It is generated automatically by using PHPXref. The reference can be found at http://docs.moodle.org/en/Development:Code_Cross-Reference. Note that it may not be up-to-date and maintained. Still, it does provide an easy overview.