Course formats: Difference between revisions
No edit summary |
|||
Line 23: | Line 23: | ||
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 | 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''', '''styles_THEMENAME.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 | 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 | ||
File styles.css will be included always, styles_THEMENAME.css only if theme_THEMENAME is used for the site (or for the course). | |||
'''course/format/FORMATNAME/settings.php''' (version 2.4 and above) | '''course/format/FORMATNAME/settings.php''' (version 2.4 and above) | ||
Line 33: | Line 35: | ||
'''course/format/FORMATNAME/renderer.php''' | '''course/format/FORMATNAME/renderer.php''' | ||
Optional but very recommended file containing renderer for this course format. This file will contain class format_FORMATNAME_renderer extends | Optional but very recommended file containing renderer for this course format. This file will contain ''class format_FORMATNAME_renderer extends plugin_renderer_base''. See [[Output renderers]] | ||
'''course/format/FORMATNAME/version.php''' | '''course/format/FORMATNAME/version.php''' | ||
Line 39: | Line 41: | ||
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 | 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''' | '''course/format/db/install.xml''', '''course/format/db/install.php''', '''course/format/db/upgrade.php''' | ||
Definitions of tables used by this plugin and upgrade script, see [[Upgrade API]] | Definitions of tables used by this plugin and upgrade script, see [[Upgrade API]] |
Revision as of 04:59, 31 January 2013
Course formats are plugins that determine the layout of course resources.
Course formats determine how the course main page looks like (/course/view.php) in both view and editing mode. They are also responsible for building navigation tree inside the course (displayed to user in navigation block and breadcrumb). They can organise the course content in sections. Course creator or teacher can specify course format for the course in course edit form.
Moodle 2.4 and above: Course formats also can add it's own options fields to the course edit form. They can add course dependend content to header/footer of any page inside the course, not only /course/view.php
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, styles_THEMENAME.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
File styles.css will be included always, styles_THEMENAME.css only if theme_THEMENAME is used for the site (or for the course).
course/format/FORMATNAME/settings.php (version 2.4 and above)
Optional plugin administrative settings
course/format/FORMATNAME/renderer.php
Optional but very recommended file containing renderer for this course format. This file will contain class format_FORMATNAME_renderer extends plugin_renderer_base. See Output renderers
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/install.php, 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. Course format names cannot exceed 21 characters. (In Moodle 2.3 and below the limit is 10 characters)
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. Moodle 2.3 and below: Rename callback functions in lib.php. The names of the functions is formed as callback_FORMATNAME_CALLBACKNAME()
Moodle 2.4 and above: Rename class name in lib.php to format_FORMATNAME.
6. Search and replace other occurences of the old format name, for example in renderer, capabilities names, etc.
7. The new format is ready for modification.