Moodle has evolved into one of the most widely-used Learning Management Systems in the world, with over 35,000 installed sites and 25 million users. Much of its popularity is due to its ability to be extended by developers, by using its open source architecture. Understanding how to develop on the Moodle platform provides an organization using Moodle the flexibility to expand its functions.
This book will teach you the inner workings of Moodle, and provide you with the ability to develop code the "Moodle way". You will learn to develop standard Moodle plugins, such as activities and blocks, by creating functioning code that you can execute in your own Moodle installation.
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 Moodle is structured, and how it can be expanded beyond the plugin system.
This is a practical, hands-on book that will allow you to build plugins as you learn. All of the technologies that you need are freely-available in the open source world.
You will begin by gaining an understanding of the basic architecture that Moodle uses to operate in. Next, you will build your first plugin, a block. You will carry on building other Moodle plugins, 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, by using a variety of methods.
By the time you have finished this book, you will have a solid understanding of Moodle programming, and will have the knowledge to extend its functionality in whatever way you want.
Chapter 1, Moodle Architecture, introduces some of the important concepts of Moodle architecture: how Moodle is structured, and how Moodle works.
Chapter 2, Creating and Modifying Blocks, covers how to create a basic block in Moodle, one of the easiest and most common customizations. Moodle blocks are plugins that display content in the right-hand or left-hand side column of a Moodle site. Several basic Moodle programming concepts that are used throughout the book are introduced.
Chapter 3, Creating and Modifying Filters, covers the basic concepts of creating a Moodle filter. The Moodle filter system is a method of processing the contents of the Moodle database (typically, user-entered content) prior to display, so that it can be modified in some beneficial way.
Chapter 4, Creating and Modifying Activity Modules, covers how to create a Moodle activity that can send results to the gradebook. Moodle activities are plugins that provide instructional activities for learners. One or more activities of each type can be added to courses, and each activity typically has a graded component that sends its results to the Moodle gradebook.
Chapter 5, Customizing the Look and Feel, elaborates on the common methods of customizing the look and feel of a Moodle site. This chapter will discuss how to tell the difference between a requirement that needs programming and one that can be completed by a theme designer.
Chapter 6, Developer's Guide to the Database, covers both the overall structure of the Moodle database and the coding methods used to access and store information there. Moodle supports a variety of SQL databases to store program information.
Chapter 7, Developing Pluggable Core Modules, covers useful programming concepts and considerations for the core Moodle system and modules. Some common ways by which popular modules can be modified are explored in this chapter.
Chapter 8, Creating Moodle Reports, covers a variety of methods of adding to Moodle's built-in reports. Moodle has an excellent logging system, but often users find they need to write a custom reporting module in order to get the data in the exact format that they desire.
Chapter 9, Integrating Moodle with Other Systems, covers four common types of integrations: user authentication, user enrollment, performance results, and Single Sign On. A common customization request for Moodle is to integrate with a third-party system.
Chapter 10, Writing Secure Code, covers various security concerns and best practices when developing code for Moodle.
Chapter 11, Sending Notifications to Users, discusses methods of messaging and notifying users through e-mail, RSS, and others.
Chapter 12, Constructing and Displaying Pages by Using the pagelib Library, covers the basic concepts of using pagelib. The pagelib library is used in the construction of display pages in Moodle.
Chapter 13, Building Forms with formslib, covers how to use the formslib library for customizations. The formslib library controls Moodle forms, user input, and input sanitation.
Chapter 14, Development for the Adventuresome: Web Services, covers two separate Moodle implementations for web services: one SOAP-based and one XML-RPC-based. The SOAP library allows remote manipulation and creation of courses, users, user enrollments, and user grades. The XML-RPC library provides a secure channel and full Moodle API exposure to the trusted site. This chapter will explore basic concepts of using both libraries.
This book is written for technologists who are interested in expanding Moodle's functions through programming, either for their own organizations or to contribute to the open source project.
This book is aimed at programmers already familiar with Moodle's basic technologies: PHP, MySQL, and HTML/CSS.
You will need an understanding of PHP in order to follow along with coding activities in the book.
In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.
Code words in text are shown as follows: "Finally, we display our table using the print_html
member function"
A block of code is set as follows:
<?php function learningisfunlink_filter($courseid, $text) { return $text; } ?>
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
function get_content() {
if ($this->content !== NULL) {
return $this->content;
}//if
$context = get_context_instance(CONTEXT_SYSTEM);
require_capability('moodle/site:doanything', $context);
$this->content = new stdClass;
$this->content->text = 'Hello World!';
return $this->content;
}//function get_content
New terms and important words are shown in bold. Words that you see on the screen, in menus, or dialog boxes for example, appear in the text like this: "Click on the Notifications link in the Site Administration block."
Note
Tips and tricks appear like this.
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.
To send us general feedback, simply send an e-mail to< [email protected]>
, and mention the book title in the subject of your message.
If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or send an e-mail to< [email protected]>
.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book on, see our author guide on www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
Note
Downloading the example code for the book
Visit https://www.packtpub.com//sites/default/files/downloads/4244_Code.zip to directly download the example code.
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us to improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the let us know link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.
Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately, so that we can pursue a remedy.
Please contact us at <[email protected]>
with a link to the suspected pirated material.
We appreciate your help in protecting our authors and our ability to bring you valuable content.
You can contact us at< [email protected]>
if you are having a problem with any aspect of the book, and we will do our best to address it.