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

Chapter 1. Moodle Architecture

Moodle is an open source Learning Management System (LMS). It can be used to deliver online learning in a variety of settings. These settings include virtual schools, K12, higher education, corporate universities, charter schools, and commercial training, to name but a few. Moodle is designed to be used primarily as an asynchronous learning tool, where learners study at different times. However, it also includes synchronous tools. Moodle is used both as the primary delivery vehicle for courses as well as a supplemental tool for face-to-face learning. To put it simply, Moodle is a teacher's toolkit to help improve learning. Moodle is designed in a community with teachers interacting directly with programmers. Moodle's intuitive and simple interface is the result of this collaboration.

Moodle originally stood for Modular Object-Oriented Dynamic Learning Environment. From a programmer's perspective, the "M" in Moodle is a very important concept. Modularity is designed throughout Moodle. This lets a developer make significant modifications to Moodle without having to modify its code. This is a very important capability in terms of reducing the amount of time taken to make modifications when new versions of Moodle are released. Writing modular plugins for Moodle will be a large focus of this book.

You can learn more about general Moodle functionality and history on the Moodle Documentation site at http://docs.moodle.org/en/About_Moodle.

This chapter introduces some of the important concepts of Moodle architecture; how Moodle is structured and how Moodle works. This chapter introduces the following concepts:

  • Components of the system (operating system, web server, PHP interpreter, database, and browser)

  • Directory and system structure (Moodle code, database, and file storage)

  • Installation (how to install, what happens during installation, and how to upgrade)

  • Program execution (the major calling structure, included libraries, execution paths, and separation of function/display/data)

  • Configuration (from the interface, from the config file, and from the database)

  • Application Programming Interface (a brief description of what the major libraries do)

  • Other common libraries (PEAR, ADOdb, YUI, and XMLDB)

  • Access control for users, courses, and other security objects

As you can see from the list, we will be covering a lot of ground in this chapter. Let's get started with a discussion of the technology stack that drives Moodle.

Understanding the stack

Moodle is an example of a "LAMP" application. LAMP originally stood for Linux, Apache, MySQL, and Perl. Over time, the various components of the acronym have shifted. For example, PHP has become the predominate language for "LAMP" applications. In truth, any of the components can be exchanged for another. However, the title has stuck to refer to applications written in web scripting languages, using an SQL database to store information. With the increasing popularity of running open source web applications on both Windows and Mac OS X, two new terms have been coined, respectively: WAMP and MAMP. See the following figure, which illustrates components of the system in Moodle:

Moodle is written in PHP, and the current version as of this writing (Version 1.9) requires PHP Version 4.3.0 or higher. Version 2.0 of Moodle, which is currently in development, will require PHP Version 5.2.8 or higher.

Database

Moodle's database layer is written using the PHP ADOdb library, which was created to provide a standardized method of accessing various database systems, using a consistent programming interface. PHP native database libraries are database specific and as a result are difficult to use to write a program that can support multiple database servers. Thanks to its use of ADOdb, Moodle provides support for a variety of databases including: MySQL, PostgreSQL, Microsoft SQL, and Oracle. Moodle supports a much longer list of databases for the purpose of external system integrations, by using its plugin architecture. While Moodle does enjoy broad database support, in practice, most systems are deployed using MySQL. As a practical result of this, more eyes are looking at MySQL installations; it has the fewest bugs, with the broadest set of third-party additions. PostgreSQL is the second most popular backend and has a strong following amongst performance enthusiasts and large deployments (tens of thousands or more users). Microsoft SQL and Oracle installations are primarily used by organizations with a pre-existing investment in one of these architectures. Because of their smaller user base, they are not as well tested. It is also more difficult to find good support for using these database types with Moodle. Many third-party add-on modules do not work under these systems without patching.

Database version requirements for Moodle 1.9:

  • MySQL 4.1.16

  • PostgreSQL 8.0

  • Microsoft SQL 9.0

  • Oracle 9.0

Proposed database requirements for Moodle 2.0:

  • MySQL 4.1.16 or

  • PostgreSQL 8.0 or

  • Microsoft SQL 9.0 or

  • Oracle 9.0

  • SQLite 3 (experimental)

The latest version of these requirements can be viewed at the following URL: http://docs.moodle.org/en/Environment#Moodle_version_1.9.

Note that the specifications for the Moodle 2.0 database layer can be found at the following location: http://docs.moodle.org/en/Development:DB_layer_2.0.

Operating system

Moodle can run on any operating system that supports the required version of PHP and the database. Moodle is generally installed on one of the three major operating systems: Windows, Mac OS X, or Linux (or Unix/Unix-like operating systems). As compared to Linux, both Mac OS X and Windows operating systems suffer from less efficient performance for large-scale deployments. For Windows, this is due to a less-optimized PHP stack, and for Mac OS X it is due to poor process forking performance, which both Apache and MySQL rely on for high concurrency. Windows Server 2008 is reported in press releases by both Microsoft and Zend, the creator of PHP, as having improved PHP performance. In a development environment, you can use any of these operating systems as an excellent platform. In a production environment, each operating system will have different performance characteristics.

Web server

Moodle will typically work with any web server that supports running the appropriate versions of PHP. In practice, the most used web server is Apache, which is available for most operating systems. Internet Information Services (IIS) is another popular web server for hosting Moodle. There are also a growing number of advocates for Lighthttpd as a web server, and this is reported in the Moodle community forums (http://moodle.org/forums/) as working well with Moodle. Lighthttpd has a growing number of advocates due to its low memory design. It is extremely popular for its use with virtual environments (VMware, Xen, and Amazon Elastic Compute Cloud), where memory footprint is more of a concern.

Moodle as a web application has support and development constraints that are different from the norm. This is due to the way in which Moodle is used. A user interacting with Moodle will have a higher than normal amount of clicks, and Moodle generates many SQL queries as it builds a page. Moodle is very efficient at what it does. However, what it does is fairly complex. This means, as developers, we need to be aware of the type of architectures that our modifications will likely be used within. It also means that we need to be aware of the performance implications of our coding. The following figure illustrates several common configurations used for Moodle in a production environment. Moodle is deployed in a broad range of settings—anywhere from a single teacher running it on his or her desktop all the way up to multi-machine clusters of high performance servers:

Moodle, as is common with the standard PHP application model, scales at particular points. The first scaling point is the database, which can easily be moved to a separate physical server. After that, we can bring in additional frontend web servers by using a load balancer. When using multiple web servers we will also need shared storage for our Moodle data. Session data can be stored in either Moodle data or in the database. The database server is the point where Moodle's scalability is most limited. To scale the database it is necessary to bring in a faster database server, replacing the older server. Currently, there is no standard method for scaling a single Moodle installation across multiple master database servers, as we do with the web application servers. It is also common practice to use Moodle with a PHP accelerator such as eAccelerator or APC. It's important to test your code in these environments to make sure that it functions correctly.