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

Setup


Let's start with the easy pieces.

We need to add a new setting that defines whether the assignment will send entry notifications and how it will send them. We will use the var2 field of the assignment table to store this setting (recall fromChapter 7, Developing Pluggable Core Modules that var2 is a field set aside, along with var1 and var3 to var5, for custom types). As var2 is an integer type, we will use numeric code to represent the various methods: 0 for no notification, 1 for e-mail, 2 for messaging, and 3 for RSS.

Let's open up our assignment.class.php file.

First, let's use good coding practices and set up some constants for the settings. Near the top of the file, enter:

/*
* Define some constants for entry notification settings.
*/
define ('ASSIGNMENT_JOURNAL_EN_NONE', 0);
define ('ASSIGNMENT_JOURNAL_EN_EMAIL', 1);
define ('ASSIGNMENT_JOURNAL_EN_MESSAGING', 2);
define ('ASSIGNMENT_JOURNAL_EN_RSS', 3);

This will allow us to use the named constants in place of the numeric values...