Creating Moodle Modules

download Creating Moodle Modules

of 22

Transcript of Creating Moodle Modules

  • 7/28/2019 Creating Moodle Modules

    1/22

    Creating Moodle modules

    sam marshall

  • 7/28/2019 Creating Moodle Modules

    2/22

    Contents

    Introduction to Moodle system Introduction to modules

    Versions and database tables

    Capabilities

    Language files and help files

    Forms

    view.php

  • 7/28/2019 Creating Moodle Modules

    3/22

    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

  • 7/28/2019 Creating Moodle Modules

    4/22

    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?

  • 7/28/2019 Creating Moodle Modules

    5/22

  • 7/28/2019 Creating Moodle Modules

    6/22

  • 7/28/2019 Creating Moodle Modules

    7/22

  • 7/28/2019 Creating Moodle Modules

    8/22

    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

  • 7/28/2019 Creating Moodle Modules

    9/22

    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

  • 7/28/2019 Creating Moodle Modules

    10/22

    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

  • 7/28/2019 Creating Moodle Modules

    11/22

  • 7/28/2019 Creating Moodle Modules

    12/22

    Capabilities

    Define capabilities for your module Array in access.php

    Specifies available capabilities and who has them bydefault

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

    Check capabilities

    Get context object for current module instance

    has_capability(mod/name:edit,$context)

  • 7/28/2019 Creating Moodle Modules

    13/22

    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)

  • 7/28/2019 Creating Moodle Modules

    14/22

    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

  • 7/28/2019 Creating Moodle Modules

    15/22

    Forms

    In case youve forgotten

  • 7/28/2019 Creating Moodle Modules

    16/22

  • 7/28/2019 Creating Moodle Modules

    17/22

    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)

  • 7/28/2019 Creating Moodle Modules

    18/22

    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

  • 7/28/2019 Creating Moodle Modules

    19/22

  • 7/28/2019 Creating Moodle Modules

    20/22

    Conclusion

    Standard platform features need to be used Maintaining

    Administration (capabilities)

    Community sharing Initial design is important

    Skills needed

    Database PHP

    And

  • 7/28/2019 Creating Moodle Modules

    21/22

    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!

  • 7/28/2019 Creating Moodle Modules

    22/22

    To end on a positive note