Course formats 2
From MoodleDocs
Course format refactoring
We will refactor the course formats to support a proper object-oriented design and full support for renderers.
Database changes
- add field course.formatoptions storing format-specific options as serialised array
- ? deprecate existing fields in table course: numsections, startdate, hiddensections, coursedisplay.
- add field course_sections.formatoptions storing format-specific options as serialised array
- add field course_sections.parent (default 0) to allow sections hierarchy
- add field course_sections.visibleold to store original visibility when one of the parent sections is hidden
OO: Class format_base
Course formats must be classes inheriting base *class format_base* instead of the current collection of callbacks. (Although some callbacks will be converted to methods)
- Method course_get_format($course) will return an instance of this class for the particular course. May be called with specific format but with empty course id (i.e. when course is being created)
Class format_base
method | description |
---|---|
is_setup_completed() | returns boolean. If setup is not yet completed, course/view.php will redirect to course/edit.php |
default_blocks() | replaces config.php with $format[‘defaultblocks’] |
? form_fields() | defines fields to be used in edit course form |
? form_validation() | performs additional validation for edit course form |
page_set_course() | is called from moodle_page::set_course() allowing course formats to run custom code at that point |
page_set_cm() | is called from moodle_page::set_cm() |
output_course_header() | displays the course-specific header. It will be included in all core themes, custom themes need to add support for it |
output_course_footer() | displays the course-specific footer |
? output_course_content_header() | displays the course-specific header to be displayed in main content section (i.e. prev-next module navigation) |
? output_course_content_footer() | displays the course-specific footer to be displayed in main content section (i.e. prev-next module navigation) |
editsection_form() | returns an instance of editsection_form (the format can overwrite this form) |
is_section_current() | replaces format_section_renderer_base::is_section_current() |
get_section_name() | replaces get_section_name() |
uses_sections() | replaces course_format_uses_sections() |
supports_ajax() | replaces course_format_ajax_support() |
- Define class format_legacy extends format_base that will call the existing callbacks and get blocks from config.php if format class is not defined (2.0-2.3 backward compartibility). Function course_get_format() will return instance of this class if the course format does not define it's own class
- Add support for inherited sections: avoid loops, store visibleold; Process moving, deleting sections; Make sure the hierarchy appears in navigation menu; Make sure changing of availability rules for both parent and child sections works correctly together
- Make sure course format can influence navigation menu and breadcrumb. This probably will be done already by set_course/set_cm callbacks
- Add events_trigger('course_format_changed') in function update_course() if course format was changed. Course format may want to watch it and insert/delete format-specific data in DB
- ? Add events_triggers in functions that create/delete/hide/move course sections
- When course is created/edited, the options specific for the format are displayed in separate form section and it dynamically changes when format is changed (with support of non-js mode). Each course format defines which display options it needs. For the standard weeks format they are [numsections, startdate, hiddensections, coursedisplay], for topics [numsections, hiddensections, coursedisplay], for scrom and social there are no options
- Make Course format selector on create/edit course page looking similar to "Add activity" with help text for each format
- Refactor class editsection_form so it is easier to overwrite and implements functions set_data() and get_data() instead of pre/post processing data in editsection.php
- Make sure file_info (Server files repository) lists modules inside the course groupped by sections
- Describe in course formats dev documentation how formats can watch the events triggers