Sei sulla pagina 1di 6

Moodle Programming: Unit 5 Part A - Moodle's Directory Structure

http://dev.moodle.org/mod/resource/view.php?id=34

Introduction to Moodle Programming

Jump to...

Moodle Dev Courses Moodle Programming Resources Unit 5 Part A - Moodle's Directory Structure

Unit 5 Part A: Moodle Directory Structure


Overview | Unit 5 "To Do" List External resources open in new browser windows. This Unit refers to the directory structure in Moodle version 1.8.

The /admin directory


Files under this directory handle all the features under the "Site Administration" block. As of November 2007, there are 635 files spread out in 137 directories under this /admin directory (in Moodle 1.8.3+ version). For purposes of this course, we will just focus on the most important file: /admin/cron.php Some of Moodle's modules require continual checks to perform tasks. For example, Moodle needs to check the discussion forums so it can mail out copies of posts to people who have subscribed. The script that performs these continual checks is located in the admin directory and is called cron.php. Usually we set up a mechanism where this script runs regularly by itself, although you could also manually run it directly from a Web browser, or from a command line. Cron.php provides a "heartbeat" to perform functions at intervals defined by each module. This kind of regular mechanism is typically implemented using a cron daemon/service via cron jobs. The cron.php script: 1. Searches the mdl_modules table (assuming the default table prefix, of course) in the Moodle database for modules scheduled to have their cron functions run 2. In each such module directory locates any function called module-name_cron in the lib.php file and runs it 3. Searches the mdl_block table for blocks scheduled for their cron methods (object functions) to be run 4. for each such block, runs the cron method for a new object associated with that block These files (the lib.php files and the files where the block classes are defined) can contain cleanup

1 of 6

9/23/2009 6:12 PM

Moodle Programming: Unit 5 Part A - Moodle's Directory Structure

http://dev.moodle.org/mod/resource/view.php?id=34

functions, email functions or anything that needs to be run on a regular basis. For example, cron will trigger the system to create the backups of courses at the time specified in the administration settings. It also triggers any messaging module or forum email notifications, but not all functions are called each time the cron runs. Some functions, such as unenrolling students who have not logged in or deleting old copies of log files, are only run occasionally. The cron.php file has a section which will randomly call these core tasks approximately 1 in 5 times the cron runs. Note that the machine performing the cron does not need to be the same machine that is running Moodle. For example, if you have a limited web hosting service that does not have a cron service, then you might choose to run cron on another server or on your home computer. All that matters is that the cron.php file is called regularly. The load of this script is not very high, so 5 minutes is usually reasonable, but you can reduce the time period to 15 minutes or even 30 minutes. It's best not to make the time period too long, as delaying mail-outs can slow down activity within the course. Remember that mail-outs also wait for the editing time to expire before being queued for sending. As long as cron is run regularly and fairly frequently, the load is not very high. However, if it hasn't been run in a long time or the proceessing frequency is too far apart the loads can be considerable depending on site activity and any background batch processes such as enrolling or un-enrolling that may need to occur. top

The /blocks directory


By now you probably already know about 'blocks' in moodle. Moodle blocks typically appear in the left and right margins of a course's main page. They typically contain a function and differ from the "sections" that appear down the center column of a course's main page that contain the content and Activities or Resources added by the instructor.

2 of 6

9/23/2009 6:12 PM

Moodle Programming: Unit 5 Part A - Moodle's Directory Structure

http://dev.moodle.org/mod/resource/view.php?id=34

When a Moodle course is created it automatically generates several 'blocks' that allow you to control how you navigate or find information in Moodle (examples of these include the "Site Administration" block for administrator, the "Search Forums" block or the "Calendar" block for all users, etc.). In addition to the blocks that automatically appear, you will notice that you have several options for further blocks of tools (from the Blocks drop down menu when editing is turned on) to add to your course. Examples include the "Remote RSS Feeds" block, the "Blog" block, etc.). Similarly, you can delete any of the existing blocks if you feel they are unnecessary to your course and you can also move the blocks so that they appear on a single side rather than on both sides of the middle content (this can only be achieved using the move or delete buttons with editing turned on). In a typical Moodle 1.8 installation, you will see a set of standard blocks available for each course creator.

If you look into your local Moodle installation and navigate to /blocks directory, you will find a matching directory for each block.

3 of 6

9/23/2009 6:12 PM

Moodle Programming: Unit 5 Part A - Moodle's Directory Structure

http://dev.moodle.org/mod/resource/view.php?id=34

If you need to debug the "Blog Menu" block, for example, you go to the "blog_menu' directory. If you need to debug the "Search Forums" block, begin with the "search_forums" directory, etc. Later in this course we will introduce more about how to write a Moodle block from a programmer's perspective. Additional details about "Blocks administration" (usually from a system administrator's perspective).

The /lang directory


This directory contains all the different language files, including their related help button content. The one to pay most attention to is the "en_utf8" directory. Under this directory you will be able to understand how Moodle defines all the strings in different modules or blocks. For example, all the strings that are related to the admin module defined in admin.php.

Important Tip:
Localized strings should be in a separate language

The /lib directory

4 of 6

9/23/2009 6:12 PM

Moodle Programming: Unit 5 Part A - Moodle's Directory Structure

http://dev.moodle.org/mod/resource/view.php?id=34

directory such as For a Moodle developer, this is probably one of the most important directories that you will use. The /lib directory contains many library files (275 directories and 2179 files, as of Moodle 1.8.3+) ranging from ajax and adodb libraries, to xmldb and yui (Yahoo User Interface) libraries. The most important three library files are probably moodlelib.php, weblib.php, and accesslib.php. These three library files will be discussed in more depth in Part B of this Unit. However, this is a brief summary of these three library files: moodlelib.php is the Moodle "main" library. This file contains of miscellaneous general-purpose Moodle functions (such as
set_user_preferences(), get_user_timezone(),

en_custom. The default is if a string is not found in one language it falls back to en_utf8. This way, your changes override the default, but you do not have to include every string or manage changing core language strings. You just have to manage your localized settings.

and so on).

weblib.php contains functions that help Moodle produce web output. For example, it has functions such as format_text_email(),
print_header(), print_group_menu(),

etc.

datalib.php contains functions that alllow moodle to access the database, it also has functions that deal with the role capabilities, such as load_defaultuser_role(),
get_guest_role(),

etc.

The /mod directory


This directory contains most of the Moodle key modules. Currently in moodle 1.8 there are 18 key modules under /mod directory.

top

5 of 6

9/23/2009 6:12 PM

Moodle Programming: Unit 5 Part A - Moodle's Directory Structure

http://dev.moodle.org/mod/resource/view.php?id=34

"To Do" List


1. Experiment with the cron script by running it directly from your browser (http://localhost/moodle/admin/cron.php). If cron is called from the command line by any user logged in to your Moodle it will create a temporary admin environment in order to run and then log the user out. You can disable command line running of cron by disabling the appropriate section in the cron.php file. See more details about how to set up automated execution of this script (cron.php) on (1) Windows, (2) Web hosting services, or (3) Using the crontab program on Unix. Usually this is a system administrator's job to set up so it is beyond the scope of this introductory Moodle programmer's course. 2. Run admin/auth.php from your Web browser (http://localhost/moodle18/moodle/admin/auth.php) to see what it does. You could also access this file through the "Site Administration" menu (under Users -> Authentication). top Overview | Unit 5 "To Do" List

Last modified: Wednesday, February 20, 2008, 09:46 AM

You are logged in as Anguillo Gulianni from Moodle.org (Logout) Moodle Programming

6 of 6

9/23/2009 6:12 PM

Potrebbero piacerti anche