Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Differences Between: [Versions 400 and 402] [Versions 401 and 402] [Versions 402 and 403]

(no description)

File Size: 994 lines (36 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: stateactions  - X-Ref

Contains the core course state actions.

The methods from this class should be executed via "core_courseformat_edit" web service.

Each format plugin could extend this class to provide new actions to the editor.
Extended classes should be locate in "format_XXX\course" namespace and
extends core_courseformat\stateactions.

cm_move(stateupdates $updates,stdClass $course,array $ids,?int $targetsectionid = null,?int $targetcmid = null)   X-Ref
Move course modules to another location in the same course.

param: stateupdates $updates the affected course elements track
param: stdClass $course the course object
param: int[] $ids the list of affected course module ids
param: int $targetsectionid optional target section id
param: int $targetcmid optional target cm id

sort_cm_ids_by_course_position(stdClass $course,array $cmids,bool $descending = false)   X-Ref
Sort the cm ids list depending on the course position.

Some actions like move should be done in an specific order.

param: stdClass $course the course object
param: int[] $cmids the array of section $ids
param: bool $descending if the sort order must be descending instead of ascending
return: int[] the array of section ids sorted by section number

section_move(stateupdates $updates,stdClass $course,array $ids,?int $targetsectionid = null,?int $targetcmid = null)   X-Ref
Move course sections to another location in the same course.

param: stateupdates $updates the affected course elements track
param: stdClass $course the course object
param: int[] $ids the list of affected course module ids
param: int $targetsectionid optional target section id
param: int $targetcmid optional target cm id

section_move_after(stateupdates $updates,stdClass $course,array $ids,?int $targetsectionid = null,?int $targetcmid = null)   X-Ref
Move course sections after to another location in the same course.

param: stateupdates $updates the affected course elements track
param: stdClass $course the course object
param: int[] $ids the list of affected course module ids
param: int $targetsectionid optional target section id
param: int $targetcmid optional target cm id

sort_section_ids_by_section_number(stdClass $course,array $sectionids,bool $descending = false)   X-Ref
Sort the sections ids depending on the section number.

Some actions like move should be done in an specific order.

param: stdClass $course the course object
param: int[] $sectionids the array of section $ids
param: bool $descending if the sort order must be descending instead of ascending
return: int[] the array of section ids sorted by section number

section_add(stateupdates $updates,stdClass $course,array $ids = [],?int $targetsectionid = null,?int $targetcmid = null)   X-Ref
Create a course section.

This method follows the same logic as changenumsections.php.

param: stateupdates $updates the affected course elements track
param: stdClass $course the course object
param: int[] $ids not used
param: int $targetsectionid optional target section id (if not passed section will be appended)
param: int $targetcmid not used

section_delete(stateupdates $updates,stdClass $course,array $ids = [],?int $targetsectionid = null,?int $targetcmid = null)   X-Ref
Delete course sections.

This method follows the same logic as editsection.php.

param: stateupdates $updates the affected course elements track
param: stdClass $course the course object
param: int[] $ids section ids
param: int $targetsectionid not used
param: int $targetcmid not used

section_hide(stateupdates $updates,stdClass $course,array $ids = [],?int $targetsectionid = null,?int $targetcmid = null)   X-Ref
Hide course sections.

param: stateupdates $updates the affected course elements track
param: stdClass $course the course object
param: int[] $ids section ids
param: int $targetsectionid not used
param: int $targetcmid not used

section_show(stateupdates $updates,stdClass $course,array $ids = [],?int $targetsectionid = null,?int $targetcmid = null)   X-Ref
Show course sections.

param: stateupdates $updates the affected course elements track
param: stdClass $course the course object
param: int[] $ids section ids
param: int $targetsectionid not used
param: int $targetcmid not used

set_section_visibility(stateupdates $updates,stdClass $course,array $ids,int $visible)   X-Ref
Show course sections.

param: stateupdates $updates the affected course elements track
param: stdClass $course the course object
param: int[] $ids section ids
param: int $visible the new visible value

cm_show(stateupdates $updates,stdClass $course,array $ids = [],?int $targetsectionid = null,?int $targetcmid = null)   X-Ref
Show course cms.

param: stateupdates $updates the affected course elements track
param: stdClass $course the course object
param: int[] $ids cm ids
param: int $targetsectionid not used
param: int $targetcmid not used

cm_hide(stateupdates $updates,stdClass $course,array $ids = [],?int $targetsectionid = null,?int $targetcmid = null)   X-Ref
Hide course cms.

param: stateupdates $updates the affected course elements track
param: stdClass $course the course object
param: int[] $ids cm ids
param: int $targetsectionid not used
param: int $targetcmid not used

cm_stealth(stateupdates $updates,stdClass $course,array $ids = [],?int $targetsectionid = null,?int $targetcmid = null)   X-Ref
Stealth course cms.

param: stateupdates $updates the affected course elements track
param: stdClass $course the course object
param: int[] $ids cm ids
param: int $targetsectionid not used
param: int $targetcmid not used

set_cm_visibility(stateupdates $updates,stdClass $course,array $ids,int $visible,int $coursevisible)   X-Ref
Internal method to define the cm visibility.

param: stateupdates $updates the affected course elements track
param: stdClass $course the course object
param: int[] $ids cm ids
param: int $visible the new visible value
param: int $coursevisible the new course visible value

cm_duplicate(stateupdates $updates,stdClass $course,array $ids = [],?int $targetsectionid = null,?int $targetcmid = null)   X-Ref
Duplicate a course modules instances into the same course.

param: stateupdates $updates the affected course elements track
param: stdClass $course the course object
param: int[] $ids course modules ids to duplicate
param: int|null $targetsectionid optional target section id destination
param: int|null $targetcmid optional target before cm id destination

cm_delete(stateupdates $updates,stdClass $course,array $ids = [],?int $targetsectionid = null,?int $targetcmid = null)   X-Ref
Delete course cms.

param: stateupdates $updates the affected course elements track
param: stdClass $course the course object
param: int[] $ids section ids
param: int $targetsectionid not used
param: int $targetcmid not used

cm_moveright(stateupdates $updates,stdClass $course,array $ids = [],?int $targetsectionid = null,?int $targetcmid = null)   X-Ref
Move course cms to the right. Indent = 1.

param: stateupdates $updates the affected course elements track
param: stdClass $course the course object
param: int[] $ids cm ids
param: int $targetsectionid not used
param: int $targetcmid not used

cm_moveleft(stateupdates $updates,stdClass $course,array $ids = [],?int $targetsectionid = null,?int $targetcmid = null)   X-Ref
Move course cms to the left. Indent = 0.

param: stateupdates $updates the affected course elements track
param: stdClass $course the course object
param: int[] $ids cm ids
param: int $targetsectionid not used
param: int $targetcmid not used

set_cm_indentation(stateupdates $updates,stdClass $course,array $ids,int $indent)   X-Ref
Internal method to define the cm indentation level.

param: stateupdates $updates the affected course elements track
param: stdClass $course the course object
param: int[] $ids cm ids
param: int $indent new value for indentation

get_cm_info(course_modinfo $modinfo, array $ids)   X-Ref
Extract several cm_info from the course_modinfo.

param: course_modinfo $modinfo the course modinfo.
param: int[] $ids the course modules $ids
return: cm_info[] the extracted cm_info objects

get_section_info(course_modinfo $modinfo, array $ids)   X-Ref
Extract several section_info from the course_modinfo.

param: course_modinfo $modinfo the course modinfo.
param: int[] $ids the course modules $ids
return: section_info[] the extracted section_info objects

section_content_collapsed(stateupdates $updates,stdClass $course,array $ids = [],?int $targetsectionid = null,?int $targetcmid = null)   X-Ref
Update the course content section collapsed value.

param: stateupdates $updates the affected course elements track
param: stdClass $course the course object
param: int[] $ids the collapsed section ids
param: int $targetsectionid not used
param: int $targetcmid not used

section_index_collapsed(stateupdates $updates,stdClass $course,array $ids = [],?int $targetsectionid = null,?int $targetcmid = null)   X-Ref
Update the course index section collapsed value.

param: stateupdates $updates the affected course elements track
param: stdClass $course the course object
param: int[] $ids the collapsed section ids
param: int $targetsectionid not used
param: int $targetcmid not used

cm_state(stateupdates $updates,stdClass $course,array $ids,?int $targetsectionid = null,?int $targetcmid = null)   X-Ref
Add the update messages of the updated version of any cm and section related to the cm ids.

This action is mainly used by legacy actions to partially update the course state when the
result of core_course_edit_module is not enough to generate the correct state data.

param: stateupdates $updates the affected course elements track
param: stdClass $course the course object
param: int[] $ids the list of affected course module ids
param: int $targetsectionid optional target section id
param: int $targetcmid optional target cm id

section_state(stateupdates $updates,stdClass $course,array $ids,?int $targetsectionid = null,?int $targetcmid = null)   X-Ref
Add the update messages of the updated version of any cm and section related to the section ids.

This action is mainly used by legacy actions to partially update the course state when the
result of core_course_edit_module is not enough to generate the correct state data.

param: stateupdates $updates the affected course elements track
param: stdClass $course the course object
param: int[] $ids the list of affected course section ids
param: int $targetsectionid optional target section id
param: int $targetcmid optional target cm id

course_state(stateupdates $updates,stdClass $course,array $ids = [],?int $targetsectionid = null,?int $targetcmid = null)   X-Ref
Add all the update messages from the complete course state.

This action is mainly used by legacy actions to partially update the course state when the
result of core_course_edit_module is not enough to generate the correct state data.

param: stateupdates $updates the affected course elements track
param: stdClass $course the course object
param: int[] $ids the list of affected course module ids (not used)
param: int $targetsectionid optional target section id (not used)
param: int $targetcmid optional target cm id (not used)

validate_sections(stdClass $course, array $sectionids, ?string $info = null)   X-Ref
Checks related to sections: course format support them, all given sections exist and topic 0 is not included.

param: stdClass $course The course where given $sectionids belong.
param: array $sectionids List of sections to validate.
param: string|null $info additional information in case of error (default null).

validate_cms(stdClass $course, array $cmids, ?string $info = null, array $capabilities = [])   X-Ref
Checks related to course modules: all given cm exist and the user has the required capabilities.

param: stdClass $course The course where given $cmids belong.
param: array $cmids List of course module ids to validate.
param: string $info additional information in case of error.
param: array $capabilities optional capabilities checks per each cm context.