Sie sind auf Seite 1von 22

Creating Moodle modules sam marshall

Contents
Introduction to Moodle system Introduction to modules Versions and database tables Capabilities Language files and help files Forms view.php

Introduction to Moodle system


PHP Database-driven
Library of simplifying database access functions Every table has auto-increment id field

Little persistent state


Session data exists, not heavily used

Mainly functions, not object-oriented Independent PHP scripts

Introduction to modules
Activities Appear on front page of course Add using dropdown Update settings Link goes to modules own PHP files Whats in a module?

mod/name
db
install.xml access.php update.php

version.php lang
en_utf8
name.php help
mods.html

lib.php mod_form.php styles.php view.php

Database structure
prefix_course_modules
An instance of a module in a particular course

prefix_name
Your table. Must have id, name, course
And index on course

$cm->instance == $name->id

Variables
$cm, $name, $course

Versions and database tables


install.xml
Used when installing for first time Create with horrible editor (not by hand!)

update.php
Used after code update on existing database Code in PHP

version.php
Module version e.g. 2007031600

Capabilities
Define capabilities for your module
Array in access.php
Specifies available capabilities and who has them by default

mod/name:edit, mod/name:view,

Check capabilities
Get context object for current module instance has_capability(mod/name:edit,$context)

Language files
All strings taken out into language files
Except system errors
But not except user errors!

Why? Now or future contribution to community

Language file goes in lang/en_utf8/name.php


$string[frogscanjump]=Frogs can jump; $string[howhigh]=How high? $a metres!;

A couple standard strings (module name)

Help files
In lang/en_utf8/help Basic XHTML content One standard file mods.html Add other files Link to them with standard help button
For example, in forms

Forms
In case youve forgotten

Forms
mod_form.php PHP QuickForm + Moodle extensions
$mform->addElement('text', 'name', get_string('name'));

Various types provided Easy to add help buttons Does formatting for you
And accessibility (hopefully)

view.php
Your own PHP code Can do anything
Should use Moodle standard functions where appropriate Header, footer, tabs, etc.

Other PHP scripts too (as needed)


view.php is just where the link goes

Conclusion
Standard platform features need to be used
Maintaining Administration (capabilities) Community sharing

Initial design is important Skills needed


Database PHP And

Bonus scare slide


Security!!!!1!!1!!eleventy-one
Public Web application Easy to make mistakes
Check permission on action as well as when showing link Avoid SQL injection

Be careful!

To end on a positive note

Das könnte Ihnen auch gefallen