Note: This documentation is for Moodle 2.7. For up-to-date documentation see Modules.

Development:Modules: Difference between revisions

From MoodleDocs
m (cat edit)
No edit summary
 
(25 intermediate revisions by 14 users not shown)
Line 1: Line 1:
'''Activity modules''' reside in the 'mod' directory. Each module is in a separate subdirectory and consists of the following mandatory elements (plus extra scripts unique to each module):
=== Activity modules ===


* ''mod.html'' - a form to set up or update an instance of this module
Activity modules reside in the '''/mod''' directory. Each module is in a separate subdirectory and consists of the following mandatory elements (plus extra scripts unique to each module):
* ''version.php'' - defines some meta-info and provides upgrading code
 
* ''mod_form.php'' - a form to set up or update an instance of this module
* ''version.php'' - defines some meta-info
* ''icon.gif'' - a 16x16 icon for the module
* ''icon.gif'' - a 16x16 icon for the module
* ''db/'' - SQL dumps of all the required db tables and data (for each database type)
* ''db/install.xml'' - defines the structure of db tables for all database types. Is used during module installation
* ''db/upgrade.php'' - defines changes in the structure of db tables. Is used during module upgrade
* ''db/access.php'' - defines module capabilities
* ''index.php'' - a page to list all instances in a course
* ''index.php'' - a page to list all instances in a course
* ''view.php'' - a page to view a particular instance
* ''view.php'' - a page to view a particular instance
* ''lib.php'' - any/all functions defined by the module should be in here. If the modulename is called widget, then the required functions include:
* ''lib.php'' - any/all functions defined by the module should be in here. If the module name is called '''widget''', then the required functions include:
:* widget_install() - will be called during the installation of the module
:* widget_add_instance() - code to add a new instance of widget
:* widget_add_instance() - code to add a new instance of widget
:* widget_update_instance() - code to update an existing instance
:* widget_update_instance() - code to update an existing instance
Line 13: Line 18:
:* widget_user_outline() - given an instance, return a summary of a user's contribution
:* widget_user_outline() - given an instance, return a summary of a user's contribution
:* widget_user_complete() - given an instance, print details of a user's contribution
:* widget_user_complete() - given an instance, print details of a user's contribution
:* widget_get_view_actions() / widget_get_post_actions() - Used by the participation report (course/report/participation/index.php) to classify actions in the logs table.
:* Other functions available but not required are:
:* Other functions available but not required are:
:** widget_delete_course() - code to clean up anything that would be leftover after all instances are deleted
:** widget_delete_course() - code to clean up anything that would be leftover after all instances are deleted
:** widget_process_options() - code to pre-process the form data from module settings
:** widget_process_options() - code to pre-process the form data from module settings
:** [[Development:Implementing Reset course functionality in a module|widget_reset_course_form() and widget_delete_userdata()]] - used to implement [[Reset course]] feature.
:* To avoid possible conflict, any module functions should be named starting with widget_ and any constants you define should start with WIDGET_
:* To avoid possible conflict, any module functions should be named starting with widget_ and any constants you define should start with WIDGET_
* ''config.html'' - (optional) a form to set up or update global settings of this module
* ''backuplib.php'' and ''restorelib.php'' (optional)
* Lastly, each module will have some language files that contain strings for that module.
* ''settings.php'' or ''settingstree.php'' - (optional) a definition of an admin settings page for this module. mod/assignment/settings.php is a good simple example. mod/quiz/settingstree.php is a more complex example.
* ''defaults.php'' - lets you easily define default values for your configuration variables. It is included by upgrade_activity_modules in lib/adminlib.php. It should define an array $defaults. These values are then loaded into the config table. Alternatively, if you set $defaults['_use_config_plugins'] to true, the values are instead loaded into the config_plugins table, which is better practice. See mod/quiz/defaults.php for an example. (This apparently only works with moodle 2.x branch.)
* ''lang/en_utf8/widget.php'' - (optional) Lastly, each module will have some language files that contain strings for that module.
 
=== IMPORTANT: ===
* When creating a new module, the new name of the module must not contain numbers or other special characters!
 
* You need a ''data base table'' with the same name as your module. This table must have at least three fields:
*# id
*# course
*# name


IMPORTANT: When creating a new module, the new name of the module must not contain numbers or other special characters!
* You should also make sure that your activity module provides appropriate support for groups and meta-courses.


You should also make sure that your activity module provides appropriate support for groups and metacourses.
== See also ==


==See also==
* [[Development:Blocks]]
* [[Development:Backup]]
* Tracker issue [http://tracker.moodle.org/browse/CONTRIB-52 CONTRIB-52 Improvements to make NEWMODULE really useful] - including download link for new module template supporting roles, formslib etc. (unfinished)
* http://download.moodle.org/plugins16/mod/NEWMODULE.zip - new module template for versions of Moodle prior to 1.7. Please follow the README instructions inside the zip.
* [[Development:NEWMODULE_Documentation]]


* http://download.moodle.org/download.php/modules/NEWMODULE.zip - new module template for starting module development. Please follow the README instructions inside the zip.
Using Moodle forum discussions:
* Using Moodle [http://moodle.org/course/view.php?id=5 Activity modules] forum
*[http://moodle.org/mod/forum/discuss.php?d=66165 A new resource type: where do I put the language strings?]
* Using Moodle [http://moodle.org/mod/forum/discuss.php?d=66165 A new resource type: where do I put the language strings?] forum discussion
*[http://moodle.org/mod/forum/discuss.php?d=65986 New Module Template Code for Moodle 1.7]
* Using Moodle [http://moodle.org/mod/forum/discuss.php?d=65986 New Module Template Code for Moodle 1.7] forum discussion
*[http://moodle.org/mod/forum/discuss.php?d=90154 LEGACY roles and capabilities]


[[Category:Developer|Modules]]
[[Category:Developer|Modules]]
[[Category:Modules]]
[[Category:Modules]]
[[Category:Tutorial]]


[[es:Módulos de actividades (desarrollador)]]
[[es:Módulos de actividades (desarrollador)]]
[[fr:Modules (développeur)]]
[[ja:モジュール (開発者)]]
[[ja:モジュール (開発者)]]
[[zh:开发:模块_(开发者)]]
[[de:Entwickler:Module]]

Latest revision as of 15:14, 18 June 2010

Activity modules

Activity modules reside in the /mod directory. Each module is in a separate subdirectory and consists of the following mandatory elements (plus extra scripts unique to each module):

  • mod_form.php - a form to set up or update an instance of this module
  • version.php - defines some meta-info
  • icon.gif - a 16x16 icon for the module
  • db/install.xml - defines the structure of db tables for all database types. Is used during module installation
  • db/upgrade.php - defines changes in the structure of db tables. Is used during module upgrade
  • db/access.php - defines module capabilities
  • index.php - a page to list all instances in a course
  • view.php - a page to view a particular instance
  • lib.php - any/all functions defined by the module should be in here. If the module name is called widget, then the required functions include:
  • widget_install() - will be called during the installation of the module
  • widget_add_instance() - code to add a new instance of widget
  • widget_update_instance() - code to update an existing instance
  • widget_delete_instance() - code to delete an instance
  • widget_user_outline() - given an instance, return a summary of a user's contribution
  • widget_user_complete() - given an instance, print details of a user's contribution
  • widget_get_view_actions() / widget_get_post_actions() - Used by the participation report (course/report/participation/index.php) to classify actions in the logs table.
  • Other functions available but not required are:
  • To avoid possible conflict, any module functions should be named starting with widget_ and any constants you define should start with WIDGET_
  • backuplib.php and restorelib.php (optional)
  • settings.php or settingstree.php - (optional) a definition of an admin settings page for this module. mod/assignment/settings.php is a good simple example. mod/quiz/settingstree.php is a more complex example.
  • defaults.php - lets you easily define default values for your configuration variables. It is included by upgrade_activity_modules in lib/adminlib.php. It should define an array $defaults. These values are then loaded into the config table. Alternatively, if you set $defaults['_use_config_plugins'] to true, the values are instead loaded into the config_plugins table, which is better practice. See mod/quiz/defaults.php for an example. (This apparently only works with moodle 2.x branch.)
  • lang/en_utf8/widget.php - (optional) Lastly, each module will have some language files that contain strings for that module.

IMPORTANT:

  • When creating a new module, the new name of the module must not contain numbers or other special characters!
  • You need a data base table with the same name as your module. This table must have at least three fields:
    1. id
    2. course
    3. name
  • You should also make sure that your activity module provides appropriate support for groups and meta-courses.

See also

Using Moodle forum discussions: