Moodle PHP Documentation 4.3
Moodle 4.3.5 (Build: 20240610) (7dcfaa79f78)
core_courseformat\base Class Reference

Base class for course formats. More...

Inheritance diagram for core_courseformat\base:
format_legacy format_singleactivity format_site format_social format_topics format_weeks

Public Member Functions

 add_section_preference_ids (string $preferencename, array $sectionids,)
 Add section preference ids.
 
 ajax_section_move ()
 Custom action after section has been moved in AJAX mode.
 
 allow_stealth_module_visibility ($cm, $section)
 Returns whether this course format allows the activity to have "triple visibility state" - visible always, hidden on course page but available, hidden.
 
 can_delete_section ($section)
 Whether this format allows to delete sections.
 
 course_content_footer ()
 Course-specific information to be output immediately below content on any course page.
 
 course_content_header ()
 Course-specific information to be output immediately above content on any course page.
 
 course_footer ()
 Course-specific information to be output on any course page (usually in the beginning of standard footer)
 
 course_format_options ($foreditform=false)
 Definitions of the additional options that this course format uses for course.
 
 course_header ()
 Course-specific information to be output on any course page (usually above navigation bar)
 
 create_edit_form_elements (&$mform, $forsection=false)
 Adds format options elements to the course/section edit form.
 
 delete_format_data ()
 Course deletion hook.
 
 delete_module (cm_info $cm, bool $async=false)
 Wrapper for course_delete_module method.
 
 delete_section ($section, $forcedeleteifnotempty=false)
 Deletes a section.
 
 duplicate_section (section_info $originalsection)
 Duplicate a section.
 
 edit_form_validation ($data, $files, $errors)
 Override if you need to perform some extra validation of the format options.
 
 editsection_form ($action, $customdata=array())
 Return an instance of moodleform to edit a specified section.
 
 extend_course_navigation ($navigation, navigation_node $node)
 Loads all of the course sections into the navigation.
 
 get_config_for_external ()
 Return the plugin config settings for external functions, in some cases the configs will need formatting or be returned only if the current user has some capabilities enabled.
 
 get_context ()
 Returns the course context.
 
 get_course ()
 Returns a record from course database table plus additional fields that course format defines.
 
 get_course_display ()
 Get the course display value for the current course.
 
 get_courseid ()
 Returns id of the course (0 if course is not specified)
 
 get_default_blocks ()
 Returns the list of blocks to be automatically added for the newly created course.
 
 get_default_course_enddate ($mform, $fieldnames=array())
 Returns the default end date value based on the start date.
 
 get_default_section_name ($section)
 Returns the default section using course_format's implementation of get_section_name.
 
 get_editor_custom_strings ()
 Return custom strings for the course editor.
 
 get_format ()
 Returns the format name used by this course.
 
 get_format_name ()
 Returns the localised name of this course format plugin.
 
 get_format_options ($section=null)
 Returns the format options stored for this course or course section.
 
 get_format_string (string $key, $data=null)
 Get the proper format plugin string if it exists.
 
 get_last_section_number ()
 Method used in the rendered and during backup instead of legacy 'numsections'.
 
 get_max_sections ()
 Method used to get the maximum number of sections for this course format.
 
 get_modinfo ()
 Return the current course modinfo.
 
 get_non_ajax_cm_action_url (string $action, cm_info $cm)
 Return the old non-ajax activity action url.
 
 get_output_classname (string $outputname)
 Returns instance of output component used by this plugin.
 
 get_renderer (moodle_page $page)
 Returns instance of page renderer used by this plugin.
 
 get_section ($section, $strictness=IGNORE_MISSING)
 Returns information about section used in course.
 
 get_section_highlighted_name ()
 Returns the name for the highlighted section.
 
 get_section_name ($section)
 Returns the display name of the given section that the course prefers.
 
 get_section_number ()
 Set if the current format instance will show multiple sections or an individual one.
 
 get_sections ()
 Returns a list of sections used in the course.
 
 get_sections_preferences ()
 Return the format section preferences.
 
 get_sections_preferences_by_preference ()
 Return the format section preferences.
 
 get_view_url ($section, $options=array())
 The URL to use for the specified course (with section)
 
 has_view_page ()
 Returns true if the course has a front page.
 
 inplace_editable_render_section_name ($section, $linkifneeded=true, $editable=null, $edithint=null, $editlabel=null)
 Prepares the templateable object to display section name.
 
 inplace_editable_update_section_name ($section, $itemtype, $newvalue)
 Updates the value in the database and modifies this object respectively.
 
 is_section_current ($section)
 Returns true if the specified section is current.
 
 is_section_visible (section_info $section)
 Returns if an specific section is visible to the current user.
 
 move_section_after (section_info $section, section_info $destination)
 Moves a section just after the target section.
 
 page_set_cm (moodle_page $page)
 Allows course format to execute code on moodle_page\set_cm()
 
 page_set_course (moodle_page $page)
 Allows course format to execute code on moodle_page\set_course()
 
 page_title ()
 Generate the title for this section page.
 
 remove_section_preference_ids (string $preferencename, array $sectionids,)
 Remove section preference ids.
 
 section_action ($section, $action, $sr)
 Callback used in WS core_course_edit_section when teacher performs an AJAX action on a section (show/hide)
 
 section_format_options ($foreditform=false)
 Definitions of the additional options that this course format uses for section.
 
 section_get_available_hook (section_info $section, &$available, &$availableinfo)
 Allows to specify for modinfo that section is not available even when it is visible and conditionally available.
 
 set_section_number (int $singlesection)
 Set if the current format instance will show multiple sections or an individual one.
 
 set_sections_preference (string $preferencename, array $sectionids)
 Return the format section preferences.
 
 show_editor (?array $capabilities=['moodle/course:manageactivities'])
 return true if the course editor must be displayed.
 
 show_groupmode (cm_info $cm)
 Check if the group mode can be displayed.
 
 supports_ajax ()
 Returns the information about the ajax support in the given source format.
 
 supports_components ()
 Returns true if this course format is compatible with content components.
 
 supports_news ()
 Indicates whether the course format supports the creation of the Announcements forum.
 
 update_course_format_options ($data, $oldcourse=null)
 Updates format options for a course.
 
 update_section_format_options ($data)
 Updates format options for a section.
 
 uses_course_index ()
 Returns true if this course format uses course index.
 
 uses_indentation ()
 Returns true if this course format uses activity indentation.
 
 uses_sections ()
 Returns true if this course format uses sections.
 
 validate_course_format_options (array $data)
 Validates format options for the course.
 

Static Public Member Functions

static instance ($courseorid)
 Returns an instance of the class.
 
static reset_course_cache ($courseid=0)
 Resets cache for the course (or all caches)
 
static session_cache (stdClass $course)
 Return the current user course format cache key.
 
static session_cache_reset (stdClass $course)
 Reset the current user course format cache.
 
static session_cache_reset_all ()
 Reset the current user for all courses.
 

Protected Member Functions

 __construct ($format, $courseid)
 Creates a new instance of class.
 
 get_form_start_date ($mform, $fieldnames)
 Get the start date value from the course settings page form.
 
 get_section_modules_updated (section_info $section)
 Return an array with all section modules content.
 
 update_format_options ($data, $sectionid=null)
 Updates format options for a course or section.
 
 validate_format_options (array $rawdata, int $sectionid=null)
 Prepares values of course or section format options before storing them in DB.
 

Static Protected Member Functions

static get_class_name ($format)
 Get class name for the format.
 
static get_format_or_default ($format)
 Validates that course format exists and enabled and returns either itself or default format.
 

Protected Attributes

stdClass $course = false
 course data for course object, please use course_format\get_course()
 
int $courseid
 Id of the course in this instance (maybe 0)
 
string $format
 format used for this course.
 
array $formatoptions = array()
 caches format options, please use course_format\get_format_options()
 
sectionmanager $sectionmanager = null
 the format section manager.
 
int $singlesection = 0
 the section number in single section format, zero for multiple section formats.
 

Detailed Description

Base class for course formats.

Each course format must declare class class format_FORMATNAME extends core_courseformat\base {} in file lib.php

For each course just one instance of this class is created and it will always be returned by course_get_format($courseorid). Format may store it's specific course-dependent options in variables of this class.

In rare cases instance of child class may be created just for format without course id i.e. to check if format supports AJAX.

Also course formats may extend class section_info and overwrite course_format\build_section_cache() to return more information about sections.

If you are upgrading from Moodle 2.3 start with copying the class format_legacy and renaming it to format_FORMATNAME, then move the code from your callback functions into appropriate functions of the class.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Constructor & Destructor Documentation

◆ __construct()

core_courseformat\base::__construct ( $format,
$courseid )
protected

Creates a new instance of class.

Please use course_get_format($courseorid) to get an instance of the format class

Parameters
string$format
int$courseid
Return values
course_format

Member Function Documentation

◆ add_section_preference_ids()

core_courseformat\base::add_section_preference_ids ( string $preferencename,
array $sectionids )

Add section preference ids.

Parameters
string$preferencenamepreference name
array$sectionidsaffected section ids

◆ ajax_section_move()

core_courseformat\base::ajax_section_move ( )

Custom action after section has been moved in AJAX mode.

Used in course/rest.php

Return values
arrayThis will be passed in ajax respose

Reimplemented in format_legacy, format_topics, and format_weeks.

◆ allow_stealth_module_visibility()

core_courseformat\base::allow_stealth_module_visibility ( $cm,
$section )

Returns whether this course format allows the activity to have "triple visibility state" - visible always, hidden on course page but available, hidden.

Parameters
stdClass | cm_info$cmcourse module (may be null if we are displaying a form for adding a module)
stdClass | section_info$sectionsection where this module is located or will be added to
Return values
bool

Reimplemented in format_site, format_social, format_topics, and format_weeks.

◆ can_delete_section()

core_courseformat\base::can_delete_section ( $section)

Whether this format allows to delete sections.

If format supports deleting sections it is also recommended to define language string 'deletesection' inside the format.

Do not call this function directly, instead use course_can_delete_section()

Parameters
int | stdClass | section_info$section
Return values
bool

Reimplemented in format_topics, and format_weeks.

◆ course_content_footer()

core_courseformat\base::course_content_footer ( )

Course-specific information to be output immediately below content on any course page.

See course_format\course_header() for usage

Return values
null|renderablenull for no output or object with data for plugin renderer

◆ course_content_header()

core_courseformat\base::course_content_header ( )

Course-specific information to be output immediately above content on any course page.

See course_format\course_header() for usage

Return values
null|renderablenull for no output or object with data for plugin renderer

◆ course_footer()

core_courseformat\base::course_footer ( )

Course-specific information to be output on any course page (usually in the beginning of standard footer)

See course_format\course_header() for usage

Return values
null|renderablenull for no output or object with data for plugin renderer

◆ course_format_options()

core_courseformat\base::course_format_options ( $foreditform = false)

Definitions of the additional options that this course format uses for course.

This function may be called often, it should be as fast as possible. Avoid using get_string() method, use "new lang_string()" instead It is not recommended to use dynamic or course-dependant expressions here This function may be also called when course does not exist yet.

Option names must be different from fields in the {course} talbe or any form elements on course edit form, it may even make sence to use special prefix for them.

Each option must have the option name as a key and the array of properties as a value: 'default' - default value for this option (assumed null if not specified) 'type' - type of the option value (PARAM_INT, PARAM_RAW, etc.)

Additional properties used by default implementation of course_format\create_edit_form_elements() (calls this method with $foreditform = true) 'label' - localised human-readable label for the edit form 'element_type' - type of the form element, default 'text' 'element_attributes' - additional attributes for the form element, these are 4th and further arguments in the moodleform\addElement() method 'help' - string for help button. Note that if 'help' value is 'myoption' then the string with the name 'myoption_help' must exist in the language file 'help_component' - language component to look for help string, by default this the component for this course format

This is an interface for creating simple form elements. If format plugin wants to use other methods such as disableIf, it can be done by overriding create_edit_form_elements().

Course format options can be accessed as: $this->get_course()->OPTIONNAME (inside the format class) course_get_format($course)->get_course()->OPTIONNAME (outside of format class)

All course options are returned by calling: $this->get_format_options();

Parameters
bool$foreditform
Return values
arrayof options

Reimplemented in format_legacy, format_singleactivity, format_site, format_social, format_topics, and format_weeks.

◆ course_header()

core_courseformat\base::course_header ( )

Course-specific information to be output on any course page (usually above navigation bar)

Example of usage: define class format_FORMATNAME_XXX implements renderable {}

create format renderer in course/format/FORMATNAME/renderer.php, define rendering function: class format_FORMATNAME_renderer extends plugin_renderer_base { protected function render_format_FORMATNAME_XXX(format_FORMATNAME_XXX $xxx) { return html_writer\tag('div', 'This is my header/footer'); } }

Return instance of format_FORMATNAME_XXX in this function, the appropriate method from plugin renderer will be called

Return values
null|renderablenull for no output or object with data for plugin renderer

◆ create_edit_form_elements()

core_courseformat\base::create_edit_form_elements ( & $mform,
$forsection = false )

Adds format options elements to the course/section edit form.

This function is called from course_edit_form\definition_after_data()

Parameters
MoodleQuickForm$mformform the elements are added to
bool$forsection'true' if this is a section edit form, 'false' if this is course edit form
Return values
arrayarray of references to the added form elements

Reimplemented in format_singleactivity, format_topics, and format_weeks.

◆ delete_format_data()

core_courseformat\base::delete_format_data ( )

Course deletion hook.

Format plugins can override this method to clean any format specific data and dependencies.

◆ delete_module()

core_courseformat\base::delete_module ( cm_info $cm,
bool $async = false )

Wrapper for course_delete_module method.

Format plugins can override this method to provide their own implementation of course_delete_module.

Parameters
cm_info$cmthe course module information
bool$asyncwhether or not to try to delete the module using an adhoc task. Async also depends on a plugin hook.
Exceptions
moodle_exception

◆ delete_section()

core_courseformat\base::delete_section ( $section,
$forcedeleteifnotempty = false )

Deletes a section.

Do not call this function directly, instead call course_delete_section()

Parameters
int | stdClass | section_info$section
bool$forcedeleteifnotemptyif set to false section will not be deleted if it has modules in it.
Return values
boolwhether section was deleted

◆ duplicate_section()

core_courseformat\base::duplicate_section ( section_info $originalsection)

Duplicate a section.

Parameters
section_info$originalsectionThe section to be duplicated
Return values
section_infoThe new duplicated section
Since
Moodle 4.2

◆ edit_form_validation()

core_courseformat\base::edit_form_validation ( $data,
$files,
$errors )

Override if you need to perform some extra validation of the format options.

Parameters
array$dataarray of ("fieldname"=>value) of submitted data
array$filesarray of uploaded files "element_name"=>tmp_file_path
array$errorserrors already discovered in edit form validation
Return values
arrayof "element_name"=>"error_description" if there are errors, or an empty array if everything is OK. Do not repeat errors from $errors param here

◆ editsection_form()

core_courseformat\base::editsection_form ( $action,
$customdata = array() )

Return an instance of moodleform to edit a specified section.

Default implementation returns instance of editsection_form that automatically adds additional fields defined in course_format\section_format_options()

Format plugins may extend editsection_form if they want to have custom edit section form.

Parameters
mixed$actionthe action attribute for the form. If empty defaults to auto detect the current url. If a moodle_url object then outputs params as hidden variables.
array$customdatathe array with custom data to be passed to the form /course/editsection.php passes section_info object in 'cs' field for filling availability fields
Return values
moodleform

◆ extend_course_navigation()

core_courseformat\base::extend_course_navigation ( $navigation,
navigation_node $node )

Loads all of the course sections into the navigation.

This method is called from global_navigation\load_course_sections()

By default the method global_navigation\load_generic_course_sections() is called

When overwriting please note that navigationlib relies on using the correct values for arguments $type and $key in navigation_node\add()

Example of code creating a section node: $sectionnode = $node->add($sectionname, $url, navigation_node\TYPE_SECTION, null, $section->id); $sectionnode->nodetype = navigation_node\NODETYPE_BRANCH;

Example of code creating an activity node: $activitynode = $sectionnode->add($activityname, $action, navigation_node\TYPE_ACTIVITY, null, $activity->id, $icon); if (global_navigation\module_extends_navigation($activity->modname)) { $activitynode->nodetype = navigation_node\NODETYPE_BRANCH; } else { $activitynode->nodetype = navigation_node\NODETYPE_LEAF; }

Also note that if $navigation->includesectionnum is not null, the section with this relative number needs is expected to be loaded

Parameters
global_navigation$navigation
navigation_node$nodeThe course node within the navigation

Reimplemented in format_legacy, format_singleactivity, format_social, format_topics, and format_weeks.

◆ get_class_name()

static core_courseformat\base::get_class_name ( $format)
staticfinalprotected

Get class name for the format.

If course format xxx does not declare class format_xxx, format_legacy will be returned. This function also includes lib.php file from corresponding format plugin

Parameters
string$format
Return values
string

◆ get_config_for_external()

core_courseformat\base::get_config_for_external ( )

Return the plugin config settings for external functions, in some cases the configs will need formatting or be returned only if the current user has some capabilities enabled.

Return values
arraythe list of configs
Since
Moodle 3.5

Reimplemented in format_singleactivity, format_social, format_topics, and format_weeks.

◆ get_context()

core_courseformat\base::get_context ( )
final

Returns the course context.

Return values
context_coursethe course context

◆ get_course()

core_courseformat\base::get_course ( )

Returns a record from course database table plus additional fields that course format defines.

Return values
stdClass

◆ get_course_display()

core_courseformat\base::get_course_display ( )

Get the course display value for the current course.

Formats extending topics or weeks will use coursedisplay as this setting name so they don't need to override the method. However, if the format uses a different display logic it must override this method to ensure the core renderers know if a COURSE_DISPLAY_MULTIPAGE or COURSE_DISPLAY_SINGLEPAGE is being used.

Return values
intThe current value (COURSE_DISPLAY_MULTIPAGE or COURSE_DISPLAY_SINGLEPAGE)

◆ get_courseid()

core_courseformat\base::get_courseid ( )
final

Returns id of the course (0 if course is not specified)

Return values
int

◆ get_default_blocks()

core_courseformat\base::get_default_blocks ( )

Returns the list of blocks to be automatically added for the newly created course.

See also
blocks_add_default_course_blocks()
Return values
arrayof default blocks, must contain two keys BLOCK_POS_LEFT and BLOCK_POS_RIGHT each of values is an array of block names (for left and right side columns)

Reimplemented in format_legacy, format_singleactivity, format_site, format_social, format_topics, and format_weeks.

◆ get_default_course_enddate()

core_courseformat\base::get_default_course_enddate ( $mform,
$fieldnames = array() )

Returns the default end date value based on the start date.

This is the default implementation for course formats, it is based on moodlecourse/courseduration setting. Course formats like format_weeks for example can overwrite this method and return a value based on their internal options.

Parameters
moodleform$mform
array$fieldnamesThe form - field names mapping.
Return values
int

Reimplemented in format_weeks.

◆ get_default_section_name()

core_courseformat\base::get_default_section_name ( $section)

Returns the default section using course_format's implementation of get_section_name.

Parameters
int | stdClass$sectionSection object from database or just field course_sections section
Return values
stringThe default value for the section name based on the given course format.

Reimplemented in format_topics, and format_weeks.

◆ get_editor_custom_strings()

core_courseformat\base::get_editor_custom_strings ( )

Return custom strings for the course editor.

This method is mainly used to translate the "section" related strings into the specific format plugins name such as "Topics" or "Weeks".

Return values
stdClass[]an array of objects with string "component" and "key"

◆ get_form_start_date()

core_courseformat\base::get_form_start_date ( $mform,
$fieldnames )
protected

Get the start date value from the course settings page form.

Parameters
moodleform$mform
array$fieldnamesThe form - field names mapping.
Return values
int

◆ get_format()

core_courseformat\base::get_format ( )
final

Returns the format name used by this course.

Return values
string

◆ get_format_name()

core_courseformat\base::get_format_name ( )
final

Returns the localised name of this course format plugin.

Return values
lang_string

◆ get_format_options()

core_courseformat\base::get_format_options ( $section = null)

Returns the format options stored for this course or course section.

When overriding please note that this function is called from rebuild_course_cache() and section_info object, therefore using of get_fast_modinfo() and/or any function that accesses it may lead to recursion.

Parameters
null | int | stdClass | section_info$sectionif null the course format options will be returned otherwise options for specified section will be returned. This can be either section object or relative section number (field course_sections.section)
Return values
array

◆ get_format_or_default()

static core_courseformat\base::get_format_or_default ( $format)
staticfinalprotected

Validates that course format exists and enabled and returns either itself or default format.

Parameters
string$format
Return values
string

◆ get_format_string()

core_courseformat\base::get_format_string ( string $key,
$data = null )

Get the proper format plugin string if it exists.

If the format_PLUGINNAME does not provide a valid string, core_courseformat will be user as the component.

Parameters
string$keythe string key
string | object | array | int$dataextra data that can be used within translation strings
Return values
stringthe get_string result

◆ get_last_section_number()

core_courseformat\base::get_last_section_number ( )

Method used in the rendered and during backup instead of legacy 'numsections'.

Default renderer will treat sections with sectionnumber greater that the value returned by this method as "orphaned" and not display them on the course page unless in editing mode. Backup will store this value as 'numsections'.

This method ensures that 3rd party course format plugins that still use 'numsections' continue to work but at the same time we no longer expect formats to have 'numsections' property.

Return values
intThe last section number, or -1 if sections are entirely missing

◆ get_max_sections()

core_courseformat\base::get_max_sections ( )

Method used to get the maximum number of sections for this course format.

Return values
int

◆ get_modinfo()

core_courseformat\base::get_modinfo ( )

Return the current course modinfo.

This method is used mainly by the output components to avoid unnecesary get_fast_modinfo calls.

Return values
course_modinfo

◆ get_non_ajax_cm_action_url()

core_courseformat\base::get_non_ajax_cm_action_url ( string $action,
cm_info $cm )

Return the old non-ajax activity action url.

BrowserKit behats tests cannot trigger javascript events, so we must translate to an old non-ajax url while non-ajax course editing is still supported.

Parameters
string$actionaction name the reactive action
cm_info$cmcourse module
Return values
moodle_url

◆ get_output_classname()

core_courseformat\base::get_output_classname ( string $outputname)

Returns instance of output component used by this plugin.

Exceptions
coding_exceptionif the format class does not extends the original core one.
Parameters
string$outputnamethe element to render (section, activity...)
Return values
stringthe output component classname

◆ get_renderer()

core_courseformat\base::get_renderer ( moodle_page $page)

Returns instance of page renderer used by this plugin.

Parameters
moodle_page$page
Return values
renderer_base

Reimplemented in format_site.

◆ get_section()

core_courseformat\base::get_section ( $section,
$strictness = IGNORE_MISSING )
final

Returns information about section used in course.

Parameters
int | stdClass$sectioneither section number (field course_section.section) or row from course_section table
int$strictness
Return values
section_info

◆ get_section_highlighted_name()

core_courseformat\base::get_section_highlighted_name ( )

Returns the name for the highlighted section.

Return values
stringThe name for the highlighted section based on the given course format.

Reimplemented in format_weeks.

◆ get_section_modules_updated()

core_courseformat\base::get_section_modules_updated ( section_info $section)
protected

Return an array with all section modules content.

This method is used in section_action method to generate the updated modules content after a modinfo change.

Parameters
section_info$sectionthe section
Return values
string[]the full modules content.

◆ get_section_name()

core_courseformat\base::get_section_name ( $section)

Returns the display name of the given section that the course prefers.

Parameters
int | stdClass$sectionSection object from database or just field course_sections.section
Return values
stringDisplay name that the course format prefers, e.g. "Topic 2"

Reimplemented in format_legacy, format_site, format_topics, and format_weeks.

◆ get_section_number()

core_courseformat\base::get_section_number ( )

Set if the current format instance will show multiple sections or an individual one.

Some formats has the hability to swith from one section to multiple sections per page, output components will use this method to know if the current display is a single or multiple sections.

Return values
intzero for all sections or the sectin number

Reimplemented in format_site.

◆ get_sections()

core_courseformat\base::get_sections ( )
final

Returns a list of sections used in the course.

This is a shortcut to get_fast_modinfo()->get_section_info_all()

See also
get_fast_modinfo()
course_modinfo\get_section_info_all()
Return values
arrayof section_info objects

◆ get_sections_preferences()

core_courseformat\base::get_sections_preferences ( )

Return the format section preferences.

Return values
arrayof preferences indexed by sectionid

◆ get_sections_preferences_by_preference()

core_courseformat\base::get_sections_preferences_by_preference ( )

Return the format section preferences.

Return values
arrayof preferences indexed by preference name

◆ get_view_url()

core_courseformat\base::get_view_url ( $section,
$options = array() )

The URL to use for the specified course (with section)

Please note that course view page /course/view.php?id=COURSEID is hardcoded in many places in core and contributed modules. If course format wants to change the location of the view script, it is not enough to change just this function. Do not forget to add proper redirection.

Parameters
int | stdClass$sectionSection object from database or just field course_sections.section if null the course view page is returned
array$optionsoptions for view URL. At the moment core uses: 'navigation' (bool) if true and section has no separate page, the function returns null 'sr' (int) used by multipage formats to specify to which section to return 'expanded' (bool) if true the section will be shown expanded, true by default
Return values
null|moodle_url

Reimplemented in format_legacy, format_singleactivity, format_site, format_social, format_topics, and format_weeks.

◆ has_view_page()

core_courseformat\base::has_view_page ( )

Returns true if the course has a front page.

This function is called to determine if the course has a view page, whether or not it contains a listing of activities. It can be useful to set this to false when the course format has only one activity and ignores the course page. Or if there are multiple activities but no page to see the centralised information.

Initially this was created to know if forms should add a button to return to the course page. So if 'Return to course' does not make sense in your format your should probably return false.

Return values
boolean
Since
Moodle 2.6

Reimplemented in format_singleactivity.

◆ inplace_editable_render_section_name()

core_courseformat\base::inplace_editable_render_section_name ( $section,
$linkifneeded = true,
$editable = null,
$edithint = null,
$editlabel = null )

Prepares the templateable object to display section name.

Parameters
section_info | stdClass$section
bool$linkifneeded
bool$editable
null | lang_string | string$edithint
null | lang_string | string$editlabel
Return values
core\output\inplace_editable

Reimplemented in format_topics, and format_weeks.

◆ inplace_editable_update_section_name()

core_courseformat\base::inplace_editable_update_section_name ( $section,
$itemtype,
$newvalue )

Updates the value in the database and modifies this object respectively.

ALWAYS check user permissions before performing an update! Throw exceptions if permissions are not sufficient or value is not legit.

Parameters
stdClass$section
string$itemtype
mixed$newvalue
Return values
core\output\inplace_editable

◆ instance()

static core_courseformat\base::instance ( $courseorid)
staticfinal

Returns an instance of the class.

Todo
MDL-35727 use MUC for caching of instances, limit the number of cached instances
Parameters
int | stdClass$courseorideither course id or an object that has the property 'format' and may contain property 'id'
Return values
course_format

◆ is_section_current()

core_courseformat\base::is_section_current ( $section)

Returns true if the specified section is current.

By default we analyze $course->marker

Parameters
int | stdClass | section_info$section
Return values
bool

Reimplemented in format_weeks.

◆ is_section_visible()

core_courseformat\base::is_section_visible ( section_info $section)

Returns if an specific section is visible to the current user.

Formats can overrride this method to implement any special section logic.

Parameters
section_info$sectionthe section modinfo
Return values
bool;

◆ move_section_after()

core_courseformat\base::move_section_after ( section_info $section,
section_info $destination )

Moves a section just after the target section.

Parameters
section_info$sectionthe section to move
section_info$destinationthe section that should be below the moved section
Return values
booleanif the section can be moved or not

◆ page_set_cm()

core_courseformat\base::page_set_cm ( moodle_page $page)

Allows course format to execute code on moodle_page\set_cm()

Current module can be accessed as $page->cm (returns instance of cm_info)

Parameters
moodle_page$pageinstance of page calling set_cm

Reimplemented in format_singleactivity.

◆ page_set_course()

core_courseformat\base::page_set_course ( moodle_page $page)

Allows course format to execute code on moodle_page\set_course()

Parameters
moodle_page$pageinstance of page calling set_course

Reimplemented in format_singleactivity.

◆ page_title()

core_courseformat\base::page_title ( )

Generate the title for this section page.

Return values
stringthe page title

Reimplemented in format_topics, and format_weeks.

◆ remove_section_preference_ids()

core_courseformat\base::remove_section_preference_ids ( string $preferencename,
array $sectionids )

Remove section preference ids.

Parameters
string$preferencenamepreference name
array$sectionidsaffected section ids

◆ reset_course_cache()

static core_courseformat\base::reset_course_cache ( $courseid = 0)
staticfinal

Resets cache for the course (or all caches)

To be called from rebuild_course_cache()

Parameters
int$courseid

◆ section_action()

core_courseformat\base::section_action ( $section,
$action,
$sr )

Callback used in WS core_course_edit_section when teacher performs an AJAX action on a section (show/hide)

Access to the course is already validated in the WS but the callback has to make sure that particular action is allowed by checking capabilities

Course formats should register

Parameters
stdClass | section_info$section
string$action
int$srthe section return
Return values
null|array|stdClassany data for the Javascript post-processor (must be json-encodeable)

Reimplemented in format_topics, and format_weeks.

◆ section_format_options()

core_courseformat\base::section_format_options ( $foreditform = false)

Definitions of the additional options that this course format uses for section.

See course_format\course_format_options() for return array definition.

Additionally section format options may have property 'cache' set to true if this option needs to be cached in get_fast_modinfo(). The 'cache' property is recommended to be set only for fields used in course_format\get_section_name(), course_format\extend_course_navigation() and course_format\get_view_url()

For better performance cached options are recommended to have 'cachedefault' property Unlike 'default', 'cachedefault' should be static and not access get_config().

Regardless of value of 'cache' all options are accessed in the code as $sectioninfo->OPTIONNAME where $sectioninfo is instance of section_info, returned by get_fast_modinfo($course)->get_section_info($sectionnum) or get_fast_modinfo($course)->get_section_info_all()

All format options for particular section are returned by calling: $this->get_format_options($section);

Parameters
bool$foreditform
Return values
array

◆ section_get_available_hook()

core_courseformat\base::section_get_available_hook ( section_info $section,
& $available,
& $availableinfo )

Allows to specify for modinfo that section is not available even when it is visible and conditionally available.

Note: affected user can be retrieved as: $section->modinfo->userid

Course format plugins can override the method to change the properties $available and $availableinfo that were calculated by conditional availability. To make section unavailable set: $available = false; To make unavailable section completely hidden set: $availableinfo = ''; To make unavailable section visible with availability message set: $availableinfo = get_string('sectionhidden', 'format_xxx');

Parameters
section_info$section
bool$availablethe 'available' propery of the section_info as it was evaluated by conditional availability. Can be changed by the method but 'false' can not be overridden by 'true'.
string$availableinfothe 'availableinfo' propery of the section_info as it was evaluated by conditional availability. Can be changed by the method

◆ session_cache()

static core_courseformat\base::session_cache ( stdClass $course)
static

Return the current user course format cache key.

The course format session cache can be used to cache the user course representation. The statekey will be reset when the the course state changes. For example when the course is edited, the user completes an activity or simply some course preference like collapsing a section happens.

Parameters
stdClass$coursethe course object
Return values
stringthe current statekey

◆ session_cache_reset()

static core_courseformat\base::session_cache_reset ( stdClass $course)
static

Reset the current user course format cache.

The course format cache resets every time the course cache resets but also when the user changes their course format preference, complete an activity...

Parameters
stdClass$coursethe course object
Return values
stringthe new statekey

◆ session_cache_reset_all()

static core_courseformat\base::session_cache_reset_all ( )
static

Reset the current user for all courses.

The course format cache resets every time the course cache resets but also when the user changes their language, all course editors

Return values
void

◆ set_section_number()

core_courseformat\base::set_section_number ( int $singlesection)

Set if the current format instance will show multiple sections or an individual one.

Some formats has the hability to swith from one section to multiple sections per page, this method replaces the old print_multiple_section_page and print_single_section_page.

Parameters
int$singlesectionzero for all sections or a section number

◆ set_sections_preference()

core_courseformat\base::set_sections_preference ( string $preferencename,
array $sectionids )

Return the format section preferences.

Parameters
string$preferencenamepreference name
int[]$sectionidsaffected section ids

◆ show_editor()

core_courseformat\base::show_editor ( ?array $capabilities = ['moodle/course:manageactivities'])

return true if the course editor must be displayed.

Parameters
array | null$capabilitiesarray of capabilities a user needs to have to see edit controls in general. If null or not specified, the user needs to have 'moodle/course:manageactivities'.
Return values
booltrue if edit controls must be displayed

◆ show_groupmode()

core_courseformat\base::show_groupmode ( cm_info $cm)

Check if the group mode can be displayed.

Parameters
cm_info$cmthe activity module
Return values
bool

◆ supports_ajax()

core_courseformat\base::supports_ajax ( )

Returns the information about the ajax support in the given source format.

The returned object's property (boolean)capable indicates that the course format supports Moodle course ajax features.

Return values
stdClass

Reimplemented in format_legacy, format_social, format_topics, and format_weeks.

◆ supports_components()

core_courseformat\base::supports_components ( )

Returns true if this course format is compatible with content components.

Using components means the content elements can watch the frontend course state and react to the changes. Formats with component compatibility can have more interactions without refreshing the page, like having drag and drop from the course index to reorder sections and activities.

Return values
boolif the format is compatible with components.

Reimplemented in format_topics, and format_weeks.

◆ supports_news()

core_courseformat\base::supports_news ( )

Indicates whether the course format supports the creation of the Announcements forum.

For course format plugin developers, please override this to return true if you want the Announcements forum to be created upon course creation.

Return values
bool

Reimplemented in format_topics, and format_weeks.

◆ update_course_format_options()

core_courseformat\base::update_course_format_options ( $data,
$oldcourse = null )

Updates format options for a course.

If $data does not contain property with the option name, the option will not be updated

Parameters
stdClass | array$datareturn value from moodleform\get_data() or array with data
stdClass$oldcourseif this function is called from update_course() this object contains information about the course before update
Return values
boolwhether there were any changes to the options values

Reimplemented in format_legacy, format_topics, and format_weeks.

◆ update_format_options()

core_courseformat\base::update_format_options ( $data,
$sectionid = null )
protected

Updates format options for a course or section.

If $data does not contain property with the option name, the option will not be updated

Parameters
stdClass | array$datareturn value from moodleform\get_data() or array with data
null | int$sectionidnull if these are options for course or section id (course_sections.id) if these are options for section
Return values
boolwhether there were any changes to the options values

◆ update_section_format_options()

core_courseformat\base::update_section_format_options ( $data)

Updates format options for a section.

Section id is expected in $data->id (or $data['id']) If $data does not contain property with the option name, the option will not be updated

Parameters
stdClass | array$datareturn value from moodleform\get_data() or array with data
Return values
boolwhether there were any changes to the options values

◆ uses_course_index()

core_courseformat\base::uses_course_index ( )

Returns true if this course format uses course index.

This function may be called without specifying the course id i.e. in course_index_drawer()

Return values
bool

Reimplemented in format_topics, and format_weeks.

◆ uses_indentation()

core_courseformat\base::uses_indentation ( )

Returns true if this course format uses activity indentation.

Return values
boolif the course format uses indentation.

Reimplemented in format_topics, and format_weeks.

◆ uses_sections()

core_courseformat\base::uses_sections ( )

Returns true if this course format uses sections.

This function may be called without specifying the course id i.e. in course_format_uses_sections()

Developers, note that if course format does use sections there should be defined a language string with the name 'sectionname' defining what the section relates to in the format, i.e. $string['sectionname'] = 'Topic'; or $string['sectionname'] = 'Week';

Return values
bool

Reimplemented in format_legacy, format_topics, and format_weeks.

◆ validate_course_format_options()

core_courseformat\base::validate_course_format_options ( array $data)

Validates format options for the course.

Parameters
array$datadata to insert/update
Return values
arrayarray of options that have valid values

◆ validate_format_options()

core_courseformat\base::validate_format_options ( array $rawdata,
int $sectionid = null )
protected

Prepares values of course or section format options before storing them in DB.

If an option has invalid value it is not returned

Parameters
array$rawdataassociative array of the proposed course/section format options
int | null$sectionidnull if it is course format option
Return values
arrayarray of options that have valid values

Member Data Documentation

◆ $format

string core_courseformat\base::$format
protected

format used for this course.

Please note that it can be different from course.format field if course referes to non-existing of disabled format


The documentation for this class was generated from the following file: