upload_test

22
Creating Moodle modules sam marshall

Upload: cheer-wang

Post on 26-May-2015

586 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: upload_test

Creating Moodle modulessam marshall

Page 2: upload_test

Contents

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

Page 3: upload_test

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

Page 4: upload_test

Introduction to modules

• ‘Activities’• Appear on front page of course• Add using dropdown• Update settings• Link goes to module’s own PHP files• What’s in a module?

Page 5: upload_test
Page 6: upload_test
Page 7: upload_test
Page 8: upload_test

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

Page 9: upload_test

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

Page 10: upload_test

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

Page 11: upload_test
Page 12: upload_test

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)

Page 13: upload_test

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)

Page 14: upload_test

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

Page 15: upload_test

Forms

• In case you’ve forgotten…

Page 16: upload_test
Page 17: upload_test

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)

Page 18: upload_test

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

Page 19: upload_test
Page 20: upload_test

Conclusion

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

• Initial design is important• Skills needed

– Database – PHP– And…

Page 21: upload_test

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!

Page 22: upload_test

To end on a positive note