Course formats 2
We will refactor the course formats to support a proper object-oriented design and flexibility
Database changes
- add field course.formatoptions storing format-specific options as serialised array
- ? deprecate existing fields in table course: numsections, 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
There is another opinion on using additional table(s) for course and course_sections format-specific options.
Object model
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. Inside it should call function from renderer |
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() |
Backward compartibility
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
Course sections hierarchy
Add support for nested course sections:
- avoid loops,
- store visibleold;
- Process moving, deleting sections;
- Make sure the hierarchy appears in navigation menu and breadcrumb;
- Make sure changing of availability rules for both parent and child sections works correctly together
Course add/edit form
- 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/topics formatd they are [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
- 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
Course sections management
- ? Add events_triggers in functions that create/delete/hide/move course sections
- 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 backup/restore correctly works with sections hierarchy and new options. Also backup made in previous versions restores correctly in 2.4
- Make sure course format can influence navigation menu and breadcrumb. This probably will be done already by set_course/set_cm callbacks
- Improvement: file_info (Server files repository) should list modules inside the course groupped by sections
- Describe in course formats dev documentation how formats can watch the events triggers