Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Course formats: Difference between revisions

From MoodleDocs
Line 7: Line 7:
'''course/format/FORMATNAME/config.php''' (deprecated since 2.4)
'''course/format/FORMATNAME/config.php''' (deprecated since 2.4)


Contains $format['defaultblocks'] which defines the default [[:en:blocks|blocks]] loaded with the format.
Contains $format['defaultblocks'] which defines the default blocks loaded with the format.


'''course/format/FORMATNAME/format.php'''
'''course/format/FORMATNAME/format.php'''


This is is the layout itself. It is loaded by course/view.php.
This is is the layout itself. It is included in course/view.php.


'''course/format/FORMATNAME/lib.php'''
'''course/format/FORMATNAME/lib.php'''


The main library of the format.
The main library of the format. In Moodle versions up to 2.3 it should contain implementations of course format callbacks. In versions 2.4 and above it should contain a class format_FORMATNAME extending format_base. Also it may contain callbacks for other core and contributed APIs if necessary


'''course/format/FORMATNAME/styles.css'''
'''course/format/FORMATNAME/styles.css'''


Optional stylesheet.
Optional stylesheet. Note that this file is included on all pages on the site, even in the courses that use other formats. In 2.4+ the class format-FORMATNAME is automatically added to body for all pages inside the course, it is recommended to prefix all directives in your styles.css with body.format-FORMATNAME


'''course/format/FORMATNAME/settings.php''' (version 2.4 and above)
'''course/format/FORMATNAME/settings.php''' (version 2.4 and above)
Line 27: Line 27:
'''course/format/FORMATNAME/version.php'''
'''course/format/FORMATNAME/version.php'''


Optional version definitions.
Version definitions, see [[version.php]]. It is highly recommended always to have it and it is required if you have any files in db folder
 
'''course/format/db/install.xml''', '''course/format/db/upgrade.php'''
 
Definitions of tables used by this plugin and upgrade script, see [[Upgrade API]]
 
'''course/format/backup'''
 
Implementation of backup and restore for additional tables defined in your plugin. See [[Backup API]]. This is only needed if you define additional tables in your db folder. Data from table course_format_options is backed up for your plugin automatically
 
'''course/format/db/access.php'''
 
Capabilities introduced by this plugin, see [[Access API]]. Please note that if you define new capabilities inside course format they should not affect accessibility of course modules because other components (for example reports and/or gradebook) will not know about them


=Creating a New Format=
=Creating a New Format=

Revision as of 08:57, 30 January 2013

Course formats are plugins that determine the layout of course resources.

Components

course/format/FORMATNAME/lang/en/format_FORMATNAME.php

Contains the English language strings used in the format. You can also define strings for other languages.

course/format/FORMATNAME/config.php (deprecated since 2.4)

Contains $format['defaultblocks'] which defines the default blocks loaded with the format.

course/format/FORMATNAME/format.php

This is is the layout itself. It is included in course/view.php.

course/format/FORMATNAME/lib.php

The main library of the format. In Moodle versions up to 2.3 it should contain implementations of course format callbacks. In versions 2.4 and above it should contain a class format_FORMATNAME extending format_base. Also it may contain callbacks for other core and contributed APIs if necessary

course/format/FORMATNAME/styles.css

Optional stylesheet. Note that this file is included on all pages on the site, even in the courses that use other formats. In 2.4+ the class format-FORMATNAME is automatically added to body for all pages inside the course, it is recommended to prefix all directives in your styles.css with body.format-FORMATNAME

course/format/FORMATNAME/settings.php (version 2.4 and above)

Optional plugin administrative settings

course/format/FORMATNAME/version.php

Version definitions, see version.php. It is highly recommended always to have it and it is required if you have any files in db folder

course/format/db/install.xml, course/format/db/upgrade.php

Definitions of tables used by this plugin and upgrade script, see Upgrade API

course/format/backup

Implementation of backup and restore for additional tables defined in your plugin. See Backup API. This is only needed if you define additional tables in your db folder. Data from table course_format_options is backed up for your plugin automatically

course/format/db/access.php

Capabilities introduced by this plugin, see Access API. Please note that if you define new capabilities inside course format they should not affect accessibility of course modules because other components (for example reports and/or gradebook) will not know about them

Creating a New Format

The easiest way to create a new course format is to copy an existing one.

1. Copy the folder containing the format files.

2. Rename the folder to the new name. NOTE: course format names cannot exceed ten characters. This is a limit set in the database.

3. Rename language files in course/format/FORMATNAME/lang/

4. Change $string['pluginname'] in course/format/FORMATNAME/lang/en/format_FORMATNAME.php to the new name.

5. Rename callback functions in lib.php. The names of the functions is formed as callback_FORMATNAME_CALLBACKNAME()

6. The new format is ready for modification.